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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 return &prevCursor, true | 145 return &prevCursor, true |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 return nil, false | 148 return nil, false |
| 149 } | 149 } |
| 150 | 150 |
| 151 var errMasterNotFound = errors.New( | 151 var errMasterNotFound = errors.New( |
| 152 "Either the request resource was not found or you have insufficient perm issions") | 152 "Either the request resource was not found or you have insufficient perm issions") |
| 153 var errNotAuth = errors.New("You are not authenticated, try logging in") | 153 var errNotAuth = errors.New("You are not authenticated, try logging in") |
| 154 | 154 |
| 155 type errBuilderNotFound struct { | |
| 156 master string | |
| 157 builder string | |
| 158 available []string | |
| 159 } | |
| 160 | |
| 161 func (e errBuilderNotFound) Error() string { | |
| 162 avail := strings.Join(e.available, "\n") | |
| 163 return fmt.Sprintf("Cannot find builder %q in master %q.\nAvailable buil ders: \n%q", | |
|
nodir
2017/05/26 18:33:04
i think the list of builders should be %s, otherwi
Ryan Tseng
2017/05/26 22:49:22
Done.
| |
| 164 e.master, e.builder, avail) | |
|
nodir
2017/05/26 18:33:04
swap e.master and e.builder, see order in the form
Ryan Tseng
2017/05/26 22:49:22
Shoot I'm blind, I even checked for this.
| |
| 165 } | |
| 166 | |
| 155 // builderImpl is the implementation for getting a milo builder page from buildb ot. | 167 // builderImpl is the implementation for getting a milo builder page from buildb ot. |
| 156 // This gets: | 168 // This gets: |
| 157 // * Current Builds from querying the master json from the datastore. | 169 // * Current Builds from querying the master json from the datastore. |
| 158 // * Recent Builds from a cron job that backfills the recent builds. | 170 // * Recent Builds from a cron job that backfills the recent builds. |
| 159 func builderImpl( | 171 func builderImpl( |
| 160 c context.Context, masterName, builderName string, limit int, cursor str ing) ( | 172 c context.Context, masterName, builderName string, limit int, cursor str ing) ( |
| 161 *resp.Builder, error) { | 173 *resp.Builder, error) { |
| 162 | 174 |
| 163 var thisCursor *datastore.Cursor | 175 var thisCursor *datastore.Cursor |
| 164 if cursor != "" { | 176 if cursor != "" { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 185 | 197 |
| 186 p, ok := master.Builders[builderName] | 198 p, ok := master.Builders[builderName] |
| 187 if !ok { | 199 if !ok { |
| 188 // This long block is just to return a good error message when a n invalid | 200 // This long block is just to return a good error message when a n invalid |
| 189 // buildbot builder is specified. | 201 // buildbot builder is specified. |
| 190 keys := make([]string, 0, len(master.Builders)) | 202 keys := make([]string, 0, len(master.Builders)) |
| 191 for k := range master.Builders { | 203 for k := range master.Builders { |
| 192 keys = append(keys, k) | 204 keys = append(keys, k) |
| 193 } | 205 } |
| 194 sort.Strings(keys) | 206 sort.Strings(keys) |
| 195 » » avail := strings.Join(keys, "\n") | 207 » » return nil, errBuilderNotFound{masterName, builderName, keys} |
| 196 » » return nil, fmt.Errorf( | |
| 197 » » » "Cannot find builder %s in master %s.\nAvailable builder s: \n%s", | |
| 198 » » » builderName, masterName, avail) | |
| 199 } | 208 } |
| 200 // Extract pending builds out of the master json. | 209 // Extract pending builds out of the master json. |
| 201 result.PendingBuilds = make([]*resp.BuildSummary, len(p.PendingBuildStat es)) | 210 result.PendingBuilds = make([]*resp.BuildSummary, len(p.PendingBuildStat es)) |
| 202 logging.Debugf(c, "Number of pending builds: %d", len(p.PendingBuildStat es)) | 211 logging.Debugf(c, "Number of pending builds: %d", len(p.PendingBuildStat es)) |
| 203 for i, pb := range p.PendingBuildStates { | 212 for i, pb := range p.PendingBuildStates { |
| 204 start := time.Unix(int64(pb.SubmittedAt), 0) | 213 start := time.Unix(int64(pb.SubmittedAt), 0) |
| 205 result.PendingBuilds[i] = &resp.BuildSummary{ | 214 result.PendingBuilds[i] = &resp.BuildSummary{ |
| 206 PendingTime: resp.Interval{ | 215 PendingTime: resp.Interval{ |
| 207 Started: start, | 216 Started: start, |
| 208 Duration: time.Now().Sub(start), | 217 Duration: time.Now().Sub(start), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 } | 253 } |
| 245 result.CurrentBuilds = currentBuilds | 254 result.CurrentBuilds = currentBuilds |
| 246 | 255 |
| 247 for _, fb := range finishedBuilds { | 256 for _, fb := range finishedBuilds { |
| 248 if fb != nil { | 257 if fb != nil { |
| 249 result.FinishedBuilds = append(result.FinishedBuilds, fb ) | 258 result.FinishedBuilds = append(result.FinishedBuilds, fb ) |
| 250 } | 259 } |
| 251 } | 260 } |
| 252 return result, nil | 261 return result, nil |
| 253 } | 262 } |
| OLD | NEW |