This repository has been archived by the owner on Jul 12, 2018. It is now read-only.
forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_list_renderer.go
60 lines (53 loc) · 1.74 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
57
58
59
60
package templatescompiler
import (
bireljob "github.com/cloudfoundry/bosh-init/release/job"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
biproperty "github.com/cloudfoundry/bosh-utils/property"
)
type JobListRenderer interface {
Render(
releaseJobs []bireljob.Job,
releaseJobProperties map[string]*biproperty.Map,
jobProperties biproperty.Map,
globalProperties biproperty.Map,
deploymentName string,
address 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,
releaseJobProperties map[string]*biproperty.Map,
jobProperties biproperty.Map,
globalProperties biproperty.Map,
deploymentName string,
address 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, releaseJobProperties[releaseJob.Name], jobProperties, globalProperties, deploymentName, address)
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
}