Search in sources :

Example 11 with CloudBlobWrapper

use of org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper in project hadoop by apache.

the class AzureNativeFileSystemStore method retrieve.

@Override
public DataInputStream retrieve(String key) throws AzureException, IOException {
    try {
        // Azure storage server.
        if (null == storageInteractionLayer) {
            final String errMsg = String.format("Storage session expected for URI '%s' but does not exist.", sessionUri);
            throw new AssertionError(errMsg);
        }
        checkContainer(ContainerAccessType.PureRead);
        // Get blob reference and open the input buffer stream.
        CloudBlobWrapper blob = getBlobReference(key);
        BufferedInputStream inBufStream = new BufferedInputStream(openInputStream(blob));
        // Return a data input stream.
        DataInputStream inDataStream = new DataInputStream(inBufStream);
        return inDataStream;
    } catch (Exception e) {
        // Re-throw as an Azure storage exception.
        throw new AzureException(e);
    }
}
Also used : CloudBlobWrapper(org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException)

Example 12 with CloudBlobWrapper

use of org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper in project hadoop by apache.

the class AzureNativeFileSystemStore method storeEmptyLinkFile.

/**
   * Stores an empty blob that's linking to the temporary file where're we're
   * uploading the initial data.
   */
@Override
public void storeEmptyLinkFile(String key, String tempBlobKey, PermissionStatus permissionStatus) throws AzureException {
    if (null == storageInteractionLayer) {
        final String errMsg = String.format("Storage session expected for URI '%s' but does not exist.", sessionUri);
        throw new AssertionError(errMsg);
    }
    // been authenticated and all access is anonymous.
    if (!isAuthenticatedAccess()) {
        // allowed to anonymous accounts.
        throw new AzureException("Uploads to to public accounts using anonymous access is prohibited.");
    }
    try {
        checkContainer(ContainerAccessType.PureWrite);
        CloudBlobWrapper blob = getBlobReference(key);
        storePermissionStatus(blob, permissionStatus);
        storeLinkAttribute(blob, tempBlobKey);
        openOutputStream(blob).close();
    } catch (Exception e) {
        // storage exception.
        throw new AzureException(e);
    }
}
Also used : CloudBlobWrapper(org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException)

Example 13 with CloudBlobWrapper

use of org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper in project hadoop by apache.

the class AzureNativeFileSystemStore method getLinkInFileMetadata.

/**
   * If the blob with the given key exists and has a link in its metadata to a
   * temporary file (see storeEmptyLinkFile), this method returns the key to
   * that temporary file. Otherwise, returns null.
   */
@Override
public String getLinkInFileMetadata(String key) throws AzureException {
    if (null == storageInteractionLayer) {
        final String errMsg = String.format("Storage session expected for URI '%s' but does not exist.", sessionUri);
        throw new AssertionError(errMsg);
    }
    try {
        checkContainer(ContainerAccessType.PureRead);
        CloudBlobWrapper blob = getBlobReference(key);
        blob.downloadAttributes(getInstrumentedContext());
        return getLinkAttributeValue(blob);
    } catch (Exception e) {
        // storage exception.
        throw new AzureException(e);
    }
}
Also used : CloudBlobWrapper(org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException)

Example 14 with CloudBlobWrapper

use of org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper in project hadoop by apache.

the class AzureNativeFileSystemStore method retrieveAppendStream.

@Override
public DataOutputStream retrieveAppendStream(String key, int bufferSize) throws IOException {
    try {
        if (isPageBlobKey(key)) {
            throw new UnsupportedOperationException("Append not supported for Page Blobs");
        }
        CloudBlobWrapper blob = this.container.getBlockBlobReference(key);
        BlockBlobAppendStream appendStream = new BlockBlobAppendStream((CloudBlockBlobWrapper) blob, key, bufferSize, getInstrumentedContext());
        appendStream.initialize();
        return new DataOutputStream(appendStream);
    } catch (Exception ex) {
        throw new AzureException(ex);
    }
}
Also used : CloudBlobWrapper(org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper) DataOutputStream(java.io.DataOutputStream) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException)

Example 15 with CloudBlobWrapper

use of org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper in project hadoop by apache.

the class AzureNativeFileSystemStore method storefile.

@Override
public DataOutputStream storefile(String key, PermissionStatus permissionStatus) throws AzureException {
    try {
        // Azure storage server.
        if (null == storageInteractionLayer) {
            final String errMsg = String.format("Storage session expected for URI '%s' but does not exist.", sessionUri);
            throw new AzureException(errMsg);
        }
        // has not been authenticated and all access is anonymous.
        if (!isAuthenticatedAccess()) {
            // allowed to anonymous accounts.
            throw new AzureException(new IOException("Uploads to public accounts using anonymous " + "access is prohibited."));
        }
        checkContainer(ContainerAccessType.PureWrite);
        // $root containers.
        if (AZURE_ROOT_CONTAINER.equals(getContainerFromAuthority(sessionUri))) {
            // Azure containers are restricted to non-root containers.
            final String errMsg = String.format("Writes to '%s' container for URI '%s' are prohibited, " + "only updates on non-root containers permitted.", AZURE_ROOT_CONTAINER, sessionUri.toString());
            throw new AzureException(errMsg);
        }
        // Get the blob reference from the store's container and
        // return it.
        CloudBlobWrapper blob = getBlobReference(key);
        storePermissionStatus(blob, permissionStatus);
        // Create the output stream for the Azure blob.
        //
        OutputStream outputStream = openOutputStream(blob);
        DataOutputStream dataOutStream = new SyncableDataOutputStream(outputStream);
        return dataOutStream;
    } catch (Exception e) {
        // Re-throw as an Azure storage exception.
        throw new AzureException(e);
    }
}
Also used : CloudBlobWrapper(org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper) DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException)

Aggregations

CloudBlobWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper)15 StorageException (com.microsoft.azure.storage.StorageException)13 IOException (java.io.IOException)13 URISyntaxException (java.net.URISyntaxException)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 InvalidKeyException (java.security.InvalidKeyException)11 BlobProperties (com.microsoft.azure.storage.blob.BlobProperties)3 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)3 BufferedInputStream (java.io.BufferedInputStream)3 DataInputStream (java.io.DataInputStream)3 DataOutputStream (java.io.DataOutputStream)3 CloudBlockBlobWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudBlockBlobWrapper)3 CloudPageBlobWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudPageBlobWrapper)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 CloudBlobDirectoryWrapper (org.apache.hadoop.fs.azure.StorageInterface.CloudBlobDirectoryWrapper)2 RetryExponentialRetry (com.microsoft.azure.storage.RetryExponentialRetry)1 BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)1 BlobRequestOptions (com.microsoft.azure.storage.blob.BlobRequestOptions)1 ArrayList (java.util.ArrayList)1