forked from vmware-archive/atc
/
build_step.go
160 lines (131 loc) · 4.27 KB
/
build_step.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
package engine
import (
"code.cloudfoundry.org/clock"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc"
"github.com/concourse/atc/db"
"github.com/concourse/atc/exec"
)
func (build *execBuild) buildAggregateStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
logger = logger.Session("aggregate")
step := exec.Aggregate{}
for _, innerPlan := range *plan.Aggregate {
innerPlan.Attempts = plan.Attempts
stepFactory := build.buildStepFactory(logger, innerPlan)
step = append(step, stepFactory)
}
return step
}
func (build *execBuild) buildDoStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
logger = logger.Session("do")
var step exec.StepFactory
step = exec.Identity{}
for i := len(*plan.Do) - 1; i >= 0; i-- {
innerPlan := (*plan.Do)[i]
innerPlan.Attempts = plan.Attempts
previous := build.buildStepFactory(logger, innerPlan)
step = exec.OnSuccess(previous, step)
}
return step
}
func (build *execBuild) buildTimeoutStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
innerPlan := plan.Timeout.Step
innerPlan.Attempts = plan.Attempts
step := build.buildStepFactory(logger, innerPlan)
return exec.Timeout(step, plan.Timeout.Duration, clock.NewClock())
}
func (build *execBuild) buildTryStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
innerPlan := plan.Try.Step
innerPlan.Attempts = plan.Attempts
step := build.buildStepFactory(logger, innerPlan)
return exec.Try(step)
}
func (build *execBuild) buildOnSuccessStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
plan.OnSuccess.Step.Attempts = plan.Attempts
step := build.buildStepFactory(logger, plan.OnSuccess.Step)
plan.OnSuccess.Next.Attempts = plan.Attempts
next := build.buildStepFactory(logger, plan.OnSuccess.Next)
return exec.OnSuccess(step, next)
}
func (build *execBuild) buildOnFailureStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
plan.OnFailure.Step.Attempts = plan.Attempts
step := build.buildStepFactory(logger, plan.OnFailure.Step)
plan.OnFailure.Next.Attempts = plan.Attempts
next := build.buildStepFactory(logger, plan.OnFailure.Next)
return exec.OnFailure(step, next)
}
func (build *execBuild) buildEnsureStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
plan.Ensure.Step.Attempts = plan.Attempts
step := build.buildStepFactory(logger, plan.Ensure.Step)
plan.Ensure.Next.Attempts = plan.Attempts
next := build.buildStepFactory(logger, plan.Ensure.Next)
return exec.Ensure(step, next)
}
// needs rootfs
func (build *execBuild) buildTaskStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
logger = logger.Session("task")
containerMetadata := build.containerMetadata(
db.ContainerTypeTask,
plan.Task.Name,
plan.Attempts,
)
return build.factory.Task(
logger,
plan,
build.dbBuild,
containerMetadata,
build.delegate.DBTaskBuildEventsDelegate(plan.ID),
build.delegate.DBActionsBuildEventsDelegate(plan.ID),
build.delegate.ImageFetchingDelegate(plan.ID),
)
}
// needs rootfs
func (build *execBuild) buildGetStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
logger = logger.Session("get", lager.Data{
"name": plan.Get.Name,
})
containerMetadata := build.containerMetadata(
db.ContainerTypeGet,
plan.Get.Name,
plan.Attempts,
)
return build.factory.Get(
logger,
plan,
build.dbBuild,
build.stepMetadata,
containerMetadata,
build.delegate.DBActionsBuildEventsDelegate(plan.ID),
build.delegate.ImageFetchingDelegate(plan.ID),
)
}
// needs rootfs
func (build *execBuild) buildPutStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
logger = logger.Session("put", lager.Data{
"name": plan.Put.Name,
})
containerMetadata := build.containerMetadata(
db.ContainerTypePut,
plan.Put.Name,
plan.Attempts,
)
return build.factory.Put(
logger,
plan,
build.dbBuild,
build.stepMetadata,
containerMetadata,
build.delegate.DBActionsBuildEventsDelegate(plan.ID),
build.delegate.ImageFetchingDelegate(plan.ID),
)
}
func (build *execBuild) buildRetryStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
logger = logger.Session("retry")
step := exec.Retry{}
for index, innerPlan := range *plan.Retry {
innerPlan.Attempts = append(plan.Attempts, index+1)
stepFactory := build.buildStepFactory(logger, innerPlan)
step = append(step, stepFactory)
}
return step
}