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

Side by Side Diff: milo/common/config.go

Issue 2991243002: Milo: Console improvements (Closed)
Patch Set: Small fixes Created 3 years, 4 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
OLDNEW
1 // Copyright 2016 The LUCI Authors. 1 // Copyright 2016 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,
(...skipping 17 matching lines...) Expand all
28 "github.com/luci/luci-go/common/data/caching/proccache" 28 "github.com/luci/luci-go/common/data/caching/proccache"
29 "github.com/luci/luci-go/common/data/stringset" 29 "github.com/luci/luci-go/common/data/stringset"
30 "github.com/luci/luci-go/common/errors" 30 "github.com/luci/luci-go/common/errors"
31 "github.com/luci/luci-go/common/logging" 31 "github.com/luci/luci-go/common/logging"
32 "github.com/luci/luci-go/luci_config/server/cfgclient" 32 "github.com/luci/luci-go/luci_config/server/cfgclient"
33 "github.com/luci/luci-go/luci_config/server/cfgclient/backend" 33 "github.com/luci/luci-go/luci_config/server/cfgclient/backend"
34 34
35 "github.com/luci/luci-go/milo/api/config" 35 "github.com/luci/luci-go/milo/api/config"
36 ) 36 )
37 37
38 // Console is af datastore entity representing a single console. 38 // Console is a datastore entity representing a single console.
39 type Console struct { 39 type Console struct {
40 // Parent is a key to the parent Project entity where this console was 40 // Parent is a key to the parent Project entity where this console was
41 // defined in. 41 // defined in.
42 Parent *datastore.Key `gae:"$parent"` 42 Parent *datastore.Key `gae:"$parent"`
43 // ID is the ID of the console. 43 // ID is the ID of the console.
44 ID string `gae:"$id"` 44 ID string `gae:"$id"`
45 // RepoURL and Ref combined defines the commits the show up on the left 45 // RepoURL and Ref combined defines the commits the show up on the left
46 // hand side of a Console. 46 // hand side of a Console.
47 RepoURL string 47 RepoURL string
48 // RepoURL and Ref combined defines the commits the show up on the left 48 // RepoURL and Ref combined defines the commits the show up on the left
49 // hand side of a Console. 49 // hand side of a Console.
50 Ref string 50 Ref string
51 // ManifestName is the name of the manifest to look for when querying fo r 51 // ManifestName is the name of the manifest to look for when querying fo r
52 // builds under this console. 52 // builds under this console.
53 ManifestName string 53 ManifestName string
54 // URL is the URL to the luci-config definition of this console. 54 // URL is the URL to the luci-config definition of this console.
55 URL string 55 URL string
56 // Revision is the luci-config reivision from when this Console was retr ieved. 56 // Revision is the luci-config reivision from when this Console was retr ieved.
57 Revision string 57 Revision string
58 » // Builders is a list of universal builder IDs. 58 » // Builders is a list of universal builder IDs. This is indexed.
59 Builders []string 59 Builders []string
60 // BuilderMeta is an expanded set of builders containing additional meta data.
61 // This should always match the Builders field.
62 BuilderMetas []BuilderMeta
63 }
64
65 // BuilderMeta is a struct containing metadata about a builder.
66 type BuilderMeta struct {
67 Category string
68 ShortName string
60 } 69 }
61 70
62 // GetProjectName retrieves the project name of the console out of the Console's 71 // GetProjectName retrieves the project name of the console out of the Console's
63 // parent key. 72 // parent key.
64 func (con *Console) GetProjectName() string { 73 func (con *Console) GetProjectName() string {
65 return con.Parent.StringID() 74 return con.Parent.StringID()
66 } 75 }
67 76
68 // NewConsole creates a fully populated console out of the luci-config proto 77 // NewConsole creates a fully populated console out of the luci-config proto
69 // definition of a console. 78 // definition of a console.
70 func NewConsole(project *datastore.Key, URL, revision string, con *config.Consol e) *Console { 79 func NewConsole(project *datastore.Key, URL, revision string, con *config.Consol e) *Console {
71 return &Console{ 80 return &Console{
72 Parent: project, 81 Parent: project,
73 ID: con.ID, 82 ID: con.ID,
74 RepoURL: con.RepoURL, 83 RepoURL: con.RepoURL,
75 Ref: con.Ref, 84 Ref: con.Ref,
76 ManifestName: con.ManifestName, 85 ManifestName: con.ManifestName,
77 Revision: revision, 86 Revision: revision,
78 URL: URL, 87 URL: URL,
79 Builders: BuilderFromProto(con.Builders), 88 Builders: BuilderFromProto(con.Builders),
89 BuilderMetas: BuilderRefFromProto(con.Builders),
80 } 90 }
81 } 91 }
82 92
83 // BuilderFromProto tranforms a luci-config proto builder format into the datast ore 93 // BuilderFromProto tranforms a luci-config proto builder format into the datast ore
84 // format. 94 // format.
85 func BuilderFromProto(cb []*config.Builder) []string { 95 func BuilderFromProto(cb []*config.Builder) []string {
86 builders := make([]string, len(cb)) 96 builders := make([]string, len(cb))
87 for i, b := range cb { 97 for i, b := range cb {
88 builders[i] = b.Name 98 builders[i] = b.Name
89 } 99 }
90 return builders 100 return builders
91 } 101 }
92 102
103 // BuilderFromProto tranforms a luci-config proto builder format into the Builde rRef
104 // format.
105 func BuilderRefFromProto(cb []*config.Builder) []BuilderMeta {
dnj 2017/08/02 23:33:04 nit: function name needs to match comment
Ryan Tseng 2017/08/03 00:46:12 oops copypasta mistake.
106 builders := make([]BuilderMeta, len(cb))
107 for i, b := range cb {
108 builders[i] = BuilderMeta{
109 Category: b.Category,
110 ShortName: b.ShortName,
111 }
112 }
113 return builders
114 }
115
93 // LuciConfigURL returns a user friendly URL that specifies where to view 116 // LuciConfigURL returns a user friendly URL that specifies where to view
94 // this console definition. 117 // this console definition.
95 func LuciConfigURL(c context.Context, configSet, path, revision string) string { 118 func LuciConfigURL(c context.Context, configSet, path, revision string) string {
96 // TODO(hinoka): This shouldn't be hardcoded, instead we should get the 119 // TODO(hinoka): This shouldn't be hardcoded, instead we should get the
97 // luci-config instance from the context. But we only use this instance at 120 // luci-config instance from the context. But we only use this instance at
98 // the moment so it is okay for now. 121 // the moment so it is okay for now.
99 // TODO(hinoka): The UI doesn't allow specifying paths and revision yet. Add 122 // TODO(hinoka): The UI doesn't allow specifying paths and revision yet. Add
100 // that in when it is supported. 123 // that in when it is supported.
101 return fmt.Sprintf("https://luci-config.appspot.com/newui#/%s", configSe t) 124 return fmt.Sprintf("https://luci-config.appspot.com/newui#/%s", configSe t)
102 } 125 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 364 }
342 365
343 // Print some stats. 366 // Print some stats.
344 processedConsoles := 0 367 processedConsoles := 0
345 for _, cons := range knownProjects { 368 for _, cons := range knownProjects {
346 if cons != nil { 369 if cons != nil {
347 processedConsoles += cons.Len() 370 processedConsoles += cons.Len()
348 } 371 }
349 } 372 }
350 logging.Infof( 373 logging.Infof(
351 » » c, "processed %d consoles over %d projects", len(knownProjects), processedConsoles) 374 » » c, "processed %d consoles over %d projects", processedConsoles, len(knownProjects))
352 375
353 if len(merr) == 0 { 376 if len(merr) == 0 {
354 return nil 377 return nil
355 } 378 }
356 return merr 379 return merr
357 } 380 }
358 381
359 // GetAllConsoles returns all registered projects with the builder name. 382 // GetAllConsoles returns all registered projects with the builder name.
360 // If builderName is empty, then this retrieves all Consoles. 383 // If builderName is empty, then this retrieves all Consoles.
361 func GetAllConsoles(c context.Context, builderName string) ([]*Console, error) { 384 func GetAllConsoles(c context.Context, builderName string) ([]*Console, error) {
362 q := datastore.NewQuery("Console") 385 q := datastore.NewQuery("Console")
363 if builderName != "" { 386 if builderName != "" {
364 q = q.Eq("Builders", builderName) 387 q = q.Eq("Builders", builderName)
365 } 388 }
366 con := []*Console{} 389 con := []*Console{}
367 err := datastore.GetAll(c, q, &con) 390 err := datastore.GetAll(c, q, &con)
368 return con, err 391 return con, err
369 } 392 }
370 393
371 // GetConsole returns the requested console. 394 // GetConsole returns the requested console.
372 func GetConsole(c context.Context, proj, id string) (*Console, error) { 395 func GetConsole(c context.Context, proj, id string) (*Console, error) {
373 // TODO(hinoka): Memcache this. 396 // TODO(hinoka): Memcache this.
374 con := Console{ 397 con := Console{
375 Parent: datastore.MakeKey(c, "Project", proj), 398 Parent: datastore.MakeKey(c, "Project", proj),
376 ID: id, 399 ID: id,
377 } 400 }
378 err := datastore.Get(c, &con) 401 err := datastore.Get(c, &con)
379 return &con, err 402 return &con, err
380 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698