forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
59 lines (50 loc) · 1.2 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
package release
import (
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
)
type Manager interface {
Add(Release)
List() []Release
Find(name string) (releases Release, found bool)
DeleteAll() error
}
type manager struct {
logger boshlog.Logger
logTag string
releases []Release
}
func NewManager(
logger boshlog.Logger,
) Manager {
return &manager{
logger: logger,
logTag: "releaseManager",
releases: []Release{},
}
}
func (m *manager) Add(release Release) {
m.logger.Info(m.logTag, "Adding extracted release '%s-%s'", release.Name(), release.Version())
m.releases = append(m.releases, release)
}
func (m *manager) List() []Release {
return append([]Release(nil), m.releases...)
}
func (m *manager) Find(name string) (Release, bool) {
for _, release := range m.releases {
if release.Name() == name {
return release, true
}
}
return nil, false
}
func (m *manager) DeleteAll() error {
for _, release := range m.releases {
deleteErr := release.Delete()
if deleteErr != nil {
return bosherr.Errorf("Failed to delete extracted release '%s': %s", release.Name(), deleteErr.Error())
}
}
m.releases = []Release{}
return nil
}