diff --git a/docs/reference/autoscaling/apis/autoscaling-apis.asciidoc b/docs/reference/autoscaling/apis/autoscaling-apis.asciidoc index d8f97a00771a..f153d93decfa 100644 --- a/docs/reference/autoscaling/apis/autoscaling-apis.asciidoc +++ b/docs/reference/autoscaling/apis/autoscaling-apis.asciidoc @@ -9,13 +9,13 @@ You can use the following APIs to perform autoscaling operations. [[autoscaling-api-top-level]] === Top-Level -* <> +* <> * <> * <> * <> // top-level -include::get-autoscaling-decision.asciidoc[] +include::get-autoscaling-capacity.asciidoc[] include::delete-autoscaling-policy.asciidoc[] include::get-autoscaling-policy.asciidoc[] include::put-autoscaling-policy.asciidoc[] diff --git a/docs/reference/autoscaling/apis/get-autoscaling-decision.asciidoc b/docs/reference/autoscaling/apis/get-autoscaling-capacity.asciidoc similarity index 53% rename from docs/reference/autoscaling/apis/get-autoscaling-decision.asciidoc rename to docs/reference/autoscaling/apis/get-autoscaling-capacity.asciidoc index dfa14ac18063..24331bbe8b83 100644 --- a/docs/reference/autoscaling/apis/get-autoscaling-decision.asciidoc +++ b/docs/reference/autoscaling/apis/get-autoscaling-capacity.asciidoc @@ -1,44 +1,44 @@ [role="xpack"] [testenv="platinum"] -[[autoscaling-get-autoscaling-decision]] -=== Get autoscaling decision API +[[autoscaling-get-autoscaling-capacity]] +=== Get autoscaling capacity API ++++ -Get autoscaling decision +Get autoscaling capacity ++++ -Get autoscaling decision. +Get autoscaling capacity. -[[autoscaling-get-autoscaling-decision-request]] +[[autoscaling-get-autoscaling-capacity-request]] ==== {api-request-title} [source,console] -------------------------------------------------- -GET /_autoscaling/decision/ +GET /_autoscaling/capacity/ -------------------------------------------------- // TEST -[[autoscaling-get-autoscaling-decision-prereqs]] +[[autoscaling-get-autoscaling-capacity-prereqs]] ==== {api-prereq-title} * If the {es} {security-features} are enabled, you must have `manage_autoscaling` cluster privileges. For more information, see <>. -[[autoscaling-get-autoscaling-decision-desc]] +[[autoscaling-get-autoscaling-capacity-desc]] ==== {api-description-title} -This API gets the current autoscaling decision based on the configured -autoscaling policy. This API will return whether or not autoscaling is -needed. +This API gets the current autoscaling capacity based on the configured +autoscaling policy. This API will return information to size the cluster +appropriately to the current workload. -[[autoscaling-get-autoscaling-decision-examples]] +[[autoscaling-get-autoscaling-capacity-examples]] ==== {api-examples-title} -This example retrieves the current autoscaling decision. +This example retrieves the current autoscaling capacity. [source,console] -------------------------------------------------- -GET /_autoscaling/decision +GET /_autoscaling/capacity -------------------------------------------------- // TEST @@ -47,6 +47,6 @@ The API returns the following result: [source,console-result] -------------------------------------------------- { - decisions: [] + policies: {} } -------------------------------------------------- diff --git a/docs/reference/autoscaling/apis/put-autoscaling-policy.asciidoc b/docs/reference/autoscaling/apis/put-autoscaling-policy.asciidoc index 3c831ebbbab8..b7f71f7b0625 100644 --- a/docs/reference/autoscaling/apis/put-autoscaling-policy.asciidoc +++ b/docs/reference/autoscaling/apis/put-autoscaling-policy.asciidoc @@ -51,7 +51,7 @@ This API puts an autoscaling policy with the provided name. ==== {api-examples-title} This example puts an autoscaling policy named `my_autoscaling_policy` using the -always autoscaling decider. +fixed autoscaling decider. [source,console] -------------------------------------------------- diff --git a/docs/reference/redirects.asciidoc b/docs/reference/redirects.asciidoc index d8fc0872fd9a..ef7f4fe053be 100644 --- a/docs/reference/redirects.asciidoc +++ b/docs/reference/redirects.asciidoc @@ -1213,3 +1213,9 @@ See <>. === elasticsearch-croneval parameters See <>. + +[role="exclude",id="autoscaling-get-autoscaling-decision"] +=== Autoscaling decision API + +The autoscaling decision API has been renamed to capacity, +see <>. diff --git a/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml b/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml new file mode 100644 index 000000000000..02f4a78c54a1 --- /dev/null +++ b/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_capacity.yml @@ -0,0 +1,39 @@ +--- +"Test get empty autoscaling capacity": + - do: + autoscaling.get_autoscaling_capacity: {} + + - match: { "policies": {} } + +--- +"Test get fixed autoscaling capacity": + - do: + autoscaling.put_autoscaling_policy: + name: my_autoscaling_policy + body: + policy: + deciders: + fixed: + storage: 1337b + memory: 7331b + nodes: 10 + + - match: { "acknowledged": true } + + - do: + autoscaling.get_autoscaling_capacity: {} + + - match: { policies.my_autoscaling_policy.required_capacity.total.storage: 13370b } + - match: { policies.my_autoscaling_policy.required_capacity.total.memory: 73310b } + - match: { policies.my_autoscaling_policy.required_capacity.node.storage: 1337b } + - match: { policies.my_autoscaling_policy.required_capacity.node.memory: 7331b } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.total.storage: 13370b } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.total.memory: 73310b } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.node.storage: 1337b } + - match: { policies.my_autoscaling_policy.deciders.fixed.required_capacity.node.memory: 7331b } + - match: { policies.my_autoscaling_policy.deciders.fixed.reason_summary: "fixed storage [1.3kb] memory [7.1kb] nodes [10]" } + + # test cleanup + - do: + autoscaling.delete_autoscaling_policy: + name: my_autoscaling_policy diff --git a/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_decision.yml b/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_decision.yml deleted file mode 100644 index da5572833043..000000000000 --- a/x-pack/plugin/autoscaling/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/autoscaling/get_autoscaling_decision.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -"Test get empty autoscaling decision": - - do: - autoscaling.get_autoscaling_decision: {} - - - match: { "decisions": [] } - ---- -"Test get fixed autoscaling decision": - - do: - autoscaling.put_autoscaling_policy: - name: my_autoscaling_policy - body: - policy: - deciders: - fixed: - storage: 1337b - memory: 7331b - nodes: 10 - - - match: { "acknowledged": true } - - - do: - autoscaling.get_autoscaling_decision: {} - - - match: { decisions.0.tier: my_autoscaling_policy } - - match: { decisions.0.required_capacity.tier.storage: 13370b } - - match: { decisions.0.required_capacity.tier.memory: 73310b } - - match: { decisions.0.required_capacity.node.storage: 1337b } - - match: { decisions.0.required_capacity.node.memory: 7331b } - - match: { decisions.0.decisions.0.name: fixed } - - match: { decisions.0.decisions.0.required_capacity.tier.storage: 13370b } - - match: { decisions.0.decisions.0.required_capacity.tier.memory: 73310b } - - match: { decisions.0.decisions.0.required_capacity.node.storage: 1337b } - - match: { decisions.0.decisions.0.required_capacity.node.memory: 7331b } - - match: { decisions.0.decisions.0.reason_summary: "fixed storage [1.3kb] memory [7.1kb] nodes [10]" } - - # test cleanup - - do: - autoscaling.delete_autoscaling_policy: - name: my_autoscaling_policy diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index ae36fd15104d..23cdb8958e1a 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -38,21 +38,21 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.autoscaling.action.DeleteAutoscalingPolicyAction; -import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingDecisionAction; +import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.TransportDeleteAutoscalingPolicyAction; -import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingDecisionAction; +import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.TransportPutAutoscalingPolicyAction; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecision; -import org.elasticsearch.xpack.autoscaling.decision.FixedAutoscalingDeciderConfiguration; -import org.elasticsearch.xpack.autoscaling.decision.FixedAutoscalingDeciderService; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderConfiguration; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderService; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisionService; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; +import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderConfiguration; +import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderService; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderConfiguration; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService; import org.elasticsearch.xpack.autoscaling.rest.RestDeleteAutoscalingPolicyHandler; -import org.elasticsearch.xpack.autoscaling.rest.RestGetAutoscalingDecisionHandler; +import org.elasticsearch.xpack.autoscaling.rest.RestGetAutoscalingCapacityHandler; import org.elasticsearch.xpack.autoscaling.rest.RestGetAutoscalingPolicyHandler; import org.elasticsearch.xpack.autoscaling.rest.RestPutAutoscalingPolicyHandler; import org.elasticsearch.xpack.core.XPackPlugin; @@ -136,14 +136,14 @@ public Collection createComponents( IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier ) { - return org.elasticsearch.common.collect.List.of(new AutoscalingDecisionService.Holder(this)); + return org.elasticsearch.common.collect.List.of(new AutoscalingCalculateCapacityService.Holder(this)); } @Override public List> getActions() { if (enabled) { return org.elasticsearch.common.collect.List.of( - new ActionHandler<>(GetAutoscalingDecisionAction.INSTANCE, TransportGetAutoscalingDecisionAction.class), + new ActionHandler<>(GetAutoscalingCapacityAction.INSTANCE, TransportGetAutoscalingCapacityAction.class), new ActionHandler<>(DeleteAutoscalingPolicyAction.INSTANCE, TransportDeleteAutoscalingPolicyAction.class), new ActionHandler<>(GetAutoscalingPolicyAction.INSTANCE, TransportGetAutoscalingPolicyAction.class), new ActionHandler<>(PutAutoscalingPolicyAction.INSTANCE, TransportPutAutoscalingPolicyAction.class) @@ -165,7 +165,7 @@ public List getRestHandlers( ) { if (enabled) { return org.elasticsearch.common.collect.List.of( - new RestGetAutoscalingDecisionHandler(), + new RestGetAutoscalingCapacityHandler(), new RestDeleteAutoscalingPolicyHandler(), new RestGetAutoscalingPolicyHandler(), new RestPutAutoscalingPolicyHandler() @@ -186,7 +186,7 @@ public List getNamedWriteables() { FixedAutoscalingDeciderConfiguration::new ), new NamedWriteableRegistry.Entry( - AutoscalingDecision.Reason.class, + AutoscalingDeciderResult.Reason.class, FixedAutoscalingDeciderConfiguration.NAME, FixedAutoscalingDeciderService.FixedReason::new ) diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingExtension.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingExtension.java index a5d05c6e3897..abdb4db9aa7f 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingExtension.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingExtension.java @@ -6,8 +6,8 @@ package org.elasticsearch.xpack.autoscaling; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderConfiguration; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderService; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderConfiguration; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService; import java.util.Collection; diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityAction.java similarity index 69% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionAction.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityAction.java index af7e2a282fd8..9918c5b6f4ec 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityAction.java @@ -14,23 +14,24 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisions; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResults; import java.io.IOException; +import java.util.Map; import java.util.Objects; import java.util.SortedMap; import java.util.TreeMap; -public class GetAutoscalingDecisionAction extends ActionType { +public class GetAutoscalingCapacityAction extends ActionType { - public static final GetAutoscalingDecisionAction INSTANCE = new GetAutoscalingDecisionAction(); - public static final String NAME = "cluster:admin/autoscaling/get_autoscaling_decision"; + public static final GetAutoscalingCapacityAction INSTANCE = new GetAutoscalingCapacityAction(); + public static final String NAME = "cluster:admin/autoscaling/get_autoscaling_capacity"; - private GetAutoscalingDecisionAction() { + private GetAutoscalingCapacityAction() { super(NAME, Response::new); } - public static class Request extends AcknowledgedRequest { + public static class Request extends AcknowledgedRequest { public Request() { @@ -66,33 +67,33 @@ public int hashCode() { public static class Response extends ActionResponse implements ToXContentObject { - private final SortedMap decisions; + private final SortedMap results; - public Response(final SortedMap decisions) { - this.decisions = Objects.requireNonNull(decisions); + public Response(final SortedMap results) { + this.results = Objects.requireNonNull(results); } public Response(final StreamInput in) throws IOException { super(in); - decisions = new TreeMap<>(in.readMap(StreamInput::readString, AutoscalingDecisions::new)); + results = new TreeMap<>(in.readMap(StreamInput::readString, AutoscalingDeciderResults::new)); } @Override public void writeTo(final StreamOutput out) throws IOException { - out.writeMap(decisions, StreamOutput::writeString, (o, decision) -> decision.writeTo(o)); + out.writeMap(results, StreamOutput::writeString, (o, decision) -> decision.writeTo(o)); } @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { builder.startObject(); { - builder.startArray("decisions"); + builder.startObject("policies"); { - for (final AutoscalingDecisions decision : decisions.values()) { - decision.toXContent(builder, params); + for (Map.Entry entry : results.entrySet()) { + builder.field(entry.getKey(), entry.getValue()); } } - builder.endArray(); + builder.endObject(); } builder.endObject(); return builder; @@ -103,12 +104,12 @@ public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Response response = (Response) o; - return decisions.equals(response.decisions); + return results.equals(response.results); } @Override public int hashCode() { - return Objects.hash(decisions); + return Objects.hash(results); } } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingDecisionAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingCapacityAction.java similarity index 63% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingDecisionAction.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingCapacityAction.java index 0f46a240d5af..8fba3d9f0cf0 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingDecisionAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportGetAutoscalingCapacityAction.java @@ -18,39 +18,39 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisionService; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService; import java.io.IOException; -public class TransportGetAutoscalingDecisionAction extends TransportMasterNodeAction< - GetAutoscalingDecisionAction.Request, - GetAutoscalingDecisionAction.Response> { +public class TransportGetAutoscalingCapacityAction extends TransportMasterNodeAction< + GetAutoscalingCapacityAction.Request, + GetAutoscalingCapacityAction.Response> { - private final AutoscalingDecisionService decisionService; + private final AutoscalingCalculateCapacityService capacityService; private final ClusterInfoService clusterInfoService; @Inject - public TransportGetAutoscalingDecisionAction( + public TransportGetAutoscalingCapacityAction( final TransportService transportService, final ClusterService clusterService, final ThreadPool threadPool, final ActionFilters actionFilters, final IndexNameExpressionResolver indexNameExpressionResolver, - final AutoscalingDecisionService.Holder decisionServiceHolder, + final AutoscalingCalculateCapacityService.Holder capacityServiceHolder, final ClusterInfoService clusterInfoService ) { super( - GetAutoscalingDecisionAction.NAME, + GetAutoscalingCapacityAction.NAME, transportService, clusterService, threadPool, actionFilters, - GetAutoscalingDecisionAction.Request::new, + GetAutoscalingCapacityAction.Request::new, indexNameExpressionResolver ); - this.decisionService = decisionServiceHolder.get(); + this.capacityService = capacityServiceHolder.get(); this.clusterInfoService = clusterInfoService; - assert this.decisionService != null; + assert this.capacityService != null; } @Override @@ -59,21 +59,23 @@ protected String executor() { } @Override - protected GetAutoscalingDecisionAction.Response read(final StreamInput in) throws IOException { - return new GetAutoscalingDecisionAction.Response(in); + protected GetAutoscalingCapacityAction.Response read(final StreamInput in) throws IOException { + return new GetAutoscalingCapacityAction.Response(in); } @Override protected void masterOperation( - final GetAutoscalingDecisionAction.Request request, + final GetAutoscalingCapacityAction.Request request, final ClusterState state, - final ActionListener listener + final ActionListener listener ) { - listener.onResponse(new GetAutoscalingDecisionAction.Response(decisionService.decide(state, clusterInfoService.getClusterInfo()))); + listener.onResponse( + new GetAutoscalingCapacityAction.Response(capacityService.calculate(state, clusterInfoService.getClusterInfo())) + ); } @Override - protected ClusterBlockException checkBlock(final GetAutoscalingDecisionAction.Request request, final ClusterState state) { + protected ClusterBlockException checkBlock(final GetAutoscalingCapacityAction.Request request, final ClusterState state) { return null; } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java similarity index 75% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionService.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java index 665cf7f5d27b..2d45540eb4ae 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.apache.lucene.util.SetOnce; import org.elasticsearch.cluster.ClusterInfo; @@ -28,35 +28,35 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -public class AutoscalingDecisionService { +public class AutoscalingCalculateCapacityService { private Map> deciderByName; - public AutoscalingDecisionService(Set> deciders) { + public AutoscalingCalculateCapacityService(Set> deciders) { assert deciders.size() >= 1; // always have fixed this.deciderByName = deciders.stream().collect(Collectors.toMap(AutoscalingDeciderService::name, Function.identity())); } public static class Holder { private final Autoscaling autoscaling; - private final SetOnce servicesSetOnce = new SetOnce<>(); + private final SetOnce servicesSetOnce = new SetOnce<>(); public Holder(Autoscaling autoscaling) { this.autoscaling = autoscaling; } - public AutoscalingDecisionService get() { + public AutoscalingCalculateCapacityService get() { // defer constructing services until transport action creation time. - AutoscalingDecisionService autoscalingDecisionService = servicesSetOnce.get(); - if (autoscalingDecisionService == null) { - autoscalingDecisionService = new AutoscalingDecisionService(autoscaling.createDeciderServices()); - servicesSetOnce.set(autoscalingDecisionService); + AutoscalingCalculateCapacityService autoscalingCalculateCapacityService = servicesSetOnce.get(); + if (autoscalingCalculateCapacityService == null) { + autoscalingCalculateCapacityService = new AutoscalingCalculateCapacityService(autoscaling.createDeciderServices()); + servicesSetOnce.set(autoscalingCalculateCapacityService); } - return autoscalingDecisionService; + return autoscalingCalculateCapacityService; } } - public SortedMap decide(ClusterState state, ClusterInfo clusterInfo) { + public SortedMap calculate(ClusterState state, ClusterInfo clusterInfo) { AutoscalingMetadata autoscalingMetadata = state.metadata().custom(AutoscalingMetadata.NAME); if (autoscalingMetadata != null) { @@ -64,7 +64,7 @@ public SortedMap decide(ClusterState state, Cluste autoscalingMetadata.policies() .entrySet() .stream() - .map(e -> Tuple.tuple(e.getKey(), getDecision(e.getValue().policy(), state, clusterInfo))) + .map(e -> Tuple.tuple(e.getKey(), calculateForPolicy(e.getValue().policy(), state, clusterInfo))) .collect(Collectors.toMap(Tuple::v1, Tuple::v2)) ); } else { @@ -72,24 +72,27 @@ public SortedMap decide(ClusterState state, Cluste } } - private AutoscalingDecisions getDecision(AutoscalingPolicy policy, ClusterState state, ClusterInfo clusterInfo) { - DecisionAutoscalingDeciderContext context = new DecisionAutoscalingDeciderContext(policy.name(), state, clusterInfo); - SortedMap decisions = policy.deciders() + private AutoscalingDeciderResults calculateForPolicy(AutoscalingPolicy policy, ClusterState state, ClusterInfo clusterInfo) { + DefaultAutoscalingDeciderContext context = new DefaultAutoscalingDeciderContext(policy.name(), state, clusterInfo); + SortedMap results = policy.deciders() .entrySet() .stream() - .map(entry -> Tuple.tuple(entry.getKey(), getDecision(entry.getValue(), context))) + .map(entry -> Tuple.tuple(entry.getKey(), calculateForDecider(entry.getValue(), context))) .collect(Collectors.toMap(Tuple::v1, Tuple::v2, (a, b) -> { throw new UnsupportedOperationException(); }, TreeMap::new)); - return new AutoscalingDecisions(context.tier, context.currentCapacity, decisions); + return new AutoscalingDeciderResults(context.currentCapacity, results); } - private AutoscalingDecision getDecision(T decider, AutoscalingDeciderContext context) { + private AutoscalingDeciderResult calculateForDecider( + T decider, + AutoscalingDeciderContext context + ) { assert deciderByName.containsKey(decider.name()); @SuppressWarnings("unchecked") AutoscalingDeciderService service = (AutoscalingDeciderService) deciderByName.get(decider.name()); return service.scale(decider, context); } - static class DecisionAutoscalingDeciderContext implements AutoscalingDeciderContext { + static class DefaultAutoscalingDeciderContext implements AutoscalingDeciderContext { private final String tier; private final ClusterState state; @@ -97,7 +100,7 @@ static class DecisionAutoscalingDeciderContext implements AutoscalingDeciderCont private final AutoscalingCapacity currentCapacity; private final boolean currentCapacityAccurate; - DecisionAutoscalingDeciderContext(String tier, ClusterState state, ClusterInfo clusterInfo) { + DefaultAutoscalingDeciderContext(String tier, ClusterState state, ClusterInfo clusterInfo) { this.tier = tier; Objects.requireNonNull(state); Objects.requireNonNull(clusterInfo); diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingCapacity.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java similarity index 83% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingCapacity.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java index 6cd9943fc536..303599de1dde 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingCapacity.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacity.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -22,7 +22,7 @@ */ public class AutoscalingCapacity implements ToXContent, Writeable { - private final AutoscalingResources tier; + private final AutoscalingResources total; private final AutoscalingResources node; public static class AutoscalingResources implements ToXContent, Writeable { @@ -139,26 +139,26 @@ public String toString() { public static final AutoscalingCapacity ZERO = new AutoscalingCapacity(AutoscalingResources.ZERO, AutoscalingResources.ZERO); - public AutoscalingCapacity(AutoscalingResources tier, AutoscalingResources node) { - assert tier != null : "Cannot provide capacity without specifying tier level capacity"; + public AutoscalingCapacity(AutoscalingResources total, AutoscalingResources node) { + assert total != null : "Cannot provide capacity without specifying tier level capacity"; assert node == null || node.memory == null // implies - || tier.memory != null : "Cannot provide node memory without tier memory"; + || total.memory != null : "Cannot provide node memory without tier memory"; assert node == null || node.storage == null // implies - || tier.storage != null : "Cannot provide node storage without tier memory"; + || total.storage != null : "Cannot provide node storage without tier memory"; - this.tier = tier; + this.total = total; this.node = node; } public AutoscalingCapacity(StreamInput in) throws IOException { - this.tier = new AutoscalingResources(in); + this.total = new AutoscalingResources(in); this.node = in.readOptionalWriteable(AutoscalingResources::new); } public AutoscalingResources tier() { - return tier; + return total; } public AutoscalingResources node() { @@ -167,7 +167,7 @@ public AutoscalingResources node() { @Override public void writeTo(StreamOutput out) throws IOException { - tier.writeTo(out); + total.writeTo(out); out.writeOptionalWriteable(node); } @@ -177,7 +177,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (node != null) { builder.field("node", node); } - builder.field("tier", tier); + builder.field("total", total); builder.endObject(); return builder; } @@ -188,7 +188,7 @@ public boolean isFragment() { } public static AutoscalingCapacity upperBound(AutoscalingCapacity c1, AutoscalingCapacity c2) { - return new AutoscalingCapacity(AutoscalingResources.max(c1.tier, c2.tier), AutoscalingResources.max(c1.node, c2.node)); + return new AutoscalingCapacity(AutoscalingResources.max(c1.total, c2.total), AutoscalingResources.max(c1.node, c2.node)); } @Override @@ -196,12 +196,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AutoscalingCapacity capacity = (AutoscalingCapacity) o; - return tier.equals(capacity.tier) && Objects.equals(node, capacity.node); + return total.equals(capacity.total) && Objects.equals(node, capacity.node); } @Override public int hashCode() { - return Objects.hash(tier, node); + return Objects.hash(total, node); } @Override @@ -214,27 +214,27 @@ public static Builder builder() { } public static class Builder { - private AutoscalingResources tier; + private AutoscalingResources total; private AutoscalingResources node; public Builder() {} public Builder capacity(AutoscalingCapacity capacity) { - this.tier = capacity.tier; + this.total = capacity.total; this.node = capacity.node; return this; } - public Builder tier(Long storage, Long memory) { - return tier(byteSizeValue(storage), byteSizeValue(memory)); + public Builder total(Long storage, Long memory) { + return total(byteSizeValue(storage), byteSizeValue(memory)); } - public Builder tier(ByteSizeValue storage, ByteSizeValue memory) { - return tier(new AutoscalingResources(storage, memory)); + public Builder total(ByteSizeValue storage, ByteSizeValue memory) { + return total(new AutoscalingResources(storage, memory)); } - public Builder tier(AutoscalingResources tier) { - this.tier = tier; + public Builder total(AutoscalingResources tier) { + this.total = tier; return this; } @@ -252,7 +252,7 @@ public Builder node(AutoscalingResources node) { } public AutoscalingCapacity build() { - return new AutoscalingCapacity(tier, node); + return new AutoscalingCapacity(total, node); } private ByteSizeValue byteSizeValue(Long memory) { diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderConfiguration.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderConfiguration.java similarity index 92% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderConfiguration.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderConfiguration.java index 4f5b6a71b4f4..a4e9123cea4d 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderConfiguration.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderConfiguration.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.xcontent.ToXContentObject; diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderContext.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderContext.java similarity index 77% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderContext.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderContext.java index aaaf61f60038..267a602d9bc9 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderContext.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderContext.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.cluster.ClusterState; @@ -13,7 +13,7 @@ public interface AutoscalingDeciderContext { /** * Return current capacity of tier. Can be null if the capacity of some nodes is unavailable. If a decider relies on this value and - * gets a null current capacity, it should return a decision with a null requiredCapacity (undecided). + * gets a null current capacity, it should return a result with a null requiredCapacity (undecided). */ AutoscalingCapacity currentCapacity(); } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecision.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResult.java similarity index 77% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecision.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResult.java index 509f3416eb21..8b35864b544f 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecision.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResult.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamInput; @@ -17,9 +17,9 @@ import java.util.Objects; /** - * Represents an autoscaling decision from a single decider + * Represents an autoscaling result from a single decider */ -public class AutoscalingDecision implements ToXContent, Writeable { +public class AutoscalingDeciderResult implements ToXContent, Writeable { private final AutoscalingCapacity requiredCapacity; private final Reason reason; @@ -29,16 +29,16 @@ public interface Reason extends ToXContent, NamedWriteable { } /** - * Create a new decision with required capacity. - * @param requiredCapacity required capacity or null if no decision can be made due to insufficient information. - * @param reason details/data behind the decision + * Create a new result with required capacity. + * @param requiredCapacity required capacity or null if no capacity can be calculated due to insufficient information. + * @param reason details/data behind the calculation */ - public AutoscalingDecision(AutoscalingCapacity requiredCapacity, Reason reason) { + public AutoscalingDeciderResult(AutoscalingCapacity requiredCapacity, Reason reason) { this.requiredCapacity = requiredCapacity; this.reason = reason; } - public AutoscalingDecision(StreamInput in) throws IOException { + public AutoscalingDeciderResult(StreamInput in) throws IOException { this.requiredCapacity = in.readOptionalWriteable(AutoscalingCapacity::new); this.reason = in.readOptionalNamedWriteable(Reason.class); } @@ -75,7 +75,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - AutoscalingDecision that = (AutoscalingDecision) o; + AutoscalingDeciderResult that = (AutoscalingDeciderResult) o; return Objects.equals(requiredCapacity, that.requiredCapacity) && Objects.equals(reason, that.reason); } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisions.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResults.java similarity index 50% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisions.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResults.java index 93d4eb6fba6d..ea9b9a131fc9 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisions.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResults.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -20,79 +20,69 @@ import java.util.TreeMap; /** - * Represents a collection of individual autoscaling decisions that can be aggregated into a single autoscaling decision for a tier + * Represents a collection of individual autoscaling decider results that can be aggregated into a single autoscaling capacity for a + * policy */ -public class AutoscalingDecisions implements ToXContent, Writeable { +public class AutoscalingDeciderResults implements ToXContent, Writeable { - private final String tier; private final AutoscalingCapacity currentCapacity; - private final SortedMap decisions; + private final SortedMap results; /** - * Return map of decisions, keyed by decider name. + * Return map of results, keyed by decider name. */ - public Map decisions() { - return decisions; + public Map results() { + return results; } - public AutoscalingDecisions( - final String tier, - final AutoscalingCapacity currentCapacity, - final SortedMap decisions - ) { - Objects.requireNonNull(tier); + public AutoscalingDeciderResults(final AutoscalingCapacity currentCapacity, final SortedMap results) { Objects.requireNonNull(currentCapacity); - this.tier = tier; this.currentCapacity = currentCapacity; - Objects.requireNonNull(decisions); - if (decisions.isEmpty()) { - throw new IllegalArgumentException("decisions can not be empty"); + Objects.requireNonNull(results); + if (results.isEmpty()) { + throw new IllegalArgumentException("results can not be empty"); } - this.decisions = decisions; + this.results = results; } - public AutoscalingDecisions(final StreamInput in) throws IOException { - this.tier = in.readString(); + public AutoscalingDeciderResults(final StreamInput in) throws IOException { this.currentCapacity = new AutoscalingCapacity(in); - this.decisions = new TreeMap<>(in.readMap(StreamInput::readString, AutoscalingDecision::new)); + this.results = new TreeMap<>(in.readMap(StreamInput::readString, AutoscalingDeciderResult::new)); } @Override public void writeTo(final StreamOutput out) throws IOException { - out.writeString(tier); currentCapacity.writeTo(out); - out.writeMap(decisions, StreamOutput::writeString, (output, decision) -> decision.writeTo(output)); + out.writeMap(results, StreamOutput::writeString, (output, result) -> result.writeTo(output)); } @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { builder.startObject(); - builder.field("tier", tier); AutoscalingCapacity requiredCapacity = requiredCapacity(); if (requiredCapacity != null) { builder.field("required_capacity", requiredCapacity); } builder.field("current_capacity", currentCapacity); - builder.startArray("decisions"); - for (Map.Entry entry : decisions.entrySet()) { - builder.startObject(); - builder.field("name", entry.getKey()); + builder.startObject("deciders"); + for (Map.Entry entry : results.entrySet()) { + builder.startObject(entry.getKey()); entry.getValue().toXContent(builder, params); builder.endObject(); } - builder.endArray(); + builder.endObject(); builder.endObject(); return builder; } public AutoscalingCapacity requiredCapacity() { - if (decisions.values().stream().map(AutoscalingDecision::requiredCapacity).anyMatch(Objects::isNull)) { - // any undetermined decider cancels out any decision making. + if (results.values().stream().map(AutoscalingDeciderResult::requiredCapacity).anyMatch(Objects::isNull)) { + // any undetermined decider cancels out all required capacities return null; } - Optional result = decisions.values() + Optional result = results.values() .stream() - .map(AutoscalingDecision::requiredCapacity) + .map(AutoscalingDeciderResult::requiredCapacity) .reduce(AutoscalingCapacity::upperBound); assert result.isPresent(); return result.get(); @@ -102,20 +92,16 @@ public AutoscalingCapacity currentCapacity() { return currentCapacity; } - public String tier() { - return tier; - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - AutoscalingDecisions that = (AutoscalingDecisions) o; - return tier.equals(that.tier) && currentCapacity.equals(that.currentCapacity) && decisions.equals(that.decisions); + AutoscalingDeciderResults that = (AutoscalingDeciderResults) o; + return currentCapacity.equals(that.currentCapacity) && results.equals(that.results); } @Override public int hashCode() { - return Objects.hash(tier, currentCapacity, decisions); + return Objects.hash(currentCapacity, results); } } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderService.java similarity index 78% rename from x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderService.java rename to x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderService.java index 9928b8b4114e..36e89cf82423 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderService.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; /** * A service to decide for a specific decider. @@ -22,8 +22,8 @@ public interface AutoscalingDeciderService routes() { - return org.elasticsearch.common.collect.List.of(new Route(GET, "/_autoscaling/decision")); + return org.elasticsearch.common.collect.List.of(new Route(GET, "/_autoscaling/capacity")); } @Override public String getName() { - return "get_autoscaling_decision"; + return "get_autoscaling_capacity"; } @Override protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { - final GetAutoscalingDecisionAction.Request request = new GetAutoscalingDecisionAction.Request(); - return channel -> client.execute(GetAutoscalingDecisionAction.INSTANCE, request, new RestToXContentListener<>(channel)); + final GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request(); + return channel -> client.execute(GetAutoscalingCapacityAction.INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/AutoscalingTestCase.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/AutoscalingTestCase.java index 26108b77da00..26c6f2990029 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/AutoscalingTestCase.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/AutoscalingTestCase.java @@ -12,12 +12,12 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingCapacity; -import org.elasticsearch.xpack.autoscaling.decision.FixedAutoscalingDeciderConfiguration; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDeciderConfiguration; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecision; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisions; -import org.elasticsearch.xpack.autoscaling.decision.FixedAutoscalingDeciderService; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCapacity; +import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderConfiguration; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderConfiguration; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResults; +import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderService; import org.elasticsearch.xpack.autoscaling.policy.AutoscalingPolicy; import org.elasticsearch.xpack.autoscaling.policy.AutoscalingPolicyMetadata; @@ -30,24 +30,24 @@ public abstract class AutoscalingTestCase extends ESTestCase { - public static AutoscalingDecision randomAutoscalingDecision() { + public static AutoscalingDeciderResult randomAutoscalingDeciderResult() { AutoscalingCapacity capacity = randomNullableAutoscalingCapacity(); - return randomAutoscalingDecisionWithCapacity(capacity); + return randomAutoscalingDeciderResultWithCapacity(capacity); } - protected static AutoscalingDecision randomAutoscalingDecisionWithCapacity(AutoscalingCapacity capacity) { - return new AutoscalingDecision( + protected static AutoscalingDeciderResult randomAutoscalingDeciderResultWithCapacity(AutoscalingCapacity capacity) { + return new AutoscalingDeciderResult( capacity, new FixedAutoscalingDeciderService.FixedReason(randomNullableByteSizeValue(), randomNullableByteSizeValue(), randomInt(1000)) ); } - public static AutoscalingDecisions randomAutoscalingDecisions() { - final SortedMap decisions = IntStream.range(0, randomIntBetween(1, 10)) - .mapToObj(i -> Tuple.tuple(Integer.toString(i), randomAutoscalingDecision())) + public static AutoscalingDeciderResults randomAutoscalingDeciderResults() { + final SortedMap results = IntStream.range(0, randomIntBetween(1, 10)) + .mapToObj(i -> Tuple.tuple(Integer.toString(i), randomAutoscalingDeciderResult())) .collect(Collectors.toMap(Tuple::v1, Tuple::v2, (a, b) -> { throw new IllegalStateException(); }, TreeMap::new)); AutoscalingCapacity capacity = new AutoscalingCapacity(randomAutoscalingResources(), randomAutoscalingResources()); - return new AutoscalingDecisions(randomAlphaOfLength(10), capacity, decisions); + return new AutoscalingDeciderResults(capacity, results); } public static AutoscalingCapacity randomAutoscalingCapacity() { diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionRequestWireSerializingTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionRequestWireSerializingTests.java similarity index 60% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionRequestWireSerializingTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionRequestWireSerializingTests.java index cae49c316f6e..4a565f5c0fc4 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionRequestWireSerializingTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionRequestWireSerializingTests.java @@ -9,17 +9,17 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; -public class GetAutoscalingDecisionActionRequestWireSerializingTests extends AbstractWireSerializingTestCase< - GetAutoscalingDecisionAction.Request> { +public class GetAutoscalingCapacityActionRequestWireSerializingTests extends AbstractWireSerializingTestCase< + GetAutoscalingCapacityAction.Request> { @Override - protected Writeable.Reader instanceReader() { - return GetAutoscalingDecisionAction.Request::new; + protected Writeable.Reader instanceReader() { + return GetAutoscalingCapacityAction.Request::new; } @Override - protected GetAutoscalingDecisionAction.Request createTestInstance() { - return new GetAutoscalingDecisionAction.Request(); + protected GetAutoscalingCapacityAction.Request createTestInstance() { + return new GetAutoscalingCapacityAction.Request(); } } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionResponseTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionResponseTests.java similarity index 73% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionResponseTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionResponseTests.java index 0c8c06977d89..0d314f8de656 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionResponseTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionResponseTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisions; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResults; import org.hamcrest.Matchers; import java.io.IOException; @@ -22,18 +22,18 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -public class GetAutoscalingDecisionActionResponseTests extends AutoscalingTestCase { +public class GetAutoscalingCapacityActionResponseTests extends AutoscalingTestCase { public void testToXContent() throws IOException { Set policyNames = IntStream.range(0, randomIntBetween(1, 10)) .mapToObj(i -> randomAlphaOfLength(10)) .collect(Collectors.toSet()); - SortedMap decisions = new TreeMap<>( - policyNames.stream().map(s -> Tuple.tuple(s, randomAutoscalingDecisions())).collect(Collectors.toMap(Tuple::v1, Tuple::v2)) + SortedMap results = new TreeMap<>( + policyNames.stream().map(s -> Tuple.tuple(s, randomAutoscalingDeciderResults())).collect(Collectors.toMap(Tuple::v1, Tuple::v2)) ); - GetAutoscalingDecisionAction.Response response = new GetAutoscalingDecisionAction.Response(decisions); + GetAutoscalingCapacityAction.Response response = new GetAutoscalingCapacityAction.Response(results); XContentType xContentType = randomFrom(XContentType.values()); XContentBuilder builder = XContentBuilder.builder(xContentType.xContent()); @@ -42,11 +42,11 @@ public void testToXContent() throws IOException { XContentBuilder expected = XContentBuilder.builder(xContentType.xContent()); expected.startObject(); - expected.startArray("decisions"); - for (Map.Entry entry : decisions.entrySet()) { - entry.getValue().toXContent(expected, null); + expected.startObject("policies"); + for (Map.Entry entry : results.entrySet()) { + expected.field(entry.getKey(), entry.getValue()); } - expected.endArray(); + expected.endObject(); expected.endObject(); BytesReference expectedBytes = BytesReference.bytes(expected); assertThat(responseBytes, Matchers.equalTo(expectedBytes)); diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionResponseWireSerializingTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionResponseWireSerializingTests.java similarity index 61% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionResponseWireSerializingTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionResponseWireSerializingTests.java index d0bf05afba6d..e63a0bccfbf7 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingDecisionActionResponseWireSerializingTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityActionResponseWireSerializingTests.java @@ -10,16 +10,16 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; -import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisions; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResults; import java.util.Collections; import java.util.SortedMap; import java.util.TreeMap; -import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingDecisions; +import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingDeciderResults; -public class GetAutoscalingDecisionActionResponseWireSerializingTests extends AbstractWireSerializingTestCase< - GetAutoscalingDecisionAction.Response> { +public class GetAutoscalingCapacityActionResponseWireSerializingTests extends AbstractWireSerializingTestCase< + GetAutoscalingCapacityAction.Response> { @Override protected NamedWriteableRegistry getNamedWriteableRegistry() { @@ -27,18 +27,18 @@ protected NamedWriteableRegistry getNamedWriteableRegistry() { } @Override - protected Writeable.Reader instanceReader() { - return GetAutoscalingDecisionAction.Response::new; + protected Writeable.Reader instanceReader() { + return GetAutoscalingCapacityAction.Response::new; } @Override - protected GetAutoscalingDecisionAction.Response createTestInstance() { + protected GetAutoscalingCapacityAction.Response createTestInstance() { final int numberOfPolicies = randomIntBetween(1, 8); - final SortedMap decisions = new TreeMap<>(); + final SortedMap results = new TreeMap<>(); for (int i = 0; i < numberOfPolicies; i++) { - decisions.put(randomAlphaOfLength(8), randomAutoscalingDecisions()); + results.put(randomAlphaOfLength(8), randomAutoscalingDeciderResults()); } - return new GetAutoscalingDecisionAction.Response(Collections.unmodifiableSortedMap(decisions)); + return new GetAutoscalingCapacityAction.Response(Collections.unmodifiableSortedMap(results)); } } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingCapacityWireSerializationTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacityWireSerializationTests.java similarity index 96% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingCapacityWireSerializationTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacityWireSerializationTests.java index bf0740493f8e..1b68c6f38082 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingCapacityWireSerializationTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCapacityWireSerializationTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.ByteSizeValue; @@ -32,7 +32,7 @@ protected AutoscalingCapacity mutateInstance(AutoscalingCapacity instance) throw // mutate tier boolean hasBothStorageAndMemory = instance.tier().memory() != null && instance.tier().storage() != null; if (randomBoolean()) { - builder.tier( + builder.total( randomByteSize( hasBothStorageAndMemory && (instance.node() == null || instance.node().storage() == null), instance.tier().storage() @@ -40,7 +40,7 @@ protected AutoscalingCapacity mutateInstance(AutoscalingCapacity instance) throw instance.tier().memory() ); } else { - builder.tier( + builder.total( instance.tier().storage(), randomByteSize( hasBothStorageAndMemory && (instance.node() == null || instance.node().memory() == null), diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultServiceTests.java similarity index 77% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionServiceTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultServiceTests.java index 0de5a0b19abd..aa92ac1494e5 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultServiceTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterInfo; @@ -31,9 +31,9 @@ import static org.hamcrest.Matchers.equalTo; -public class AutoscalingDecisionServiceTests extends AutoscalingTestCase { - public void testMultiplePoliciesFixedDecision() { - AutoscalingDecisionService service = new AutoscalingDecisionService( +public class AutoscalingDeciderResultServiceTests extends AutoscalingTestCase { + public void testMultiplePoliciesFixedCapacity() { + AutoscalingCalculateCapacityService service = new AutoscalingCalculateCapacityService( org.elasticsearch.common.collect.Set.of(new FixedAutoscalingDeciderService()) ); Set policyNames = IntStream.range(0, randomIntBetween(1, 10)) @@ -48,32 +48,31 @@ public void testMultiplePoliciesFixedDecision() { ClusterState state = ClusterState.builder(ClusterName.DEFAULT) .metadata(Metadata.builder().putCustom(AutoscalingMetadata.NAME, new AutoscalingMetadata(policies))) .build(); - SortedMap decisions = service.decide(state, new ClusterInfo() { + SortedMap resultsMap = service.calculate(state, new ClusterInfo() { }); - assertThat(decisions.keySet(), equalTo(policyNames)); - for (Map.Entry entry : decisions.entrySet()) { - AutoscalingDecisions decision = entry.getValue(); - assertThat(decision.tier(), equalTo(entry.getKey())); - SortedMap deciders = policies.get(decision.tier()).policy().deciders(); + assertThat(resultsMap.keySet(), equalTo(policyNames)); + for (Map.Entry entry : resultsMap.entrySet()) { + AutoscalingDeciderResults results = entry.getValue(); + SortedMap deciders = policies.get(entry.getKey()).policy().deciders(); assertThat(deciders.size(), equalTo(1)); FixedAutoscalingDeciderConfiguration configuration = (FixedAutoscalingDeciderConfiguration) deciders.values().iterator().next(); - AutoscalingCapacity requiredCapacity = calculateFixedDecisionCapacity(configuration); - assertThat(decision.requiredCapacity(), equalTo(requiredCapacity)); - assertThat(decision.decisions().size(), equalTo(1)); - AutoscalingDecision deciderDecision = decision.decisions().get(deciders.firstKey()); - assertNotNull(deciderDecision); - assertThat(deciderDecision.requiredCapacity(), equalTo(requiredCapacity)); + AutoscalingCapacity requiredCapacity = calculateFixedDeciderCapacity(configuration); + assertThat(results.requiredCapacity(), equalTo(requiredCapacity)); + assertThat(results.results().size(), equalTo(1)); + AutoscalingDeciderResult deciderResult = results.results().get(deciders.firstKey()); + assertNotNull(deciderResult); + assertThat(deciderResult.requiredCapacity(), equalTo(requiredCapacity)); ByteSizeValue storage = configuration.storage(); ByteSizeValue memory = configuration.memory(); int nodes = configuration.nodes(); - assertThat(deciderDecision.reason(), equalTo(new FixedAutoscalingDeciderService.FixedReason(storage, memory, nodes))); + assertThat(deciderResult.reason(), equalTo(new FixedAutoscalingDeciderService.FixedReason(storage, memory, nodes))); assertThat( - deciderDecision.reason().summary(), + deciderResult.reason().summary(), equalTo("fixed storage [" + storage + "] memory [" + memory + "] nodes [" + nodes + "]") ); // there is no nodes in any tier. - assertThat(decision.currentCapacity(), equalTo(AutoscalingCapacity.ZERO)); + assertThat(results.currentCapacity(), equalTo(AutoscalingCapacity.ZERO)); } } @@ -90,7 +89,7 @@ private SortedMap randomFixedDeciders() ); } - private AutoscalingCapacity calculateFixedDecisionCapacity(FixedAutoscalingDeciderConfiguration configuration) { + private AutoscalingCapacity calculateFixedDeciderCapacity(FixedAutoscalingDeciderConfiguration configuration) { ByteSizeValue totalStorage = configuration.storage() != null ? new ByteSizeValue(configuration.storage().getBytes() * configuration.nodes()) : null; @@ -112,8 +111,8 @@ public void testContext() { String tier = randomAlphaOfLength(5); ClusterState state = ClusterState.builder(ClusterName.DEFAULT).build(); ClusterInfo info = ClusterInfo.EMPTY; - AutoscalingDecisionService.DecisionAutoscalingDeciderContext context = - new AutoscalingDecisionService.DecisionAutoscalingDeciderContext(tier, state, info); + AutoscalingCalculateCapacityService.DefaultAutoscalingDeciderContext context = + new AutoscalingCalculateCapacityService.DefaultAutoscalingDeciderContext(tier, state, info); assertSame(state, context.state()); // there is no nodes in any tier. @@ -123,7 +122,7 @@ public void testContext() { state = ClusterState.builder(ClusterName.DEFAULT) .nodes(DiscoveryNodes.builder().add(new DiscoveryNode("nodeId", buildNewFakeTransportAddress(), Version.CURRENT))) .build(); - context = new AutoscalingDecisionService.DecisionAutoscalingDeciderContext(tier, state, info); + context = new AutoscalingCalculateCapacityService.DefaultAutoscalingDeciderContext(tier, state, info); assertNull(context.currentCapacity()); @@ -146,7 +145,7 @@ public void testContext() { } state = ClusterState.builder(ClusterName.DEFAULT).nodes(nodes).build(); info = new ClusterInfo(leastUsages.build(), mostUsages.build(), null, null, null); - context = new AutoscalingDecisionService.DecisionAutoscalingDeciderContext(tier, state, info); + context = new AutoscalingCalculateCapacityService.DefaultAutoscalingDeciderContext(tier, state, info); AutoscalingCapacity capacity = context.currentCapacity(); assertThat(capacity.node().storage(), equalTo(new ByteSizeValue(maxTotal))); diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionWireSerializingTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultWireSerializingTests.java similarity index 61% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionWireSerializingTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultWireSerializingTests.java index db8594a91d89..7e76680444b6 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionWireSerializingTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultWireSerializingTests.java @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; -public class AutoscalingDecisionWireSerializingTests extends AbstractWireSerializingTestCase { +public class AutoscalingDeciderResultWireSerializingTests extends AbstractWireSerializingTestCase { @Override protected NamedWriteableRegistry getNamedWriteableRegistry() { @@ -19,13 +19,13 @@ protected NamedWriteableRegistry getNamedWriteableRegistry() { } @Override - protected Writeable.Reader instanceReader() { - return AutoscalingDecision::new; + protected Writeable.Reader instanceReader() { + return AutoscalingDeciderResult::new; } @Override - protected AutoscalingDecision createTestInstance() { - return AutoscalingTestCase.randomAutoscalingDecision(); + protected AutoscalingDeciderResult createTestInstance() { + return AutoscalingTestCase.randomAutoscalingDeciderResult(); } } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionsTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultsTests.java similarity index 80% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionsTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultsTests.java index ca80982b0143..dc6128332b74 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionsTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultsTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.Randomness; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; @@ -21,24 +21,23 @@ import static org.hamcrest.Matchers.equalTo; -public class AutoscalingDecisionsTests extends AutoscalingTestCase { +public class AutoscalingDeciderResultsTests extends AutoscalingTestCase { - public void testAutoscalingDecisionsRejectsEmptyDecisions() { + public void testAutoscalingDeciderResultsRejectsEmptyResults() { final IllegalArgumentException e = expectThrows( IllegalArgumentException.class, - () -> new AutoscalingDecisions( - randomAlphaOfLength(10), + () -> new AutoscalingDeciderResults( new AutoscalingCapacity(randomAutoscalingResources(), randomAutoscalingResources()), new TreeMap<>() ) ); - assertThat(e.getMessage(), equalTo("decisions can not be empty")); + assertThat(e.getMessage(), equalTo("results can not be empty")); } public void testRequiredCapacity() { AutoscalingCapacity single = randomBoolean() ? randomAutoscalingCapacity() : null; verifyRequiredCapacity(single, single); - // any undecided decider nulls out any decision making + // any undecided decider nulls out any required capacities verifyRequiredCapacity(null, single, null); verifyRequiredCapacity(null, null, single); @@ -73,7 +72,7 @@ private void verifySingleMetricLarger( autoscalingCapacities.add(larger); Randomness.shuffle(autoscalingCapacities); AutoscalingCapacity.Builder expectedBuilder = AutoscalingCapacity.builder() - .tier(expectedStorage.tier().storage(), expectedMemory.tier().memory()); + .total(expectedStorage.tier().storage(), expectedMemory.tier().memory()); if (node) { expectedBuilder.node(expectedStorage.node().storage(), expectedMemory.node().memory()); } @@ -82,8 +81,8 @@ private void verifySingleMetricLarger( private void verifyRequiredCapacity(AutoscalingCapacity expected, AutoscalingCapacity... capacities) { AtomicInteger uniqueGenerator = new AtomicInteger(); - SortedMap decisions = Arrays.stream(capacities) - .map(AutoscalingDecisionsTests::randomAutoscalingDecisionWithCapacity) + SortedMap results = Arrays.stream(capacities) + .map(AutoscalingDeciderResultsTests::randomAutoscalingDeciderResultWithCapacity) .collect( Collectors.toMap( k -> randomAlphaOfLength(10) + "-" + uniqueGenerator.incrementAndGet(), @@ -92,15 +91,12 @@ private void verifyRequiredCapacity(AutoscalingCapacity expected, AutoscalingCap TreeMap::new ) ); - assertThat( - new AutoscalingDecisions(randomAlphaOfLength(10), randomAutoscalingCapacity(), decisions).requiredCapacity(), - equalTo(expected) - ); + assertThat(new AutoscalingDeciderResults(randomAutoscalingCapacity(), results).requiredCapacity(), equalTo(expected)); } private AutoscalingCapacity randomCapacity(boolean node, boolean storage, boolean memory, int lower, int upper) { AutoscalingCapacity.Builder builder = AutoscalingCapacity.builder(); - builder.tier(storage ? randomLongBetween(lower, upper) : null, memory ? randomLongBetween(lower, upper) : null); + builder.total(storage ? randomLongBetween(lower, upper) : null, memory ? randomLongBetween(lower, upper) : null); if (node) { builder.node(storage ? randomLongBetween(lower, upper) : null, memory ? randomLongBetween(lower, upper) : null); } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionsWireSerializingTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultsWireSerializingTests.java similarity index 61% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionsWireSerializingTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultsWireSerializingTests.java index e3e6664b4c8d..116ca8f4fdcf 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/AutoscalingDecisionsWireSerializingTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingDeciderResultsWireSerializingTests.java @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; -public class AutoscalingDecisionsWireSerializingTests extends AbstractWireSerializingTestCase { +public class AutoscalingDeciderResultsWireSerializingTests extends AbstractWireSerializingTestCase { @Override protected NamedWriteableRegistry getNamedWriteableRegistry() { @@ -19,13 +19,13 @@ protected NamedWriteableRegistry getNamedWriteableRegistry() { } @Override - protected Writeable.Reader instanceReader() { - return AutoscalingDecisions::new; + protected Writeable.Reader instanceReader() { + return AutoscalingDeciderResults::new; } @Override - protected AutoscalingDecisions createTestInstance() { - return AutoscalingTestCase.randomAutoscalingDecisions(); + protected AutoscalingDeciderResults createTestInstance() { + return AutoscalingTestCase.randomAutoscalingDeciderResults(); } } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/FixedAutoscalingDeciderConfigurationSerializationTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderConfigurationSerializationTests.java similarity index 97% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/FixedAutoscalingDeciderConfigurationSerializationTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderConfigurationSerializationTests.java index 8625222a2302..c0cd4035c4fa 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/FixedAutoscalingDeciderConfigurationSerializationTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderConfigurationSerializationTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.ByteSizeValue; diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/FixedAutoscalingDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderServiceTests.java similarity index 84% rename from x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/FixedAutoscalingDeciderServiceTests.java rename to x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderServiceTests.java index 96cc14bdbceb..7e1f781832d3 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/decision/FixedAutoscalingDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/FixedAutoscalingDeciderServiceTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.autoscaling.decision; +package org.elasticsearch.xpack.autoscaling.capacity; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; @@ -23,20 +23,20 @@ public void testScale() { ByteSizeValue memory = storage != null ? randomNullableByteSizeValue() : randomByteSizeValue(); verify( new FixedAutoscalingDeciderConfiguration(storage, memory, null), - AutoscalingCapacity.builder().node(storage, memory).tier(storage, memory).build() + AutoscalingCapacity.builder().node(storage, memory).total(storage, memory).build() ); int nodes = randomIntBetween(1, 1000); verify( new FixedAutoscalingDeciderConfiguration(storage, memory, nodes), - AutoscalingCapacity.builder().node(storage, memory).tier(multiply(storage, nodes), multiply(memory, nodes)).build() + AutoscalingCapacity.builder().node(storage, memory).total(multiply(storage, nodes), multiply(memory, nodes)).build() ); } private void verify(FixedAutoscalingDeciderConfiguration configuration, AutoscalingCapacity expected) { FixedAutoscalingDeciderService service = new FixedAutoscalingDeciderService(); - AutoscalingDecision decision = service.scale(configuration, null); - assertThat(decision.requiredCapacity(), Matchers.equalTo(expected)); + AutoscalingDeciderResult result = service.scale(configuration, null); + assertThat(result.requiredCapacity(), Matchers.equalTo(expected)); } private ByteSizeValue multiply(ByteSizeValue bytes, int nodes) { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/autoscaling.get_autoscaling_capacity.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/autoscaling.get_autoscaling_capacity.json new file mode 100644 index 000000000000..8e5654025b58 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/autoscaling.get_autoscaling_capacity.json @@ -0,0 +1,19 @@ +{ + "autoscaling.get_autoscaling_capacity":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-get-autoscaling-capacity.html", + "description": "Gets the current autoscaling capacity based on the configured autoscaling policy." + }, + "stability":"experimental", + "url":{ + "paths":[ + { + "path":"/_autoscaling/capacity", + "methods":[ + "GET" + ] + } + ] + } + } +} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/autoscaling.get_autoscaling_decision.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/autoscaling.get_autoscaling_decision.json deleted file mode 100644 index 26ce055aad35..000000000000 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/autoscaling.get_autoscaling_decision.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "autoscaling.get_autoscaling_decision":{ - "documentation":{ - "url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-get-autoscaling-decision.html", - "description": "Gets the current autoscaling decision based on the configured autoscaling policy, indicating whether or not autoscaling is needed." - }, - "stability":"experimental", - "url":{ - "paths":[ - { - "path":"/_autoscaling/decision", - "methods":[ - "GET" - ] - } - ] - } - } -}