forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
70 lines (58 loc) · 1.87 KB
/
manager.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
package deployment
import (
bidisk "github.com/cloudfoundry/bosh-init/deployment/disk"
biinstance "github.com/cloudfoundry/bosh-init/deployment/instance"
bosherr "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors"
bistemcell "github.com/cloudfoundry/bosh-init/stemcell"
biui "github.com/cloudfoundry/bosh-init/ui"
)
type Manager interface {
FindCurrent() (deployment Deployment, found bool, err error)
Cleanup(biui.Stage) error
}
type manager struct {
instanceManager biinstance.Manager
diskManager bidisk.Manager
stemcellManager bistemcell.Manager
deploymentFactory Factory
}
func NewManager(
instanceManager biinstance.Manager,
diskManager bidisk.Manager,
stemcellManager bistemcell.Manager,
deploymentFactory Factory,
) Manager {
return &manager{
instanceManager: instanceManager,
diskManager: diskManager,
stemcellManager: stemcellManager,
deploymentFactory: deploymentFactory,
}
}
func (m *manager) FindCurrent() (deployment Deployment, found bool, err error) {
instances, err := m.instanceManager.FindCurrent()
if err != nil {
return nil, false, bosherr.WrapError(err, "Finding current deployment instances")
}
disks, err := m.diskManager.FindCurrent()
if err != nil {
return nil, false, bosherr.WrapError(err, "Finding current deployment disks")
}
stemcells, err := m.stemcellManager.FindCurrent()
if err != nil {
return nil, false, bosherr.WrapError(err, "Finding current deployment stemcells")
}
if len(instances) == 0 && len(disks) == 0 && len(stemcells) == 0 {
return nil, false, nil
}
return m.deploymentFactory.NewDeployment(instances, disks, stemcells), true, nil
}
func (m *manager) Cleanup(stage biui.Stage) error {
if err := m.diskManager.DeleteUnused(stage); err != nil {
return err
}
if err := m.stemcellManager.DeleteUnused(stage); err != nil {
return err
}
return nil
}