OLD | NEW |
| (Empty) |
1 // Copyright 2017 The LUCI Authors. All rights reserved. | |
2 // Use of this source code is governed under the Apache License, Version 2.0 | |
3 // that can be found in the LICENSE file. | |
4 | |
5 package rpc | |
6 | |
7 import ( | |
8 "github.com/luci/luci-go/grpc/grpcutil" | |
9 "github.com/luci/luci-go/luci_config/common/cfgtypes" | |
10 milo "github.com/luci/luci-go/milo/api/proto" | |
11 "github.com/luci/luci-go/milo/appengine/job_source/buildbot" | |
12 "github.com/luci/luci-go/milo/appengine/job_source/swarming" | |
13 | |
14 "google.golang.org/grpc/codes" | |
15 | |
16 "golang.org/x/net/context" | |
17 ) | |
18 | |
19 // BuildInfoService is a BuildInfoServer implementation. | |
20 type BuildInfoService struct { | |
21 // BuildBot is the BuildInfoProvider for the BuildBot service. | |
22 BuildBot buildbot.BuildInfoProvider | |
23 // Swarming is the BuildInfoProvider for the Swarming service. | |
24 Swarming swarming.BuildInfoProvider | |
25 } | |
26 | |
27 var _ milo.BuildInfoServer = (*BuildInfoService)(nil) | |
28 | |
29 // Get implements milo.BuildInfoServer. | |
30 func (svc *BuildInfoService) Get(c context.Context, req *milo.BuildInfoRequest)
(*milo.BuildInfoResponse, error) { | |
31 projectHint := cfgtypes.ProjectName(req.ProjectHint) | |
32 if projectHint != "" { | |
33 if err := projectHint.Validate(); err != nil { | |
34 return nil, grpcutil.Errf(codes.InvalidArgument, "invali
d project hint: %s", err.Error()) | |
35 } | |
36 } | |
37 | |
38 switch { | |
39 case req.GetBuildbot() != nil: | |
40 resp, err := svc.BuildBot.GetBuildInfo(c, req.GetBuildbot(), pro
jectHint) | |
41 if err != nil { | |
42 return nil, err | |
43 } | |
44 return resp, nil | |
45 | |
46 case req.GetSwarming() != nil: | |
47 resp, err := svc.Swarming.GetBuildInfo(c, req.GetSwarming(), pro
jectHint) | |
48 if err != nil { | |
49 return nil, err | |
50 } | |
51 return resp, nil | |
52 | |
53 default: | |
54 return nil, grpcutil.Errf(codes.InvalidArgument, "must supply a
build") | |
55 } | |
56 } | |
OLD | NEW |