• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 0187edda-cc12-4da0-ba2d-55e31bfc9153

05 May 2023 10:05PM UTC coverage: 57.282% (+0.08%) from 57.202%
0187edda-cc12-4da0-ba2d-55e31bfc9153

Pull #5252

buildkite

David Porter
Merge branch 'master' into feature/merging-zonal-isolation
Pull Request #5252: Feature/zonal partitioning

2164 of 2164 new or added lines in 89 files covered. (100.0%)

86949 of 151792 relevant lines covered (57.28%)

2484.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.59
/tools/cli/isolation-groups.go
1
// Copyright (c) 2017 Uber Technologies, Inc.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
package cli
22

23
import (
24
        "encoding/json"
25
        "fmt"
26

27
        "github.com/uber/cadence/common/types"
28

29
        "github.com/urfave/cli"
30
)
31

32
func AdminGetGlobalIsolationGroups(c *cli.Context) {
×
33
        adminClient := cFactory.ServerAdminClient(c)
×
34

×
35
        ctx, cancel := newContext(c)
×
36
        defer cancel()
×
37

×
38
        req := &types.GetGlobalIsolationGroupsRequest{}
×
39
        igs, err := adminClient.GetGlobalIsolationGroups(ctx, req)
×
40
        if err != nil {
×
41
                ErrorAndExit("failed to get isolation-groups:", err)
×
42
        }
×
43
        prettyPrintJSONObject(igs.IsolationGroups.ToPartitionList())
×
44
}
45

46
func AdminUpdateGlobalIsolationGroups(c *cli.Context) {
×
47
        adminClient := cFactory.ServerAdminClient(c)
×
48

×
49
        ctx, cancel := newContext(c)
×
50
        defer cancel()
×
51

×
52
        err := validateIsolationGroupUpdateArgs(
×
53
                c.String(FlagDomain),
×
54
                c.GlobalString(FlagDomain),
×
55
                c.StringSlice(FlagIsolationGroupSetDrains),
×
56
                c.String(FlagIsolationGroupJSONConfigurations),
×
57
                c.Bool(FlagIsolationGroupsRemoveAllDrains),
×
58
                false,
×
59
        )
×
60
        if err != nil {
×
61
                ErrorAndExit("invalid args:", err)
×
62
        }
×
63

64
        cfg, err := parseIsolationGroupCliInputCfg(
×
65
                c.StringSlice(FlagIsolationGroupSetDrains),
×
66
                c.String(FlagIsolationGroupJSONConfigurations),
×
67
                c.Bool(FlagIsolationGroupsRemoveAllDrains),
×
68
        )
×
69
        if err != nil {
×
70
                ErrorAndExit("failed to parse input:", err)
×
71
        }
×
72

73
        _, err = adminClient.UpdateGlobalIsolationGroups(ctx, &types.UpdateGlobalIsolationGroupsRequest{
×
74
                IsolationGroups: *cfg,
×
75
        })
×
76
        if err != nil {
×
77
                ErrorAndExit("failed to update isolation-groups", fmt.Errorf("used %#v, got %v", cfg, err))
×
78
        }
×
79
}
80

81
func AdminGetDomainIsolationGroups(c *cli.Context) {
×
82
        adminClient := cFactory.ServerAdminClient(c)
×
83
        domain := c.String(FlagDomain)
×
84

×
85
        ctx, cancel := newContext(c)
×
86
        defer cancel()
×
87

×
88
        req := &types.GetDomainIsolationGroupsRequest{
×
89
                Domain: domain,
×
90
        }
×
91
        igs, err := adminClient.GetDomainIsolationGroups(ctx, req)
×
92
        if err != nil {
×
93
                ErrorAndExit("failed to get isolation-groups:", err)
×
94
        }
×
95
        prettyPrintJSONObject(igs.IsolationGroups.ToPartitionList())
×
96
}
97

98
func AdminUpdateDomainIsolationGroups(c *cli.Context) {
×
99
        adminClient := cFactory.ServerAdminClient(c)
×
100
        domain := c.String(FlagDomain)
×
101

×
102
        err := validateIsolationGroupUpdateArgs(
×
103
                c.String(FlagDomain),
×
104
                c.GlobalString(FlagDomain),
×
105
                c.StringSlice(FlagIsolationGroupSetDrains),
×
106
                c.String(FlagIsolationGroupJSONConfigurations),
×
107
                c.Bool(FlagIsolationGroupsRemoveAllDrains),
×
108
                true,
×
109
        )
×
110
        if err != nil {
×
111
                ErrorAndExit("invalid args:", err)
×
112
        }
×
113

114
        ctx, cancel := newContext(c)
×
115
        defer cancel()
×
116

×
117
        cfg, err := parseIsolationGroupCliInputCfg(
×
118
                c.StringSlice(FlagIsolationGroupSetDrains),
×
119
                c.String(FlagIsolationGroupJSONConfigurations),
×
120
                c.Bool(FlagIsolationGroupsRemoveAllDrains),
×
121
        )
×
122
        if err != nil {
×
123
                ErrorAndExit("failed to parse input:", err)
×
124
        }
×
125

126
        req := &types.UpdateDomainIsolationGroupsRequest{
×
127
                Domain:          domain,
×
128
                IsolationGroups: *cfg,
×
129
        }
×
130
        _, err = adminClient.UpdateDomainIsolationGroups(ctx, req)
×
131

×
132
        if err != nil {
×
133
                ErrorAndExit("failed to update isolation-groups", fmt.Errorf("used %#v, got %v", req, err))
×
134
        }
×
135
}
136

137
func validateIsolationGroupUpdateArgs(
138
        domainArgs string,
139
        globalDomainArg string,
140
        setDrainsArgs []string,
141
        jsonCfgArgs string,
142
        removeAllDrainsArgs bool,
143
        requiresDomain bool,
144
) error {
5✔
145
        if requiresDomain {
8✔
146
                if globalDomainArg != "" {
4✔
147
                        return fmt.Errorf("the flag '--domain' has to go at the end")
1✔
148
                }
1✔
149
                if domainArgs == "" {
3✔
150
                        return fmt.Errorf("the --domain flag is required")
1✔
151
                }
1✔
152
        }
153

154
        if len(setDrainsArgs) == 0 &&
3✔
155
                jsonCfgArgs == "" &&
3✔
156
                !removeAllDrainsArgs {
4✔
157
                return fmt.Errorf("need to specify either %q, %q or %q flags",
1✔
158
                        FlagIsolationGroupSetDrains,
1✔
159
                        FlagIsolationGroupJSONConfigurations,
1✔
160
                        FlagIsolationGroupsRemoveAllDrains,
1✔
161
                )
1✔
162
        }
1✔
163

164
        if removeAllDrainsArgs && (len(setDrainsArgs) != 0 || jsonCfgArgs != "") {
2✔
165
                return fmt.Errorf("specify either remove or set-drains, not both")
×
166
        }
×
167

168
        return nil
2✔
169
}
170

171
func parseIsolationGroupCliInputCfg(drains []string, jsonInput string, removeAllDrains bool) (*types.IsolationGroupConfiguration, error) {
2✔
172

2✔
173
        req := types.IsolationGroupConfiguration{}
2✔
174
        if removeAllDrains {
2✔
175
                return &req, nil
×
176
        }
×
177

178
        if len(drains) != 0 {
3✔
179
                req := types.IsolationGroupConfiguration{}
1✔
180
                for _, drain := range drains {
3✔
181
                        req[drain] = types.IsolationGroupPartition{
2✔
182
                                Name:  drain,
2✔
183
                                State: types.IsolationGroupStateDrained,
2✔
184
                        }
2✔
185
                }
2✔
186
                return &req, nil
1✔
187
        }
188

189
        var input []types.IsolationGroupPartition
1✔
190
        err := json.Unmarshal([]byte(jsonInput), &input)
1✔
191

1✔
192
        if err != nil {
1✔
193
                return nil, fmt.Errorf(`failed to marshal input. Trying to marshal []types.IsolationGroupPartition
×
194

×
195
examples: 
×
196
- []                                    # will remove all isolation groups
×
197
- [{"Name": "zone-123", "State": 2}]    # drain zone-123
×
198

×
199
%v`, err)
×
200
        }
×
201
        for _, g := range input {
3✔
202
                req[g.Name] = g
2✔
203
        }
2✔
204

205
        return &req, nil
1✔
206
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc