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

Side by Side Diff: milo/appengine/buildbot/grpc.go

Issue 2366763002: Milo: Grpc endpoint for multiple builds on a builder (Closed)
Patch Set: Review comments, add smoke test Created 4 years, 2 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/api/proto/pb.discovery.go ('k') | milo/appengine/buildbot/grpc_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 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 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "encoding/json" 10 "encoding/json"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 bs, err := json.Marshal(b) 47 bs, err := json.Marshal(b)
48 if err != nil { 48 if err != nil {
49 return nil, err 49 return nil, err
50 } 50 }
51 51
52 // Marshal the build back into JSON format. 52 // Marshal the build back into JSON format.
53 return &milo.BuildbotBuildJSON{Data: bs}, nil 53 return &milo.BuildbotBuildJSON{Data: bs}, nil
54 } 54 }
55 55
56 func (s *Service) GetBuildbotBuildsJSON(
57 c context.Context, req *milo.BuildbotBuildsRequest) (
58 *milo.BuildbotBuildsJSON, error) {
59
60 if req.Master == "" {
61 return nil, grpc.Errorf(codes.InvalidArgument, "No master specif ied")
62 }
63 if req.Builder == "" {
64 return nil, grpc.Errorf(codes.InvalidArgument, "No builder speci fied")
65 }
66
67 // Perform an ACL check by fetching the master.
68 _, err := getMasterEntry(c, req.Master)
69 switch {
70 case err == errMasterNotFound:
71 return nil, grpc.Errorf(codes.NotFound, "Master not found")
72 case err != nil:
73 return nil, err
74 }
75
76 limit := req.Limit
77 if limit == 0 {
78 limit = 20
79 }
80
81 q := ds.NewQuery("buildbotBuild")
82 q = q.Eq("master", req.Master).
83 Eq("builder", req.Builder).
84 Limit(limit).
85 Order("-number")
86 if req.IncludeCurrent == false {
87 q = q.Eq("finished", true)
88 }
89 builds := []*buildbotBuild{}
90 err = ds.GetAll(c, q, &builds)
91 if err != nil {
92 return nil, err
93 }
94
95 results := make([]*milo.BuildbotBuildJSON, len(builds))
96 for i, b := range builds {
97 // In theory we could do this in parallel, but it doesn't actual ly go faster
98 // since AppEngine is single-cored.
99 bs, err := json.Marshal(b)
100 if err != nil {
101 return nil, err
102 }
103 results[i] = &milo.BuildbotBuildJSON{Data: bs}
104 }
105 return &milo.BuildbotBuildsJSON{
106 Builds: results,
107 }, nil
108 }
109
56 // GetCompressedMasterJSON assembles a CompressedMasterJSON object from the 110 // GetCompressedMasterJSON assembles a CompressedMasterJSON object from the
57 // provided MasterRequest. 111 // provided MasterRequest.
58 func (s *Service) GetCompressedMasterJSON( 112 func (s *Service) GetCompressedMasterJSON(
59 c context.Context, req *milo.MasterRequest) (*milo.CompressedMasterJSON, error) { 113 c context.Context, req *milo.MasterRequest) (*milo.CompressedMasterJSON, error) {
60 114
61 if req.Name == "" { 115 if req.Name == "" {
62 return nil, grpc.Errorf(codes.InvalidArgument, "No master specif ied") 116 return nil, grpc.Errorf(codes.InvalidArgument, "No master specif ied")
63 } 117 }
64 118
65 entry, err := getMasterEntry(c, req.Name) 119 entry, err := getMasterEntry(c, req.Name)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 189
136 return &milo.CompressedMasterJSON{ 190 return &milo.CompressedMasterJSON{
137 Internal: entry.Internal, 191 Internal: entry.Internal,
138 Modified: &google.Timestamp{ 192 Modified: &google.Timestamp{
139 Seconds: entry.Modified.Unix(), 193 Seconds: entry.Modified.Unix(),
140 Nanos: int32(entry.Modified.Nanosecond()), 194 Nanos: int32(entry.Modified.Nanosecond()),
141 }, 195 },
142 Data: gzbs.Bytes(), 196 Data: gzbs.Bytes(),
143 }, nil 197 }, nil
144 } 198 }
OLDNEW
« no previous file with comments | « milo/api/proto/pb.discovery.go ('k') | milo/appengine/buildbot/grpc_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698