Chromium Code Reviews| 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 host string, slaves []string, slaveMap map[string]*buildbotSlave) *resp. MachinePool { | |
| 169 | |
| 170 total := len(slaves) | |
| 171 idle := 0 | |
| 172 busy := 0 | |
| 173 disconnected := 0 | |
| 174 bots := make([]resp.Bot, 0, len(slaves)) | |
|
nodir
2017/06/13 02:38:40
MachinePool struct has all these variables. Consid
Ryan Tseng
2017/06/13 23:10:33
Done.
| |
| 175 for _, slaveName := range slaves { | |
| 176 slave, ok := slaveMap[slaveName] | |
| 177 bot := resp.Bot{ | |
| 178 Name: &resp.Link{ | |
| 179 Label: slaveName, | |
| 180 URL: fmt.Sprintf("https://%s/buildslaves/%s", host, slaveName), | |
| 181 }, | |
| 182 } | |
| 183 switch { | |
| 184 case !ok: | |
| 185 // This shouldn't happen | |
| 186 case !slave.Connected: | |
| 187 bot.Status = resp.Disconnected | |
| 188 disconnected++ | |
| 189 case len(slave.RunningbuildsMap) > 0: | |
| 190 bot.Status = resp.Busy | |
| 191 busy++ | |
| 192 default: | |
| 193 bot.Status = resp.Idle | |
| 194 idle++ | |
| 195 } | |
| 196 bots = append(bots, bot) | |
| 197 } | |
| 198 return &resp.MachinePool{ | |
| 199 Total: total, | |
| 200 Disconnected: disconnected, | |
| 201 Idle: idle, | |
| 202 Busy: busy, | |
| 203 Bots: bots, | |
| 204 } | |
| 205 } | |
| 206 | |
| 167 // builderImpl is the implementation for getting a milo builder page from buildb ot. | 207 // builderImpl is the implementation for getting a milo builder page from buildb ot. |
| 168 // This gets: | 208 // This gets: |
| 169 // * Current Builds from querying the master json from the datastore. | 209 // * Current Builds from querying the master json from the datastore. |
| 170 // * Recent Builds from a cron job that backfills the recent builds. | 210 // * Recent Builds from a cron job that backfills the recent builds. |
| 171 func builderImpl( | 211 func builderImpl( |
| 172 c context.Context, masterName, builderName string, limit int, cursor str ing) ( | 212 c context.Context, masterName, builderName string, limit int, cursor str ing) ( |
| 173 *resp.Builder, error) { | 213 *resp.Builder, error) { |
| 174 | 214 |
| 175 var thisCursor *datastore.Cursor | 215 var thisCursor *datastore.Cursor |
| 176 if cursor != "" { | 216 if cursor != "" { |
| 177 tmpCur, err := datastore.DecodeCursor(c, cursor) | 217 tmpCur, err := datastore.DecodeCursor(c, cursor) |
| 178 if err != nil { | 218 if err != nil { |
| 179 return nil, fmt.Errorf("bad cursor: %s", err) | 219 return nil, fmt.Errorf("bad cursor: %s", err) |
| 180 } | 220 } |
| 181 thisCursor = &tmpCur | 221 thisCursor = &tmpCur |
| 182 } | 222 } |
| 183 | 223 |
| 184 result := &resp.Builder{ | 224 result := &resp.Builder{ |
| 185 Name: builderName, | 225 Name: builderName, |
| 186 } | 226 } |
| 187 » master, t, err := getMasterJSON(c, masterName) | 227 » master, internal, t, err := getMasterJSON(c, masterName) |
| 188 if err != nil { | 228 if err != nil { |
| 189 return nil, err | 229 return nil, err |
| 190 } | 230 } |
| 191 if clock.Now(c).Sub(t) > 2*time.Minute { | 231 if clock.Now(c).Sub(t) > 2*time.Minute { |
| 192 warning := fmt.Sprintf( | 232 warning := fmt.Sprintf( |
| 193 "WARNING: Master data is stale (last updated %s)", t) | 233 "WARNING: Master data is stale (last updated %s)", t) |
| 194 logging.Warningf(c, warning) | 234 logging.Warningf(c, warning) |
| 195 result.Warning = warning | 235 result.Warning = warning |
| 196 } | 236 } |
| 197 | 237 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 219 } | 259 } |
| 220 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour ce.Changes)) | 260 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour ce.Changes)) |
| 221 for j, cm := range pb.Source.Changes { | 261 for j, cm := range pb.Source.Changes { |
| 222 result.PendingBuilds[i].Blame[j] = &resp.Commit{ | 262 result.PendingBuilds[i].Blame[j] = &resp.Commit{ |
| 223 AuthorEmail: cm.Who, | 263 AuthorEmail: cm.Who, |
| 224 CommitURL: cm.Revlink, | 264 CommitURL: cm.Revlink, |
| 225 } | 265 } |
| 226 } | 266 } |
| 227 } | 267 } |
| 228 | 268 |
| 269 host := "build.chromium.org/p/" | |
|
nodir
2017/06/13 02:38:40
this is not a host. Host cannot have a path.
cons
Ryan Tseng
2017/06/13 23:10:33
Done.
| |
| 270 if internal { | |
| 271 host = "uberchromegw.corp.google.com/i/" | |
| 272 } | |
| 273 result.MachinePool = summarizeSlavePool(host+master.Name, p.Slaves, mast er.Slaves) | |
| 274 | |
| 229 // This is CPU bound anyways, so there's no need to do this in parallel. | 275 // 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) | 276 finishedBuilds, nextCursor, err := getBuilds(c, masterName, builderName, true, limit, thisCursor) |
| 231 if err != nil { | 277 if err != nil { |
| 232 return nil, err | 278 return nil, err |
| 233 } | 279 } |
| 234 if prevCursor, ok := maybeSetGetCursor(c, thisCursor, nextCursor, limit) ; ok { | 280 if prevCursor, ok := maybeSetGetCursor(c, thisCursor, nextCursor, limit) ; ok { |
| 235 if prevCursor == nil { | 281 if prevCursor == nil { |
| 236 // Magic string to signal display prev without cursor | 282 // Magic string to signal display prev without cursor |
| 237 result.PrevCursor = "EMPTY" | 283 result.PrevCursor = "EMPTY" |
| 238 } else { | 284 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 253 } | 299 } |
| 254 result.CurrentBuilds = currentBuilds | 300 result.CurrentBuilds = currentBuilds |
| 255 | 301 |
| 256 for _, fb := range finishedBuilds { | 302 for _, fb := range finishedBuilds { |
| 257 if fb != nil { | 303 if fb != nil { |
| 258 result.FinishedBuilds = append(result.FinishedBuilds, fb ) | 304 result.FinishedBuilds = append(result.FinishedBuilds, fb ) |
| 259 } | 305 } |
| 260 } | 306 } |
| 261 return result, nil | 307 return result, nil |
| 262 } | 308 } |
| OLD | NEW |