org.elasticsearch.common.ValidationException Java Examples

The following examples show how to use org.elasticsearch.common.ValidationException. 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: ElasticSearchIndexer.java    From james-project with Apache License 2.0 6 votes vote down vote up
public Mono<BulkResponse> update(List<UpdatedRepresentation> updatedDocumentParts, RoutingKey routingKey) {
    Preconditions.checkNotNull(updatedDocumentParts);
    Preconditions.checkNotNull(routingKey);
    BulkRequest request = new BulkRequest();
    updatedDocumentParts.forEach(updatedDocumentPart -> request.add(
        new UpdateRequest(aliasName.getValue(),
            NodeMappingFactory.DEFAULT_MAPPING_NAME,
            updatedDocumentPart.getId().asString())
            .doc(updatedDocumentPart.getUpdatedDocumentPart(), XContentType.JSON)
            .routing(routingKey.asString())));

    return client.bulk(request, RequestOptions.DEFAULT)
        .onErrorResume(ValidationException.class, exception -> {
            LOGGER.warn("Error while updating index", exception);
            return Mono.empty();
        });
}
 
Example #2
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 #3
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 #4
Source File: ElasticSearchIndexer.java    From james-project with Apache License 2.0 5 votes vote down vote up
public Mono<BulkResponse> delete(List<DocumentId> ids, RoutingKey routingKey) {
    BulkRequest request = new BulkRequest();
    ids.forEach(id -> request.add(
        new DeleteRequest(aliasName.getValue())
            .type(NodeMappingFactory.DEFAULT_MAPPING_NAME)
            .id(id.asString())
            .routing(routingKey.asString())));

    return client.bulk(request, RequestOptions.DEFAULT)
        .onErrorResume(ValidationException.class, exception -> {
            LOGGER.warn("Error while deleting index", exception);
            return Mono.empty();
        });
}
 
Example #5
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 #6
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 #7
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) + "]");
        }
    }
}