-
Notifications
You must be signed in to change notification settings - Fork 114
/
run_script.go
73 lines (56 loc) · 1.7 KB
/
run_script.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
package action
import (
"errors"
boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
boshscript "github.com/cloudfoundry/bosh-agent/agent/script"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type RunScriptAction struct {
scriptProvider boshscript.JobScriptProvider
specService boshas.V1Service
logTag string
logger boshlog.Logger
}
func NewRunScript(
scriptProvider boshscript.JobScriptProvider,
specService boshas.V1Service,
logger boshlog.Logger,
) RunScriptAction {
return RunScriptAction{
scriptProvider: scriptProvider,
specService: specService,
logTag: "RunScript Action",
logger: logger,
}
}
func (a RunScriptAction) IsAsynchronous(_ ProtocolVersion) bool {
return true
}
func (a RunScriptAction) IsPersistent() bool {
return false
}
func (a RunScriptAction) IsLoggable() bool {
return true
}
func (a RunScriptAction) Run(scriptName string, options map[string]interface{}) (map[string]string, error) {
// May be used in future to return more information
emptyResults := map[string]string{}
currentSpec, err := a.specService.Get()
if err != nil {
return emptyResults, bosherr.WrapError(err, "Getting current spec")
}
var scripts []boshscript.Script
for _, job := range currentSpec.Jobs() {
script := a.scriptProvider.NewScript(job.BundleName(), scriptName)
scripts = append(scripts, script)
}
parallelScript := a.scriptProvider.NewParallelScript(scriptName, scripts)
return emptyResults, parallelScript.Run()
}
func (a RunScriptAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a RunScriptAction) Cancel() error {
return errors.New("not supported")
}