This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
70 lines (58 loc) · 1.82 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-cli/deployment/disk"
biinstance "github.com/cloudfoundry/bosh-cli/deployment/instance"
bistemcell "github.com/cloudfoundry/bosh-cli/stemcell"
biui "github.com/cloudfoundry/bosh-cli/ui"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
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
}