forked from elastic/elasticsearch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
action.destructive_requires_name
that controls whether wildca…
…rd expressions and `_all` is allowed to be used for destructive operat Also the delete index api requires always an index to be specified (either concrete index, alias or wildcard expression) Closes elastic#4549 elastic#4481
- Loading branch information
Showing
18 changed files
with
430 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,8 @@ | |
package org.elasticsearch.action.admin.indices.delete; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.ElasticsearchIllegalArgumentException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction; | ||
import org.elasticsearch.action.support.DestructiveOperations; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; | ||
import org.elasticsearch.cluster.ClusterService; | ||
import org.elasticsearch.cluster.ClusterState; | ||
|
@@ -32,28 +31,26 @@ | |
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.concurrent.CountDown; | ||
import org.elasticsearch.node.settings.NodeSettingsService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
/** | ||
* Delete index action. | ||
*/ | ||
public class TransportDeleteIndexAction extends TransportMasterNodeOperationAction<DeleteIndexRequest, DeleteIndexResponse> { | ||
public class TransportDeleteIndexAction extends TransportMasterNodeOperationAction<DeleteIndexRequest, DeleteIndexResponse> implements NodeSettingsService.Listener { | ||
|
||
private final MetaDataDeleteIndexService deleteIndexService; | ||
|
||
private final TransportDeleteMappingAction deleteMappingAction; | ||
|
||
private final boolean disableDeleteAllIndices; | ||
private volatile boolean destructiveRequiresName; | ||
|
||
@Inject | ||
public TransportDeleteIndexAction(Settings settings, TransportService transportService, ClusterService clusterService, | ||
ThreadPool threadPool, MetaDataDeleteIndexService deleteIndexService, TransportDeleteMappingAction deleteMappingAction) { | ||
ThreadPool threadPool, MetaDataDeleteIndexService deleteIndexService, | ||
NodeSettingsService nodeSettingsService) { | ||
super(settings, transportService, clusterService, threadPool); | ||
this.deleteIndexService = deleteIndexService; | ||
this.deleteMappingAction = deleteMappingAction; | ||
|
||
this.disableDeleteAllIndices = settings.getAsBoolean("action.disable_delete_all_indices", false); | ||
this.destructiveRequiresName = settings.getAsBoolean(DestructiveOperations.REQUIRES_NAME, false); | ||
nodeSettingsService.addListener(this); | ||
} | ||
|
||
@Override | ||
|
@@ -78,17 +75,7 @@ protected DeleteIndexResponse newResponse() { | |
|
||
@Override | ||
protected void doExecute(DeleteIndexRequest request, ActionListener<DeleteIndexResponse> listener) { | ||
ClusterState state = clusterService.state(); | ||
String[] indicesOrAliases = request.indices(); | ||
|
||
request.indices(state.metaData().concreteIndices(request.indices(), request.indicesOptions())); | ||
|
||
if (disableDeleteAllIndices) { | ||
if (state.metaData().isAllIndices(indicesOrAliases) || | ||
state.metaData().isPatternMatchingAllIndices(indicesOrAliases, request.indices())) { | ||
throw new ElasticsearchIllegalArgumentException("deleting all indices is disabled"); | ||
} | ||
} | ||
DestructiveOperations.failDestructive(request.indices(), destructiveRequiresName); | ||
super.doExecute(request, listener); | ||
} | ||
|
||
|
@@ -99,6 +86,7 @@ protected ClusterBlockException checkBlock(DeleteIndexRequest request, ClusterSt | |
|
||
@Override | ||
protected void masterOperation(final DeleteIndexRequest request, final ClusterState state, final ActionListener<DeleteIndexResponse> listener) throws ElasticsearchException { | ||
request.indices(state.metaData().concreteIndices(request.indices(), request.indicesOptions())); | ||
if (request.indices().length == 0) { | ||
listener.onResponse(new DeleteIndexResponse(true)); | ||
return; | ||
|
@@ -136,4 +124,13 @@ public void onFailure(Throwable t) { | |
}); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRefreshSettings(Settings settings) { | ||
boolean newValue = settings.getAsBoolean("action.destructive_requires_name", destructiveRequiresName); | ||
This comment has been minimized.
Sorry, something went wrong.
s1monw
|
||
if (destructiveRequiresName != newValue) { | ||
logger.info("updating [action.operate_all_indices] from [{}] to [{}]", destructiveRequiresName, newValue); | ||
this.destructiveRequiresName = newValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
also use the constant
REQUIRES_NAME
here?