Preserve ILM operation mode when creating new lifecycles (#38134)
There was a bug where creating a new policy would start the ILM service, even if it was stopped. This change ensures that there is no change to the existing operation mode
This commit is contained in:
parent
3ecdfe1060
commit
bae656dcea
|
@ -23,7 +23,6 @@ import org.elasticsearch.xpack.core.ClientHelper;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata;
|
import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy;
|
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata;
|
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.OperationMode;
|
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction;
|
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Request;
|
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Request;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Response;
|
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Response;
|
||||||
|
@ -93,7 +92,7 @@ public class TransportPutLifecycleAction extends TransportMasterNodeAction<Reque
|
||||||
} else {
|
} else {
|
||||||
logger.info("updating index lifecycle policy [{}]", request.getPolicy().getName());
|
logger.info("updating index lifecycle policy [{}]", request.getPolicy().getName());
|
||||||
}
|
}
|
||||||
IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies, OperationMode.RUNNING);
|
IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies, currentMetadata.getOperationMode());
|
||||||
newState.metaData(MetaData.builder(currentState.getMetaData())
|
newState.metaData(MetaData.builder(currentState.getMetaData())
|
||||||
.putCustom(IndexLifecycleMetadata.TYPE, newMetadata).build());
|
.putCustom(IndexLifecycleMetadata.TYPE, newMetadata).build());
|
||||||
return newState.build();
|
return newState.build();
|
||||||
|
|
|
@ -37,13 +37,17 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings;
|
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType;
|
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.MockAction;
|
import org.elasticsearch.xpack.core.indexlifecycle.MockAction;
|
||||||
|
import org.elasticsearch.xpack.core.indexlifecycle.OperationMode;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.Phase;
|
import org.elasticsearch.xpack.core.indexlifecycle.Phase;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.PhaseExecutionInfo;
|
import org.elasticsearch.xpack.core.indexlifecycle.PhaseExecutionInfo;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.Step;
|
import org.elasticsearch.xpack.core.indexlifecycle.Step;
|
||||||
|
import org.elasticsearch.xpack.core.indexlifecycle.StopILMRequest;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep;
|
import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction;
|
import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction;
|
import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction;
|
||||||
|
import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction;
|
import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction;
|
||||||
|
import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -364,6 +368,39 @@ public class IndexLifecycleInitialisationTests extends ESIntegTestCase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCreatePolicyWhenStopped() throws Exception {
|
||||||
|
// start master node
|
||||||
|
logger.info("Starting server1");
|
||||||
|
final String server_1 = internalCluster().startNode();
|
||||||
|
final String node1 = getLocalNodeId(server_1);
|
||||||
|
|
||||||
|
assertAcked(client().execute(StopILMAction.INSTANCE, new StopILMRequest()).get());
|
||||||
|
assertBusy(() -> assertThat(
|
||||||
|
client().execute(GetStatusAction.INSTANCE, new GetStatusAction.Request()).get().getMode(),
|
||||||
|
equalTo(OperationMode.STOPPED)));
|
||||||
|
|
||||||
|
logger.info("Creating lifecycle [test_lifecycle]");
|
||||||
|
PutLifecycleAction.Request putLifecycleRequest = new PutLifecycleAction.Request(lifecyclePolicy);
|
||||||
|
long lowerBoundModifiedDate = Instant.now().toEpochMilli();
|
||||||
|
PutLifecycleAction.Response putLifecycleResponse = client().execute(PutLifecycleAction.INSTANCE, putLifecycleRequest).get();
|
||||||
|
assertAcked(putLifecycleResponse);
|
||||||
|
long upperBoundModifiedDate = Instant.now().toEpochMilli();
|
||||||
|
|
||||||
|
// assert version and modified_date
|
||||||
|
GetLifecycleAction.Response getLifecycleResponse = client().execute(GetLifecycleAction.INSTANCE,
|
||||||
|
new GetLifecycleAction.Request()).get();
|
||||||
|
assertThat(getLifecycleResponse.getPolicies().size(), equalTo(1));
|
||||||
|
GetLifecycleAction.LifecyclePolicyResponseItem responseItem = getLifecycleResponse.getPolicies().get(0);
|
||||||
|
assertThat(responseItem.getLifecyclePolicy(), equalTo(lifecyclePolicy));
|
||||||
|
assertThat(responseItem.getVersion(), equalTo(1L));
|
||||||
|
long actualModifiedDate = Instant.parse(responseItem.getModifiedDate()).toEpochMilli();
|
||||||
|
assertThat(actualModifiedDate,
|
||||||
|
is(both(greaterThanOrEqualTo(lowerBoundModifiedDate)).and(lessThanOrEqualTo(upperBoundModifiedDate))));
|
||||||
|
// assert ILM is still stopped
|
||||||
|
GetStatusAction.Response statusResponse = client().execute(GetStatusAction.INSTANCE, new GetStatusAction.Request()).get();
|
||||||
|
assertThat(statusResponse.getMode(), equalTo(OperationMode.STOPPED));
|
||||||
|
}
|
||||||
|
|
||||||
public void testPollIntervalUpdate() throws Exception {
|
public void testPollIntervalUpdate() throws Exception {
|
||||||
TimeValue pollInterval = TimeValue.timeValueSeconds(randomLongBetween(1, 5));
|
TimeValue pollInterval = TimeValue.timeValueSeconds(randomLongBetween(1, 5));
|
||||||
final String server_1 = internalCluster().startMasterOnlyNode(
|
final String server_1 = internalCluster().startMasterOnlyNode(
|
||||||
|
|
Loading…
Reference in New Issue