Search in sources :

Example 51 with StorageException

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

the class NativeAzureFileSystem method listStatus.

/**
   * Retrieve the status of a given path if it is a file, or of all the
   * contained files if it is a directory.
   */
@Override
public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException {
    LOG.debug("Listing status for {}", f.toString());
    Path absolutePath = makeAbsolute(f);
    performAuthCheck(absolutePath.toString(), WasbAuthorizationOperations.EXECUTE.toString(), "list");
    String key = pathToKey(absolutePath);
    Set<FileStatus> status = new TreeSet<FileStatus>();
    FileMetadata meta = null;
    try {
        meta = store.retrieveMetadata(key);
    } catch (IOException ex) {
        Throwable innerException = NativeAzureFileSystemHelper.checkForAzureStorageException(ex);
        if (innerException instanceof StorageException && NativeAzureFileSystemHelper.isFileNotFoundException((StorageException) innerException)) {
            throw new FileNotFoundException(String.format("%s is not found", f));
        }
        throw ex;
    }
    if (meta != null) {
        if (!meta.isDir()) {
            LOG.debug("Found path as a file");
            return new FileStatus[] { newFile(meta, absolutePath) };
        }
        String partialKey = null;
        PartialListing listing = null;
        try {
            listing = store.list(key, AZURE_LIST_ALL, 1, partialKey);
        } catch (IOException 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;
        }
        // NOTE: We don't check for Null condition as the Store API should return
        // an empty list if there are not listing.
        // For any -RenamePending.json files in the listing,
        // push the rename forward.
        boolean renamed = conditionalRedoFolderRenames(listing);
        // since the current one may have changed due to the redo.
        if (renamed) {
            listing = null;
            try {
                listing = store.list(key, AZURE_LIST_ALL, 1, partialKey);
            } catch (IOException 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;
            }
        }
        for (FileMetadata fileMetadata : listing.getFiles()) {
            Path subpath = keyToPath(fileMetadata.getKey());
            // using "-lsr" down the file system hierarchy.
            if (fileMetadata.isDir()) {
                // Make sure we hide the temp upload folder
                if (fileMetadata.getKey().equals(AZURE_TEMP_FOLDER)) {
                    // Don't expose that.
                    continue;
                }
                status.add(newDirectory(fileMetadata, subpath));
            } else {
                status.add(newFile(fileMetadata, subpath));
            }
        }
        LOG.debug("Found path as a directory with {}" + " files in it.", status.size());
    } else {
        // There is no metadata found for the path.
        LOG.debug("Did not find any metadata for path: {}", key);
        throw new FileNotFoundException("File" + f + " does not exist.");
    }
    return status.toArray(new FileStatus[0]);
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) TreeSet(java.util.TreeSet) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 52 with StorageException

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

the class NativeAzureFileSystem method getFileStatus.

@Override
public FileStatus getFileStatus(Path f) throws FileNotFoundException, IOException {
    LOG.debug("Getting the file status for {}", f.toString());
    // Capture the absolute path and the path to key.
    Path absolutePath = makeAbsolute(f);
    performAuthCheck(absolutePath.toString(), WasbAuthorizationOperations.EXECUTE.toString(), "getFileStatus");
    String key = pathToKey(absolutePath);
    if (key.length() == 0) {
        // root always exists
        return newDirectory(null, absolutePath);
    }
    // The path is either a folder or a file. Retrieve metadata to
    // determine if it is a directory or file.
    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) {
        if (meta.isDir()) {
            // The path is a folder with files in it.
            //
            LOG.debug("Path {} is a folder.", f.toString());
            // Then the file does not exist, so signal that.
            if (conditionalRedoFolderRename(f)) {
                throw new FileNotFoundException(absolutePath + ": No such file or directory.");
            }
            // Return reference to the directory object.
            return newDirectory(meta, absolutePath);
        }
        // The path is a file.
        LOG.debug("Found the path: {} as a file.", f.toString());
        // Return with reference to a file object.
        return newFile(meta, absolutePath);
    }
    //
    throw new FileNotFoundException(absolutePath + ": No such file or directory.");
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) 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 53 with StorageException

use of com.microsoft.azure.storage.StorageException in project azure-sdk-for-java by Azure.

the class ManageWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 54 with StorageException

use of com.microsoft.azure.storage.StorageException in project azure-sdk-for-java by Azure.

the class ManageLinuxWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 55 with StorageException

use of com.microsoft.azure.storage.StorageException in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method addMetadataRecordImpl.

private void addMetadataRecordImpl(final InputStream input, String name, long recordLength) throws DataStoreException {
    try {
        CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
        CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
        blob.upload(input, recordLength);
    } catch (StorageException e) {
        LOG.info("Error adding metadata record. metadataName={} length={}", name, recordLength, e);
        throw new DataStoreException(e);
    } catch (URISyntaxException | IOException e) {
        throw new DataStoreException(e);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

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