Skip to content

Commit 7ae1b54

Browse files
authored
depresourceapi: Change the 'Name' field in ElasticsearchTopologyElement for 'NodeType' (#182)
In order to make things simpler for our users, this patch changes the 'Name' field in ElasticsearchTopologyElement for 'NodeType'
1 parent e188910 commit 7ae1b54

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

pkg/api/deploymentapi/depresourceapi/elasticsearch_parser_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import (
3232

3333
func TestParseElasticsearchInput(t *testing.T) {
3434
var rawClusterTopology = []string{
35-
`{"name": "data", "size": 2048, "zone_count": 2}`,
36-
`{"name": "ml", "size": 4096, "zone_count": 1}`,
37-
`{"name": "master", "size": 1024, "zone_count": 1}`,
35+
`{"node_type": "data", "size": 2048, "zone_count": 2}`,
36+
`{"node_type": "ml", "size": 4096, "zone_count": 1}`,
37+
`{"node_type": "master", "size": 1024, "zone_count": 1}`,
3838
}
3939
var clusterTopology = []*models.ElasticsearchClusterTopologyElement{
4040
{
@@ -167,11 +167,11 @@ func TestParseElasticsearchInput(t *testing.T) {
167167
Version: "7.8.0",
168168
},
169169
TopologyElements: []string{
170-
`{"name": ""}`,
170+
`{"node_type": ""}`,
171171
},
172172
}},
173173
err: multierror.NewPrefixed("elasticsearch topology",
174-
errors.New("name cannot be empty"),
174+
errors.New("node_type cannot be empty"),
175175
errors.New("size cannot be empty"),
176176
),
177177
},

pkg/api/deploymentapi/depresourceapi/elasticsearch_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestNewElasticsearch(t *testing.T) {
9797
errors.New("deployment template info is not specified and is required for the operation"),
9898
errors.New("region cannot be empty"),
9999
errors.New("version cannot be empty"),
100-
errors.New("element[0]: elasticsearch topology: name cannot be empty"),
100+
errors.New("element[0]: elasticsearch topology: node_type cannot be empty"),
101101
errors.New("element[0]: elasticsearch topology: size cannot be empty"),
102102
),
103103
},
@@ -109,10 +109,10 @@ func TestNewElasticsearch(t *testing.T) {
109109
TemplateID: "default",
110110
DeploymentTemplateInfoV2: &elasticsearchTemplateResponse,
111111
Topology: []ElasticsearchTopologyElement{
112-
{Name: "some", Size: 1024},
112+
{NodeType: "some", Size: 1024},
113113
},
114114
}},
115-
err: errors.New(`deployment topology: failed to obtain desired topology names ([{Name:some ZoneCount:0 Size:1024}]) in deployment template id "default"`),
115+
err: errors.New(`deployment topology: failed to obtain desired topology names ([{NodeType:some ZoneCount:0 Size:1024}]) in deployment template id "default"`),
116116
},
117117
{
118118
name: "fails due to unknown invalid template",
@@ -127,7 +127,7 @@ func TestNewElasticsearch(t *testing.T) {
127127
},
128128
},
129129
Topology: []ElasticsearchTopologyElement{
130-
{Name: "some", Size: 1024},
130+
{NodeType: "some", Size: 1024},
131131
},
132132
}},
133133
err: errors.New("deployment: the default template is not configured for Elasticsearch. Please use another template if you wish to start Elasticsearch instances"),
@@ -175,9 +175,9 @@ func TestNewElasticsearch(t *testing.T) {
175175
TemplateID: "default",
176176
DeploymentTemplateInfoV2: &elasticsearchTemplateResponse,
177177
Topology: []ElasticsearchTopologyElement{
178-
{Name: DataNode, Size: 8192, ZoneCount: 2},
179-
{Name: MasterNode, Size: 1024, ZoneCount: 1},
180-
{Name: MLNode, Size: 2048, ZoneCount: 1},
178+
{NodeType: DataNode, Size: 8192, ZoneCount: 2},
179+
{NodeType: MasterNode, Size: 1024, ZoneCount: 1},
180+
{NodeType: MLNode, Size: 2048, ZoneCount: 1},
181181
},
182182
}},
183183
want: &models.ElasticsearchPayload{

pkg/api/deploymentapi/depresourceapi/elasticsearch_topology.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var (
4646

4747
// DefaultTopologyElement defines the element used in DefaultTopology
4848
DefaultTopologyElement = ElasticsearchTopologyElement{
49-
Name: DataNode,
49+
NodeType: DataNode,
5050
Size: DefaultDataSize,
5151
ZoneCount: DefaultDataZoneCount,
5252
}
@@ -67,8 +67,8 @@ type BuildElasticsearchTopologyParams struct {
6767
// ElasticsearchTopologyElement is a single cluster topology element, meaning
6868
// a number of instances (controlled by ZoneCount) for a single NodeType.
6969
type ElasticsearchTopologyElement struct {
70-
// Name can be one of "data", "master" or "ml".
71-
Name string `json:"name"`
70+
// NodeType can be one of "data", "master" or "ml".
71+
NodeType string `json:"node_type"`
7272

7373
// Number of zones to span the cluster on.
7474
ZoneCount int32 `json:"zone_count,omitempty"`
@@ -87,8 +87,8 @@ func (element *ElasticsearchTopologyElement) fillDefaults() {
8787
// Validate ensures the parameters are usable by the consuming function.
8888
func (element *ElasticsearchTopologyElement) Validate() error {
8989
var merr = multierror.NewPrefixed("elasticsearch topology")
90-
if element.Name == "" {
91-
merr = merr.Append(errors.New("name cannot be empty"))
90+
if element.NodeType == "" {
91+
merr = merr.Append(errors.New("node_type cannot be empty"))
9292
}
9393

9494
if element.Size == 0 {
@@ -173,19 +173,19 @@ func BuildElasticsearchTopology(params BuildElasticsearchTopologyParams) ([]*mod
173173

174174
// matchNodeType compares ElasticsearchTopologyElement name (NodeType) to the
175175
// actual NodeTypes specified in a deployment template cluster topology. The
176-
// Name field can be ["data", "master", "ml"].
176+
// NodeType field can be ["data", "master", "ml"].
177177
func matchNodeType(got models.ElasticsearchNodeType, want ElasticsearchTopologyElement) bool {
178-
if want.Name == DataNode {
178+
if want.NodeType == DataNode {
179179
return got.Data != nil && *got.Data
180180
}
181181

182-
if want.Name == MasterNode {
182+
if want.NodeType == MasterNode {
183183
var dataFalse = (got.Data != nil && !*got.Data) || got.Data == nil
184184
var masterTrue = got.Master != nil && *got.Master
185185
return dataFalse && masterTrue
186186
}
187187

188-
if want.Name == MLNode {
188+
if want.NodeType == MLNode {
189189
var dataFalse = (got.Data != nil && !*got.Data) || got.Data == nil
190190
var mlTrue = got.Ml != nil && *got.Ml
191191
return dataFalse && mlTrue

pkg/api/deploymentapi/depresourceapi/elasticsearch_topology_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,30 @@ func TestNewElasticsearchTopology(t *testing.T) {
4242
{
4343
name: "correctly parses a single element topology",
4444
args: args{topology: []string{
45-
`{"name": "data", "size": 1024, "zone_count": 1}`,
45+
`{"node_type": "data", "size": 1024, "zone_count": 1}`,
4646
}},
4747
want: []ElasticsearchTopologyElement{
48-
{Name: "data", Size: 1024, ZoneCount: 1},
48+
{NodeType: "data", Size: 1024, ZoneCount: 1},
4949
},
5050
},
5151
{
5252
name: "correctly parses a multi element topology",
5353
args: args{topology: []string{
54-
`{"name": "data", "size": 2048, "zone_count": 2}`,
55-
`{"name": "ml", "size": 4096, "zone_count": 1}`,
56-
`{"name": "master", "size": 1024, "zone_count": 1}`,
54+
`{"node_type": "data", "size": 2048, "zone_count": 2}`,
55+
`{"node_type": "ml", "size": 4096, "zone_count": 1}`,
56+
`{"node_type": "master", "size": 1024, "zone_count": 1}`,
5757
}},
5858
want: []ElasticsearchTopologyElement{
59-
{Name: "data", Size: 2048, ZoneCount: 2},
60-
{Name: "ml", Size: 4096, ZoneCount: 1},
61-
{Name: "master", Size: 1024, ZoneCount: 1},
59+
{NodeType: "data", Size: 2048, ZoneCount: 2},
60+
{NodeType: "ml", Size: 4096, ZoneCount: 1},
61+
{NodeType: "master", Size: 1024, ZoneCount: 1},
6262
},
6363
},
6464
{
6565
name: "fails due to invalid json parses a multi element topology",
6666
args: args{topology: []string{
67-
`{"name": "data", "size": 2048, "zone_count": 2}`,
68-
`{"name": "ml", "size": 4096, "zone_count": 1}`,
67+
`{"node_type": "data", "size": 2048, "zone_count": 2}`,
68+
`{"node_type": "ml", "size": 4096, "zone_count": 1}`,
6969
`{"aaaaaaaaaa`,
7070
}},
7171
err: errors.New("depresourceapi: failed unpacking raw topology: unexpected end of JSON input"),
@@ -76,7 +76,7 @@ func TestNewElasticsearchTopology(t *testing.T) {
7676
`{"zone_count": 2}`,
7777
}},
7878
err: multierror.NewPrefixed("elasticsearch topology",
79-
errors.New("name cannot be empty"),
79+
errors.New("node_type cannot be empty"),
8080
errors.New("size cannot be empty"),
8181
),
8282
},
@@ -114,7 +114,7 @@ func TestNewElasticsearchTopologyElement(t *testing.T) {
114114
name: "returns a parametrized ElasticsearchTopologyElement",
115115
args: args{size: 2048, zoneCount: 3},
116116
want: ElasticsearchTopologyElement{
117-
Name: DataNode,
117+
NodeType: DataNode,
118118
Size: 2048,
119119
ZoneCount: 3,
120120
},
@@ -180,20 +180,20 @@ func TestBuildElasticsearchTopology(t *testing.T) {
180180
args: args{params: BuildElasticsearchTopologyParams{
181181
TemplateID: "sometemplateid",
182182
Topology: []ElasticsearchTopologyElement{
183-
{Name: "something weird", Size: 2048, ZoneCount: 1},
183+
{NodeType: "something weird", Size: 2048, ZoneCount: 1},
184184
},
185185
ClusterTopology: topologies,
186186
}},
187-
err: errors.New(`deployment topology: failed to obtain desired topology names ([{Name:something weird ZoneCount:1 Size:2048}]) in deployment template id "sometemplateid"`),
187+
err: errors.New(`deployment topology: failed to obtain desired topology names ([{NodeType:something weird ZoneCount:1 Size:2048}]) in deployment template id "sometemplateid"`),
188188
},
189189
{
190190
name: "matches the topologies",
191191
args: args{params: BuildElasticsearchTopologyParams{
192192
TemplateID: "sometemplateid",
193193
Topology: []ElasticsearchTopologyElement{
194-
{Name: DataNode, Size: 8192, ZoneCount: 2},
195-
{Name: MasterNode, Size: 1024, ZoneCount: 1},
196-
{Name: MLNode, Size: 2048, ZoneCount: 1},
194+
{NodeType: DataNode, Size: 8192, ZoneCount: 2},
195+
{NodeType: MasterNode, Size: 1024, ZoneCount: 1},
196+
{NodeType: MLNode, Size: 2048, ZoneCount: 1},
197197
},
198198
ClusterTopology: topologies,
199199
}},

0 commit comments

Comments
 (0)