use of com.microsoft.azure.storage.blob.CloudBlobContainer in project camel by apache.
the class BlobServiceProducer method listBlobs.
private void listBlobs(Exchange exchange) throws Exception {
CloudBlobContainer client = BlobServiceUtil.createBlobContainerClient(getConfiguration());
BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
LOG.trace("Getting the blob list from the container [{}] from exchange [{}]...", getConfiguration().getContainerName(), exchange);
BlobServiceConfiguration cfg = getConfiguration();
EnumSet<BlobListingDetails> details = null;
Object detailsObject = exchange.getIn().getHeader(BlobServiceConstants.BLOB_LISTING_DETAILS);
if (detailsObject instanceof EnumSet) {
@SuppressWarnings("unchecked") EnumSet<BlobListingDetails> theDetails = (EnumSet<BlobListingDetails>) detailsObject;
details = theDetails;
} else if (detailsObject instanceof BlobListingDetails) {
details = EnumSet.of((BlobListingDetails) detailsObject);
}
Iterable<ListBlobItem> items = client.listBlobs(cfg.getBlobPrefix(), cfg.isUseFlatListing(), details, opts.getRequestOpts(), opts.getOpContext());
ExchangeUtil.getMessageForResponse(exchange).setBody(items);
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project camel by apache.
the class BlobServiceUtil method createBlobContainerClient.
public static CloudBlobContainer createBlobContainerClient(BlobServiceConfiguration cfg) throws Exception {
URI uri = prepareStorageBlobUri(cfg, false);
StorageCredentials creds = getAccountCredentials(cfg);
return new CloudBlobContainer(uri, creds);
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer 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]);
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer 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());
}
use of com.microsoft.azure.storage.blob.CloudBlobContainer in project hadoop by apache.
the class TestContainerChecks method testContainerCreateOnWrite.
@Test
public void testContainerCreateOnWrite() 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());
// A list shouldn't create the container.
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());
// Neither should a read.
try {
fs.open(new Path("/foo"));
assertFalse("Should've thrown.", true);
} catch (FileNotFoundException ex) {
}
assertFalse(container.exists());
// Neither should a rename
assertFalse(fs.rename(new Path("/foo"), new Path("/bar")));
assertFalse(container.exists());
// But a write should.
assertTrue(fs.createNewFile(new Path("/foo")));
assertTrue(container.exists());
}
Aggregations