Warmers: delete _all should not throw exception when no warmers are registered

Closes #8991
Closes #13058
This commit is contained in:
André Carvalho 2015-08-22 16:30:37 -03:00 committed by Luca Cavanna
parent 33e04083a7
commit 793fcb6998
2 changed files with 25 additions and 3 deletions

View File

@ -92,6 +92,14 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
boolean globalFoundAtLeastOne = false; boolean globalFoundAtLeastOne = false;
boolean deleteAll = false;
for (int i=0; i<request.names().length; i++){
if (request.names()[i].equals(MetaData.ALL)) {
deleteAll = true;
break;
}
}
for (String index : concreteIndices) { for (String index : concreteIndices) {
IndexMetaData indexMetaData = currentState.metaData().index(index); IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData == null) { if (indexMetaData == null) {
@ -103,7 +111,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet
for (IndexWarmersMetaData.Entry entry : warmers.entries()) { for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
boolean keepWarmer = true; boolean keepWarmer = true;
for (String warmer : request.names()) { for (String warmer : request.names()) {
if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals("_all")) { if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals(MetaData.ALL)) {
globalFoundAtLeastOne = true; globalFoundAtLeastOne = true;
keepWarmer = false; keepWarmer = false;
// don't add it... // don't add it...
@ -123,7 +131,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet
} }
} }
if (!globalFoundAtLeastOne) { if (globalFoundAtLeastOne == false && deleteAll == false) {
throw new IndexWarmerMissingException(request.names()); throw new IndexWarmerMissingException(request.names());
} }
@ -137,11 +145,13 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeAction<Delet
if (warmers != null) { if (warmers != null) {
for (IndexWarmersMetaData.Entry entry : warmers.entries()) { for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
for (String warmer : request.names()) { for (String warmer : request.names()) {
if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals("_all")) { if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals(MetaData.ALL)) {
logger.info("[{}] delete warmer [{}]", index, entry.name()); logger.info("[{}] delete warmer [{}]", index, entry.name());
} }
} }
} }
} else if(deleteAll){
logger.debug("no warmers to delete on index [{}]", index);
} }
} }
} }

View File

@ -173,6 +173,18 @@ public class SimpleIndicesWarmerIT extends ESIntegTestCase {
} }
} }
@Test // issue 8991
public void deleteAllIndexWarmerDoesNotThrowWhenNoWarmers() {
createIndex("test");
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer()
.setIndices("test").setNames("_all").execute().actionGet();
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));
deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer()
.setIndices("test").setNames("foo", "_all", "bar").execute().actionGet();
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));
}
@Test @Test
public void deleteIndexWarmerTest() { public void deleteIndexWarmerTest() {
createIndex("test"); createIndex("test");