| OLD | NEW |
| 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 "crypto/sha1" | 8 "crypto/sha1" |
| 9 "encoding/base64" | 9 "encoding/base64" |
| 10 "errors" | 10 "errors" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 builder string | 157 builder string |
| 158 available []string | 158 available []string |
| 159 } | 159 } |
| 160 | 160 |
| 161 func (e errBuilderNotFound) Error() string { | 161 func (e errBuilderNotFound) Error() string { |
| 162 avail := strings.Join(e.available, "\n") | 162 avail := strings.Join(e.available, "\n") |
| 163 return fmt.Sprintf("Cannot find builder %q in master %q.\nAvailable buil
ders: \n%s", | 163 return fmt.Sprintf("Cannot find builder %q in master %q.\nAvailable buil
ders: \n%s", |
| 164 e.builder, e.master, avail) | 164 e.builder, e.master, avail) |
| 165 } | 165 } |
| 166 | 166 |
| 167 func summarizeSlavePool( |
| 168 baseURL string, slaves []string, slaveMap map[string]*buildbotSlave) *re
sp.MachinePool { |
| 169 |
| 170 mp := &resp.MachinePool{ |
| 171 Total: len(slaves), |
| 172 Bots: make([]resp.Bot, 0, len(slaves)), |
| 173 } |
| 174 for _, slaveName := range slaves { |
| 175 slave, ok := slaveMap[slaveName] |
| 176 bot := resp.Bot{ |
| 177 Name: resp.Link{ |
| 178 Label: slaveName, |
| 179 URL: fmt.Sprintf("%s/buildslaves/%s", baseURL,
slaveName), |
| 180 }, |
| 181 } |
| 182 switch { |
| 183 case !ok: |
| 184 // This shouldn't happen |
| 185 case !slave.Connected: |
| 186 bot.Status = resp.Disconnected |
| 187 mp.Disconnected++ |
| 188 case len(slave.RunningbuildsMap) > 0: |
| 189 bot.Status = resp.Busy |
| 190 mp.Busy++ |
| 191 default: |
| 192 bot.Status = resp.Idle |
| 193 mp.Idle++ |
| 194 } |
| 195 mp.Bots = append(mp.Bots, bot) |
| 196 } |
| 197 return mp |
| 198 } |
| 199 |
| 167 // builderImpl is the implementation for getting a milo builder page from buildb
ot. | 200 // builderImpl is the implementation for getting a milo builder page from buildb
ot. |
| 168 // This gets: | 201 // This gets: |
| 169 // * Current Builds from querying the master json from the datastore. | 202 // * Current Builds from querying the master json from the datastore. |
| 170 // * Recent Builds from a cron job that backfills the recent builds. | 203 // * Recent Builds from a cron job that backfills the recent builds. |
| 171 func builderImpl( | 204 func builderImpl( |
| 172 c context.Context, masterName, builderName string, limit int, cursor str
ing) ( | 205 c context.Context, masterName, builderName string, limit int, cursor str
ing) ( |
| 173 *resp.Builder, error) { | 206 *resp.Builder, error) { |
| 174 | 207 |
| 175 var thisCursor *datastore.Cursor | 208 var thisCursor *datastore.Cursor |
| 176 if cursor != "" { | 209 if cursor != "" { |
| 177 tmpCur, err := datastore.DecodeCursor(c, cursor) | 210 tmpCur, err := datastore.DecodeCursor(c, cursor) |
| 178 if err != nil { | 211 if err != nil { |
| 179 return nil, fmt.Errorf("bad cursor: %s", err) | 212 return nil, fmt.Errorf("bad cursor: %s", err) |
| 180 } | 213 } |
| 181 thisCursor = &tmpCur | 214 thisCursor = &tmpCur |
| 182 } | 215 } |
| 183 | 216 |
| 184 result := &resp.Builder{ | 217 result := &resp.Builder{ |
| 185 Name: builderName, | 218 Name: builderName, |
| 186 } | 219 } |
| 187 » master, t, err := getMasterJSON(c, masterName) | 220 » master, internal, t, err := getMasterJSON(c, masterName) |
| 188 if err != nil { | 221 if err != nil { |
| 189 return nil, err | 222 return nil, err |
| 190 } | 223 } |
| 191 if clock.Now(c).Sub(t) > 2*time.Minute { | 224 if clock.Now(c).Sub(t) > 2*time.Minute { |
| 192 warning := fmt.Sprintf( | 225 warning := fmt.Sprintf( |
| 193 "WARNING: Master data is stale (last updated %s)", t) | 226 "WARNING: Master data is stale (last updated %s)", t) |
| 194 logging.Warningf(c, warning) | 227 logging.Warningf(c, warning) |
| 195 result.Warning = warning | 228 result.Warning = warning |
| 196 } | 229 } |
| 197 | 230 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 219 } | 252 } |
| 220 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour
ce.Changes)) | 253 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour
ce.Changes)) |
| 221 for j, cm := range pb.Source.Changes { | 254 for j, cm := range pb.Source.Changes { |
| 222 result.PendingBuilds[i].Blame[j] = &resp.Commit{ | 255 result.PendingBuilds[i].Blame[j] = &resp.Commit{ |
| 223 AuthorEmail: cm.Who, | 256 AuthorEmail: cm.Who, |
| 224 CommitURL: cm.Revlink, | 257 CommitURL: cm.Revlink, |
| 225 } | 258 } |
| 226 } | 259 } |
| 227 } | 260 } |
| 228 | 261 |
| 262 baseURL := "https://build.chromium.org/p/" |
| 263 if internal { |
| 264 baseURL = "https://uberchromegw.corp.google.com/i/" |
| 265 } |
| 266 result.MachinePool = summarizeSlavePool(baseURL+master.Name, p.Slaves, m
aster.Slaves) |
| 267 |
| 229 // This is CPU bound anyways, so there's no need to do this in parallel. | 268 // This is CPU bound anyways, so there's no need to do this in parallel. |
| 230 finishedBuilds, nextCursor, err := getBuilds(c, masterName, builderName,
true, limit, thisCursor) | 269 finishedBuilds, nextCursor, err := getBuilds(c, masterName, builderName,
true, limit, thisCursor) |
| 231 if err != nil { | 270 if err != nil { |
| 232 return nil, err | 271 return nil, err |
| 233 } | 272 } |
| 234 if prevCursor, ok := maybeSetGetCursor(c, thisCursor, nextCursor, limit)
; ok { | 273 if prevCursor, ok := maybeSetGetCursor(c, thisCursor, nextCursor, limit)
; ok { |
| 235 if prevCursor == nil { | 274 if prevCursor == nil { |
| 236 // Magic string to signal display prev without cursor | 275 // Magic string to signal display prev without cursor |
| 237 result.PrevCursor = "EMPTY" | 276 result.PrevCursor = "EMPTY" |
| 238 } else { | 277 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 253 } | 292 } |
| 254 result.CurrentBuilds = currentBuilds | 293 result.CurrentBuilds = currentBuilds |
| 255 | 294 |
| 256 for _, fb := range finishedBuilds { | 295 for _, fb := range finishedBuilds { |
| 257 if fb != nil { | 296 if fb != nil { |
| 258 result.FinishedBuilds = append(result.FinishedBuilds, fb
) | 297 result.FinishedBuilds = append(result.FinishedBuilds, fb
) |
| 259 } | 298 } |
| 260 } | 299 } |
| 261 return result, nil | 300 return result, nil |
| 262 } | 301 } |
| OLD | NEW |