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

Side by Side Diff: common/api/dm/service/v1/execution_state_evolve.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file Created 4 years, 6 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 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 dm 5 package dm
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 ) 9 )
10 10
11 // validExecutionStateEvolution defines all valid {From -> []To} state 11 // validExecutionStateEvolution defines all valid {From -> []To} state
12 // transitions. The identity transition (X -> X) is implied, as long as X has an 12 // transitions. The identity transition (X -> X) is implied, as long as X has an
13 // entry in this mapping. 13 // entry in this mapping.
14 var validExecutionStateEvolution = map[Execution_State][]Execution_State{ 14 var validExecutionStateEvolution = map[Execution_State][]Execution_State{
15 » Execution_SCHEDULED: {Execution_RUNNING, Execution_FINISHED, Execution_M ISSING, Execution_CANCELLED, Execution_TIMED_OUT}, 15 » Execution_SCHEDULING: {
16 » Execution_RUNNING: {Execution_FINISHED, Execution_FAILED, Execution_MI SSING, Execution_CANCELLED}, 16 » » Execution_RUNNING, // ActivateExecution
17 » » Execution_ABNORMAL_FINISHED, // cancel/timeout/err/etc.
18 » },
19 » Execution_RUNNING: {
20 » » Execution_STOPPING, // FinishAttempt/EnsureGraphData
21 » » Execution_ABNORMAL_FINISHED, // cancel/timeout/err/etc.
22 » },
23 » Execution_STOPPING: {
24 » » Execution_FINISHED, // got persistent state from distri butor
25 » » Execution_ABNORMAL_FINISHED, // cancel/timeout/err/etc.
26 » },
17 27
18 » Execution_CANCELLED: {}, 28 » Execution_FINISHED: {},
19 » Execution_FINISHED: {}, 29 » Execution_ABNORMAL_FINISHED: {},
20 » Execution_FAILED: {},
21 » Execution_MISSING: {},
22 » Execution_REJECTED: {},
23 » Execution_TIMED_OUT: {},
24 } 30 }
25 31
26 // Evolve attempts to evolve the state of this Attempt. If the state 32 // Evolve attempts to evolve the state of this Attempt. If the state
27 // evolution is not allowed (e.g. invalid state transition), this returns an 33 // evolution is not allowed (e.g. invalid state transition), this returns an
28 // error. 34 // error.
29 func (s *Execution_State) Evolve(newState Execution_State) error { 35 func (s *Execution_State) Evolve(newState Execution_State) error {
30 nextStates := validExecutionStateEvolution[*s] 36 nextStates := validExecutionStateEvolution[*s]
31 if nextStates == nil { 37 if nextStates == nil {
32 return fmt.Errorf("invalid state transition: no transitions defi ned for %s", *s) 38 return fmt.Errorf("invalid state transition: no transitions defi ned for %s", *s)
33 } 39 }
(...skipping 18 matching lines...) Expand all
52 if err != nil { 58 if err != nil {
53 panic(err) 59 panic(err)
54 } 60 }
55 } 61 }
56 62
57 // Terminal returns true iff there are no valid evolutions from the current 63 // Terminal returns true iff there are no valid evolutions from the current
58 // state. 64 // state.
59 func (s Execution_State) Terminal() bool { 65 func (s Execution_State) Terminal() bool {
60 return len(validExecutionStateEvolution[s]) == 0 66 return len(validExecutionStateEvolution[s]) == 0
61 } 67 }
OLDNEW
« no previous file with comments | « common/api/dm/service/v1/execution_data.go ('k') | common/api/dm/service/v1/execution_state_evolve_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698