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;
}
}
}
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);
}
}
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));
}
}
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);
}
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));
}
Aggregations