Search in sources :

Example 36 with CloudBlockBlob

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

the class BlobServiceUtilTest method testGetConfiguredClient.

@Test
public void testGetConfiguredClient() throws Exception {
    CloudBlockBlob client = new CloudBlockBlob(URI.create("https://camelazure.blob.core.windows.net/container/blob"));
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("azureBlobClient", client);
    BlobServiceComponent component = new BlobServiceComponent(context);
    BlobServiceEndpoint endpoint = (BlobServiceEndpoint) component.createEndpoint("azure-blob://camelazure/container/blob?azureBlobClient=#azureBlobClient&publicForRead=true");
    assertSame(client, BlobServiceUtil.getConfiguredClient(endpoint.getConfiguration()));
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 37 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob 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)

Example 38 with CloudBlockBlob

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

the class LocalSASKeyGeneratorImpl method getRelativeBlobSASUri.

/**
   * Implementation for generation of Relative Path Blob SAS Uri.
   */
@Override
public URI getRelativeBlobSASUri(String accountName, String container, String relativePath) throws SASKeyGenerationException {
    CloudBlobContainer sc = null;
    CloudBlobClient client = null;
    try {
        CloudStorageAccount account = getSASKeyBasedStorageAccountInstance(accountName);
        client = account.createCloudBlobClient();
        sc = client.getContainerReference(container);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException " + "while getting container references for container " + container + " inside storage account : " + accountName, uriSyntaxEx);
    } catch (StorageException stoEx) {
        throw new SASKeyGenerationException("Encountered StorageException while " + "getting  container references for container " + container + " inside storage account : " + accountName, stoEx);
    }
    CloudBlockBlob blob = null;
    try {
        blob = sc.getBlockBlobReference(relativePath);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException while " + "getting Block Blob references for container " + container + " inside storage account : " + accountName, uriSyntaxEx);
    } catch (StorageException stoEx) {
        throw new SASKeyGenerationException("Encountered StorageException while " + "getting Block Blob references for container " + container + " inside storage account : " + accountName, stoEx);
    }
    try {
        return client.getCredentials().transformUri(blob.getUri());
    } catch (StorageException stoEx) {
        throw new SASKeyGenerationException("Encountered StorageException while " + "generating SAS key for Blob: " + relativePath + " inside " + "container : " + container + " in Storage Account : " + accountName, stoEx);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException " + "while generating SAS key for Blob: " + relativePath + " inside " + "container: " + container + " in Storage Account : " + accountName, uriSyntaxEx);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 39 with CloudBlockBlob

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_rename_rootLevelFiles.

// WASB must force explicit parent directories in create, delete, mkdirs, rename.
// scenario for this particular test described at MONARCH-HADOOP-764
@Test
public void outOfBandFolder_rename_rootLevelFiles() throws Exception {
    // NOTE: manual use of CloubBlockBlob targets working directory explicitly.
    // WASB driver methods prepend working directory implicitly.
    CloudBlockBlob blob = testAccount.getBlobReference("fileX");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    Path srcFilePath = new Path("/fileX");
    assertTrue(fs.exists(srcFilePath));
    Path destFilePath = new Path("/fileXrename");
    fs.rename(srcFilePath, destFilePath);
}
Also used : Path(org.apache.hadoop.fs.Path) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 40 with CloudBlockBlob

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandSingleFile_rename.

// Verify that you can rename a file which is the only file in an implicit folder in the
// WASB file system.
// scenario for this particular test described at MONARCH-HADOOP-892
@Test
public void outOfBandSingleFile_rename() throws Exception {
    //NOTE: manual use of CloubBlockBlob targets working directory explicitly.
    //       WASB driver methods prepend working directory implicitly.
    String workingDir = "user/" + UserGroupInformation.getCurrentUser().getShortUserName() + "/";
    CloudBlockBlob blob = testAccount.getBlobReference(workingDir + "testFolder5/a/input/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    Path srcFilePath = new Path("testFolder5/a/input/file");
    assertTrue(fs.exists(srcFilePath));
    Path destFilePath = new Path("testFolder5/file2");
    fs.rename(srcFilePath, destFilePath);
}
Also used : Path(org.apache.hadoop.fs.Path) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Aggregations

CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)42 Test (org.junit.Test)17 StorageException (com.microsoft.azure.storage.StorageException)11 Path (org.apache.hadoop.fs.Path)11 URISyntaxException (java.net.URISyntaxException)10 BlobOutputStream (com.microsoft.azure.storage.blob.BlobOutputStream)9 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)9 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)8 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileNotFoundException (java.io.FileNotFoundException)5 BlockEntry (com.microsoft.azure.storage.blob.BlockEntry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 JndiRegistry (org.apache.camel.impl.JndiRegistry)4 URI (java.net.URI)3 InvalidKeyException (java.security.InvalidKeyException)3 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)2