forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_list_renderer.go
56 lines (49 loc) · 1.69 KB
/
job_list_renderer.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
package templatescompiler
import (
bosherr "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
biproperty "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/property"
bireljob "github.com/cloudfoundry/bosh-init/release/job"
)
type JobListRenderer interface {
Render(
releaseJobs []bireljob.Job,
jobProperties biproperty.Map,
globalProperties biproperty.Map,
deploymentName string,
) (RenderedJobList, error)
}
type jobListRenderer struct {
jobRenderer JobRenderer
logger boshlog.Logger
logTag string
}
func NewJobListRenderer(
jobRenderer JobRenderer,
logger boshlog.Logger,
) JobListRenderer {
return &jobListRenderer{
jobRenderer: jobRenderer,
logger: logger,
logTag: "jobListRenderer",
}
}
func (r *jobListRenderer) Render(
releaseJobs []bireljob.Job,
jobProperties biproperty.Map,
globalProperties biproperty.Map,
deploymentName string,
) (RenderedJobList, error) {
r.logger.Debug(r.logTag, "Rendering job list: deploymentName='%s' jobProperties=%#v globalProperties=%#v", deploymentName, jobProperties, globalProperties)
renderedJobList := NewRenderedJobList()
// render all the jobs' templates
for _, releaseJob := range releaseJobs {
renderedJob, err := r.jobRenderer.Render(releaseJob, jobProperties, globalProperties, deploymentName)
if err != nil {
defer renderedJobList.DeleteSilently()
return renderedJobList, bosherr.WrapErrorf(err, "Rendering templates for job '%s/%s'", releaseJob.Name, releaseJob.Fingerprint)
}
renderedJobList.Add(renderedJob)
}
return renderedJobList, nil
}