-
Notifications
You must be signed in to change notification settings - Fork 111
/
disablesharding.go
92 lines (80 loc) · 2.14 KB
/
disablesharding.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package upgradeinspectorv4
import (
"fmt"
"strings"
"github.com/chef/automate/components/automate-deployment/pkg/cli"
"github.com/chef/automate/components/automate-deployment/pkg/inspector"
"github.com/fatih/color"
"github.com/pkg/errors"
)
const (
ES_URL = "http://localhost:10141/_cluster/settings"
)
type DisableShardingInspection struct {
writer *cli.Writer
upgradeUtils UpgradeV4Utils
isExecuted bool
exitError error
exitedWithError bool
}
func NewDisableShardingInspection(w *cli.Writer, utls UpgradeV4Utils) *DisableShardingInspection {
return &DisableShardingInspection{
writer: w,
upgradeUtils: utls,
}
}
func (ds *DisableShardingInspection) ShowInfo(index *int) error {
return nil
}
func (ds *DisableShardingInspection) Skip() {
return
}
func (ds *DisableShardingInspection) GetShortInfo() []string {
return nil
}
func (ds *DisableShardingInspection) Inspect() (err error) {
disableShardingPayload := strings.NewReader(`{
"persistent": {
"cluster.routing.allocation.enable": "primaries"
}
}`)
_, err = ds.upgradeUtils.ExecRequest(ES_URL, "PUT", disableShardingPayload)
if err != nil {
err = errors.Wrap(err, "Failed to disable sharding")
ds.setExitError(err)
return err
}
ds.setExecuted()
return nil
}
func (ds *DisableShardingInspection) setExitError(err error) {
ds.exitError = err
ds.exitedWithError = true
}
func (ds *DisableShardingInspection) setExecuted() {
ds.isExecuted = true
}
func (ds *DisableShardingInspection) RollBackHandler() (err error) {
if !ds.isExecuted {
return nil
}
enableShardingPayload := strings.NewReader(`{
"persistent": {
"cluster.routing.allocation.enable": null
}
}`)
_, err = ds.upgradeUtils.ExecRequest(ES_URL, "PUT", enableShardingPayload)
if err != nil {
return errors.Wrap(err, "Failed to enable sharding")
}
return nil
}
func (ds *DisableShardingInspection) GetInstallationType() inspector.InstallationType {
return inspector.EMBEDDED
}
func (ds *DisableShardingInspection) ExitHandler() error {
if ds.exitedWithError {
ds.writer.Println(fmt.Errorf("["+color.New(color.FgRed).Sprint("Error")+"] %w", ds.exitError).Error())
}
return nil
}