Search in sources :

Example 11 with CloudBlockBlob

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

the class TestBlobDataValidation method testStoreBlobMd5.

private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception {
    assumeNotNull(testAccount);
    // Write a test file.
    String testFileKey = "testFile";
    Path testFilePath = new Path("/" + testFileKey);
    OutputStream outStream = testAccount.getFileSystem().create(testFilePath);
    outStream.write(new byte[] { 5, 15 });
    outStream.close();
    // Check that we stored/didn't store the MD5 field as configured.
    CloudBlockBlob blob = testAccount.getBlobReference(testFileKey);
    blob.downloadAttributes();
    String obtainedMd5 = blob.getProperties().getContentMD5();
    if (expectMd5Stored) {
        assertNotNull(obtainedMd5);
    } else {
        assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5);
    }
    // Mess with the content so it doesn't match the MD5.
    String newBlockId = Base64.encode(new byte[] { 55, 44, 33, 22 });
    blob.uploadBlock(newBlockId, new ByteArrayInputStream(new byte[] { 6, 45 }), 2);
    blob.commitBlockList(Arrays.asList(new BlockEntry[] { new BlockEntry(newBlockId, BlockSearchMode.UNCOMMITTED) }));
    // Now read back the content. If we stored the MD5 for the blob content
    // we should get a data corruption error.
    InputStream inStream = testAccount.getFileSystem().open(testFilePath);
    try {
        byte[] inBuf = new byte[100];
        while (inStream.read(inBuf) > 0) {
        //nothing;
        }
        inStream.close();
        if (expectMd5Stored) {
            fail("Should've thrown because of data corruption.");
        }
    } catch (IOException ex) {
        if (!expectMd5Stored) {
            throw ex;
        }
        StorageException cause = (StorageException) ex.getCause();
        assertNotNull(cause);
        assertTrue("Unexpected cause: " + cause, cause.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MD5));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) BlockEntry(com.microsoft.azure.storage.blob.BlockEntry) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Example 12 with CloudBlockBlob

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_rootFileDelete.

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

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

the class TestOutOfBandAzureBlobOperationsLive method outOfBandFolder_parentDelete.

// scenario for this particular test described at MONARCH-HADOOP-764
@Test
public void outOfBandFolder_parentDelete() 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 + "testFolder2/a/input/file");
    BlobOutputStream s = blob.openOutputStream();
    s.close();
    assertTrue(fs.exists(new Path("testFolder2/a/input/file")));
    Path targetFolder = new Path("testFolder2/a/input");
    assertTrue(fs.delete(targetFolder, 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 14 with CloudBlockBlob

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

the class TestContainerChecks method testContainerExistAfterDoesNotExist.

@Test
public void testContainerExistAfterDoesNotExist() throws Exception {
    testAccount = AzureBlobStorageTestAccount.create("", EnumSet.noneOf(CreateOptions.class));
    assumeNotNull(testAccount);
    CloudBlobContainer container = testAccount.getRealContainer();
    FileSystem fs = testAccount.getFileSystem();
    // Starting off with the container not there
    assertFalse(container.exists());
    // state to DoesNotExist
    try {
        fs.listStatus(new Path("/"));
        assertTrue("Should've thrown.", false);
    } catch (FileNotFoundException ex) {
        assertTrue("Unexpected exception: " + ex, ex.getMessage().contains("does not exist."));
    }
    assertFalse(container.exists());
    // Create a container outside of the WASB FileSystem
    container.create();
    // Add a file to the container outside of the WASB FileSystem
    CloudBlockBlob blob = testAccount.getBlobReference("foo");
    BlobOutputStream outputStream = blob.openOutputStream();
    outputStream.write(new byte[10]);
    outputStream.close();
    // Make sure the file is visible
    assertTrue(fs.exists(new Path("/foo")));
    assertTrue(container.exists());
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobOutputStream(com.microsoft.azure.storage.blob.BlobOutputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 15 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project elasticsearch by elastic.

the class AzureStorageServiceImpl method getOutputStream.

@Override
public OutputStream getOutputStream(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
    logger.trace("writing container [{}], blob [{}]", container, blob);
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlockBlob blockBlobReference = client.getContainerReference(container).getBlockBlobReference(blob);
    return SocketAccess.doPrivilegedException(blockBlobReference::openOutputStream);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

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