This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_config.go
171 lines (133 loc) · 4.13 KB
/
job_config.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package atc
type JobConfig struct {
Name string `yaml:"name" json:"name" mapstructure:"name"`
Public bool `yaml:"public,omitempty" json:"public,omitempty" mapstructure:"public"`
DisableManualTrigger bool `yaml:"disable_manual_trigger,omitempty" json:"disable_manual_trigger,omitempty" mapstructure:"disable_manual_trigger"`
Serial bool `yaml:"serial,omitempty" json:"serial,omitempty" mapstructure:"serial"`
Interruptible bool `yaml:"interruptible,omitempty" json:"interruptible,omitempty" mapstructure:"interruptible"`
SerialGroups []string `yaml:"serial_groups,omitempty" json:"serial_groups,omitempty" mapstructure:"serial_groups"`
RawMaxInFlight int `yaml:"max_in_flight,omitempty" json:"max_in_flight,omitempty" mapstructure:"max_in_flight"`
BuildLogsToRetain int `yaml:"build_logs_to_retain,omitempty" json:"build_logs_to_retain,omitempty" mapstructure:"build_logs_to_retain"`
Plan PlanSequence `yaml:"plan,omitempty" json:"plan,omitempty" mapstructure:"plan"`
Abort *PlanConfig `yaml:"on_abort,omitempty" json:"on_abort,omitempty" mapstructure:"on_abort"`
Failure *PlanConfig `yaml:"on_failure,omitempty" json:"on_failure,omitempty" mapstructure:"on_failure"`
Ensure *PlanConfig `yaml:"ensure,omitempty" json:"ensure,omitempty" mapstructure:"ensure"`
Success *PlanConfig `yaml:"on_success,omitempty" json:"on_success,omitempty" mapstructure:"on_success"`
}
func (config JobConfig) Hooks() Hooks {
return Hooks{Abort: config.Abort, Failure: config.Failure, Ensure: config.Ensure, Success: config.Success}
}
func (config JobConfig) MaxInFlight() int {
if config.Serial || len(config.SerialGroups) > 0 {
return 1
}
if config.RawMaxInFlight != 0 {
return config.RawMaxInFlight
}
return 0
}
func (config JobConfig) GetSerialGroups() []string {
if len(config.SerialGroups) > 0 {
return config.SerialGroups
}
if config.Serial || config.RawMaxInFlight > 0 {
return []string{config.Name}
}
return []string{}
}
func (config JobConfig) Plans() []PlanConfig {
plan := collectPlans(PlanConfig{
Do: &config.Plan,
Abort: config.Abort,
Ensure: config.Ensure,
Failure: config.Failure,
Success: config.Success,
})
return plan
}
func collectPlans(plan PlanConfig) []PlanConfig {
var plans []PlanConfig
if plan.Abort != nil {
plans = append(plans, collectPlans(*plan.Abort)...)
}
if plan.Success != nil {
plans = append(plans, collectPlans(*plan.Success)...)
}
if plan.Failure != nil {
plans = append(plans, collectPlans(*plan.Failure)...)
}
if plan.Ensure != nil {
plans = append(plans, collectPlans(*plan.Ensure)...)
}
if plan.Try != nil {
plans = append(plans, collectPlans(*plan.Try)...)
}
if plan.Do != nil {
for _, p := range *plan.Do {
plans = append(plans, collectPlans(p)...)
}
}
if plan.Aggregate != nil {
for _, p := range *plan.Aggregate {
plans = append(plans, collectPlans(p)...)
}
}
return append(plans, plan)
}
func (config JobConfig) InputPlans() []PlanConfig {
var inputs []PlanConfig
for _, plan := range config.Plans() {
if plan.Get != "" {
inputs = append(inputs, plan)
}
}
return inputs
}
func (config JobConfig) OutputPlans() []PlanConfig {
var outputs []PlanConfig
for _, plan := range config.Plans() {
if plan.Put != "" {
outputs = append(outputs, plan)
}
}
return outputs
}
func (config JobConfig) Inputs() []JobInput {
var inputs []JobInput
for _, plan := range config.Plans() {
if plan.Get != "" {
get := plan.Get
resource := get
if plan.Resource != "" {
resource = plan.Resource
}
inputs = append(inputs, JobInput{
Name: get,
Resource: resource,
Passed: plan.Passed,
Version: plan.Version,
Trigger: plan.Trigger,
Params: plan.Params,
Tags: plan.Tags,
})
}
}
return inputs
}
func (config JobConfig) Outputs() []JobOutput {
var outputs []JobOutput
for _, plan := range config.Plans() {
if plan.Put != "" {
put := plan.Put
resource := put
if plan.Resource != "" {
resource = plan.Resource
}
outputs = append(outputs, JobOutput{
Name: put,
Resource: resource,
})
}
}
return outputs
}