Java Code Examples for com.microsoft.azure.storage.blob.CloudBlobContainer#delete()
The following examples show how to use
com.microsoft.azure.storage.blob.CloudBlobContainer#delete() .
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: 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 2
Source File: AzureSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
private void validateWasbFileSystem(SpiFileSystem fileSystem) throws URISyntaxException, InvalidKeyException, StorageException { CloudWasbView cloudFileSystem = (CloudWasbView) fileSystem.getCloudFileSystems().get(0); String accountName = cloudFileSystem.getAccountName(); String accountKey = cloudFileSystem.getAccountKey(); String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey; 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 3
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 4
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
public static AzureBlobStorageTestAccount create(String containerNameSuffix, EnumSet<CreateOptions> createOptions, Configuration initialConfiguration) throws Exception { saveMetricsConfigFile(); NativeAzureFileSystem fs = null; CloudBlobContainer container = null; Configuration conf = createTestConfiguration(initialConfiguration); configurePageBlobDir(conf); configureAtomicRenameDir(conf); CloudStorageAccount account = createTestAccount(conf); if (account == null) { return null; } fs = new NativeAzureFileSystem(); String containerName = String.format("wasbtests-%s-%tQ%s", System.getProperty("user.name"), new Date(), containerNameSuffix); container = account.createCloudBlobClient().getContainerReference( containerName); if (createOptions.contains(CreateOptions.CreateContainer)) { container.create(); } String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME); if (createOptions.contains(CreateOptions.UseSas)) { String sas = generateSAS(container, createOptions.contains(CreateOptions.Readonly)); if (!createOptions.contains(CreateOptions.CreateContainer)) { // The caller doesn't want the container to be pre-created, // so delete it now that we have generated the SAS. container.delete(); } // Remove the account key from the configuration to make sure we don't // cheat and use that. conf.set(ACCOUNT_KEY_PROPERTY_NAME + accountName, ""); // Set the SAS key. conf.set(SAS_PROPERTY_NAME + containerName + "." + accountName, sas); } // Check if throttling is turned on and set throttling parameters // appropriately. if (createOptions.contains(CreateOptions.useThrottling)) { conf.setBoolean(KEY_DISABLE_THROTTLING, false); } else { conf.setBoolean(KEY_DISABLE_THROTTLING, true); } // Set account URI and initialize Azure file system. URI accountUri = createAccountUri(accountName, containerName); fs.initialize(accountUri, conf); // Create test account initializing the appropriate member variables. // AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(fs, account, container); return testAcct; }
Example 5
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
public static AzureBlobStorageTestAccount create(String containerNameSuffix, EnumSet<CreateOptions> createOptions, Configuration initialConfiguration) throws Exception { saveMetricsConfigFile(); NativeAzureFileSystem fs = null; CloudBlobContainer container = null; Configuration conf = createTestConfiguration(initialConfiguration); configurePageBlobDir(conf); configureAtomicRenameDir(conf); CloudStorageAccount account = createTestAccount(conf); if (account == null) { return null; } fs = new NativeAzureFileSystem(); String containerName = String.format("wasbtests-%s-%tQ%s", System.getProperty("user.name"), new Date(), containerNameSuffix); container = account.createCloudBlobClient().getContainerReference( containerName); if (createOptions.contains(CreateOptions.CreateContainer)) { container.create(); } String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME); if (createOptions.contains(CreateOptions.UseSas)) { String sas = generateSAS(container, createOptions.contains(CreateOptions.Readonly)); if (!createOptions.contains(CreateOptions.CreateContainer)) { // The caller doesn't want the container to be pre-created, // so delete it now that we have generated the SAS. container.delete(); } // Remove the account key from the configuration to make sure we don't // cheat and use that. conf.set(ACCOUNT_KEY_PROPERTY_NAME + accountName, ""); // Set the SAS key. conf.set(SAS_PROPERTY_NAME + containerName + "." + accountName, sas); } // Check if throttling is turned on and set throttling parameters // appropriately. if (createOptions.contains(CreateOptions.useThrottling)) { conf.setBoolean(KEY_DISABLE_THROTTLING, false); } else { conf.setBoolean(KEY_DISABLE_THROTTLING, true); } // Set account URI and initialize Azure file system. URI accountUri = createAccountUri(accountName, containerName); fs.initialize(accountUri, conf); // Create test account initializing the appropriate member variables. // AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(fs, account, container); return testAcct; }
Example 6
Source File: FileSasTests.java From azure-storage-android with Apache License 2.0 | 4 votes |
@Test public void testFileCopyFromBlobWithSasAndSnapshot() throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudBlobContainer container = TestHelper.createCloudBlobClient().getContainerReference(BlobTestHelper.generateRandomContainerName()); container.createIfNotExists(); CloudBlockBlob source = container.getBlockBlobReference(blobName); String data = "String data"; source.uploadText(data, Constants.UTF8_CHARSET, null, null, null); byte[] buffer = BlobTestHelper.getRandomBuffer(512); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); source.upload(stream, buffer.length); source.getMetadata().put("Test", "value"); source.uploadMetadata(); SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.WRITE, SharedAccessFilePermissions.LIST, SharedAccessFilePermissions.DELETE), 5000); CloudFile copy = this.share.getRootDirectoryReference().getFileReference("copy"); String sasToken = copy.generateSharedAccessSignature(policy, null); CloudFile copySas = new CloudFile(new URI(copy.getUri().toString() + "?" + sasToken)); // Generate account SAS for the source // Cannot generate a SAS directly on a snapshot and the SAS for the destination is only for the destination SharedAccessAccountPolicy accountPolicy = new SharedAccessAccountPolicy(); accountPolicy.setPermissions(EnumSet.of(SharedAccessAccountPermissions.READ, SharedAccessAccountPermissions.WRITE)); accountPolicy.setServices(EnumSet.of(SharedAccessAccountService.BLOB)); accountPolicy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT, SharedAccessAccountResourceType.CONTAINER)); accountPolicy.setSharedAccessExpiryTime(policy.getSharedAccessExpiryTime()); final CloudBlobClient sasClient = TestHelper.createCloudBlobClient(accountPolicy, false); CloudBlockBlob snapshot = (CloudBlockBlob) source.createSnapshot(); CloudBlockBlob sasBlob = (CloudBlockBlob) sasClient.getContainerReference(container.getName()) .getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null); sasBlob.exists(); String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob)); FileTestHelper.waitForCopy(copySas); copySas.downloadAttributes(); FileProperties prop1 = copySas.getProperties(); BlobProperties prop2 = sasBlob.getProperties(); assertEquals(prop1.getCacheControl(), prop2.getCacheControl()); assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding()); assertEquals(prop1.getContentDisposition(), prop2.getContentDisposition()); assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage()); assertEquals(prop1.getContentMD5(), prop2.getContentMD5()); assertEquals(prop1.getContentType(), prop2.getContentType()); assertEquals("value", copySas.getMetadata().get("Test")); assertEquals(copyId, copySas.getCopyState().getCopyId()); snapshot.delete(); source.delete(); copySas.delete(); container.delete(); }