|
@@ -16,26 +16,30 @@ import org.elasticsearch.xcontent.NamedXContentRegistry;
|
|
|
import org.elasticsearch.xcontent.ParseField;
|
|
import org.elasticsearch.xcontent.ParseField;
|
|
|
import org.elasticsearch.xpack.core.ilm.ErrorStep;
|
|
import org.elasticsearch.xpack.core.ilm.ErrorStep;
|
|
|
import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse;
|
|
import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse;
|
|
|
|
|
+import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
|
|
|
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
|
|
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
|
|
|
|
|
+import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadataTests;
|
|
|
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
|
|
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
|
|
|
|
|
+import org.elasticsearch.xpack.core.ilm.OperationMode;
|
|
|
import org.elasticsearch.xpack.core.ilm.RolloverAction;
|
|
import org.elasticsearch.xpack.core.ilm.RolloverAction;
|
|
|
import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
|
|
import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
|
|
|
import org.elasticsearch.xpack.ilm.IndexLifecycleService;
|
|
import org.elasticsearch.xpack.ilm.IndexLifecycleService;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
|
import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
|
|
import static org.elasticsearch.xpack.ilm.action.TransportExplainLifecycleAction.getIndexLifecycleExplainResponse;
|
|
import static org.elasticsearch.xpack.ilm.action.TransportExplainLifecycleAction.getIndexLifecycleExplainResponse;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
import static org.hamcrest.Matchers.is;
|
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
-import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.when;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
|
|
|
|
|
|
|
+ private static final String POLICY_NAME = "my-policy";
|
|
|
public static final String PHASE_DEFINITION = """
|
|
public static final String PHASE_DEFINITION = """
|
|
|
{
|
|
{
|
|
|
"policy" : "my-policy",
|
|
"policy" : "my-policy",
|
|
@@ -62,9 +66,6 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
public void testGetIndexLifecycleExplainResponse() throws IOException {
|
|
public void testGetIndexLifecycleExplainResponse() throws IOException {
|
|
|
{
|
|
{
|
|
|
// only errors index
|
|
// only errors index
|
|
|
- IndexLifecycleService indexLifecycleService = mock(IndexLifecycleService.class);
|
|
|
|
|
- when(indexLifecycleService.policyExists("my-policy")).thenReturn(true);
|
|
|
|
|
-
|
|
|
|
|
LifecycleExecutionState.Builder errorStepState = LifecycleExecutionState.builder()
|
|
LifecycleExecutionState.Builder errorStepState = LifecycleExecutionState.builder()
|
|
|
.setPhase("hot")
|
|
.setPhase("hot")
|
|
|
.setAction("rollover")
|
|
.setAction("rollover")
|
|
@@ -72,19 +73,21 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
.setPhaseDefinition(PHASE_DEFINITION);
|
|
.setPhaseDefinition(PHASE_DEFINITION);
|
|
|
String indexInErrorStep = "index_in_error";
|
|
String indexInErrorStep = "index_in_error";
|
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(indexInErrorStep)
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(indexInErrorStep)
|
|
|
- .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, "my-policy"))
|
|
|
|
|
|
|
+ .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, POLICY_NAME))
|
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
|
.putCustom(ILM_CUSTOM_METADATA_KEY, errorStepState.build().asMap())
|
|
.putCustom(ILM_CUSTOM_METADATA_KEY, errorStepState.build().asMap())
|
|
|
.build();
|
|
.build();
|
|
|
- Metadata metadata = Metadata.builder().put(indexMetadata, true).build();
|
|
|
|
|
|
|
+ Metadata metadata = Metadata.builder()
|
|
|
|
|
+ .put(indexMetadata, true)
|
|
|
|
|
+ .putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
|
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
|
|
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
|
|
|
indexInErrorStep,
|
|
indexInErrorStep,
|
|
|
metadata,
|
|
metadata,
|
|
|
true,
|
|
true,
|
|
|
true,
|
|
true,
|
|
|
- indexLifecycleService,
|
|
|
|
|
REGISTRY,
|
|
REGISTRY,
|
|
|
randomBoolean()
|
|
randomBoolean()
|
|
|
);
|
|
);
|
|
@@ -95,9 +98,6 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
// only managed index
|
|
// only managed index
|
|
|
- IndexLifecycleService indexLifecycleService = mock(IndexLifecycleService.class);
|
|
|
|
|
- when(indexLifecycleService.policyExists("my-policy")).thenReturn(true);
|
|
|
|
|
-
|
|
|
|
|
LifecycleExecutionState.Builder checkRolloverReadyStepState = LifecycleExecutionState.builder()
|
|
LifecycleExecutionState.Builder checkRolloverReadyStepState = LifecycleExecutionState.builder()
|
|
|
.setPhase("hot")
|
|
.setPhase("hot")
|
|
|
.setAction("rollover")
|
|
.setAction("rollover")
|
|
@@ -106,19 +106,21 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
|
|
|
|
|
String indexInCheckRolloverStep = "index_in_check_rollover";
|
|
String indexInCheckRolloverStep = "index_in_check_rollover";
|
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(indexInCheckRolloverStep)
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(indexInCheckRolloverStep)
|
|
|
- .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, "my-policy"))
|
|
|
|
|
|
|
+ .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, POLICY_NAME))
|
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
|
.putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap())
|
|
.putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap())
|
|
|
.build();
|
|
.build();
|
|
|
- Metadata metadata = Metadata.builder().put(indexMetadata, true).build();
|
|
|
|
|
|
|
+ Metadata metadata = Metadata.builder()
|
|
|
|
|
+ .put(indexMetadata, true)
|
|
|
|
|
+ .putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
|
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
|
|
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
|
|
|
indexInCheckRolloverStep,
|
|
indexInCheckRolloverStep,
|
|
|
metadata,
|
|
metadata,
|
|
|
true,
|
|
true,
|
|
|
true,
|
|
true,
|
|
|
- indexLifecycleService,
|
|
|
|
|
REGISTRY,
|
|
REGISTRY,
|
|
|
randomBoolean()
|
|
randomBoolean()
|
|
|
);
|
|
);
|
|
@@ -129,7 +131,6 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
metadata,
|
|
metadata,
|
|
|
false,
|
|
false,
|
|
|
true,
|
|
true,
|
|
|
- indexLifecycleService,
|
|
|
|
|
REGISTRY,
|
|
REGISTRY,
|
|
|
randomBoolean()
|
|
randomBoolean()
|
|
|
);
|
|
);
|
|
@@ -149,14 +150,16 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
|
.build();
|
|
.build();
|
|
|
- Metadata metadata = Metadata.builder().put(indexMetadata, true).build();
|
|
|
|
|
|
|
+ Metadata metadata = Metadata.builder()
|
|
|
|
|
+ .put(indexMetadata, true)
|
|
|
|
|
+ .putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
|
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
|
|
IndexLifecycleExplainResponse onlyErrorsResponse = getIndexLifecycleExplainResponse(
|
|
|
indexWithMissingPolicy,
|
|
indexWithMissingPolicy,
|
|
|
metadata,
|
|
metadata,
|
|
|
true,
|
|
true,
|
|
|
true,
|
|
true,
|
|
|
- indexLifecycleService,
|
|
|
|
|
REGISTRY,
|
|
REGISTRY,
|
|
|
randomBoolean()
|
|
randomBoolean()
|
|
|
);
|
|
);
|
|
@@ -167,22 +170,21 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
// not managed index
|
|
// not managed index
|
|
|
- IndexLifecycleService indexLifecycleService = mock(IndexLifecycleService.class);
|
|
|
|
|
- when(indexLifecycleService.policyExists(anyString())).thenReturn(true);
|
|
|
|
|
-
|
|
|
|
|
IndexMetadata indexMetadata = IndexMetadata.builder("index")
|
|
IndexMetadata indexMetadata = IndexMetadata.builder("index")
|
|
|
.settings(settings(IndexVersion.current()))
|
|
.settings(settings(IndexVersion.current()))
|
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
|
.build();
|
|
.build();
|
|
|
- Metadata metadata = Metadata.builder().put(indexMetadata, true).build();
|
|
|
|
|
|
|
+ Metadata metadata = Metadata.builder()
|
|
|
|
|
+ .put(indexMetadata, true)
|
|
|
|
|
+ .putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
|
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
IndexLifecycleExplainResponse onlyManaged = getIndexLifecycleExplainResponse(
|
|
IndexLifecycleExplainResponse onlyManaged = getIndexLifecycleExplainResponse(
|
|
|
"index",
|
|
"index",
|
|
|
metadata,
|
|
metadata,
|
|
|
false,
|
|
false,
|
|
|
true,
|
|
true,
|
|
|
- indexLifecycleService,
|
|
|
|
|
REGISTRY,
|
|
REGISTRY,
|
|
|
randomBoolean()
|
|
randomBoolean()
|
|
|
);
|
|
);
|
|
@@ -191,9 +193,6 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
// validate addition of default condition with `rolloverOnlyIfHasDocuments` true
|
|
// validate addition of default condition with `rolloverOnlyIfHasDocuments` true
|
|
|
- IndexLifecycleService indexLifecycleService = mock(IndexLifecycleService.class);
|
|
|
|
|
- when(indexLifecycleService.policyExists("my-policy")).thenReturn(true);
|
|
|
|
|
-
|
|
|
|
|
LifecycleExecutionState.Builder checkRolloverReadyStepState = LifecycleExecutionState.builder()
|
|
LifecycleExecutionState.Builder checkRolloverReadyStepState = LifecycleExecutionState.builder()
|
|
|
.setPhase("hot")
|
|
.setPhase("hot")
|
|
|
.setAction("rollover")
|
|
.setAction("rollover")
|
|
@@ -201,19 +200,21 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
.setPhaseDefinition(PHASE_DEFINITION);
|
|
.setPhaseDefinition(PHASE_DEFINITION);
|
|
|
String indexInCheckRolloverStep = "index_in_check_rollover";
|
|
String indexInCheckRolloverStep = "index_in_check_rollover";
|
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(indexInCheckRolloverStep)
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(indexInCheckRolloverStep)
|
|
|
- .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, "my-policy"))
|
|
|
|
|
|
|
+ .settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, POLICY_NAME))
|
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
.numberOfShards(randomIntBetween(1, 5))
|
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
.numberOfReplicas(randomIntBetween(0, 5))
|
|
|
.putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap())
|
|
.putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap())
|
|
|
.build();
|
|
.build();
|
|
|
- Metadata metadata = Metadata.builder().put(indexMetadata, true).build();
|
|
|
|
|
|
|
+ Metadata metadata = Metadata.builder()
|
|
|
|
|
+ .put(indexMetadata, true)
|
|
|
|
|
+ .putCustom(IndexLifecycleMetadata.TYPE, createIndexLifecycleMetadata())
|
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
IndexLifecycleExplainResponse response = getIndexLifecycleExplainResponse(
|
|
IndexLifecycleExplainResponse response = getIndexLifecycleExplainResponse(
|
|
|
indexInCheckRolloverStep,
|
|
indexInCheckRolloverStep,
|
|
|
metadata,
|
|
metadata,
|
|
|
false,
|
|
false,
|
|
|
true,
|
|
true,
|
|
|
- indexLifecycleService,
|
|
|
|
|
REGISTRY,
|
|
REGISTRY,
|
|
|
true
|
|
true
|
|
|
);
|
|
);
|
|
@@ -222,4 +223,11 @@ public class TransportExplainLifecycleActionTests extends ESTestCase {
|
|
|
assertThat(rolloverAction.getConditions().getMinDocs(), is(1L));
|
|
assertThat(rolloverAction.getConditions().getMinDocs(), is(1L));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static IndexLifecycleMetadata createIndexLifecycleMetadata() {
|
|
|
|
|
+ return new IndexLifecycleMetadata(
|
|
|
|
|
+ Map.of(POLICY_NAME, LifecyclePolicyMetadataTests.createRandomPolicyMetadata(POLICY_NAME)),
|
|
|
|
|
+ randomFrom(OperationMode.values())
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|