Skip to content

Commit 54911ac

Browse files
Autoscaling policy roles specification (#64222)
Add a roles specification to autoscaling policies. This is used to map the policy to a set of nodes governed by the policy. The list of roles is mandatory when adding a policy, optional on updates. This commit also removes the outer level "policy" element from autoscaling policy PUT and GET requests.
1 parent fc8c6dd commit 54911ac

20 files changed

+442
-135
lines changed

docs/reference/autoscaling/apis/delete-autoscaling-policy.asciidoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ Delete autoscaling policy.
1515
--------------------------------------------------
1616
PUT /_autoscaling/policy/my_autoscaling_policy
1717
{
18-
"policy": {
19-
"deciders": {
20-
"fixed": {
21-
}
18+
"roles": [],
19+
"deciders": {
20+
"fixed": {
2221
}
2322
}
2423
}

docs/reference/autoscaling/apis/get-autoscaling-policy.asciidoc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ Get autoscaling policy.
1515
--------------------------------------------------
1616
PUT /_autoscaling/policy/my_autoscaling_policy
1717
{
18-
"policy": {
19-
"deciders": {
20-
"fixed": {
21-
}
18+
"roles" : [],
19+
"deciders": {
20+
"fixed": {
2221
}
2322
}
2423
}
@@ -70,9 +69,9 @@ The API returns the following result:
7069
[source,console-result]
7170
--------------------------------------------------
7271
{
73-
"policy": {
74-
"deciders": <deciders>
75-
}
72+
"roles": <roles>,
73+
"deciders": <deciders>
7674
}
7775
--------------------------------------------------
78-
// TEST[s/<deciders>/$body.policy.deciders/]
76+
// TEST[s/<roles>/$body.roles/]
77+
// TEST[s/<deciders>/$body.deciders/]

docs/reference/autoscaling/apis/put-autoscaling-policy.asciidoc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ Put autoscaling policy.
1515
--------------------------------------------------
1616
PUT /_autoscaling/policy/<name>
1717
{
18-
"policy": {
19-
"deciders": {
20-
"fixed": {
21-
}
18+
"roles": [],
19+
"deciders": {
20+
"fixed": {
2221
}
2322
}
2423
}
@@ -51,16 +50,16 @@ This API puts an autoscaling policy with the provided name.
5150
==== {api-examples-title}
5251

5352
This example puts an autoscaling policy named `my_autoscaling_policy` using the
54-
fixed autoscaling decider.
53+
fixed autoscaling decider, applying to the set of nodes having (only) the
54+
"data_hot" role.
5555

5656
[source,console]
5757
--------------------------------------------------
5858
PUT /_autoscaling/policy/my_autoscaling_policy
5959
{
60-
"policy": {
61-
"deciders": {
62-
"fixed": {
63-
}
60+
"roles" : [ "data_hot" ],
61+
"deciders": {
62+
"fixed": {
6463
}
6564
}
6665
}

x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/delete_autoscaling_policy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
autoscaling.put_autoscaling_policy:
55
name: my_autoscaling_policy
66
body:
7-
policy:
8-
deciders:
9-
fixed: {}
7+
roles: []
8+
deciders:
9+
fixed: {}
1010

1111
- match: { "acknowledged": true }
1212

x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
autoscaling.put_autoscaling_policy:
1212
name: my_autoscaling_policy
1313
body:
14-
policy:
15-
deciders:
16-
fixed:
17-
storage: 1337b
18-
memory: 7331b
19-
nodes: 10
14+
roles : []
15+
deciders:
16+
fixed:
17+
storage: 1337b
18+
memory: 7331b
19+
nodes: 10
2020

2121
- match: { "acknowledged": true }
2222

x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_policy.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
autoscaling.put_autoscaling_policy:
55
name: my_autoscaling_policy
66
body:
7-
policy:
8-
deciders:
9-
fixed: {}
7+
roles: [ master ]
8+
deciders:
9+
fixed: {}
1010

1111
- match: { "acknowledged": true }
1212

1313
- do:
1414
autoscaling.get_autoscaling_policy:
1515
name: my_autoscaling_policy
1616

17-
- match: { policy.deciders.fixed: {} }
17+
- match: { roles: [ master ] }
18+
- match: { deciders.fixed: {} }
1819

1920
# test cleanup
2021
- do:

x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/put_autoscaling_policy.yml

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,88 @@
44
autoscaling.put_autoscaling_policy:
55
name: my_autoscaling_policy
66
body:
7-
policy:
8-
deciders:
9-
fixed: {}
7+
roles: [ master ]
108

119
- match: { "acknowledged": true }
1210

11+
# update deciders
12+
- do:
13+
autoscaling.put_autoscaling_policy:
14+
name: my_autoscaling_policy
15+
body:
16+
deciders:
17+
fixed: {}
18+
19+
- do:
20+
autoscaling.get_autoscaling_policy:
21+
name: my_autoscaling_policy
22+
- match: { roles: [ master ] }
23+
- match: { deciders.fixed: {} }
24+
25+
# update roles
26+
- do:
27+
autoscaling.put_autoscaling_policy:
28+
name: my_autoscaling_policy
29+
body:
30+
roles: [ data ]
31+
32+
- do:
33+
autoscaling.get_autoscaling_policy:
34+
name: my_autoscaling_policy
35+
- match: { roles: [ data ] }
36+
- match: { deciders.fixed: {} }
37+
1338
# test cleanup
1439
- do:
1540
autoscaling.delete_autoscaling_policy:
1641
name: my_autoscaling_policy
1742

1843
---
44+
"Test add autoscaling policy with deciders":
45+
- do:
46+
autoscaling.put_autoscaling_policy:
47+
name: my_autoscaling_policy
48+
body:
49+
roles: [ master ]
50+
deciders:
51+
fixed: {}
52+
53+
- match: { "acknowledged": true }
54+
55+
- do:
56+
autoscaling.get_autoscaling_policy:
57+
name: my_autoscaling_policy
58+
- match: { roles: [ master ] }
59+
- match: { deciders.fixed: {} }
60+
61+
# test cleanup
62+
- do:
63+
autoscaling.delete_autoscaling_policy:
64+
name: my_autoscaling_policy
65+
---
1966
"Test put autoscaling policy with non-existent decider":
2067
- do:
2168
catch: bad_request
2269
autoscaling.put_autoscaling_policy:
2370
name: my_autoscaling_policy
2471
body:
25-
policy:
26-
deciders:
27-
does_not_exist: {}
72+
roles: [ master ]
73+
deciders:
74+
does_not_exist: {}
2875

76+
---
77+
"Test put autoscaling policy with non-existent roles":
78+
- do:
79+
catch: bad_request
80+
autoscaling.put_autoscaling_policy:
81+
name: my_autoscaling_policy
82+
body:
83+
roles: [ non-existing ]
84+
85+
---
86+
"Test add autoscaling policy with no roles":
87+
- do:
88+
catch: bad_request
89+
autoscaling.put_autoscaling_policy:
90+
name: my_autoscaling_policy
91+
body: {}

x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/TransportDeleteAutoscalingPolicyActionIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public class TransportDeleteAutoscalingPolicyActionIT extends AutoscalingIntegTe
2323

2424
public void testDeletePolicy() {
2525
final AutoscalingPolicy policy = randomAutoscalingPolicy();
26-
final PutAutoscalingPolicyAction.Request putRequest = new PutAutoscalingPolicyAction.Request(policy);
26+
final PutAutoscalingPolicyAction.Request putRequest = new PutAutoscalingPolicyAction.Request(
27+
policy.name(),
28+
policy.roles(),
29+
policy.deciders()
30+
);
2731
assertAcked(client().execute(PutAutoscalingPolicyAction.INSTANCE, putRequest).actionGet());
2832
// we trust that the policy is in the cluster state since we have tests for putting policies
2933
final DeleteAutoscalingPolicyAction.Request deleteRequest = new DeleteAutoscalingPolicyAction.Request(policy.name());

x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingPolicyActionIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public class TransportGetAutoscalingPolicyActionIT extends AutoscalingIntegTestC
2020
public void testGetPolicy() {
2121
final String name = randomAlphaOfLength(8);
2222
final AutoscalingPolicy expectedPolicy = randomAutoscalingPolicyOfName(name);
23-
final PutAutoscalingPolicyAction.Request putRequest = new PutAutoscalingPolicyAction.Request(expectedPolicy);
23+
final PutAutoscalingPolicyAction.Request putRequest = new PutAutoscalingPolicyAction.Request(
24+
expectedPolicy.name(),
25+
expectedPolicy.roles(),
26+
expectedPolicy.deciders()
27+
);
2428
assertAcked(client().execute(PutAutoscalingPolicyAction.INSTANCE, putRequest).actionGet());
2529
// we trust that the policy is in the cluster state since we have tests for putting policies
2630
final GetAutoscalingPolicyAction.Request getRequest = new GetAutoscalingPolicyAction.Request(name);

x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/TransportPutAutoscalingPolicyActionIT.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.cluster.service.ClusterService;
1111
import org.elasticsearch.xpack.autoscaling.AutoscalingIntegTestCase;
1212
import org.elasticsearch.xpack.autoscaling.AutoscalingMetadata;
13+
import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase;
1314
import org.elasticsearch.xpack.autoscaling.policy.AutoscalingPolicy;
1415

1516
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@@ -32,7 +33,11 @@ public void testAddPolicy() {
3233

3334
public void testUpdatePolicy() {
3435
final AutoscalingPolicy policy = putRandomAutoscalingPolicy();
35-
final AutoscalingPolicy updatedPolicy = new AutoscalingPolicy(policy.name(), mutateAutoscalingDeciders(policy.deciders()));
36+
final AutoscalingPolicy updatedPolicy = new AutoscalingPolicy(
37+
policy.name(),
38+
AutoscalingTestCase.randomRoles(),
39+
mutateAutoscalingDeciders(policy.deciders())
40+
);
3641
putAutoscalingPolicy(updatedPolicy);
3742
final ClusterState state = client().admin().cluster().prepareState().get().getState();
3843
final AutoscalingMetadata metadata = state.metadata().custom(AutoscalingMetadata.NAME);
@@ -59,7 +64,11 @@ private AutoscalingPolicy putRandomAutoscalingPolicy() {
5964
}
6065

6166
private void putAutoscalingPolicy(final AutoscalingPolicy policy) {
62-
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request(policy);
67+
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request(
68+
policy.name(),
69+
policy.roles(),
70+
policy.deciders()
71+
);
6372
assertAcked(client().execute(PutAutoscalingPolicyAction.INSTANCE, request).actionGet());
6473
}
6574

x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingPolicyAction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ public void writeTo(final StreamOutput out) throws IOException {
9494

9595
@Override
9696
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
97-
builder.startObject();
98-
{
99-
builder.field("policy", policy);
100-
}
101-
builder.endObject();
97+
policy.toXContent(builder, params);
10298
return builder;
10399
}
104100

0 commit comments

Comments
 (0)