forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concrete_factory.go
102 lines (87 loc) · 3.7 KB
/
concrete_factory.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
package action
import (
boshappl "github.com/cloudfoundry/bosh-agent/agent/applier"
boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
boshcomp "github.com/cloudfoundry/bosh-agent/agent/compiler"
boshscript "github.com/cloudfoundry/bosh-agent/agent/script"
boshtask "github.com/cloudfoundry/bosh-agent/agent/task"
boshjobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor"
boshnotif "github.com/cloudfoundry/bosh-agent/notification"
boshplatform "github.com/cloudfoundry/bosh-agent/platform"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshblob "github.com/cloudfoundry/bosh-utils/blobstore"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type concreteFactory struct {
availableActions map[string]Action
}
func NewFactory(
settingsService boshsettings.Service,
platform boshplatform.Platform,
blobstore boshblob.DigestBlobstore,
blobManager boshblob.BlobManagerInterface,
taskService boshtask.Service,
notifier boshnotif.Notifier,
applier boshappl.Applier,
compiler boshcomp.Compiler,
jobSupervisor boshjobsuper.JobSupervisor,
specService boshas.V1Service,
jobScriptProvider boshscript.JobScriptProvider,
logger boshlog.Logger,
) (factory Factory) {
compressor := platform.GetCompressor()
copier := platform.GetCopier()
dirProvider := platform.GetDirProvider()
vitalsService := platform.GetVitalsService()
certManager := platform.GetCertManager()
factory = concreteFactory{
availableActions: map[string]Action{
// API
"ping": NewPing(),
"info": NewInfo(),
// Task management
"get_task": NewGetTask(taskService),
"cancel_task": NewCancelTask(taskService),
// VM admin
"ssh": NewSSH(settingsService, platform, dirProvider, logger),
"fetch_logs": NewFetchLogs(compressor, copier, blobstore, dirProvider),
"update_settings": NewUpdateSettings(settingsService, platform, certManager, logger),
// Job management
"prepare": NewPrepare(applier),
"apply": NewApply(applier, specService, settingsService, dirProvider, platform.GetFs()),
"start": NewStart(jobSupervisor, applier, specService),
"stop": NewStop(jobSupervisor),
"drain": NewDrain(notifier, specService, jobScriptProvider, jobSupervisor, logger),
"get_state": NewGetState(settingsService, specService, jobSupervisor, vitalsService),
"run_errand": NewRunErrand(specService, dirProvider.JobsDir(), platform.GetRunner(), logger),
"run_script": NewRunScript(jobScriptProvider, specService, logger),
// Compilation
"compile_package": NewCompilePackage(compiler),
"release_apply_spec": NewReleaseApplySpec(platform),
// Rendered Templates
"upload_blob": NewUploadBlobAction(blobManager),
// Disk management
"list_disk": NewListDisk(settingsService, platform, logger),
"migrate_disk": NewMigrateDisk(platform, dirProvider),
"mount_disk": NewMountDisk(settingsService, platform, dirProvider, logger),
"unmount_disk": NewUnmountDisk(settingsService, platform),
// ARP cache management
"delete_arp_entries": NewDeleteARPEntries(platform),
// Networking
"prepare_network_change": NewPrepareNetworkChange(platform.GetFs(), settingsService, NewAgentKiller()),
"prepare_configure_networks": NewPrepareConfigureNetworks(platform, settingsService),
"configure_networks": NewConfigureNetworks(NewAgentKiller()),
// DNS
"sync_dns": NewSyncDNS(blobstore, settingsService, platform, logger),
},
}
return
}
func (f concreteFactory) Create(method string) (Action, error) {
action, found := f.availableActions[method]
if !found {
return nil, bosherr.Errorf("Could not create action with method %s", method)
}
return action, nil
}