Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: milo/appengine/buildbot/builder.go

Issue 2275123002: Milo: pRPC endpoint for getting Buildbot master data (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Update config tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "net/http"
11 "os" 10 "os"
12 "sort" 11 "sort"
13 "strings" 12 "strings"
14 "time" 13 "time"
15 14
16 "github.com/luci/gae/service/datastore" 15 "github.com/luci/gae/service/datastore"
17 16
18 "github.com/luci/luci-go/common/clock" 17 "github.com/luci/luci-go/common/clock"
19 "github.com/luci/luci-go/common/logging" 18 "github.com/luci/luci-go/common/logging"
20 "github.com/luci/luci-go/milo/api/resp" 19 "github.com/luci/luci-go/milo/api/resp"
21 "github.com/luci/luci-go/milo/appengine/settings"
22 "github.com/luci/luci-go/milo/common/miloerror"
23 "golang.org/x/net/context" 20 "golang.org/x/net/context"
24 ) 21 )
25 22
26 // builderRef is used for keying specific builds in a master json. 23 // builderRef is used for keying specific builds in a master json.
27 type builderRef struct { 24 type builderRef struct {
28 builder string 25 builder string
29 buildNum int 26 buildNum int
30 } 27 }
31 28
32 // buildMap contains all of the current build within a master json. We use this 29 // buildMap contains all of the current build within a master json. We use this
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bMap := createRunningBuildMap(master) 104 bMap := createRunningBuildMap(master)
108 for _, bn := range b.Currentbuilds { 105 for _, bn := range b.Currentbuilds {
109 cb := getCurrentBuild(c, bMap, builderName, bn) 106 cb := getCurrentBuild(c, bMap, builderName, bn)
110 if cb != nil { 107 if cb != nil {
111 results = append(results, cb) 108 results = append(results, cb)
112 } 109 }
113 } 110 }
114 return results 111 return results
115 } 112 }
116 113
117 var errMasterNotFound = miloerror.Error{
118 Message: "Master not found",
119 Code: http.StatusNotFound,
120 }
121
122 // builderImpl is the implementation for getting a milo builder page from buildb ot. 114 // builderImpl is the implementation for getting a milo builder page from buildb ot.
123 // This gets: 115 // This gets:
124 // * Current Builds from querying the master json from the datastore. 116 // * Current Builds from querying the master json from the datastore.
125 // * Recent Builds from a cron job that backfills the recent builds. 117 // * Recent Builds from a cron job that backfills the recent builds.
126 func builderImpl(c context.Context, masterName, builderName string) (*resp.Build er, error) { 118 func builderImpl(c context.Context, masterName, builderName string) (*resp.Build er, error) {
127 result := &resp.Builder{} 119 result := &resp.Builder{}
128 » master, internal, t, err := getMasterJSON(c, masterName) 120 » master, t, err := getMasterJSON(c, masterName)
129 » if internal {
130 » » allowed, err := settings.IsAllowedInternal(c)
131 » » if err != nil {
132 » » » return nil, err
133 » » }
134 » » if !allowed {
135 » » » return nil, errMasterNotFound
136 » » }
137 » }
138 if err != nil { 121 if err != nil {
139 return nil, fmt.Errorf("Cannot find master %s\n%s", masterName, err.Error()) 122 return nil, fmt.Errorf("Cannot find master %s\n%s", masterName, err.Error())
140 } 123 }
141 if clock.Now(c).Sub(t) > 2*time.Minute { 124 if clock.Now(c).Sub(t) > 2*time.Minute {
142 warning := fmt.Sprintf( 125 warning := fmt.Sprintf(
143 "WARNING: Master data is stale (last updated %s)", t) 126 "WARNING: Master data is stale (last updated %s)", t)
144 logging.Warningf(c, warning) 127 logging.Warningf(c, warning)
145 result.Warning = warning 128 result.Warning = warning
146 } 129 }
147 130
(...skipping 24 matching lines...) Expand all
172 result.CurrentBuilds = currentBuilds 155 result.CurrentBuilds = currentBuilds
173 for _, fb := range recentBuilds { 156 for _, fb := range recentBuilds {
174 // Yes recent builds is synonymous with finished builds. 157 // Yes recent builds is synonymous with finished builds.
175 // TODO(hinoka): Implement limits. 158 // TODO(hinoka): Implement limits.
176 if fb != nil { 159 if fb != nil {
177 result.FinishedBuilds = append(result.FinishedBuilds, fb ) 160 result.FinishedBuilds = append(result.FinishedBuilds, fb )
178 } 161 }
179 } 162 }
180 return result, nil 163 return result, nil
181 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698