Search in sources :

Example 21 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)

Aggregations

IOException (java.io.IOException)21 ElasticsearchGenerationException (org.elasticsearch.ElasticsearchGenerationException)21 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)19 UncheckedIOException (java.io.UncheckedIOException)7 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