|
@@ -8,10 +8,6 @@ package org.elasticsearch.xpack.core.indexlifecycle;
|
|
|
import org.apache.lucene.util.SetOnce;
|
|
import org.apache.lucene.util.SetOnce;
|
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
-import org.elasticsearch.action.admin.indices.rollover.Condition;
|
|
|
|
|
-import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition;
|
|
|
|
|
-import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition;
|
|
|
|
|
-import org.elasticsearch.action.admin.indices.rollover.MaxSizeCondition;
|
|
|
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
|
|
|
import org.elasticsearch.client.AdminClient;
|
|
import org.elasticsearch.client.AdminClient;
|
|
@@ -19,10 +15,6 @@ import org.elasticsearch.client.Client;
|
|
|
import org.elasticsearch.client.IndicesAdminClient;
|
|
import org.elasticsearch.client.IndicesAdminClient;
|
|
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
-import org.elasticsearch.common.unit.ByteSizeUnit;
|
|
|
|
|
-import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
|
|
-import org.elasticsearch.common.unit.TimeValue;
|
|
|
|
|
-import org.elasticsearch.common.xcontent.ToXContentObject;
|
|
|
|
|
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
|
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
|
import org.mockito.Mockito;
|
|
import org.mockito.Mockito;
|
|
@@ -30,10 +22,7 @@ import org.mockito.invocation.InvocationOnMock;
|
|
|
import org.mockito.stubbing.Answer;
|
|
import org.mockito.stubbing.Answer;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
-import java.util.HashSet;
|
|
|
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
|
-import java.util.Set;
|
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
|
@@ -50,65 +39,42 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
public RolloverStep createRandomInstance() {
|
|
public RolloverStep createRandomInstance() {
|
|
|
StepKey stepKey = randomStepKey();
|
|
StepKey stepKey = randomStepKey();
|
|
|
StepKey nextStepKey = randomStepKey();
|
|
StepKey nextStepKey = randomStepKey();
|
|
|
- ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values());
|
|
|
|
|
- ByteSizeValue maxSize = randomBoolean() ? null : new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit);
|
|
|
|
|
- Long maxDocs = randomBoolean() ? null : randomNonNegativeLong();
|
|
|
|
|
- TimeValue maxAge = (maxDocs == null && maxSize == null || randomBoolean())
|
|
|
|
|
- ? TimeValue.parseTimeValue(randomPositiveTimeValue(), "rollover_action_test")
|
|
|
|
|
- : null;
|
|
|
|
|
- return new RolloverStep(stepKey, nextStepKey, client, maxSize, maxAge, maxDocs);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return new RolloverStep(stepKey, nextStepKey, client);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public RolloverStep mutateInstance(RolloverStep instance) {
|
|
public RolloverStep mutateInstance(RolloverStep instance) {
|
|
|
StepKey key = instance.getKey();
|
|
StepKey key = instance.getKey();
|
|
|
StepKey nextKey = instance.getNextStepKey();
|
|
StepKey nextKey = instance.getNextStepKey();
|
|
|
- ByteSizeValue maxSize = instance.getMaxSize();
|
|
|
|
|
- TimeValue maxAge = instance.getMaxAge();
|
|
|
|
|
- Long maxDocs = instance.getMaxDocs();
|
|
|
|
|
|
|
|
|
|
- switch (between(0, 4)) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ switch (between(0, 1)) {
|
|
|
case 0:
|
|
case 0:
|
|
|
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
|
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
|
|
break;
|
|
break;
|
|
|
case 1:
|
|
case 1:
|
|
|
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
|
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
|
|
break;
|
|
break;
|
|
|
- case 2:
|
|
|
|
|
- maxSize = randomValueOtherThan(maxSize, () -> {
|
|
|
|
|
- ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values());
|
|
|
|
|
- return new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit);
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
- case 3:
|
|
|
|
|
- maxAge = TimeValue.parseTimeValue(randomPositiveTimeValue(), "rollover_action_test");
|
|
|
|
|
- break;
|
|
|
|
|
- case 4:
|
|
|
|
|
- maxDocs = randomNonNegativeLong();
|
|
|
|
|
- break;
|
|
|
|
|
default:
|
|
default:
|
|
|
throw new AssertionError("Illegal randomisation branch");
|
|
throw new AssertionError("Illegal randomisation branch");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return new RolloverStep(key, nextKey, instance.getClient(), maxSize, maxAge, maxDocs);
|
|
|
|
|
|
|
+ return new RolloverStep(key, nextKey, instance.getClient());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public RolloverStep copyInstance(RolloverStep instance) {
|
|
public RolloverStep copyInstance(RolloverStep instance) {
|
|
|
- return new RolloverStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(),
|
|
|
|
|
- instance.getMaxSize(), instance.getMaxAge(), instance.getMaxDocs());
|
|
|
|
|
|
|
+ return new RolloverStep(instance.getKey(), instance.getNextStepKey(), instance.getClient());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static void assertRolloverIndexRequest(RolloverRequest request, String alias, Set<Condition<?>> expectedConditions) {
|
|
|
|
|
|
|
+ private static void assertRolloverIndexRequest(RolloverRequest request, String alias) {
|
|
|
assertNotNull(request);
|
|
assertNotNull(request);
|
|
|
assertEquals(1, request.indices().length);
|
|
assertEquals(1, request.indices().length);
|
|
|
assertEquals(alias, request.indices()[0]);
|
|
assertEquals(alias, request.indices()[0]);
|
|
|
assertEquals(alias, request.getAlias());
|
|
assertEquals(alias, request.getAlias());
|
|
|
- assertEquals(expectedConditions.size(), request.getConditions().size());
|
|
|
|
|
- Set<Object> expectedConditionValues = expectedConditions.stream().map(Condition::value).collect(Collectors.toSet());
|
|
|
|
|
- Set<Object> actualConditionValues = request.getConditions().values().stream()
|
|
|
|
|
- .map(Condition::value).collect(Collectors.toSet());
|
|
|
|
|
- assertEquals(expectedConditionValues, actualConditionValues);
|
|
|
|
|
|
|
+ assertFalse(request.isDryRun());
|
|
|
|
|
+ assertEquals(0, request.getConditions().size());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void testPerformAction() {
|
|
public void testPerformAction() {
|
|
@@ -132,17 +98,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
RolloverRequest request = (RolloverRequest) invocation.getArguments()[0];
|
|
RolloverRequest request = (RolloverRequest) invocation.getArguments()[0];
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
ActionListener<RolloverResponse> listener = (ActionListener<RolloverResponse>) invocation.getArguments()[1];
|
|
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, alias, expectedConditions);
|
|
|
|
|
|
|
+ assertRolloverIndexRequest(request, alias);
|
|
|
listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), true, true, true));
|
|
listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), true, true, true));
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -150,10 +106,10 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
}).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
}).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
|
|
|
|
|
SetOnce<Boolean> actionCompleted = new SetOnce<>();
|
|
SetOnce<Boolean> actionCompleted = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
|
|
|
|
|
|
|
+ step.performAction(indexMetaData, null, new AsyncActionStep.Listener() {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void onResponse(boolean complete, ToXContentObject obj) {
|
|
|
|
|
|
|
+ public void onResponse(boolean complete) {
|
|
|
actionCompleted.set(complete);
|
|
actionCompleted.set(complete);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -170,64 +126,6 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
|
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void testPerformActionNotComplete() {
|
|
|
|
|
- String alias = randomAlphaOfLength(5);
|
|
|
|
|
- IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
|
|
|
|
- .putAlias(AliasMetaData.builder(alias))
|
|
|
|
|
- .settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
|
|
|
|
- .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
|
|
|
|
- RolloverStep step = createRandomInstance();
|
|
|
|
|
-
|
|
|
|
|
- AdminClient adminClient = Mockito.mock(AdminClient.class);
|
|
|
|
|
- IndicesAdminClient indicesClient = Mockito.mock(IndicesAdminClient.class);
|
|
|
|
|
-
|
|
|
|
|
- Mockito.when(client.admin()).thenReturn(adminClient);
|
|
|
|
|
- Mockito.when(adminClient.indices()).thenReturn(indicesClient);
|
|
|
|
|
- Mockito.doAnswer(new Answer<Void>() {
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public Void answer(InvocationOnMock invocation) throws Throwable {
|
|
|
|
|
- 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, alias, expectedConditions);
|
|
|
|
|
- listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), false, true, true));
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
|
|
-
|
|
|
|
|
- SetOnce<Boolean> actionCompleted = new SetOnce<>();
|
|
|
|
|
- step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onResponse(boolean complete, ToXContentObject obj) {
|
|
|
|
|
- actionCompleted.set(complete);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onFailure(Exception e) {
|
|
|
|
|
- throw new AssertionError("Unexpected method call", e);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- assertEquals(false, actionCompleted.get());
|
|
|
|
|
-
|
|
|
|
|
- Mockito.verify(client, Mockito.only()).admin();
|
|
|
|
|
- Mockito.verify(adminClient, Mockito.only()).indices();
|
|
|
|
|
- Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public void testPerformActionFailure() {
|
|
public void testPerformActionFailure() {
|
|
|
String alias = randomAlphaOfLength(5);
|
|
String alias = randomAlphaOfLength(5);
|
|
|
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
|
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
|
@@ -249,17 +147,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
RolloverRequest request = (RolloverRequest) invocation.getArguments()[0];
|
|
RolloverRequest request = (RolloverRequest) invocation.getArguments()[0];
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
ActionListener<RolloverResponse> listener = (ActionListener<RolloverResponse>) invocation.getArguments()[1];
|
|
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, alias, expectedConditions);
|
|
|
|
|
|
|
+ assertRolloverIndexRequest(request, alias);
|
|
|
listener.onFailure(exception);
|
|
listener.onFailure(exception);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -267,10 +155,10 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
}).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
}).when(indicesClient).rolloverIndex(Mockito.any(), Mockito.any());
|
|
|
|
|
|
|
|
SetOnce<Boolean> exceptionThrown = new SetOnce<>();
|
|
SetOnce<Boolean> exceptionThrown = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
|
|
|
|
|
|
|
+ step.performAction(indexMetaData, null, new AsyncActionStep.Listener() {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void onResponse(boolean complete, ToXContentObject obj) {
|
|
|
|
|
|
|
+ public void onResponse(boolean complete) {
|
|
|
throw new AssertionError("Unexpected method call");
|
|
throw new AssertionError("Unexpected method call");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -296,9 +184,9 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
RolloverStep step = createRandomInstance();
|
|
RolloverStep step = createRandomInstance();
|
|
|
|
|
|
|
|
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
|
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
|
|
|
|
|
|
|
+ step.performAction(indexMetaData, null, new AsyncActionStep.Listener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void onResponse(boolean complete, ToXContentObject obj) {
|
|
|
|
|
|
|
+ public void onResponse(boolean complete) {
|
|
|
throw new AssertionError("Unexpected method call");
|
|
throw new AssertionError("Unexpected method call");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -321,9 +209,9 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
RolloverStep step = createRandomInstance();
|
|
RolloverStep step = createRandomInstance();
|
|
|
|
|
|
|
|
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
|
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
|
|
- step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
|
|
|
|
|
|
|
+ step.performAction(indexMetaData, null, new AsyncActionStep.Listener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void onResponse(boolean complete, ToXContentObject obj) {
|
|
|
|
|
|
|
+ public void onResponse(boolean complete) {
|
|
|
throw new AssertionError("Unexpected method call");
|
|
throw new AssertionError("Unexpected method call");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -336,6 +224,5 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|
|
assertThat(exceptionThrown.get().getMessage(), equalTo(String.format(Locale.ROOT,
|
|
assertThat(exceptionThrown.get().getMessage(), equalTo(String.format(Locale.ROOT,
|
|
|
"%s [%s] does not point to index [%s]", RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias,
|
|
"%s [%s] does not point to index [%s]", RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias,
|
|
|
indexMetaData.getIndex().getName())));
|
|
indexMetaData.getIndex().getName())));
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|