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

Side by Side Diff: scheduler/appengine/apiservers/scheduler.go

Issue 2986033003: [scheduler]: ACLs phase 1 - per Job ACL specification and enforcement. (Closed)
Patch Set: [WIP] ACLs into engine public API. Created 3 years, 4 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
OLDNEW
1 // Copyright 2016 The LUCI Authors. 1 // Copyright 2016 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 28 matching lines...) Expand all
39 // GetJobs fetches all jobs satisfying JobsRequest and visibility ACLs. 39 // GetJobs fetches all jobs satisfying JobsRequest and visibility ACLs.
40 func (s SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) (*scheduler.JobsReply, error) { 40 func (s SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) (*scheduler.JobsReply, error) {
41 if in.GetCursor() != "" { 41 if in.GetCursor() != "" {
42 // Paging in GetJobs isn't implemented until we have enough jobs to care. 42 // Paging in GetJobs isn't implemented until we have enough jobs to care.
43 // Until then, not empty cursor implies no more jobs to return. 43 // Until then, not empty cursor implies no more jobs to return.
44 return &scheduler.JobsReply{Jobs: []*scheduler.Job{}, NextCursor : ""}, nil 44 return &scheduler.JobsReply{Jobs: []*scheduler.Job{}, NextCursor : ""}, nil
45 } 45 }
46 var ejobs []*engine.Job 46 var ejobs []*engine.Job
47 var err error 47 var err error
48 if in.GetProject() == "" { 48 if in.GetProject() == "" {
49 » » ejobs, err = s.Engine.GetAllJobs(ctx) 49 » » ejobs, err = s.Engine.GetAllJobsRA(ctx)
50 } else { 50 } else {
51 » » ejobs, err = s.Engine.GetProjectJobs(ctx, in.GetProject()) 51 » » ejobs, err = s.Engine.GetProjectJobsRA(ctx, in.GetProject())
52 } 52 }
53 if err != nil { 53 if err != nil {
54 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e rr) 54 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e rr)
55 } 55 }
56 56
57 jobs := make([]*scheduler.Job, len(ejobs)) 57 jobs := make([]*scheduler.Job, len(ejobs))
58 for i, ej := range ejobs { 58 for i, ej := range ejobs {
59 traits, err := presentation.GetJobTraits(ctx, s.Catalog, ej) 59 traits, err := presentation.GetJobTraits(ctx, s.Catalog, ej)
60 if err != nil { 60 if err != nil {
61 return nil, grpc.Errorf(codes.Internal, "failed to get t raits: %s", err) 61 return nil, grpc.Errorf(codes.Internal, "failed to get t raits: %s", err)
62 } 62 }
63 jobs[i] = &scheduler.Job{ 63 jobs[i] = &scheduler.Job{
64 JobRef: &scheduler.JobRef{ 64 JobRef: &scheduler.JobRef{
65 Project: ej.ProjectID, 65 Project: ej.ProjectID,
66 Job: ej.GetJobName(), 66 Job: ej.GetJobName(),
67 }, 67 },
68 Schedule: ej.Schedule, 68 Schedule: ej.Schedule,
69 State: &scheduler.JobState{ 69 State: &scheduler.JobState{
70 UiStatus: string(presentation.GetPublicStateKind (ej, traits)), 70 UiStatus: string(presentation.GetPublicStateKind (ej, traits)),
71 }, 71 },
72 Paused: ej.Paused, 72 Paused: ej.Paused,
73 } 73 }
74 } 74 }
75 return &scheduler.JobsReply{Jobs: jobs, NextCursor: ""}, nil 75 return &scheduler.JobsReply{Jobs: jobs, NextCursor: ""}, nil
76 } 76 }
77 77
78 func (s SchedulerServer) GetInvocations(ctx context.Context, in *scheduler.Invoc ationsRequest) (*scheduler.InvocationsReply, error) { 78 func (s SchedulerServer) GetInvocations(ctx context.Context, in *scheduler.Invoc ationsRequest) (*scheduler.InvocationsReply, error) {
79 » ejob, err := s.Engine.GetJob(ctx, getJobId(in.GetJobRef())) 79 » ejob, err := s.Engine.GetJobRA(ctx, getJobId(in.GetJobRef()))
80 if err != nil { 80 if err != nil {
81 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e rr) 81 return nil, grpc.Errorf(codes.Internal, "datastore error: %s", e rr)
82 } 82 }
83 if ejob == nil { 83 if ejob == nil {
84 return nil, grpc.Errorf(codes.NotFound, "Job does not exist or y ou have no access") 84 return nil, grpc.Errorf(codes.NotFound, "Job does not exist or y ou have no access")
85 } 85 }
86 86
87 pageSize := 50 87 pageSize := 50
88 if in.PageSize > 0 && int(in.PageSize) < pageSize { 88 if in.PageSize > 0 && int(in.PageSize) < pageSize {
89 pageSize = int(in.PageSize) 89 pageSize = int(in.PageSize)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 case err == engine.ErrNoSuchInvocation: 158 case err == engine.ErrNoSuchInvocation:
159 return nil, grpc.Errorf(codes.NotFound, "no such invocation") 159 return nil, grpc.Errorf(codes.NotFound, "no such invocation")
160 default: 160 default:
161 return nil, grpc.Errorf(codes.Internal, "internal error: %s", er r) 161 return nil, grpc.Errorf(codes.Internal, "internal error: %s", er r)
162 } 162 }
163 } 163 }
164 164
165 func getJobId(jobRef *scheduler.JobRef) string { 165 func getJobId(jobRef *scheduler.JobRef) string {
166 return jobRef.GetProject() + "/" + jobRef.GetJob() 166 return jobRef.GetProject() + "/" + jobRef.GetJob()
167 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698