Search in sources :

Example 6 with CloudBlockBlob

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

the class BlobServiceUtilTest method testGetConfiguredClientTypeMismatch.

@Test
public void testGetConfiguredClientTypeMismatch() 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" + "&blobType=appendBlob");
    try {
        BlobServiceUtil.getConfiguredClient(endpoint.getConfiguration());
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("Invalid Client Type", ex.getMessage());
    }
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 7 with CloudBlockBlob

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

the class TestWasbUriAndConfiguration method testConnectUsingSASReadonly.

@Test
public void testConnectUsingSASReadonly() throws Exception {
    Assume.assumeFalse(runningInSASMode);
    // Create the test account with SAS credentials.
    testAccount = AzureBlobStorageTestAccount.create("", EnumSet.of(CreateOptions.UseSas, CreateOptions.CreateContainer, CreateOptions.Readonly));
    assumeNotNull(testAccount);
    // Create a blob in there
    final String blobKey = "blobForReadonly";
    CloudBlobContainer container = testAccount.getRealContainer();
    CloudBlockBlob blob = container.getBlockBlobReference(blobKey);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] { 1, 2, 3 });
    blob.upload(inputStream, 3);
    inputStream.close();
    // Make sure we can read it from the file system
    Path filePath = new Path("/" + blobKey);
    FileSystem fs = testAccount.getFileSystem();
    assertTrue(fs.exists(filePath));
    byte[] obtained = new byte[3];
    DataInputStream obtainedInputStream = fs.open(filePath);
    obtainedInputStream.readFully(obtained);
    obtainedInputStream.close();
    assertEquals(3, obtained[2]);
}
Also used : Path(org.apache.hadoop.fs.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) FileSystem(org.apache.hadoop.fs.FileSystem) AbstractFileSystem(org.apache.hadoop.fs.AbstractFileSystem) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 8 with CloudBlockBlob

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_firstLevelFolderDelete.

@Test
public void outOfBandFolder_firstLevelFolderDelete() throws Exception {
    CloudBlockBlob blob = testAccount.getBlobReference("folderW/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    assertTrue(fs.exists(new Path("/folderW")));
    assertTrue(fs.exists(new Path("/folderW/file")));
    assertTrue(fs.delete(new Path("/folderW"), true));
}
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 9 with CloudBlockBlob

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_rename.

// scenario for this particular test described at MONARCH-HADOOP-764
@Test
public void outOfBandFolder_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 + "testFolder4/a/input/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    Path srcFilePath = new Path("testFolder4/a/input/file");
    assertTrue(fs.exists(srcFilePath));
    Path destFilePath = new Path("testFolder4/a/input/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)

Example 10 with CloudBlockBlob

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_siblingCreate.

// scenario for this particular test described at MONARCH-HADOOP-764
@Test
public void outOfBandFolder_siblingCreate() 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 + "testFolder3/a/input/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    assertTrue(fs.exists(new Path("testFolder3/a/input/file")));
    Path targetFile = new Path("testFolder3/a/input/file2");
    FSDataOutputStream s2 = fs.create(targetFile);
    s2.close();
}
Also used : Path(org.apache.hadoop.fs.Path) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) 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