@Override public boolean exists(OperationContext opContext) throws StorageException { return container.exists(AccessCondition.generateEmptyCondition(), null, opContext); }
/** * Returns a value that indicates whether the container exists. * * @return <code>true</code> if the container exists, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public boolean exists() throws StorageException { return this.exists(null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Returns a value that indicates whether the container exists. * * @return <code>true</code> if the container exists, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public boolean exists() throws StorageException { return this.exists(null /* accessCondition */, null /* options */, null /* opContext */); }
@Override public boolean exists(OperationContext opContext) throws StorageException { return container.exists(AccessCondition.generateEmptyCondition(), null, opContext); }
private CompletableFuture<Boolean> storeExistsInternal(BlobRequestOptions options, String action, String trace) { CompletableFuture<Boolean> future = null; try { future = CompletableFuture.completedFuture(this.eventHubContainer.exists(null, options, null)); } catch (StorageException e) { TRACE_LOGGER.error(this.hostContext.withHost(trace), e); future = new CompletableFuture<Boolean>(); future.completeExceptionally(LoggingUtils.wrapException(e, action)); } return future; }
@Override public boolean exists() { try { return this.blobContainer.exists() && blockBlob.exists(); } catch (StorageException e) { log.error(MSG_FAIL_CHECK_EXIST, e); throw new StorageRuntimeException(MSG_FAIL_CHECK_EXIST, e); } }
public static void deleteBlob(final CloudStorageAccount storageAccount, final String containerName, final String blobName) throws Exception { final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName); if (blobContainer.exists()) { final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName); blob.deleteIfExists(); } }
/** * @return true if the a container exist with the given name, false otherwise */ public boolean containerExist(final String containerName) throws StorageException, URISyntaxException, InvalidKeyException { CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient(); CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName); return cloudBlobContainer.exists(null, null, AzureStorageUtils.getTalendOperationContext()); }
/** * @return true if the a container exist with the given name, false otherwise */ public boolean containerExist(final String containerName) throws StorageException, URISyntaxException, InvalidKeyException { CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient(); CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName); return cloudBlobContainer.exists(null, null, AzureStorageUtils.getTalendOperationContext()); }
@Override public void validate(ConfigProblemSetBuilder ps, AzsPersistentStore n) { String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + n.getStorageAccountName() + ";AccountKey=" + n.getStorageAccountKey(); try { CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString); CloudBlobContainer container = storageAccount.createCloudBlobClient().getContainerReference(n.getStorageContainerName()); container.exists(); } catch (Exception e) { ps.addProblem(Problem.Severity.ERROR, "Failed to connect to the Azure storage account \"" + n.getStorageAccountName() + "\": " + e.getMessage()); return; } } }
@Override public void validate(ConfigProblemSetBuilder ps, AzsPersistentStore n) { String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + n.getStorageAccountName() + ";AccountKey=" + n.getStorageAccountKey(); try { CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString); CloudBlobContainer container = storageAccount.createCloudBlobClient().getContainerReference(n.getStorageContainerName()); container.exists(); } catch (Exception e) { ps.addProblem(Problem.Severity.ERROR, "Failed to connect to the Azure storage account \"" + n.getStorageAccountName() + "\": " + e.getMessage()); return; } } }
@Override public void eventOccurred(SendingRequestEvent eventArg) { if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) { try { container.delete(); assertFalse(container.exists()); } catch (StorageException e) { fail("Delete should succeed."); } } } });
/** * Check a container's existence * * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerExists() throws StorageException { assertFalse(this.container.exists()); this.container.create(); assertTrue(this.container.exists()); assertNotNull(this.container.getProperties().getEtag()); this.container.delete(); assertFalse(this.container.exists()); }
@Test public void testContainerChecksWithSas() throws Exception { testAccount = AzureBlobStorageTestAccount.create("", EnumSet.of(CreateOptions.UseSas)); assumeNotNull(testAccount); CloudBlobContainer container = testAccount.getRealContainer(); FileSystem fs = testAccount.getFileSystem(); // The container shouldn't be there assertFalse(container.exists()); // A write should just fail try { fs.createNewFile(new Path("/foo")); assertFalse("Should've thrown.", true); } catch (AzureException ex) { } assertFalse(container.exists()); } }
@Test public void testContainerCreateAfterDoesNotExist() throws Exception { testAccount = blobStorageTestAccount(); 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 and will set file system store // state to DoesNotExist try { assertNull(fs.listStatus(new Path("/"))); assertTrue("Should've thrown.", false); } catch (FileNotFoundException ex) { assertTrue("Unexpected exception: " + ex, ex.getMessage().contains("is not found")); } assertFalse(container.exists()); // Create a container outside of the WASB FileSystem container.create(); // Write should succeed assertTrue(fs.createNewFile(new Path("/foo"))); assertTrue(container.exists()); }
@Test public void testContainerChecksWithSas() throws Exception { Assume.assumeFalse(runningInSASMode); testAccount = AzureBlobStorageTestAccount.create("", EnumSet.of(CreateOptions.UseSas)); assumeNotNull(testAccount); CloudBlobContainer container = testAccount.getRealContainer(); FileSystem fs = testAccount.getFileSystem(); // The container shouldn't be there assertFalse(container.exists()); // A write should just fail try { fs.createNewFile(new Path("/testContainerChecksWithSas-foo")); assertFalse("Should've thrown.", true); } catch (AzureException ex) { } assertFalse(container.exists()); } }
@Test public void testNullRetryPolicy() throws URISyntaxException, StorageException { CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); blobClient.getDefaultRequestOptions().setRetryPolicyFactory(null); container.exists(); }
@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"); } } }
/** * Try to create a container after it is created * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerCreateIfNotExists() throws StorageException { assertTrue(this.container.createIfNotExists()); assertTrue(this.container.exists()); assertFalse(this.container.createIfNotExists()); }
/** * Try to delete a non-existing container * * @throws StorageException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerDeleteIfExists() throws StorageException { assertFalse(container.deleteIfExists()); container.create(); assertTrue(container.deleteIfExists()); assertFalse(container.exists()); assertFalse(container.deleteIfExists()); }