use of org.elasticsearch.indices.InvalidIndexTemplateException in project elasticsearch by elastic.
the class MetaDataIndexTemplateService method validate.
private void validate(PutRequest request) {
List<String> validationErrors = new ArrayList<>();
if (request.name.contains(" ")) {
validationErrors.add("name must not contain a space");
}
if (request.name.contains(",")) {
validationErrors.add("name must not contain a ','");
}
if (request.name.contains("#")) {
validationErrors.add("name must not contain a '#'");
}
if (request.name.startsWith("_")) {
validationErrors.add("name must not start with '_'");
}
if (!request.name.toLowerCase(Locale.ROOT).equals(request.name)) {
validationErrors.add("name must be lower cased");
}
for (String indexPattern : request.indexPatterns) {
if (indexPattern.contains(" ")) {
validationErrors.add("template must not contain a space");
}
if (indexPattern.contains(",")) {
validationErrors.add("template must not contain a ','");
}
if (indexPattern.contains("#")) {
validationErrors.add("template must not contain a '#'");
}
if (indexPattern.startsWith("_")) {
validationErrors.add("template must not start with '_'");
}
if (!Strings.validFileNameExcludingAstrix(indexPattern)) {
validationErrors.add("template must not contain the following characters " + Strings.INVALID_FILENAME_CHARS);
}
}
try {
indexScopedSettings.validate(request.settings);
} catch (IllegalArgumentException iae) {
validationErrors.add(iae.getMessage());
for (Throwable t : iae.getSuppressed()) {
validationErrors.add(t.getMessage());
}
}
List<String> indexSettingsValidation = metaDataCreateIndexService.getIndexSettingsValidationErrors(request.settings);
validationErrors.addAll(indexSettingsValidation);
if (!validationErrors.isEmpty()) {
ValidationException validationException = new ValidationException();
validationException.addValidationErrors(validationErrors);
throw new InvalidIndexTemplateException(request.name, validationException.getMessage());
}
for (Alias alias : request.aliases) {
//we validate the alias only partially, as we don't know yet to which index it'll get applied to
aliasValidator.validateAliasStandalone(alias);
if (request.indexPatterns.contains(alias.name())) {
throw new IllegalArgumentException("Alias [" + alias.name() + "] cannot be the same as any pattern in [" + String.join(", ", request.indexPatterns) + "]");
}
}
}
use of org.elasticsearch.indices.InvalidIndexTemplateException in project elasticsearch by elastic.
the class SearchPhaseExecutionExceptionTests method testToAndFromXContent.
public void testToAndFromXContent() throws IOException {
final XContent xContent = randomFrom(XContentType.values()).xContent();
ShardSearchFailure[] shardSearchFailures = new ShardSearchFailure[randomIntBetween(1, 5)];
for (int i = 0; i < shardSearchFailures.length; i++) {
Exception cause = randomFrom(new ParsingException(1, 2, "foobar", null), new InvalidIndexTemplateException("foo", "bar"), new TimestampParsingException("foo", null), new NullPointerException());
shardSearchFailures[i] = new ShardSearchFailure(cause, new SearchShardTarget("node_" + i, new Index("test", "_na_"), i));
}
final String phase = randomFrom("query", "search", "other");
SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", shardSearchFailures);
BytesReference exceptionBytes = XContentHelper.toXContent(actual, xContent.type(), randomBoolean());
ElasticsearchException parsedException;
try (XContentParser parser = createParser(xContent, exceptionBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedException = ElasticsearchException.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertNull(parser.nextToken());
}
assertNotNull(parsedException);
assertThat(parsedException.getHeaderKeys(), hasSize(0));
assertThat(parsedException.getMetadataKeys(), hasSize(1));
assertThat(parsedException.getMetadata("es.phase"), hasItem(phase));
// SearchPhaseExecutionException has no cause field
assertNull(parsedException.getCause());
}
use of org.elasticsearch.indices.InvalidIndexTemplateException in project elasticsearch by elastic.
the class ExceptionSerializationTests method testInvalidIndexTemplateException.
public void testInvalidIndexTemplateException() throws IOException {
InvalidIndexTemplateException ex = serialize(new InvalidIndexTemplateException("foo", "bar"));
assertEquals(ex.getMessage(), "index_template [foo] invalid, cause [bar]");
assertEquals(ex.name(), "foo");
ex = serialize(new InvalidIndexTemplateException(null, "bar"));
assertEquals(ex.getMessage(), "index_template [null] invalid, cause [bar]");
assertEquals(ex.name(), null);
}
Aggregations