| OLD | NEW |
| 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 apiservers | 5 package apiservers |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "github.com/luci/luci-go/scheduler/api/scheduler/v1" | 8 "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
| 9 "github.com/luci/luci-go/scheduler/appengine/catalog" | 9 "github.com/luci/luci-go/scheduler/appengine/catalog" |
| 10 "github.com/luci/luci-go/scheduler/appengine/engine" | 10 "github.com/luci/luci-go/scheduler/appengine/engine" |
| 11 "github.com/luci/luci-go/scheduler/appengine/presentation" |
| 12 "golang.org/x/net/context" |
| 13 "google.golang.org/grpc" |
| 14 "google.golang.org/grpc/codes" |
| 11 ) | 15 ) |
| 12 | 16 |
| 13 // SchedulerServer implements scheduler.Scheduler API. | 17 // SchedulerServer implements scheduler.Scheduler API. |
| 14 type SchedulerServer struct { | 18 type SchedulerServer struct { |
| 15 Engine engine.Engine | 19 Engine engine.Engine |
| 16 Catalog catalog.Catalog | 20 Catalog catalog.Catalog |
| 17 } | 21 } |
| 18 | 22 |
| 19 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) | 23 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) |
| 24 |
| 25 // GetJobs fetches all jobs satisfying JobsRequest and visibility ACLs. |
| 26 func (s SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest)
(*scheduler.JobsReply, error) { |
| 27 var ejobs []*engine.Job |
| 28 var err error |
| 29 if in.GetProject() == "" { |
| 30 ejobs, err = s.Engine.GetAllJobs(ctx) |
| 31 } else { |
| 32 ejobs, err = s.Engine.GetProjectJobs(ctx, in.GetProject()) |
| 33 } |
| 34 if err != nil { |
| 35 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e
rr) |
| 36 } |
| 37 |
| 38 jobs := make([]*scheduler.Job, len(ejobs)) |
| 39 for i, ej := range ejobs { |
| 40 traits, err := presentation.GetJobTraits(ctx, s.Catalog, ej) |
| 41 if err != nil { |
| 42 return nil, grpc.Errorf(codes.Internal, "failed to get t
raits: %s", err) |
| 43 } |
| 44 jobs[i] = &scheduler.Job{ |
| 45 Id: ej.JobID, |
| 46 Project: ej.ProjectID, |
| 47 Schedule: ej.Schedule, |
| 48 State: &scheduler.JobState{ |
| 49 UiStatus: string(presentation.GetPublicStateKind
(ej, traits)), |
| 50 }, |
| 51 } |
| 52 } |
| 53 return &scheduler.JobsReply{Jobs: jobs}, nil |
| 54 } |
| OLD | NEW |