| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The LUCI Authors. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 package buildbot | |
| 16 | |
| 17 import ( | |
| 18 "fmt" | |
| 19 "strings" | |
| 20 | |
| 21 ds "github.com/luci/gae/service/datastore" | |
| 22 "github.com/luci/luci-go/common/clock" | |
| 23 log "github.com/luci/luci-go/common/logging" | |
| 24 "github.com/luci/luci-go/common/sync/parallel" | |
| 25 "github.com/luci/luci-go/milo/api/resp" | |
| 26 "github.com/luci/luci-go/milo/common/model" | |
| 27 | |
| 28 "golang.org/x/net/context" | |
| 29 ) | |
| 30 | |
| 31 // getFullBuilds fetches all of the recent builds from the datastore. | |
| 32 func getFullBuilds(c context.Context, masterName, builderName string, finished b
ool) ([]*buildbotBuild, error) { | |
| 33 // TODO(hinoka): Builder specific structs. | |
| 34 q := ds.NewQuery("buildbotBuild") | |
| 35 q = q.Eq("finished", finished) | |
| 36 q = q.Eq("master", masterName) | |
| 37 q = q.Eq("builder", builderName) | |
| 38 q = q.Order("-number") | |
| 39 q.Finalize() | |
| 40 // Ignore the cursor, we don't need it. | |
| 41 buildbots, _, err := runBuildsQuery(c, q, 25) | |
| 42 return buildbots, err | |
| 43 } | |
| 44 | |
| 45 // GetConsoleBuilds takes commits and builders and returns a matrix of | |
| 46 // resp.ConsoleBuild objects. The expected format of the result | |
| 47 // is [len(commits)][len(builders)]*resp.ConsoleBuild. The first level matches | |
| 48 // 1:1 to a commit, and the second level matches 1:1 to a builder. | |
| 49 func GetConsoleBuilds( | |
| 50 c context.Context, builders []resp.BuilderRef, commits []string) ( | |
| 51 [][]*resp.ConsoleBuild, error) { | |
| 52 | |
| 53 results := make([][]*resp.ConsoleBuild, len(commits)) | |
| 54 for i := range results { | |
| 55 results[i] = make([]*resp.ConsoleBuild, len(builders)) | |
| 56 } | |
| 57 // HACK(hinoka): This fetches 25 full builds and then filters them. Repl
ace this | |
| 58 // with something more reasonable. | |
| 59 // This is kind of a hack but it's okay for now. | |
| 60 err := parallel.FanOutIn(func(taskC chan<- func() error) { | |
| 61 for i, builder := range builders { | |
| 62 i := i | |
| 63 builder := builder | |
| 64 builderComponents := strings.SplitN(builder.Name, "/", 2
) | |
| 65 if len(builderComponents) != 2 { | |
| 66 taskC <- func() error { | |
| 67 return fmt.Errorf("%s is an invalid buil
der name", builder.Name) | |
| 68 } | |
| 69 return | |
| 70 } | |
| 71 master := builderComponents[0] | |
| 72 builderName := builderComponents[1] | |
| 73 taskC <- func() error { | |
| 74 t1 := clock.Now(c) | |
| 75 builds, err := getFullBuilds(c, master, builderN
ame, true) | |
| 76 if err != nil { | |
| 77 return err | |
| 78 } | |
| 79 t2 := clock.Now(c) | |
| 80 var currentStatus *model.Status | |
| 81 for j, commit := range commits { | |
| 82 for _, build := range builds { | |
| 83 if build.Sourcestamp.Revision ==
commit { | |
| 84 results[j][i] = &resp.Co
nsoleBuild{ | |
| 85 Link: resp.NewLi
nk( | |
| 86 strings.
Join(build.Text, " "), | |
| 87 fmt.Spri
ntf("/buildbot/%s/%s/%d", master, builderName, build.Number), | |
| 88 ), | |
| 89 Status: build.to
Status(), | |
| 90 } | |
| 91 currentStatus = &results
[j][i].Status | |
| 92 } | |
| 93 } | |
| 94 if currentStatus != nil && results[j][i]
== nil { | |
| 95 results[j][i] = &resp.ConsoleBui
ld{Status: *currentStatus} | |
| 96 } | |
| 97 } | |
| 98 log.Debugf(c, | |
| 99 "Builder %s took %s to query, %s to comp
ute.", builderName, | |
| 100 t2.Sub(t1), clock.Since(c, t2)) | |
| 101 return nil | |
| 102 } | |
| 103 } | |
| 104 }) | |
| 105 return results, err | |
| 106 } | |
| OLD | NEW |