/** * Executes all wrapped commands on a given {@link RoutingAllocation} * @param allocation {@link RoutingAllocation} to apply this command to * @throws org.elasticsearch.ElasticsearchException if something happens during execution */ public RoutingExplanations execute(RoutingAllocation allocation, boolean explain) { RoutingExplanations explanations = new RoutingExplanations(); for (AllocationCommand command : commands) { explanations.add(command.execute(allocation, explain)); } return explanations; }
@Override public void readFrom(StreamInput in) throws IOException { if (in.getVersion().onOrAfter(Version.V_6_4_0)) { super.readFrom(in); state = ClusterState.readFrom(in, null); explanations = RoutingExplanations.readFrom(in); } else { state = ClusterState.readFrom(in, null); acknowledged = in.readBoolean(); explanations = RoutingExplanations.readFrom(in); } }
@Override public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().onOrAfter(Version.V_6_4_0)) { super.writeTo(out); state.writeTo(out); RoutingExplanations.writeTo(explanations, out); } else { if (out.getVersion().onOrAfter(Version.V_6_3_0)) { state.writeTo(out); } else { ClusterModule.filterCustomsForPre63Clients(state).writeTo(out); } out.writeBoolean(acknowledged); RoutingExplanations.writeTo(explanations, out); } }
@Override public void onAckTimeout() { listener.onResponse(new ClusterRerouteResponse(false, clusterStateToSend, new RoutingExplanations())); }
@Override protected void addCustomFields(XContentBuilder builder, Params params) throws IOException { builder.startObject("state"); state.toXContent(builder, params); builder.endObject(); if (params.paramAsBoolean("explain", false)) { explanations.toXContent(builder, ToXContent.EMPTY_PARAMS); } } }
/** * Provides feedback from commands with a YES decision that should be displayed to the user after the command has been applied */ public List<String> getYesDecisionMessages() { return explanations().stream() .filter(explanation -> explanation.decisions().type().equals(Decision.Type.YES)) .map(explanation -> explanation.command().getMessage()) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); }
@Override protected void masterOperation(final ClusterRerouteRequest request, final ClusterState state, final ActionListener<ClusterRerouteResponse> listener) { ActionListener<ClusterRerouteResponse> logWrapper = ActionListener.wrap( response -> { if (request.dryRun() == false) { response.getExplanations().getYesDecisionMessages().forEach(logger::info); } listener.onResponse(response); }, listener::onFailure ); clusterService.submitStateUpdateTask("cluster_reroute (api)", new ClusterRerouteResponseAckedClusterStateUpdateTask(logger, allocationService, request, logWrapper)); }
@Override public void onAckTimeout() { listener.onResponse(new ClusterRerouteResponse(false, clusterStateToSend, new RoutingExplanations())); }
@Override protected void addCustomFields(XContentBuilder builder, Params params) throws IOException { builder.startObject("state"); state.toXContent(builder, params); builder.endObject(); if (params.paramAsBoolean("explain", false)) { explanations.toXContent(builder, ToXContent.EMPTY_PARAMS); } } }
/** * Provides feedback from commands with a YES decision that should be displayed to the user after the command has been applied */ public List<String> getYesDecisionMessages() { return explanations().stream() .filter(explanation -> explanation.decisions().type().equals(Decision.Type.YES)) .map(explanation -> explanation.command().getMessage()) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); }
@Override protected void masterOperation(final ClusterRerouteRequest request, final ClusterState state, final ActionListener<ClusterRerouteResponse> listener) { ActionListener<ClusterRerouteResponse> logWrapper = ActionListener.wrap( response -> { if (request.dryRun() == false) { response.getExplanations().getYesDecisionMessages().forEach(logger::info); } listener.onResponse(response); }, listener::onFailure ); clusterService.submitStateUpdateTask("cluster_reroute (api)", new ClusterRerouteResponseAckedClusterStateUpdateTask(logger, allocationService, request, logWrapper)); }
/** * Read in a RoutingExplanations object */ public static RoutingExplanations readFrom(StreamInput in) throws IOException { int exCount = in.readVInt(); RoutingExplanations exp = new RoutingExplanations(); for (int i = 0; i < exCount; i++) { RerouteExplanation explanation = RerouteExplanation.readFrom(in); exp.add(explanation); } return exp; }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); state = ClusterState.readFrom(in, null); readAcknowledged(in); explanations = RoutingExplanations.readFrom(in); }
@Override public void onAckTimeout() { listener.onResponse(new ClusterRerouteResponse(false, clusterStateToSend, new RoutingExplanations())); }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); state.writeTo(out); writeAcknowledged(out); RoutingExplanations.writeTo(explanations, out); } }
@Override protected void addCustomFields(XContentBuilder builder, Params params) throws IOException { builder.startObject("state"); state.toXContent(builder, params); builder.endObject(); if (params.paramAsBoolean("explain", false)) { explanations.toXContent(builder, ToXContent.EMPTY_PARAMS); } } }
/** * Provides feedback from commands with a YES decision that should be displayed to the user after the command has been applied */ public List<String> getYesDecisionMessages() { return explanations().stream() .filter(explanation -> explanation.decisions().type().equals(Decision.Type.YES)) .map(explanation -> explanation.command().getMessage()) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); }
@Override protected void masterOperation(final ClusterRerouteRequest request, final ClusterState state, final ActionListener<ClusterRerouteResponse> listener) { ActionListener<ClusterRerouteResponse> logWrapper = ActionListener.wrap( response -> { if (request.dryRun() == false) { response.getExplanations().getYesDecisionMessages().forEach(logger::info); } listener.onResponse(response); }, listener::onFailure ); clusterService.submitStateUpdateTask("cluster_reroute (api)", new ClusterRerouteResponseAckedClusterStateUpdateTask(logger, allocationService, request, logWrapper)); }
/** * Executes all wrapped commands on a given {@link RoutingAllocation} * @param allocation {@link RoutingAllocation} to apply this command to * @throws org.elasticsearch.ElasticsearchException if something happens during execution */ public RoutingExplanations execute(RoutingAllocation allocation, boolean explain) { RoutingExplanations explanations = new RoutingExplanations(); for (AllocationCommand command : commands) { explanations.add(command.execute(allocation, explain)); } return explanations; }
@Override public void readFrom(StreamInput in) throws IOException { if (in.getVersion().onOrAfter(Version.V_6_4_0)) { super.readFrom(in); state = ClusterState.readFrom(in, null); explanations = RoutingExplanations.readFrom(in); } else { state = ClusterState.readFrom(in, null); acknowledged = in.readBoolean(); explanations = RoutingExplanations.readFrom(in); } }