Java Code Examples for org.elasticsearch.common.ValidationException#addValidationErrors()

The following examples show how to use org.elasticsearch.common.ValidationException#addValidationErrors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlterTableClusterStateExecutor.java    From crate with Apache License 2.0 6 votes vote down vote up
private static void validateSettings(String name,
                                     Settings settings,
                                     IndexScopedSettings indexScopedSettings,
                                     MetaDataCreateIndexService metaDataCreateIndexService) {
    List<String> validationErrors = new ArrayList<>();
    try {
        indexScopedSettings.validate(settings, true); // templates must be consistent with regards to dependencies
    } catch (IllegalArgumentException iae) {
        validationErrors.add(iae.getMessage());
        for (Throwable t : iae.getSuppressed()) {
            validationErrors.add(t.getMessage());
        }
    }
    List<String> indexSettingsValidation = metaDataCreateIndexService.getIndexSettingsValidationErrors(settings, true);
    validationErrors.addAll(indexSettingsValidation);
    if (!validationErrors.isEmpty()) {
        ValidationException validationException = new ValidationException();
        validationException.addValidationErrors(validationErrors);
        throw new InvalidIndexTemplateException(name, validationException.getMessage());
    }
}
 
Example 2
Source File: MetaDataCreateIndexService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void validateIndexSettings(String indexName, Settings settings) throws IndexCreationException {
    List<String> validationErrors = getIndexSettingsValidationErrors(settings);
    if (validationErrors.isEmpty() == false) {
        ValidationException validationException = new ValidationException();
        validationException.addValidationErrors(validationErrors);
        throw new IndexCreationException(new Index(indexName), validationException);
    }
}
 
Example 3
Source File: MetaDataCreateIndexService.java    From crate with Apache License 2.0 5 votes vote down vote up
public void validateIndexSettings(String indexName, final Settings settings, final ClusterState clusterState,
                                  final boolean forbidPrivateIndexSettings) throws IndexCreationException {
    List<String> validationErrors = getIndexSettingsValidationErrors(settings, forbidPrivateIndexSettings);
    if (validationErrors.isEmpty() == false) {
        ValidationException validationException = new ValidationException();
        validationException.addValidationErrors(validationErrors);
        throw new IndexCreationException(indexName, validationException);
    }
}
 
Example 4
Source File: MetaDataIndexTemplateService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
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");
    }
    if (request.template.contains(" ")) {
        validationErrors.add("template must not contain a space");
    }
    if (request.template.contains(",")) {
        validationErrors.add("template must not contain a ','");
    }
    if (request.template.contains("#")) {
        validationErrors.add("template must not contain a '#'");
    }
    if (request.template.startsWith("_")) {
        validationErrors.add("template must not start with '_'");
    }
    if (!Strings.validFileNameExcludingAstrix(request.template)) {
        validationErrors.add("template must not container the following characters " + Strings.INVALID_FILENAME_CHARS);
    }

    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.template.equals(alias.name())) {
            throw new IllegalArgumentException("Alias [" + alias.name() + "] cannot be the same as the template pattern [" + request.template + "]");
        }
    }
}
 
Example 5
Source File: MetaDataIndexTemplateService.java    From crate with Apache License 2.0 4 votes vote down vote up
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, true); // templates must be consistent with regards to dependencies
    } catch (IllegalArgumentException iae) {
        validationErrors.add(iae.getMessage());
        for (Throwable t : iae.getSuppressed()) {
            validationErrors.add(t.getMessage());
        }
    }
    List<String> indexSettingsValidation = metaDataCreateIndexService.getIndexSettingsValidationErrors(request.settings, true);
    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) + "]");
        }
    }
}