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