forked from raystack/optimus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_status.go
84 lines (74 loc) · 2.72 KB
/
resource_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package resource
import (
"fmt"
"github.com/goto/optimus/internal/errors"
)
func (r *Resource) MarkValidationSuccess() error {
if r.status == StatusUnknown {
r.status = StatusValidationSuccess
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status [%s] is not allowed", r.FullName(), r.status, StatusValidationSuccess)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkValidationFailure() error {
if r.status == StatusUnknown {
r.status = StatusValidationFailure
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status [%s] is not allowed", r.FullName(), r.status, StatusValidationFailure)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkSkipped() error {
if r.status == StatusValidationSuccess {
r.status = StatusSkipped
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status [%s] is not allowed", r.FullName(), r.status, StatusSkipped)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkToCreate() error {
if r.status == StatusValidationSuccess {
r.status = StatusToCreate
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status [%s] is not allowed", r.FullName(), r.status, StatusToCreate)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkToUpdate() error {
if r.status == StatusValidationSuccess {
r.status = StatusToUpdate
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status [%s] is not allowed", r.FullName(), r.status, StatusToUpdate)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkExistInStore() error {
if r.status == StatusToCreate {
r.status = StatusExistInStore
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status [%s] is not allowed", r.FullName(), r.status, StatusExistInStore)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkFailure() error {
switch r.status {
case StatusToCreate:
r.status = StatusCreateFailure
return nil
case StatusToUpdate:
r.status = StatusUpdateFailure
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status failure is not allowed", r.FullName(), r.status)
return errors.InvalidStateTransition(EntityResource, msg)
}
func (r *Resource) MarkSuccess() error {
switch r.status {
case StatusToCreate, StatusToUpdate:
r.status = StatusSuccess
return nil
}
msg := fmt.Sprintf("status transition for [%s] from status [%s] to status success is not allowed", r.FullName(), r.status)
return errors.InvalidStateTransition(EntityResource, msg)
}