Open and close index to honour allow_no_indices option (#24222)
Open/close index API when executed providing an index expressions that matched no indices, threw an error even when allow_no_indices was set to true. The APIs should rather honour the option and behave as a no-op in that case. Closes #24031
This commit is contained in:
parent
2508df6cc8
commit
55daf743d7
|
@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.close;
|
||||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||||
import org.apache.logging.log4j.util.Supplier;
|
import org.apache.logging.log4j.util.Supplier;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
|
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.DestructiveOperations;
|
import org.elasticsearch.action.support.DestructiveOperations;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
||||||
|
@ -97,6 +98,10 @@ public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIn
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(final CloseIndexRequest request, final ClusterState state, final ActionListener<CloseIndexResponse> listener) {
|
protected void masterOperation(final CloseIndexRequest request, final ClusterState state, final ActionListener<CloseIndexResponse> listener) {
|
||||||
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
|
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
|
||||||
|
if (concreteIndices == null || concreteIndices.length == 0) {
|
||||||
|
listener.onResponse(new CloseIndexResponse(true));
|
||||||
|
return;
|
||||||
|
}
|
||||||
CloseIndexClusterStateUpdateRequest updateRequest = new CloseIndexClusterStateUpdateRequest()
|
CloseIndexClusterStateUpdateRequest updateRequest = new CloseIndexClusterStateUpdateRequest()
|
||||||
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
||||||
.indices(concreteIndices);
|
.indices(concreteIndices);
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.open;
|
||||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||||
import org.apache.logging.log4j.util.Supplier;
|
import org.apache.logging.log4j.util.Supplier;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
|
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.DestructiveOperations;
|
import org.elasticsearch.action.support.DestructiveOperations;
|
||||||
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
||||||
|
@ -82,6 +83,10 @@ public class TransportOpenIndexAction extends TransportMasterNodeAction<OpenInde
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(final OpenIndexRequest request, final ClusterState state, final ActionListener<OpenIndexResponse> listener) {
|
protected void masterOperation(final OpenIndexRequest request, final ClusterState state, final ActionListener<OpenIndexResponse> listener) {
|
||||||
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
|
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
|
||||||
|
if (concreteIndices == null || concreteIndices.length == 0) {
|
||||||
|
listener.onResponse(new OpenIndexResponse(true));
|
||||||
|
return;
|
||||||
|
}
|
||||||
OpenIndexClusterStateUpdateRequest updateRequest = new OpenIndexClusterStateUpdateRequest()
|
OpenIndexClusterStateUpdateRequest updateRequest = new OpenIndexClusterStateUpdateRequest()
|
||||||
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
||||||
.indices(concreteIndices);
|
.indices(concreteIndices);
|
||||||
|
|
|
@ -191,6 +191,41 @@ public class OpenCloseIndexIT extends ESIntegTestCase {
|
||||||
assertIndexIsOpened("test1", "test2", "test3");
|
assertIndexIsOpened("test1", "test2", "test3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there are no indices to open/close throw an exception
|
||||||
|
public void testOpenCloseWildCardsNoIndicesDefault() {
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareOpen("test").execute().actionGet());
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test").execute().actionGet());
|
||||||
|
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareOpen("test*").execute().actionGet());
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("test*").execute().actionGet());
|
||||||
|
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareOpen("*").execute().actionGet());
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("*").execute().actionGet());
|
||||||
|
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareOpen("_all").execute().actionGet());
|
||||||
|
expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareClose("_all").execute().actionGet());
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there are no indices to open/close and allow_no_indices=true, the open/close is a no-op
|
||||||
|
public void testOpenCloseWildCardsNoIndicesAllowNoIndices() throws InterruptedException, ExecutionException {
|
||||||
|
IndicesOptions openIndicesOptions = IndicesOptions.fromOptions(false, true, false, true);
|
||||||
|
IndicesOptions closeIndicesOptions = IndicesOptions.fromOptions(false, true, true, false);
|
||||||
|
|
||||||
|
expectThrows(IndexNotFoundException.class,
|
||||||
|
() -> client().admin().indices().prepareOpen("test").setIndicesOptions(openIndicesOptions).execute().actionGet());
|
||||||
|
expectThrows(IndexNotFoundException.class,
|
||||||
|
() -> client().admin().indices().prepareClose("test").setIndicesOptions(closeIndicesOptions).execute().actionGet());
|
||||||
|
|
||||||
|
assertAcked(client().admin().indices().prepareOpen("test*").setIndicesOptions(openIndicesOptions).execute().get());
|
||||||
|
assertAcked(client().admin().indices().prepareClose("test*").setIndicesOptions(closeIndicesOptions).execute().get());
|
||||||
|
|
||||||
|
assertAcked(client().admin().indices().prepareOpen("*").setIndicesOptions(openIndicesOptions).execute().get());
|
||||||
|
assertAcked(client().admin().indices().prepareClose("*").setIndicesOptions(closeIndicesOptions).execute().get());
|
||||||
|
|
||||||
|
assertAcked(client().admin().indices().prepareOpen("_all").setIndicesOptions(openIndicesOptions).execute().get());
|
||||||
|
assertAcked(client().admin().indices().prepareClose("_all").setIndicesOptions(closeIndicesOptions).execute().get());
|
||||||
|
}
|
||||||
|
|
||||||
public void testCloseNoIndex() {
|
public void testCloseNoIndex() {
|
||||||
Client client = client();
|
Client client = client();
|
||||||
Exception e = expectThrows(ActionRequestValidationException.class, () ->
|
Exception e = expectThrows(ActionRequestValidationException.class, () ->
|
||||||
|
|
Loading…
Reference in New Issue