-
Notifications
You must be signed in to change notification settings - Fork 162
/
release_manager.go
63 lines (49 loc) · 1.39 KB
/
release_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
package installation
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshrel "github.com/cloudfoundry/bosh-cli/release"
)
type ReleaseManager interface {
Add(boshrel.Release)
List() []boshrel.Release
Find(string) (boshrel.Release, bool)
DeleteAll() error
}
type releaseManager struct {
releases []boshrel.Release
logTag string
logger boshlog.Logger
}
func NewReleaseManager(logger boshlog.Logger) ReleaseManager {
return &releaseManager{
releases: []boshrel.Release{},
logTag: "installation.releaseManager",
logger: logger,
}
}
func (m *releaseManager) Add(release boshrel.Release) {
m.logger.Info(m.logTag, "Adding extracted release '%s-%s'", release.Name(), release.Version())
m.releases = append(m.releases, release)
}
func (m *releaseManager) List() []boshrel.Release {
return append([]boshrel.Release(nil), m.releases...)
}
func (m *releaseManager) Find(name string) (boshrel.Release, bool) {
for _, release := range m.releases {
if release.Name() == name {
return release, true
}
}
return nil, false
}
func (m *releaseManager) DeleteAll() error {
for _, release := range m.releases {
deleteErr := release.CleanUp()
if deleteErr != nil {
return bosherr.Errorf("Failed to delete extracted release '%s': %s", release.Name(), deleteErr.Error())
}
}
m.releases = []boshrel.Release{}
return nil
}