Search in sources :

Example 1 with StorageException

use of com.microsoft.azure.storage.StorageException in project camel by apache.

the class BlobServiceConsumer method poll.

@Override
protected int poll() throws Exception {
    Exchange exchange = super.getEndpoint().createExchange();
    try {
        LOG.trace("Getting the blob content");
        getBlob(exchange);
        super.getAsyncProcessor().process(exchange);
        return 1;
    } catch (StorageException ex) {
        if (404 == ex.getHttpStatusCode()) {
            return 0;
        } else {
            throw ex;
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) StorageException(com.microsoft.azure.storage.StorageException)

Example 2 with StorageException

use of com.microsoft.azure.storage.StorageException in project hadoop by apache.

the class LocalSASKeyGeneratorImpl method getSASKeyBasedStorageAccountInstance.

/**
   * Helper method that creates a CloudStorageAccount instance based on
   *  SAS key for accountName
   *
   * @param accountName Storage Account Name
   * @return CloudStorageAccount instance created using SAS key for
   *   the Storage Account.
   * @throws SASKeyGenerationException
   */
private CloudStorageAccount getSASKeyBasedStorageAccountInstance(String accountName) throws SASKeyGenerationException {
    try {
        String accountNameWithoutDomain = getAccountNameWithoutDomain(accountName);
        CloudStorageAccount account = getStorageAccountInstance(accountNameWithoutDomain, AzureNativeFileSystemStore.getAccountKeyFromConfiguration(accountName, getConf()));
        return new CloudStorageAccount(new StorageCredentialsSharedAccessSignature(account.generateSharedAccessSignature(getDefaultAccountAccessPolicy())), false, account.getEndpointSuffix(), accountNameWithoutDomain);
    } catch (KeyProviderException keyProviderEx) {
        throw new SASKeyGenerationException("Encountered KeyProviderException" + " while retrieving Storage key from configuration for account " + accountName, keyProviderEx);
    } catch (InvalidKeyException invalidKeyEx) {
        throw new SASKeyGenerationException("Encoutered InvalidKeyException " + "while generating Account level SAS key for account" + accountName, invalidKeyEx);
    } catch (StorageException storeEx) {
        throw new SASKeyGenerationException("Encoutered StorageException while " + "generating Account level SAS key for account" + accountName, storeEx);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException for" + " account " + accountName, uriSyntaxEx);
    }
}
Also used : StorageCredentialsSharedAccessSignature(com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 3 with StorageException

use of com.microsoft.azure.storage.StorageException in project hadoop by apache.

the class NativeAzureFileSystem method setPermission.

@Override
public void setPermission(Path p, FsPermission permission) throws FileNotFoundException, IOException {
    Path absolutePath = makeAbsolute(p);
    performAuthCheck(absolutePath.toString(), WasbAuthorizationOperations.EXECUTE.toString(), "setPermission");
    String key = pathToKey(absolutePath);
    FileMetadata metadata = null;
    try {
        metadata = store.retrieveMetadata(key);
    } catch (IOException ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("File %s doesn't exists.", p));
        }
        throw ex;
    }
    if (metadata == null) {
        throw new FileNotFoundException("File doesn't exist: " + p);
    }
    permission = applyUMask(permission, metadata.isDir() ? UMaskApplyMode.ChangeExistingDirectory : UMaskApplyMode.ChangeExistingFile);
    if (metadata.getBlobMaterialization() == BlobMaterialization.Implicit) {
        // It's an implicit folder, need to materialize it.
        store.storeEmptyFolder(key, createPermissionStatus(permission));
    } else if (!metadata.getPermissionStatus().getPermission().equals(permission)) {
        store.changePermissionStatus(key, new PermissionStatus(metadata.getPermissionStatus().getUserName(), metadata.getPermissionStatus().getGroupName(), permission));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException) PermissionStatus(org.apache.hadoop.fs.permission.PermissionStatus)

Example 4 with StorageException

use of com.microsoft.azure.storage.StorageException in project hadoop by apache.

the class NativeAzureFileSystem method append.

/** This optional operation is not yet supported. */
@Override
public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException {
    if (!appendSupportEnabled) {
        throw new UnsupportedOperationException("Append Support not enabled");
    }
    LOG.debug("Opening file: {} for append", f);
    Path absolutePath = makeAbsolute(f);
    performAuthCheck(absolutePath.toString(), WasbAuthorizationOperations.WRITE.toString(), "append");
    String key = pathToKey(absolutePath);
    FileMetadata meta = null;
    try {
        meta = store.retrieveMetadata(key);
    } catch (Exception ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", key));
        } else {
            throw ex;
        }
    }
    if (meta == null) {
        throw new FileNotFoundException(f.toString());
    }
    if (meta.isDir()) {
        throw new FileNotFoundException(f.toString() + " is a directory not a file.");
    }
    if (store.isPageBlobKey(key)) {
        throw new IOException("Append not supported for Page Blobs");
    }
    DataOutputStream appendStream = null;
    try {
        appendStream = store.retrieveAppendStream(key, bufferSize);
    } catch (Exception ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", key));
        } else {
            throw ex;
        }
    }
    return new FSDataOutputStream(appendStream, statistics);
}
Also used : Path(org.apache.hadoop.fs.Path) DataOutputStream(java.io.DataOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) StorageException(com.microsoft.azure.storage.StorageException) URISyntaxException(java.net.URISyntaxException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) StorageException(com.microsoft.azure.storage.StorageException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException)

Example 5 with StorageException

use of com.microsoft.azure.storage.StorageException in project hadoop by apache.

the class NativeAzureFileSystem method open.

@Override
public FSDataInputStream open(Path f, int bufferSize) throws FileNotFoundException, IOException {
    LOG.debug("Opening file: {}", f.toString());
    Path absolutePath = makeAbsolute(f);
    performAuthCheck(absolutePath.toString(), WasbAuthorizationOperations.READ.toString(), "read");
    String key = pathToKey(absolutePath);
    FileMetadata meta = null;
    try {
        meta = store.retrieveMetadata(key);
    } catch (Exception ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", key));
        }
        throw ex;
    }
    if (meta == null) {
        throw new FileNotFoundException(f.toString());
    }
    if (meta.isDir()) {
        throw new FileNotFoundException(f.toString() + " is a directory not a file.");
    }
    DataInputStream inputStream = null;
    try {
        inputStream = store.retrieve(key);
    } catch (Exception ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", key));
        }
        throw ex;
    }
    return new FSDataInputStream(new BufferedFSInputStream(new NativeAzureFsInputStream(inputStream, key, meta.getLength()), bufferSize));
}
Also used : Path(org.apache.hadoop.fs.Path) BufferedFSInputStream(org.apache.hadoop.fs.BufferedFSInputStream) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream) StorageException(com.microsoft.azure.storage.StorageException) URISyntaxException(java.net.URISyntaxException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) StorageException(com.microsoft.azure.storage.StorageException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException)

Aggregations

StorageException (com.microsoft.azure.storage.StorageException)55 URISyntaxException (java.net.URISyntaxException)34 IOException (java.io.IOException)31 Path (org.apache.hadoop.fs.Path)13 FileNotFoundException (java.io.FileNotFoundException)10 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)10 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)8 InputStream (java.io.InputStream)7 JsonParseException (com.fasterxml.jackson.core.JsonParseException)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)5 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)5 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)5 EOFException (java.io.EOFException)5 InvalidKeyException (java.security.InvalidKeyException)5 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)5 AccessCondition (com.microsoft.azure.storage.AccessCondition)4 BlobRequestOptions (com.microsoft.azure.storage.blob.BlobRequestOptions)4 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)4 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)4 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)4