Delete Template: When deleting with * and no templates exists, don't 404

closes #3723
This commit is contained in:
Shay Banon 2013-09-18 12:28:12 +02:00
parent 2d52973783
commit 6a04c16932
3 changed files with 16 additions and 4 deletions

View File

@ -78,6 +78,11 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
}
}
if (templateNames.isEmpty()) {
// if its a match all pattern, and no templates are found (we have none), don't
// fail with index missing...
if (Regex.isMatchAllPattern(request.name)) {
return currentState;
}
throw new IndexTemplateMissingException(request.name);
}
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData());

View File

@ -29,11 +29,10 @@ import java.util.regex.Pattern;
*
*/
public class Regex {
/**
* This Regex / {@link Pattern} flag is supported from Java 7 on.
* If set on a Java6 JVM the flag will be ignored.
*
*/
public static final int UNICODE_CHARACTER_CLASS = 0x100; // supported in JAVA7
@ -44,6 +43,10 @@ public class Regex {
return str.indexOf('*') != -1;
}
public static boolean isMatchAllPattern(String str) {
return str.equals("*");
}
/**
* Match a String against the given pattern, supporting the following simple
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
@ -179,7 +182,7 @@ public class Regex {
}
if ((flags & Pattern.COMMENTS) != 0) {
sb.append("COMMENTS|");
}
}
if ((flags & UNICODE_CHARACTER_CLASS) != 0) {
sb.append("UNICODE_CHAR_CLASS|");
}

View File

@ -20,13 +20,13 @@
package org.elasticsearch.indices.template;
import com.google.common.collect.Lists;
import org.elasticsearch.AbstractSharedClusterTest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
import org.elasticsearch.AbstractSharedClusterTest;
import org.junit.Test;
import java.util.Arrays;
@ -152,6 +152,10 @@ public class SimpleIndexTemplateTests extends AbstractSharedClusterTest {
logger.info("--> delete template*");
admin().indices().prepareDeleteTemplate("template*").execute().actionGet();
assertThat(admin().cluster().prepareState().execute().actionGet().getState().metaData().templates().size(), equalTo(0));
logger.info("--> delete * with no templates, make sure we don't get a failure");
admin().indices().prepareDeleteTemplate("*").execute().actionGet();
assertThat(admin().cluster().prepareState().execute().actionGet().getState().metaData().templates().size(), equalTo(0));
}
@Test