Chromium Code Reviews| 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/common/logging" | |
| 8 "github.com/luci/luci-go/scheduler/api/scheduler/v1" | 9 "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
| 9 "github.com/luci/luci-go/scheduler/appengine/catalog" | 10 "github.com/luci/luci-go/scheduler/appengine/catalog" |
| 10 "github.com/luci/luci-go/scheduler/appengine/engine" | 11 "github.com/luci/luci-go/scheduler/appengine/engine" |
| 12 "github.com/luci/luci-go/scheduler/appengine/presentation" | |
| 13 "github.com/luci/luci-go/scheduler/appengine/task" | |
| 14 "golang.org/x/net/context" | |
| 15 "google.golang.org/grpc" | |
| 16 "google.golang.org/grpc/codes" | |
| 11 ) | 17 ) |
| 12 | 18 |
| 13 // SchedulerServer implements scheduler.Scheduler API. | 19 // SchedulerServer implements scheduler.Scheduler API. |
| 14 type SchedulerServer struct { | 20 type SchedulerServer struct { |
| 15 Engine engine.Engine | 21 Engine engine.Engine |
| 16 Catalog catalog.Catalog | 22 Catalog catalog.Catalog |
| 17 } | 23 } |
| 18 | 24 |
| 19 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) | 25 var _ scheduler.SchedulerServer = (*SchedulerServer)(nil) |
| 26 | |
| 27 // GetJobs fetches all jobs satisfying JobsRequest and visibility ACLs. | |
| 28 func (s SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) (*scheduler.JobsReply, error) { | |
| 29 var ejobs []*engine.Job | |
| 30 var err error | |
| 31 if in.GetProject() == "" { | |
| 32 ejobs, err = s.Engine.GetAllJobs(ctx) | |
| 33 } else { | |
| 34 ejobs, err = s.Engine.GetProjectJobs(ctx, in.GetProject()) | |
| 35 } | |
| 36 if err != nil { | |
| 37 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e rr) | |
| 38 } | |
| 39 | |
| 40 jobs := make([]*scheduler.Job, len(ejobs)) | |
| 41 for i, ej := range ejobs { | |
| 42 jobs[i] = &scheduler.Job{ | |
| 43 Id: ej.JobID, | |
| 44 Project: ej.ProjectID, | |
| 45 Schedule: ej.Schedule, | |
| 46 State: &scheduler.JobState{ | |
| 47 UiStatus: string(presentation.GetPublicStateKind (ej, s.getTaskTraits(ctx, ej))), | |
| 48 }, | |
| 49 } | |
| 50 } | |
| 51 return &scheduler.JobsReply{Jobs: jobs}, nil | |
| 52 } | |
| 53 | |
| 54 //// | |
| 55 | |
| 56 func (s SchedulerServer) getTaskTraits(ctx context.Context, j *engine.Job) task. Traits { | |
|
Vadim Sh.
2017/06/20 17:48:54
I think this should be moved somewhere else, so it
tandrii(chromium)
2017/06/20 19:48:36
Done.
| |
| 57 var manager task.Manager | |
| 58 taskDef, err := s.Catalog.UnmarshalTask(j.Task) | |
| 59 if err != nil { | |
| 60 logging.WithError(err).Warningf(ctx, "Failed to unmarshal task p roto for %s", j.JobID) | |
| 61 } else { | |
| 62 manager = s.Catalog.GetTaskManager(taskDef) | |
| 63 } | |
| 64 if manager != nil { | |
| 65 return manager.Traits() | |
| 66 } | |
| 67 return task.Traits{} | |
| 68 } | |
| OLD | NEW |