/
waitforhealthystatus.go
71 lines (61 loc) · 1.7 KB
/
waitforhealthystatus.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 migratorv4
import (
"fmt"
"time"
"github.com/briandowns/spinner"
"github.com/chef/automate/components/automate-deployment/pkg/cli"
"github.com/fatih/color"
)
type WaitForHealthy struct {
writer *cli.Writer
utils MigratorV4Utils
spinner *spinner.Spinner
healthStatus *bool
spinnerTimeout time.Duration
}
func NewWaitForHealthy(writer *cli.Writer, utils MigratorV4Utils, healthStatus *bool, spinnerTimeout time.Duration) *WaitForHealthy {
return &WaitForHealthy{
writer: writer,
utils: utils,
healthStatus: healthStatus,
spinnerTimeout: spinnerTimeout,
}
}
func (wfh *WaitForHealthy) Run() error {
return nil
}
func (wfh *WaitForHealthy) ErrorHandler() {
return
}
func (wfh *WaitForHealthy) showErrorStatus() {
wfh.spinner.FinalMSG = SPACES_BEFORE_STEPS + " " + color.New(color.FgRed).Sprint("✖") + " Chef Automate status is unhealthy"
wfh.spinner.Stop()
wfh.writer.Println("")
}
func (wfh *WaitForHealthy) showSuccessStatus() {
wfh.spinner.FinalMSG = SPACES_BEFORE_STEPS + " " + color.New(color.FgGreen).Sprint("✔") + " Chef Automate status is healthy"
wfh.spinner.Stop()
wfh.writer.Println("")
}
func (wfh *WaitForHealthy) showStartStatus() {
wfh.spinner = wfh.writer.NewSpinnerWithTab()
wfh.spinner.Suffix = fmt.Sprintf(" Checking Chef automate status")
wfh.spinner.Start()
time.Sleep(wfh.spinnerTimeout)
}
func (wfh *WaitForHealthy) DefferedHandler() error {
if *wfh.healthStatus {
wfh.showStartStatus()
args := []string{
"status",
"--wait-for-healthy",
}
err := wfh.utils.ExecuteCommand("chef-automate", args, "")
if err != nil {
wfh.showErrorStatus()
return err
}
wfh.showSuccessStatus()
}
return nil
}