Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
Expand Down Expand Up @@ -128,7 +129,12 @@ protected void masterOperation(
return;
}

deleteIndicesAndPolicy(request.getName(), ActionListener.wrap((response) -> {
GetIndexRequest indices = new GetIndexRequest().indices(EnrichPolicy.getBaseName(request.getName()) + "-*")
.indicesOptions(IndicesOptions.lenientExpand());

String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, indices);

deleteIndicesAndPolicy(concreteIndices, request.getName(), ActionListener.wrap((response) -> {
enrichPolicyLocks.releasePolicy(request.getName());
listener.onResponse(response);
}, (exc) -> {
Expand All @@ -137,9 +143,14 @@ protected void masterOperation(
}));
}

private void deleteIndicesAndPolicy(String name, ActionListener<AcknowledgedResponse> listener) {
private void deleteIndicesAndPolicy(String[] indices, String name, ActionListener<AcknowledgedResponse> listener) {
if (indices.length == 0) {
deletePolicy(name, listener);
return;
}

// delete all enrich indices for this policy
DeleteIndexRequest deleteRequest = new DeleteIndexRequest().indices(EnrichPolicy.getBaseName(name) + "-*")
DeleteIndexRequest deleteRequest = new DeleteIndexRequest().indices(indices)
.indicesOptions(LENIENT_OPTIONS);

client.admin().indices().delete(deleteRequest, ActionListener.wrap((response) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionTestUtils;
import org.elasticsearch.action.support.DestructiveOperations;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexNotFoundException;
Expand All @@ -24,6 +26,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.enrich.EnrichPolicyTests.randomEnrichPolicy;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -116,6 +119,12 @@ public void testDeleteIsNotLocked() throws Exception {
AtomicReference<Exception> error = saveEnrichPolicy(name, policy, clusterService);
assertThat(error.get(), nullValue());

boolean destructiveRequiresName = randomBoolean();
if (destructiveRequiresName) {
Settings settings = Settings.builder().put(DestructiveOperations.REQUIRES_NAME_SETTING.getKey(), destructiveRequiresName).build();
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings));
}

createIndex(EnrichPolicy.getBaseName(name) + "-foo1");
createIndex(EnrichPolicy.getBaseName(name) + "-foo2");

Expand Down Expand Up @@ -152,6 +161,11 @@ public void onFailure(final Exception e) {
.get()
);

if (destructiveRequiresName) {
Settings settings = Settings.builder().putNull(DestructiveOperations.REQUIRES_NAME_SETTING.getKey()).build();
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings));
}

EnrichPolicyLocks enrichPolicyLocks = getInstanceFromNode(EnrichPolicyLocks.class);
assertFalse(enrichPolicyLocks.captureExecutionState().isAnyPolicyInFlight());

Expand Down