|
|
@@ -17,7 +17,9 @@ import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
|
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
|
|
|
import org.elasticsearch.cluster.metadata.AliasMetadata;
|
|
|
+import org.elasticsearch.cluster.metadata.DataStream;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
+import org.elasticsearch.cluster.metadata.Metadata;
|
|
|
import org.elasticsearch.common.unit.ByteSizeUnit;
|
|
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
|
@@ -26,6 +28,7 @@ import org.mockito.Mockito;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -90,11 +93,11 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
instance.getMaxSize(), instance.getMaxAge(), instance.getMaxDocs());
|
|
|
}
|
|
|
|
|
|
- private static void assertRolloverIndexRequest(RolloverRequest request, String alias, Set<Condition<?>> expectedConditions) {
|
|
|
+ private static void assertRolloverIndexRequest(RolloverRequest request, String rolloverTarget, Set<Condition<?>> expectedConditions) {
|
|
|
assertNotNull(request);
|
|
|
assertEquals(1, request.indices().length);
|
|
|
- assertEquals(alias, request.indices()[0]);
|
|
|
- assertEquals(alias, request.getRolloverTarget());
|
|
|
+ assertEquals(rolloverTarget, request.indices()[0]);
|
|
|
+ assertEquals(rolloverTarget, request.getRolloverTarget());
|
|
|
assertEquals(expectedConditions.size(), request.getConditions().size());
|
|
|
assertTrue(request.isDryRun());
|
|
|
Set<Object> expectedConditionValues = expectedConditions.stream().map(Condition::value).collect(Collectors.toSet());
|
|
|
@@ -103,7 +106,6 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
assertEquals(expectedConditionValues, actualConditionValues);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public void testEvaluateCondition() {
|
|
|
String alias = randomAlphaOfLength(5);
|
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10))
|
|
|
@@ -113,29 +115,44 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
- Mockito.doAnswer(invocation -> {
|
|
|
- RolloverRequest request = (RolloverRequest) invocation.getArguments()[0];
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- ActionListener<RolloverResponse> listener = (ActionListener<RolloverResponse>) invocation.getArguments()[1];
|
|
|
- Set<Condition<?>> expectedConditions = new HashSet<>();
|
|
|
- if (step.getMaxAge() != null) {
|
|
|
- expectedConditions.add(new MaxAgeCondition(step.getMaxAge()));
|
|
|
- }
|
|
|
- if (step.getMaxSize() != null) {
|
|
|
- expectedConditions.add(new MaxSizeCondition(step.getMaxSize()));
|
|
|
+ mockRolloverIndexCall(alias, step);
|
|
|
+
|
|
|
+ SetOnce<Boolean> conditionsMet = new SetOnce<>();
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
+ conditionsMet.set(complete);
|
|
|
}
|
|
|
- if (step.getMaxDocs() != null) {
|
|
|
- expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Exception e) {
|
|
|
+ throw new AssertionError("Unexpected method call", e);
|
|
|
}
|
|
|
- assertRolloverIndexRequest(request, alias, expectedConditions);
|
|
|
- Map<String, Boolean> conditionResults = expectedConditions.stream()
|
|
|
- .collect(Collectors.toMap(Condition::toString, condition -> true));
|
|
|
- listener.onResponse(new RolloverResponse(null, null, conditionResults, request.isDryRun(), false, false, false));
|
|
|
- return null;
|
|
|
- }).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
+ }, MASTER_TIMEOUT);
|
|
|
+
|
|
|
+ assertEquals(true, conditionsMet.get());
|
|
|
+
|
|
|
+ verify(client, Mockito.only()).admin();
|
|
|
+ verify(adminClient, Mockito.only()).indices();
|
|
|
+ verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testEvaluateConditionOnDataStreamTarget() {
|
|
|
+ String dataStreamName = "test-datastream";
|
|
|
+ IndexMetadata indexMetadata = IndexMetadata.builder(dataStreamName + "-000001")
|
|
|
+ .settings(settings(Version.CURRENT))
|
|
|
+ .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
|
|
+
|
|
|
+ WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
+
|
|
|
+ mockRolloverIndexCall(dataStreamName, step);
|
|
|
|
|
|
SetOnce<Boolean> conditionsMet = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ Metadata metadata = Metadata.builder().put(indexMetadata, true)
|
|
|
+ .put(new DataStream(dataStreamName, "timestamp", List.of(indexMetadata.getIndex()), 1L))
|
|
|
+ .build();
|
|
|
+ step.evaluateCondition(metadata, indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
@@ -155,6 +172,29 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
}
|
|
|
|
|
|
+ private void mockRolloverIndexCall(String rolloverTarget, WaitForRolloverReadyStep step) {
|
|
|
+ Mockito.doAnswer(invocation -> {
|
|
|
+ RolloverRequest request = (RolloverRequest) invocation.getArguments()[0];
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ ActionListener<RolloverResponse> listener = (ActionListener<RolloverResponse>) invocation.getArguments()[1];
|
|
|
+ Set<Condition<?>> expectedConditions = new HashSet<>();
|
|
|
+ if (step.getMaxAge() != null) {
|
|
|
+ expectedConditions.add(new MaxAgeCondition(step.getMaxAge()));
|
|
|
+ }
|
|
|
+ if (step.getMaxSize() != null) {
|
|
|
+ expectedConditions.add(new MaxSizeCondition(step.getMaxSize()));
|
|
|
+ }
|
|
|
+ if (step.getMaxDocs() != null) {
|
|
|
+ expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
|
|
|
+ }
|
|
|
+ assertRolloverIndexRequest(request, rolloverTarget, expectedConditions);
|
|
|
+ Map<String, Boolean> conditionResults = expectedConditions.stream()
|
|
|
+ .collect(Collectors.toMap(Condition::toString, condition -> true));
|
|
|
+ listener.onResponse(new RolloverResponse(null, null, conditionResults, request.isDryRun(), false, false, false));
|
|
|
+ return null;
|
|
|
+ }).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
+ }
|
|
|
+
|
|
|
public void testEvaluateDoesntTriggerRolloverForIndexManuallyRolledOnLifecycleRolloverAlias() {
|
|
|
String rolloverAlias = randomAlphaOfLength(5);
|
|
|
IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10))
|
|
|
@@ -166,7 +206,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject informationContext) {
|
|
|
@@ -195,7 +235,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject informationContext) {
|
|
|
@@ -220,7 +260,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
|
|
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
@@ -249,7 +289,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
SetOnce<Boolean> conditionsMet = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
@@ -277,7 +317,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
SetOnce<Boolean> correctFailureCalled = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
@@ -324,7 +364,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
}).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
|
|
|
SetOnce<Boolean> actionCompleted = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
@@ -373,7 +413,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
}).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
|
|
|
SetOnce<Boolean> exceptionThrown = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
@@ -402,7 +442,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
throw new AssertionError("Unexpected method call");
|
|
|
@@ -427,7 +467,7 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
|
|
|
WaitForRolloverReadyStep step = createRandomInstance();
|
|
|
|
|
|
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetadata, new AsyncWaitStep.Listener() {
|
|
|
+ step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() {
|
|
|
@Override
|
|
|
public void onResponse(boolean complete, ToXContentObject infomationContext) {
|
|
|
throw new AssertionError("Unexpected method call");
|