Search in sources :

Example 26 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project elasticsearch by elastic.

the class HdfsRepository method doStart.

@Override
protected void doStart() {
    String uriSetting = getMetadata().settings().get("uri");
    if (Strings.hasText(uriSetting) == false) {
        throw new IllegalArgumentException("No 'uri' defined for hdfs snapshot/restore");
    }
    URI uri = URI.create(uriSetting);
    if ("hdfs".equalsIgnoreCase(uri.getScheme()) == false) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Invalid scheme [%s] specified in uri [%s]; only 'hdfs' uri allowed for hdfs snapshot/restore", uri.getScheme(), uriSetting));
    }
    if (Strings.hasLength(uri.getPath()) && uri.getPath().equals("/") == false) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Use 'path' option to specify a path [%s], not the uri [%s] for hdfs snapshot/restore", uri.getPath(), uriSetting));
    }
    String pathSetting = getMetadata().settings().get("path");
    // get configuration
    if (pathSetting == null) {
        throw new IllegalArgumentException("No 'path' defined for hdfs snapshot/restore");
    }
    int bufferSize = getMetadata().settings().getAsBytesSize("buffer_size", DEFAULT_BUFFER_SIZE).bytesAsInt();
    try {
        // initialize our filecontext
        SpecialPermission.check();
        FileContext fileContext = AccessController.doPrivileged((PrivilegedAction<FileContext>) () -> createContext(uri, getMetadata().settings()));
        blobStore = new HdfsBlobStore(fileContext, pathSetting, bufferSize);
        logger.debug("Using file-system [{}] for URI [{}], path [{}]", fileContext.getDefaultFileSystem(), fileContext.getDefaultFileSystem().getUri(), pathSetting);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException(String.format(Locale.ROOT, "Cannot create HDFS repository for uri [%s]", uri), e);
    }
    super.doStart();
}
Also used : IOException(java.io.IOException) URI(java.net.URI) FileContext(org.apache.hadoop.fs.FileContext) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 27 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project crate by crate.

the class PutMappingRequest method source.

/**
 * The mapping source definition.
 */
@SuppressWarnings("unchecked")
public PutMappingRequest source(Map mappingSource) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(mappingSource);
        return source(Strings.toString(builder), XContentType.JSON);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + mappingSource + "]", e);
    }
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 28 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project crate by crate.

the class PutIndexTemplateRequest method mapping.

/**
 * Adds mapping that will be added when the index gets created.
 *
 * @param type   The mapping type
 * @param source The mapping source
 */
public PutIndexTemplateRequest mapping(String type, Map<String, Object> source) {
    // wrap it in a type map if its not
    if (source.size() != 1 || !source.containsKey(type)) {
        source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map();
    }
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        return mapping(type, builder);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 29 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project crate by crate.

the class PutIndexTemplateRequest method settings.

/**
 * The settings to create the index template with (either json or yaml format).
 */
public PutIndexTemplateRequest settings(Map<String, Object> source) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.map(source);
        settings(Strings.toString(builder), XContentType.JSON);
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
    return this;
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Example 30 with ElasticsearchGenerationException

use of org.elasticsearch.ElasticsearchGenerationException in project crate by crate.

the class PutIndexTemplateRequest method aliases.

/**
 * Sets the aliases that will be associated with the index when it gets created
 */
@SuppressWarnings("unchecked")
public PutIndexTemplateRequest aliases(Map source) {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.map(source);
        return aliases(BytesReference.bytes(builder));
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
    }
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchGenerationException(org.elasticsearch.ElasticsearchGenerationException)

Aggregations

IOException (java.io.IOException)36 ElasticsearchGenerationException (org.elasticsearch.ElasticsearchGenerationException)36 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)34 UncheckedIOException (java.io.UncheckedIOException)14 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 FileContext (org.apache.hadoop.fs.FileContext)1 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)1 XContentType (org.elasticsearch.common.xcontent.XContentType)1 GetResult (org.elasticsearch.index.get.GetResult)1 InvalidTypeNameException (org.elasticsearch.indices.InvalidTypeNameException)1 TypeMissingException (org.elasticsearch.indices.TypeMissingException)1