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

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

Issue 2998623002: scheduler ACLs: fix ACLs saving upon job config change. (Closed)
Patch Set: fix import order 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
« no previous file with comments | « scheduler/appengine/acl/acl.go ('k') | scheduler/appengine/engine/engine_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. 1 // Copyright 2015 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // isEqual returns true iff 'e' is equal to 'other'. 326 // isEqual returns true iff 'e' is equal to 'other'.
327 func (e *Job) isEqual(other *Job) bool { 327 func (e *Job) isEqual(other *Job) bool {
328 return e == other || (e.JobID == other.JobID && 328 return e == other || (e.JobID == other.JobID &&
329 e.ProjectID == other.ProjectID && 329 e.ProjectID == other.ProjectID &&
330 e.Flavor == other.Flavor && 330 e.Flavor == other.Flavor &&
331 e.Enabled == other.Enabled && 331 e.Enabled == other.Enabled &&
332 e.Paused == other.Paused && 332 e.Paused == other.Paused &&
333 e.Revision == other.Revision && 333 e.Revision == other.Revision &&
334 e.RevisionURL == other.RevisionURL && 334 e.RevisionURL == other.RevisionURL &&
335 e.Schedule == other.Schedule && 335 e.Schedule == other.Schedule &&
336 e.Acls.Equal(&other.Acls) &&
Vadim Sh. 2017/08/08 19:11:16 err... I remember reviewing this line. What happen
tandrii(chromium) 2017/08/08 19:20:02 you've reviewed very similar line below.
336 bytes.Equal(e.Task, other.Task) && 337 bytes.Equal(e.Task, other.Task) &&
337 e.State == other.State) 338 e.State == other.State)
338 } 339 }
339 340
340 // matches returns true if job definition in the entity matches the one 341 // matches returns true if job definition in the entity matches the one
341 // specified by catalog.Definition struct. UpdateProjectJobs skips updates for 342 // specified by catalog.Definition struct. UpdateProjectJobs skips updates for
342 // such jobs (assuming they are up-to-date). 343 // such jobs (assuming they are up-to-date).
343 func (e *Job) matches(def catalog.Definition) bool { 344 func (e *Job) matches(def catalog.Definition) bool {
344 return e.JobID == def.JobID && 345 return e.JobID == def.JobID &&
345 e.Flavor == def.Flavor && 346 e.Flavor == def.Flavor &&
346 e.Schedule == def.Schedule && 347 e.Schedule == def.Schedule &&
347 e.Acls.Equal(&def.Acls) && 348 e.Acls.Equal(&def.Acls) &&
tandrii(chromium) 2017/08/08 19:20:02 it was this line :)
348 bytes.Equal(e.Task, def.Task) 349 bytes.Equal(e.Task, def.Task)
349 } 350 }
350 351
351 // Invocation entity stores single attempt to run a job. Its parent entity 352 // Invocation entity stores single attempt to run a job. Its parent entity
352 // is corresponding Job, its ID is generated based on time. 353 // is corresponding Job, its ID is generated based on time.
353 type Invocation struct { 354 type Invocation struct {
354 _kind string `gae:"$kind,Invocation"` 355 _kind string `gae:"$kind,Invocation"`
355 _extra ds.PropertyMap `gae:"-,extra"` 356 _extra ds.PropertyMap `gae:"-,extra"`
356 357
357 // ID is identifier of this particular attempt to run a job. Multiple at tempts 358 // ID is identifier of this particular attempt to run a job. Multiple at tempts
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 } 1295 }
1295 1296
1296 // updateJob updates an existing job if its definition has changed, adds 1297 // updateJob updates an existing job if its definition has changed, adds
1297 // a completely new job or enables a previously disabled job. 1298 // a completely new job or enables a previously disabled job.
1298 func (e *engineImpl) updateJob(c context.Context, def catalog.Definition) error { 1299 func (e *engineImpl) updateJob(c context.Context, def catalog.Definition) error {
1299 return e.txn(c, def.JobID, func(c context.Context, job *Job, isNew bool) error { 1300 return e.txn(c, def.JobID, func(c context.Context, job *Job, isNew bool) error {
1300 if !isNew && job.Enabled && job.matches(def) { 1301 if !isNew && job.Enabled && job.matches(def) {
1301 return errSkipPut 1302 return errSkipPut
1302 } 1303 }
1303 if isNew { 1304 if isNew {
1304 » » » // JobID is <projectID>/<name>, it's ensure by Catalog. 1305 » » » // JobID is <projectID>/<name>, it's ensured by Catalog.
1305 chunks := strings.Split(def.JobID, "/") 1306 chunks := strings.Split(def.JobID, "/")
1306 if len(chunks) != 2 { 1307 if len(chunks) != 2 {
1307 return fmt.Errorf("unexpected jobID format: %s", def.JobID) 1308 return fmt.Errorf("unexpected jobID format: %s", def.JobID)
1308 } 1309 }
1309 *job = Job{ 1310 *job = Job{
1310 JobID: def.JobID, 1311 JobID: def.JobID,
1311 ProjectID: chunks[0], 1312 ProjectID: chunks[0],
1312 Flavor: def.Flavor, 1313 Flavor: def.Flavor,
1313 Enabled: false, // to trigger 'if !oldEnabled' below 1314 Enabled: false, // to trigger 'if !oldEnabled' below
1314 Schedule: def.Schedule, 1315 Schedule: def.Schedule,
1315 Task: def.Task, 1316 Task: def.Task,
1316 State: JobState{State: JobStateDisabled}, 1317 State: JobState{State: JobStateDisabled},
1317 } 1318 }
1318 } 1319 }
1319 oldEnabled := job.Enabled 1320 oldEnabled := job.Enabled
1320 oldEffectiveSchedule := job.effectiveSchedule() 1321 oldEffectiveSchedule := job.effectiveSchedule()
1321 1322
1322 // Update the job in full before running any state changes. 1323 // Update the job in full before running any state changes.
1323 job.Flavor = def.Flavor 1324 job.Flavor = def.Flavor
1324 job.Revision = def.Revision 1325 job.Revision = def.Revision
1325 job.RevisionURL = def.RevisionURL 1326 job.RevisionURL = def.RevisionURL
1327 job.Acls = def.Acls
1326 job.Enabled = true 1328 job.Enabled = true
1327 job.Schedule = def.Schedule 1329 job.Schedule = def.Schedule
1328 job.Task = def.Task 1330 job.Task = def.Task
1329 1331
1330 // Do state machine transitions. 1332 // Do state machine transitions.
1331 if !oldEnabled { 1333 if !oldEnabled {
1332 err := e.rollSM(c, job, func(sm *StateMachine) error { 1334 err := e.rollSM(c, job, func(sm *StateMachine) error {
1333 sm.OnJobEnabled() 1335 sm.OnJobEnabled()
1334 return nil 1336 return nil
1335 }) 1337 })
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 } 2072 }
2071 if hasFinished { 2073 if hasFinished {
2072 return ctl.eng.rollSM(c, job, func(sm *StateMachine) err or { 2074 return ctl.eng.rollSM(c, job, func(sm *StateMachine) err or {
2073 sm.OnInvocationDone(saving.ID) 2075 sm.OnInvocationDone(saving.ID)
2074 return nil 2076 return nil
2075 }) 2077 })
2076 } 2078 }
2077 return nil 2079 return nil
2078 }) 2080 })
2079 } 2081 }
OLDNEW
« no previous file with comments | « scheduler/appengine/acl/acl.go ('k') | scheduler/appengine/engine/engine_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698