Java Code Examples for com.microsoft.azure.storage.blob.CloudBlobClient#getContainerReference()
The following examples show how to use
com.microsoft.azure.storage.blob.CloudBlobClient#getContainerReference() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 7 votes |
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient, String accountName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient.getContainerReference("https://" + accountName + "/" + "$root"); container.createIfNotExists(); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); // Return a reference to the block blob object. return blob; }
Example 2
Source File: AzureConnectionManager.java From sunbird-lms-service with MIT License | 7 votes |
/** * This method will provide Azure CloudBlobContainer object or in case of error it will provide * null; * * @param containerName String * @return CloudBlobContainer or null */ public static CloudBlobContainer getContainer(String containerName, boolean isPublicAccess) { try { CloudBlobClient cloudBlobClient = getBlobClient(); // Get a reference to a container , The container name must be lower case CloudBlobContainer container = cloudBlobClient.getContainerReference(containerName.toLowerCase(Locale.ENGLISH)); // Create the container if it does not exist. boolean response = container.createIfNotExists(); ProjectLogger.log("container creation done if not exist==" + response); // Create a permissions object. if (isPublicAccess) { BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Include public access in the permissions object. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the permissions on the container. container.uploadPermissions(containerPermissions); } return container; } catch (Exception e) { ProjectLogger.log(e.getMessage(), e); } return null; }
Example 3
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 7 votes |
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient, String accountName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient.getContainerReference("https://" + accountName + "/" + "$root"); container.createIfNotExists(); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); // Return a reference to the block blob object. return blob; }
Example 4
Source File: StorageAccountTests.java From azure-storage-android with Apache License 2.0 | 6 votes |
@Test public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString()); CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference("queue1"); assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString()); CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient(); CloudTable table = tableClient.getTableReference("table1"); assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString()); CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference("share1"); assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString()); }
Example 5
Source File: BlobBasics.java From storage-blob-java-getting-started with MIT License | 6 votes |
/** * Creates and returns a container for the sample application to use. * * @param blobClient CloudBlobClient object * @param containerName Name of the container to create * @return The newly created CloudBlobContainer object * * @throws StorageException * @throws RuntimeException * @throws IOException * @throws URISyntaxException * @throws IllegalArgumentException * @throws InvalidKeyException * @throws IllegalStateException */ private static CloudBlobContainer createContainer(CloudBlobClient blobClient, String containerName) throws StorageException, RuntimeException, IOException, InvalidKeyException, IllegalArgumentException, URISyntaxException, IllegalStateException { // Create a new container CloudBlobContainer container = blobClient.getContainerReference(containerName); try { if (container.createIfNotExists() == false) { throw new IllegalStateException(String.format("Container with name \"%s\" already exists.", containerName)); } } catch (StorageException s) { if (s.getCause() instanceof java.net.ConnectException) { System.out.println("Caught connection exception from the client. If running with the default configuration please make sure you have started the storage emulator."); } throw s; } return container; }
Example 6
Source File: AzureSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateAdlsGen2FileSystem(SpiFileSystem fileSystem) throws URISyntaxException, InvalidKeyException, StorageException { CloudAdlsGen2View cloudFileSystem = (CloudAdlsGen2View) fileSystem.getCloudFileSystems().get(0); String accountName = cloudFileSystem.getAccountName(); String accountKey = cloudFileSystem.getAccountKey(); String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=core.windows.net"; CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString); CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); CloudBlobContainer containerReference = blobClient.getContainerReference(TEST_CONTAINER + System.nanoTime()); try { containerReference.createIfNotExists(); containerReference.delete(); } catch (StorageException e) { if (e.getCause() instanceof UnknownHostException) { throw new CloudConnectorException("The provided account does not belong to a valid storage account"); } } }
Example 7
Source File: GenericTests.java From azure-storage-android with Apache License 2.0 | 6 votes |
@Test public void testDefaultProxy() throws URISyntaxException, StorageException { CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); // Use a default proxy OperationContext.setDefaultProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8888))); // Turn off retries to make the failure happen faster BlobRequestOptions opt = new BlobRequestOptions(); opt.setRetryPolicyFactory(new RetryNoRetry()); // Unfortunately HttpURLConnection doesn't expose a getter and the usingProxy method it does have doesn't // work as one would expect and will always for us return false. So, we validate by making sure the request // fails when we set a bad proxy rather than check the proxy setting itself succeeding. try { container.exists(null, opt, null); fail("Bad proxy should throw an exception."); } catch (StorageException e) { if (e.getCause().getClass() != ConnectException.class && e.getCause().getClass() != SocketTimeoutException.class && e.getCause().getClass() != SocketException.class) { Assert.fail("Unepected exception for bad proxy"); } } }
Example 8
Source File: DeleteAzureBlobStorage.java From nifi with Apache License 2.0 | 5 votes |
@Override public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException { FlowFile flowFile = session.get(); if(flowFile == null) { return; } final long startNanos = System.nanoTime(); final String containerName = context.getProperty(AzureStorageUtils.CONTAINER).evaluateAttributeExpressions(flowFile).getValue(); final String blobPath = context.getProperty(BLOB).evaluateAttributeExpressions(flowFile).getValue(); final String deleteSnapshotOptions = context.getProperty(DELETE_SNAPSHOTS_OPTION).getValue(); try { CloudBlobClient blobClient = AzureStorageUtils.createCloudBlobClient(context, getLogger(), flowFile); CloudBlobContainer container = blobClient.getContainerReference(containerName); CloudBlob blob = container.getBlockBlobReference(blobPath); final OperationContext operationContext = new OperationContext(); AzureStorageUtils.setProxy(operationContext, context); blob.deleteIfExists(DeleteSnapshotsOption.valueOf(deleteSnapshotOptions), null, null, operationContext); session.transfer(flowFile, REL_SUCCESS); final long transferMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos); session.getProvenanceReporter().invokeRemoteProcess(flowFile, blob.getSnapshotQualifiedUri().toString(), "Blob deleted"); } catch ( StorageException | URISyntaxException e) { getLogger().error("Failed to delete the specified blob {} from Azure Storage. Routing to failure", new Object[]{blobPath}, e); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); } }
Example 9
Source File: AbstractAzureBlobStorageIT.java From nifi with Apache License 2.0 | 5 votes |
@Before public void setUpAzureBlobStorageIT() throws Exception { String containerName = String.format("%s-%s", TEST_CONTAINER_NAME_PREFIX, UUID.randomUUID()); CloudBlobClient blobClient = getStorageAccount().createCloudBlobClient(); container = blobClient.getContainerReference(containerName); container.createIfNotExists(); runner.setProperty(AzureStorageUtils.CONTAINER, containerName); }
Example 10
Source File: StorageServiceImpl.java From cs-actions with Apache License 2.0 | 5 votes |
@NotNull public static String deleteContainer(@NotNull final StorageInputs inputs) throws Exception { final CloudBlobClient blobClient = getCloudBlobClient(inputs); final CloudBlobContainer container = blobClient.getContainerReference(inputs.getContainerName()); container.delete(); return inputs.getContainerName(); }
Example 11
Source File: GenericTests.java From azure-storage-android with Apache License 2.0 | 5 votes |
@Test public void testProxyOverridesDefault() throws URISyntaxException, StorageException { CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); // Set a default proxy OperationContext.setDefaultProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8888))); // Turn off retries to make the failure happen faster BlobRequestOptions opt = new BlobRequestOptions(); opt.setRetryPolicyFactory(new RetryNoRetry()); // Unfortunately HttpURLConnection doesn't expose a getter and the usingProxy method it does have doesn't // work as one would expect and will always for us return false. So, we validate by making sure the request // fails when we set a bad proxy rather than check the proxy setting itself succeeding. try { container.exists(null, opt, null); fail("Bad proxy should throw an exception."); } catch (StorageException e) { if (e.getCause().getClass() != ConnectException.class && e.getCause().getClass() != SocketTimeoutException.class) { Assert.fail("Unepected exception for bad proxy"); } } // Override it with no proxy OperationContext opContext = new OperationContext(); opContext.setProxy(Proxy.NO_PROXY); // Should succeed as request-level proxy should override the bad default proxy container.exists(null, null, opContext); }
Example 12
Source File: GenericTests.java From azure-storage-android with Apache License 2.0 | 5 votes |
@Test public void testProxy() throws URISyntaxException, StorageException { CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); // Use a request-level proxy OperationContext opContext = new OperationContext(); opContext.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8888))); // Turn of retries to make the failure happen faster BlobRequestOptions opt = new BlobRequestOptions(); opt.setRetryPolicyFactory(new RetryNoRetry()); // Unfortunately HttpURLConnection doesn't expose a getter and the usingProxy method it does have doesn't // work as one would expect and will always for us return false. So, we validate by making sure the request // fails when we set a bad proxy rather than check the proxy setting itself. try { container.exists(null, opt, opContext); fail("Bad proxy should throw an exception."); } catch (StorageException e) { if (e.getCause().getClass() != ConnectException.class && e.getCause().getClass() != SocketTimeoutException.class && e.getCause().getClass() != SocketException.class) { Assert.fail("Unepected exception for bad proxy"); } } }
Example 13
Source File: PreviewStorageAzure.java From arcusplatform with Apache License 2.0 | 5 votes |
private static CloudBlobContainer getStorageContainer(CloudBlobClient client, String container) { try { CloudBlobContainer cnt = client.getContainerReference(container); cnt.createIfNotExists(); return cnt; } catch (Exception ex) { VIDEO_PREVIEW_AZURE_NO_CONTAINER.inc(); throw new RuntimeException(ex); } }
Example 14
Source File: GenericTests.java From azure-storage-android with Apache License 2.0 | 4 votes |
public void testReadTimeoutIssue() throws URISyntaxException, StorageException, IOException { // part 1 byte[] buffer = BlobTestHelper.getRandomBuffer(1 * 1024 * 1024); // set the maximum execution time BlobRequestOptions options = new BlobRequestOptions(); options.setMaximumExecutionTimeInMs(5000); CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName()); String blobName = "testBlob"; final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName); blockBlobRef.setStreamWriteSizeInBytes(1 * 1024 * 1024); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); BlobOutputStream blobOutputStream = null; try { container.createIfNotExists(); blobOutputStream = blockBlobRef.openOutputStream(null, options, null); try { blobOutputStream.write(inputStream, buffer.length); } finally { blobOutputStream.close(); } assertTrue(blockBlobRef.exists()); } finally { inputStream.close(); container.deleteIfExists(); } // part 2 int length2 = 10 * 1024 * 1024; byte[] uploadBuffer2 = BlobTestHelper.getRandomBuffer(length2); CloudBlobClient blobClient2 = TestHelper.createCloudBlobClient(); CloudBlobContainer container2 = blobClient2.getContainerReference(generateRandomContainerName()); String blobName2 = "testBlob"; final CloudBlockBlob blockBlobRef2 = container2.getBlockBlobReference(blobName2); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(uploadBuffer2); try { container2.createIfNotExists(); blockBlobRef2.upload(inputStream2, length2); } finally { inputStream2.close(); container2.deleteIfExists(); } }
Example 15
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, String blobName, int fileSize) throws Exception { // Create a container if it does not exist. The container name // must be lower case. CloudBlobContainer container = blobClient .getContainerReference(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example 16
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
public static AzureBlobStorageTestAccount createRoot(final String blobName, final int fileSize) throws Exception { NativeAzureFileSystem fs = null; CloudBlobContainer container = null; Configuration conf = createTestConfiguration(); // Set up a session with the cloud blob client to generate SAS and check the // existence of a container and capture the container object. CloudStorageAccount account = createTestAccount(conf); if (account == null) { return null; } CloudBlobClient blobClient = account.createCloudBlobClient(); // Capture the account URL and the account name. String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME); // Set up public container with the specified blob name. CloudBlockBlob blobRoot = primeRootContainer(blobClient, accountName, blobName, fileSize); // Capture the blob container object. It should exist after generating the // shared access signature. container = blobClient.getContainerReference(AZURE_ROOT_CONTAINER); if (null == container || !container.exists()) { final String errMsg = String .format("Container '%s' expected but not found while creating SAS account."); throw new Exception(errMsg); } // Set the account URI without a container name. URI accountUri = createAccountUri(accountName); // Initialize the Native Azure file system with anonymous credentials. fs = new NativeAzureFileSystem(); fs.initialize(accountUri, conf); // Create test account initializing the appropriate member variables. // Set the container value to null for the default root container. // AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount( fs, account, blobRoot); // Return to caller with test account. return testAcct; }
Example 17
Source File: ListAzureBlobStorage.java From nifi with Apache License 2.0 | 4 votes |
@Override protected List<BlobInfo> performListing(final ProcessContext context, final Long minTimestamp) throws IOException { String containerName = context.getProperty(AzureStorageUtils.CONTAINER).evaluateAttributeExpressions().getValue(); String prefix = context.getProperty(PROP_PREFIX).evaluateAttributeExpressions().getValue(); if (prefix == null) { prefix = ""; } final List<BlobInfo> listing = new ArrayList<>(); try { CloudBlobClient blobClient = AzureStorageUtils.createCloudBlobClient(context, getLogger(), null); CloudBlobContainer container = blobClient.getContainerReference(containerName); final OperationContext operationContext = new OperationContext(); AzureStorageUtils.setProxy(operationContext, context); for (ListBlobItem blob : container.listBlobs(prefix, true, EnumSet.of(BlobListingDetails.METADATA), null, operationContext)) { if (blob instanceof CloudBlob) { CloudBlob cloudBlob = (CloudBlob) blob; BlobProperties properties = cloudBlob.getProperties(); StorageUri uri = cloudBlob.getSnapshotQualifiedStorageUri(); Builder builder = new BlobInfo.Builder() .primaryUri(uri.getPrimaryUri().toString()) .blobName(cloudBlob.getName()) .containerName(containerName) .contentType(properties.getContentType()) .contentLanguage(properties.getContentLanguage()) .etag(properties.getEtag()) .lastModifiedTime(properties.getLastModified().getTime()) .length(properties.getLength()); if (uri.getSecondaryUri() != null) { builder.secondaryUri(uri.getSecondaryUri().toString()); } if (blob instanceof CloudBlockBlob) { builder.blobType(AzureStorageUtils.BLOCK); } else { builder.blobType(AzureStorageUtils.PAGE); } listing.add(builder.build()); } } } catch (Throwable t) { throw new IOException(ExceptionUtils.getRootCause(t)); } return listing; }
Example 18
Source File: TestBatchAI.java From azure-libraries-for-java with MIT License | 4 votes |
@Override public BatchAIWorkspace createResource(BatchAIWorkspaces workspaces) throws Exception { final String groupName = SdkContext.randomResourceName("rg", 10); final String workspaceName = SdkContext.randomResourceName("ws", 10); final String vnetName = SdkContext.randomResourceName("vnet", 15); final String saName = SdkContext.randomResourceName("cluster", 15); final String shareName = "myfileshare"; final String shareMountPath = "azurefileshare"; final String blobFileSystemPath = "myblobsystem"; final String containerName = "mycontainer"; final String userName = "tirekicker"; final String subnetName = "MySubnet"; String storageAccountKey; String fileShareUri; BatchAIWorkspace workspace = workspaces.define(workspaceName) .withRegion(region) .withNewResourceGroup(groupName) .create(); if (isPlaybackMode()) { storageAccountKey = "dummy_key"; fileShareUri = "dummy_uri"; } else { storageAccountKey = ensureStorageAccount(storageAccounts, saName, groupName, shareName); String connectionString = String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s", saName, storageAccountKey); CloudFileShare cloudFileShare = CloudStorageAccount.parse(String.format("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net", saName, storageAccountKey)) .createCloudFileClient() .getShareReference(shareName); cloudFileShare.create(); CloudStorageAccount account = CloudStorageAccount.parse(connectionString); CloudBlobClient cloudBlobClient = account.createCloudBlobClient(); CloudBlobContainer container = cloudBlobClient.getContainerReference(containerName); container.createIfNotExists(); fileShareUri = cloudFileShare.getStorageUri().getPrimaryUri().toString(); } Network network = networks.define(vnetName) .withRegion(region) .withExistingResourceGroup(groupName) .withAddressSpace("192.168.0.0/16") .withSubnet(subnetName, "192.168.200.0/24") .create(); BatchAICluster cluster = workspace.clusters().define(clusterName) .withVMSize(VirtualMachineSizeTypes.STANDARD_D1_V2.toString()) .withUserName(userName) .withPassword("MyPassword") .withAutoScale(1, 1) .withLowPriority() .defineSetupTask() .withCommandLine("echo Hello World!") .withStdOutErrPath("./outputpath") .attach() .defineAzureFileShare() .withStorageAccountName(saName) .withAzureFileUrl(fileShareUri) .withRelativeMountPath(shareMountPath) .withAccountKey(storageAccountKey) .attach() .defineAzureBlobFileSystem() .withStorageAccountName(saName) .withContainerName(containerName) .withRelativeMountPath(blobFileSystemPath) .withAccountKey(storageAccountKey) .attach() .withVirtualMachineImage("microsoft-ads", "linux-data-science-vm-ubuntu", "linuxdsvmubuntu") .withSubnet(network.id(), subnetName) .withAppInsightsComponentId("appinsightsId") .withInstrumentationKey("appInsightsKey") .create(); printBatchAICluster(cluster); Assert.assertEquals("resizing", cluster.allocationState().toString()); Assert.assertEquals(userName, cluster.adminUserName()); Assert.assertEquals(VmPriority.LOWPRIORITY, cluster.vmPriority()); Assert.assertEquals(1, cluster.nodeSetup().mountVolumes().azureFileShares().size()); Assert.assertEquals(shareMountPath, cluster.nodeSetup().mountVolumes().azureFileShares().get(0).relativeMountPath()); Assert.assertEquals(1, cluster.nodeSetup().mountVolumes().azureBlobFileSystems().size()); Assert.assertEquals(blobFileSystemPath, cluster.nodeSetup().mountVolumes().azureBlobFileSystems().get(0).relativeMountPath()); Assert.assertEquals(network.id() + "/subnets/" + subnetName, cluster.subnet().id()); Assert.assertEquals("appinsightsId", cluster.nodeSetup().performanceCountersSettings().appInsightsReference().component().id()); Assert.assertEquals("linux-data-science-vm-ubuntu", cluster.virtualMachineConfiguration().imageReference().offer()); return workspace; }
Example 19
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
public static AzureBlobStorageTestAccount createRoot(final String blobName, final int fileSize) throws Exception { NativeAzureFileSystem fs = null; CloudBlobContainer container = null; Configuration conf = createTestConfiguration(); // Set up a session with the cloud blob client to generate SAS and check the // existence of a container and capture the container object. CloudStorageAccount account = createTestAccount(conf); if (account == null) { return null; } CloudBlobClient blobClient = account.createCloudBlobClient(); // Capture the account URL and the account name. String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME); // Set up public container with the specified blob name. CloudBlockBlob blobRoot = primeRootContainer(blobClient, accountName, blobName, fileSize); // Capture the blob container object. It should exist after generating the // shared access signature. container = blobClient.getContainerReference(AZURE_ROOT_CONTAINER); if (null == container || !container.exists()) { final String errMsg = String .format("Container '%s' expected but not found while creating SAS account."); throw new Exception(errMsg); } // Set the account URI without a container name. URI accountUri = createAccountUri(accountName); // Initialize the Native Azure file system with anonymous credentials. fs = new NativeAzureFileSystem(); fs.initialize(accountUri, conf); // Create test account initializing the appropriate member variables. // Set the container value to null for the default root container. // AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount( fs, account, blobRoot); // Return to caller with test account. return testAcct; }
Example 20
Source File: AzureStorageHelper.java From azure-gradle-plugins with MIT License | 4 votes |
private static CloudBlobContainer getBlobContainer(final CloudStorageAccount storageAccount, final String containerName) throws Exception { final CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); return blobClient.getContainerReference(containerName); }