|
@@ -17,14 +17,10 @@ import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
|
|
|
import org.elasticsearch.cluster.metadata.Metadata;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
-import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.index.Index;
|
|
|
import org.elasticsearch.license.XPackLicenseState;
|
|
|
-import org.elasticsearch.xcontent.ToXContent;
|
|
|
import org.elasticsearch.xcontent.ToXContentObject;
|
|
|
-import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
-import org.elasticsearch.xcontent.json.JsonXContent;
|
|
|
import org.elasticsearch.xpack.core.ilm.ErrorStep;
|
|
|
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
|
|
|
import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep;
|
|
@@ -38,8 +34,6 @@ import org.elasticsearch.xpack.core.ilm.RolloverAction;
|
|
|
import org.elasticsearch.xpack.core.ilm.Step;
|
|
|
import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -48,8 +42,8 @@ import java.util.Set;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.LongSupplier;
|
|
|
|
|
|
-import static org.elasticsearch.ElasticsearchException.REST_EXCEPTION_SKIP_STACK_TRACE;
|
|
|
import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
|
|
+import static org.elasticsearch.xcontent.ToXContent.EMPTY_PARAMS;
|
|
|
|
|
|
/**
|
|
|
* The {@link IndexLifecycleTransition} class handles cluster state transitions
|
|
@@ -61,9 +55,6 @@ import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUS
|
|
|
*/
|
|
|
public final class IndexLifecycleTransition {
|
|
|
private static final Logger logger = LogManager.getLogger(IndexLifecycleTransition.class);
|
|
|
- private static final ToXContent.Params STACKTRACE_PARAMS = new ToXContent.MapParams(
|
|
|
- Collections.singletonMap(REST_EXCEPTION_SKIP_STACK_TRACE, "false")
|
|
|
- );
|
|
|
|
|
|
/**
|
|
|
* Validates that the given transition from {@code currentStepKey} to {@code newStepKey} can be accomplished
|
|
@@ -158,14 +149,10 @@ public final class IndexLifecycleTransition {
|
|
|
Exception cause,
|
|
|
LongSupplier nowSupplier,
|
|
|
BiFunction<IndexMetadata, Step.StepKey, Step> stepLookupFunction
|
|
|
- ) throws IOException {
|
|
|
+ ) {
|
|
|
IndexMetadata idxMeta = clusterState.getMetadata().index(index);
|
|
|
IndexLifecycleMetadata ilmMeta = clusterState.metadata().custom(IndexLifecycleMetadata.TYPE);
|
|
|
LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(idxMeta.getLifecyclePolicyName());
|
|
|
- XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
|
|
- causeXContentBuilder.startObject();
|
|
|
- ElasticsearchException.generateThrowableXContent(causeXContentBuilder, STACKTRACE_PARAMS, cause);
|
|
|
- causeXContentBuilder.endObject();
|
|
|
LifecycleExecutionState currentState = idxMeta.getLifecycleExecutionState();
|
|
|
Step.StepKey currentStep;
|
|
|
// if an error is encountered while initialising the policy the lifecycle execution state will not yet contain any step information
|
|
@@ -189,7 +176,10 @@ public final class IndexLifecycleTransition {
|
|
|
|
|
|
LifecycleExecutionState.Builder failedState = LifecycleExecutionState.builder(nextStepState);
|
|
|
failedState.setFailedStep(currentStep.getName());
|
|
|
- failedState.setStepInfo(BytesReference.bytes(causeXContentBuilder).utf8ToString());
|
|
|
+ failedState.setStepInfo(Strings.toString(((builder, params) -> {
|
|
|
+ ElasticsearchException.generateThrowableXContent(builder, EMPTY_PARAMS, cause);
|
|
|
+ return builder;
|
|
|
+ })));
|
|
|
Step failedStep = stepLookupFunction.apply(idxMeta, currentStep);
|
|
|
|
|
|
if (failedStep != null) {
|
|
@@ -444,20 +434,15 @@ public final class IndexLifecycleTransition {
|
|
|
* @param stepInfo the new step info to update
|
|
|
* @return Updated cluster state with <code>stepInfo</code> if changed, otherwise the same cluster state
|
|
|
* if no changes to step info exist
|
|
|
- * @throws IOException if parsing step info fails
|
|
|
*/
|
|
|
- static ClusterState addStepInfoToClusterState(Index index, ClusterState clusterState, ToXContentObject stepInfo) throws IOException {
|
|
|
+ static ClusterState addStepInfoToClusterState(Index index, ClusterState clusterState, ToXContentObject stepInfo) {
|
|
|
IndexMetadata indexMetadata = clusterState.getMetadata().index(index);
|
|
|
if (indexMetadata == null) {
|
|
|
// This index doesn't exist anymore, we can't do anything
|
|
|
return clusterState;
|
|
|
}
|
|
|
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
|
|
|
- final String stepInfoString;
|
|
|
- try (XContentBuilder infoXContentBuilder = JsonXContent.contentBuilder()) {
|
|
|
- stepInfo.toXContent(infoXContentBuilder, ToXContent.EMPTY_PARAMS);
|
|
|
- stepInfoString = BytesReference.bytes(infoXContentBuilder).utf8ToString();
|
|
|
- }
|
|
|
+ final String stepInfoString = Strings.toString(stepInfo);
|
|
|
if (stepInfoString.equals(lifecycleState.stepInfo())) {
|
|
|
return clusterState;
|
|
|
}
|