mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-20 03:45:02 +00:00
Delete Template: When deleting with * and no templates exists, don't 404
closes #3723
This commit is contained in:
parent
2d52973783
commit
6a04c16932
@ -78,6 +78,11 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (templateNames.isEmpty()) {
|
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);
|
throw new IndexTemplateMissingException(request.name);
|
||||||
}
|
}
|
||||||
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData());
|
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData());
|
||||||
|
@ -33,7 +33,6 @@ public class Regex {
|
|||||||
/**
|
/**
|
||||||
* This Regex / {@link Pattern} flag is supported from Java 7 on.
|
* This Regex / {@link Pattern} flag is supported from Java 7 on.
|
||||||
* If set on a Java6 JVM the flag will be ignored.
|
* If set on a Java6 JVM the flag will be ignored.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static final int UNICODE_CHARACTER_CLASS = 0x100; // supported in JAVA7
|
public static final int UNICODE_CHARACTER_CLASS = 0x100; // supported in JAVA7
|
||||||
|
|
||||||
@ -44,6 +43,10 @@ public class Regex {
|
|||||||
return str.indexOf('*') != -1;
|
return str.indexOf('*') != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isMatchAllPattern(String str) {
|
||||||
|
return str.equals("*");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Match a String against the given pattern, supporting the following simple
|
* Match a String against the given pattern, supporting the following simple
|
||||||
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
|
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
package org.elasticsearch.indices.template;
|
package org.elasticsearch.indices.template;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import org.elasticsearch.AbstractSharedClusterTest;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.Priority;
|
import org.elasticsearch.common.Priority;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
|
import org.elasticsearch.indices.IndexTemplateAlreadyExistsException;
|
||||||
import org.elasticsearch.AbstractSharedClusterTest;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -152,6 +152,10 @@ public class SimpleIndexTemplateTests extends AbstractSharedClusterTest {
|
|||||||
logger.info("--> delete template*");
|
logger.info("--> delete template*");
|
||||||
admin().indices().prepareDeleteTemplate("template*").execute().actionGet();
|
admin().indices().prepareDeleteTemplate("template*").execute().actionGet();
|
||||||
assertThat(admin().cluster().prepareState().execute().actionGet().getState().metaData().templates().size(), equalTo(0));
|
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
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user