This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
installer.go
71 lines (60 loc) · 2.41 KB
/
installer.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
package release
import (
biinstall "github.com/cloudfoundry/bosh-init/installation"
biinstallmanifest "github.com/cloudfoundry/bosh-init/installation/manifest"
bosherr "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors"
birel "github.com/cloudfoundry/bosh-init/release"
biui "github.com/cloudfoundry/bosh-init/ui"
)
type CpiInstaller struct {
ReleaseManager birel.Manager
InstallerFactory biinstall.InstallerFactory
Validator Validator
}
func (i CpiInstaller) ValidateCpiRelease(installationManifest biinstallmanifest.Manifest, stage biui.Stage) error {
return stage.Perform("Validating cpi release", func() error {
cpiReleaseName := installationManifest.Template.Release
cpiRelease, found := i.ReleaseManager.Find(cpiReleaseName)
if !found {
return bosherr.Errorf("installation release '%s' must refer to a provided release", cpiReleaseName)
}
err := i.Validator.Validate(cpiRelease, installationManifest.Template.Name)
if err != nil {
return bosherr.WrapErrorf(err, "Invalid CPI release '%s'", cpiReleaseName)
}
return nil
})
}
func (i CpiInstaller) installCpiRelease(installer biinstall.Installer, installationManifest biinstallmanifest.Manifest, target biinstall.Target, stage biui.Stage) (biinstall.Installation, error) {
var installation biinstall.Installation
var err error
err = stage.PerformComplex("installing CPI", func(installStage biui.Stage) error {
installation, err = installer.Install(installationManifest, installStage)
return err
})
if err != nil {
return installation, bosherr.WrapError(err, "Installing CPI")
}
return installation, nil
}
func (i CpiInstaller) WithInstalledCpiRelease(installationManifest biinstallmanifest.Manifest, target biinstall.Target, stage biui.Stage, fn func(biinstall.Installation) error) (errToReturn error) {
installer := i.InstallerFactory.NewInstaller(target)
installation, err := i.installCpiRelease(installer, installationManifest, target, stage)
if err != nil {
errToReturn = err
return
}
defer func() {
err = i.cleanupInstall(installation, installer, stage)
if errToReturn == nil {
errToReturn = err
}
}()
errToReturn = fn(installation)
return
}
func (i CpiInstaller) cleanupInstall(installation biinstall.Installation, installer biinstall.Installer, stage biui.Stage) error {
return stage.Perform("Cleaning up rendered CPI jobs", func() error {
return installer.Cleanup(installation)
})
}