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

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

Issue 2364653002: Buildbot build json grpc endpoint (Closed)
Patch Set: Pass tests Created 4 years, 3 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/appengine/buildbot/build_test.go ('k') | milo/appengine/buildbot/html.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"
11 11
12 "google.golang.org/grpc" 12 "google.golang.org/grpc"
13 "google.golang.org/grpc/codes" 13 "google.golang.org/grpc/codes"
14 14
15 ds "github.com/luci/gae/service/datastore" 15 ds "github.com/luci/gae/service/datastore"
16 "github.com/luci/luci-go/common/iotools" 16 "github.com/luci/luci-go/common/iotools"
17 "github.com/luci/luci-go/common/logging" 17 "github.com/luci/luci-go/common/logging"
18 "github.com/luci/luci-go/common/proto/google" 18 "github.com/luci/luci-go/common/proto/google"
19 milo "github.com/luci/luci-go/milo/api/proto" 19 milo "github.com/luci/luci-go/milo/api/proto"
20 "golang.org/x/net/context" 20 "golang.org/x/net/context"
21 ) 21 )
22 22
23 // Service is a service implementation that displays BuildBot builds. 23 // Service is a service implementation that displays BuildBot builds.
24 type Service struct{} 24 type Service struct{}
25 25
26 var errNotFoundGRPC = grpc.Errorf(codes.NotFound, "Master Not Found") 26 var errNotFoundGRPC = grpc.Errorf(codes.NotFound, "Master Not Found")
27 27
28 func (s *Service) GetBuildbotBuildJSON(
29 c context.Context, req *milo.BuildbotBuildRequest) (
30 *milo.BuildbotBuildJSON, error) {
31
32 if req.Master == "" {
33 return nil, grpc.Errorf(codes.InvalidArgument, "No master specif ied")
34 }
35 if req.Builder == "" {
36 return nil, grpc.Errorf(codes.InvalidArgument, "No builder speci fied")
37 }
38
39 b, err := build(c, req.Master, req.Builder, int(req.BuildNum))
40 switch {
41 case err == errBuildNotFound:
42 return nil, grpc.Errorf(codes.NotFound, "Build not found")
43 case err != nil:
44 return nil, err
45 }
46
47 bs, err := json.Marshal(b)
48 if err != nil {
49 return nil, err
50 }
51
52 // Marshal the build back into JSON format.
53 return &milo.BuildbotBuildJSON{Data: bs}, nil
54 }
55
28 // GetCompressedMasterJSON assembles a CompressedMasterJSON object from the 56 // GetCompressedMasterJSON assembles a CompressedMasterJSON object from the
29 // provided MasterRequest. 57 // provided MasterRequest.
30 func (s *Service) GetCompressedMasterJSON( 58 func (s *Service) GetCompressedMasterJSON(
31 c context.Context, req *milo.MasterRequest) (*milo.CompressedMasterJSON, error) { 59 c context.Context, req *milo.MasterRequest) (*milo.CompressedMasterJSON, error) {
32 60
33 if req.Name == "" { 61 if req.Name == "" {
34 return nil, grpc.Errorf(codes.InvalidArgument, "No master specif ied") 62 return nil, grpc.Errorf(codes.InvalidArgument, "No master specif ied")
35 } 63 }
36 64
37 entry, err := getMasterEntry(c, req.Name) 65 entry, err := getMasterEntry(c, req.Name)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 135
108 return &milo.CompressedMasterJSON{ 136 return &milo.CompressedMasterJSON{
109 Internal: entry.Internal, 137 Internal: entry.Internal,
110 Modified: &google.Timestamp{ 138 Modified: &google.Timestamp{
111 Seconds: entry.Modified.Unix(), 139 Seconds: entry.Modified.Unix(),
112 Nanos: int32(entry.Modified.Nanosecond()), 140 Nanos: int32(entry.Modified.Nanosecond()),
113 }, 141 },
114 Data: gzbs.Bytes(), 142 Data: gzbs.Bytes(),
115 }, nil 143 }, nil
116 } 144 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbot/build_test.go ('k') | milo/appengine/buildbot/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698