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

Side by Side Diff: milo/buildsource/console.go

Issue 2982183002: Milo: Store console defs as their own entities (Closed)
Patch Set: Rebase fixes and Working Created 3 years, 5 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/buildsource/buildbot/pubsub_test.go ('k') | milo/common/acl_test.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 2017 The LUCI Authors. 1 // Copyright 2017 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with 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 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package buildsource 15 package buildsource
16 16
17 import ( 17 import (
18 "encoding/hex" 18 "encoding/hex"
19 19
20 "golang.org/x/net/context" 20 "golang.org/x/net/context"
21 21
22 "github.com/luci/gae/service/datastore" 22 "github.com/luci/gae/service/datastore"
23 23
24 "github.com/luci/luci-go/common/data/stringset" 24 "github.com/luci/luci-go/common/data/stringset"
25 "github.com/luci/luci-go/common/errors" 25 "github.com/luci/luci-go/common/errors"
26 "github.com/luci/luci-go/common/sync/parallel" 26 "github.com/luci/luci-go/common/sync/parallel"
27 27
28 » "github.com/luci/luci-go/milo/api/config" 28 » "github.com/luci/luci-go/milo/common"
29 "github.com/luci/luci-go/milo/common/model" 29 "github.com/luci/luci-go/milo/common/model"
30 ) 30 )
31 31
32 // ConsoleRow is one row of a particular console. 32 // ConsoleRow is one row of a particular console.
33 // 33 //
34 // It has the git commit for the row, as well as a mapping of BuilderID to any 34 // It has the git commit for the row, as well as a mapping of BuilderID to any
35 // BuildSummaries which reported using this commit. 35 // BuildSummaries which reported using this commit.
36 type ConsoleRow struct { 36 type ConsoleRow struct {
37 Commit string 37 Commit string
38 Builds map[BuilderID][]*model.BuildSummary 38 Builds map[BuilderID][]*model.BuildSummary
39 } 39 }
40 40
41 // GetConsoleRows returns a row-oriented collection of BuildSummary 41 // GetConsoleRows returns a row-oriented collection of BuildSummary
42 // objects. Each row corresponds to the similarly-indexed commit in the 42 // objects. Each row corresponds to the similarly-indexed commit in the
43 // `commits` slice. 43 // `commits` slice.
44 func GetConsoleRows(c context.Context, project string, console *config.Console, commits, builders []string) ([]*ConsoleRow, error) { 44 func GetConsoleRows(c context.Context, project string, console *common.Console, commits, builders []string) ([]*ConsoleRow, error) {
45 rawCommits := make([][]byte, len(commits)) 45 rawCommits := make([][]byte, len(commits))
46 for i, c := range commits { 46 for i, c := range commits {
47 var err error 47 var err error
48 if rawCommits[i], err = hex.DecodeString(c); err != nil { 48 if rawCommits[i], err = hex.DecodeString(c); err != nil {
49 return nil, errors.Annotate(err, "bad commit[%d]: %q", i , c).Err() 49 return nil, errors.Annotate(err, "bad commit[%d]: %q", i , c).Err()
50 } 50 }
51 } 51 }
52 52
53 builderSet := stringset.NewFromSlice(builders...) 53 builderSet := stringset.NewFromSlice(builders...)
54 54
55 ret := make([]*ConsoleRow, len(commits)) 55 ret := make([]*ConsoleRow, len(commits))
56 url := console.RepoURL 56 url := console.RepoURL
57 // HACK(iannucci): This little hack should be removed when console defin itions 57 // HACK(iannucci): This little hack should be removed when console defin itions
58 // no longer use a manifest name of "REVISION". REVISION was used to ind ex the 58 // no longer use a manifest name of "REVISION". REVISION was used to ind ex the
59 // 'got_revision' value before manifests were implemented. 59 // 'got_revision' value before manifests were implemented.
60 if console.ManifestName == "REVISION" { 60 if console.ManifestName == "REVISION" {
61 url = "" 61 url = ""
62 } 62 }
63 » partialKey := model.NewPartialManifestKey(project, console.Name, console .ManifestName, url) 63 » partialKey := model.NewPartialManifestKey(project, console.ID, console.M anifestName, url)
64 q := datastore.NewQuery("BuildSummary").KeysOnly(true) 64 q := datastore.NewQuery("BuildSummary").KeysOnly(true)
65 err := parallel.WorkPool(4, func(ch chan<- func() error) { 65 err := parallel.WorkPool(4, func(ch chan<- func() error) {
66 for i := range rawCommits { 66 for i := range rawCommits {
67 i := i 67 i := i
68 r := &ConsoleRow{Commit: commits[i]} 68 r := &ConsoleRow{Commit: commits[i]}
69 ret[i] = r 69 ret[i] = r
70 ch <- func() error { 70 ch <- func() error {
71 fullQ := q.Eq("ManifestKey", partialKey.AddRevis ion(rawCommits[i])) 71 fullQ := q.Eq("ManifestKey", partialKey.AddRevis ion(rawCommits[i]))
72 return datastore.Run(c, fullQ, func(bs *model.Bu ildSummary) { 72 return datastore.Run(c, fullQ, func(bs *model.Bu ildSummary) {
73 if builderSet.Has(bs.BuilderID) { 73 if builderSet.Has(bs.BuilderID) {
74 bid := BuilderID(bs.BuilderID) 74 bid := BuilderID(bs.BuilderID)
75 if r.Builds == nil { 75 if r.Builds == nil {
76 r.Builds = map[BuilderID ][]*model.BuildSummary{} 76 r.Builds = map[BuilderID ][]*model.BuildSummary{}
77 } 77 }
78 r.Builds[bid] = append(r.Builds[ bid], bs) 78 r.Builds[bid] = append(r.Builds[ bid], bs)
79 } 79 }
80 }) 80 })
81 } 81 }
82 } 82 }
83 }) 83 })
84 84
85 return ret, err 85 return ret, err
86 } 86 }
OLDNEW
« no previous file with comments | « milo/buildsource/buildbot/pubsub_test.go ('k') | milo/common/acl_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698