-
Notifications
You must be signed in to change notification settings - Fork 115
/
concrete_job_script_provider.go
60 lines (48 loc) · 1.86 KB
/
concrete_job_script_provider.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 script
import (
"fmt"
"path"
"path/filepath"
"code.cloudfoundry.org/clock"
boshdrain "github.com/cloudfoundry/bosh-agent/agent/script/drain"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type ConcreteJobScriptProvider struct {
cmdRunner boshsys.CmdRunner
fs boshsys.FileSystem
dirProvider boshdir.Provider
timeService clock.Clock
logger boshlog.Logger
}
func NewConcreteJobScriptProvider(
cmdRunner boshsys.CmdRunner,
fs boshsys.FileSystem,
dirProvider boshdir.Provider,
timeService clock.Clock,
logger boshlog.Logger,
) ConcreteJobScriptProvider {
return ConcreteJobScriptProvider{
cmdRunner: cmdRunner,
fs: fs,
dirProvider: dirProvider,
timeService: timeService,
logger: logger,
}
}
func (p ConcreteJobScriptProvider) NewScript(jobName string, scriptName string) Script {
path := path.Join(p.dirProvider.JobBinDir(jobName), scriptName+ScriptExt)
stdoutLogFilename := fmt.Sprintf("%s.stdout.log", scriptName)
stdoutLogPath := filepath.Join(p.dirProvider.LogsDir(), jobName, stdoutLogFilename)
stderrLogFilename := fmt.Sprintf("%s.stderr.log", scriptName)
stderrLogPath := filepath.Join(p.dirProvider.LogsDir(), jobName, stderrLogFilename)
return NewScript(p.fs, p.cmdRunner, jobName, path, stdoutLogPath, stderrLogPath)
}
func (p ConcreteJobScriptProvider) NewDrainScript(jobName string, params boshdrain.ScriptParams) CancellableScript {
path := path.Join(p.dirProvider.JobsDir(), jobName, "bin", "drain"+ScriptExt)
return boshdrain.NewConcreteScript(p.fs, p.cmdRunner, jobName, path, params, p.timeService, p.logger)
}
func (p ConcreteJobScriptProvider) NewParallelScript(scriptName string, scripts []Script) CancellableScript {
return NewParallelScript(scriptName, scripts, p.logger)
}