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

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: Renamed stuff 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
« no previous file with comments | « milo/api/proto/pb.discovery.go ('k') | milo/appengine/buildbot/grpc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 switch { 121 switch {
139 case err == datastore.ErrNoSuchEntity: 122 case err == datastore.ErrNoSuchEntity:
140 return nil, errMasterNotFound 123 return nil, errMasterNotFound
141 case err != nil: 124 case err != nil:
142 return nil, err 125 return nil, err
143 } 126 }
144 if clock.Now(c).Sub(t) > 2*time.Minute { 127 if clock.Now(c).Sub(t) > 2*time.Minute {
145 warning := fmt.Sprintf( 128 warning := fmt.Sprintf(
146 "WARNING: Master data is stale (last updated %s)", t) 129 "WARNING: Master data is stale (last updated %s)", t)
147 logging.Warningf(c, warning) 130 logging.Warningf(c, warning)
(...skipping 27 matching lines...) Expand all
175 result.CurrentBuilds = currentBuilds 158 result.CurrentBuilds = currentBuilds
176 for _, fb := range recentBuilds { 159 for _, fb := range recentBuilds {
177 // Yes recent builds is synonymous with finished builds. 160 // Yes recent builds is synonymous with finished builds.
178 // TODO(hinoka): Implement limits. 161 // TODO(hinoka): Implement limits.
179 if fb != nil { 162 if fb != nil {
180 result.FinishedBuilds = append(result.FinishedBuilds, fb ) 163 result.FinishedBuilds = append(result.FinishedBuilds, fb )
181 } 164 }
182 } 165 }
183 return result, nil 166 return result, nil
184 } 167 }
OLDNEW
« no previous file with comments | « milo/api/proto/pb.discovery.go ('k') | milo/appengine/buildbot/grpc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698