@Override public String getFilename() { return this.blockBlob.getName(); }
@Override public String getDescription() { return String .format("Azure storage account blob resource [container='%s', blob='%s']", this.blobContainer.getName(), this.blockBlob.getName()); }
public void deleteIfExist(RuntimeContainer runtimeContainer) { try { for (RemoteBlob rmtb : createRemoteBlobFilter()) { for (ListBlobItem blob : azureStorageBlobService.listBlobs(containerName, rmtb.prefix, rmtb.include)) { if (blob instanceof CloudBlockBlob) { // FIXME - problem with blobs with space in name... boolean successfulyDeleted = azureStorageBlobService.deleteBlobBlockIfExist((CloudBlockBlob) blob); if (!successfulyDeleted) { LOGGER.warn(messages.getMessage("warn.FaildDelete", ((CloudBlockBlob) blob).getName())); } } } } } catch (StorageException | URISyntaxException | InvalidKeyException e) { LOGGER.error(e.getLocalizedMessage()); if (dieOnError) { throw new ComponentException(e); } } }
public void deleteIfExist(RuntimeContainer runtimeContainer) { try { for (RemoteBlob rmtb : createRemoteBlobFilter()) { for (ListBlobItem blob : azureStorageBlobService.listBlobs(containerName, rmtb.prefix, rmtb.include)) { if (blob instanceof CloudBlockBlob) { // FIXME - problem with blobs with space in name... boolean successfulyDeleted = azureStorageBlobService.deleteBlobBlockIfExist((CloudBlockBlob) blob); if (!successfulyDeleted) { LOGGER.warn(messages.getMessage("warn.FaildDelete", ((CloudBlockBlob) blob).getName())); } } } } } catch (StorageException | URISyntaxException | InvalidKeyException e) { LOGGER.error(e.getLocalizedMessage()); if (dieOnError) { throw new ComponentException(e); } } }
connectionString, containerName, new DataIdentifier(getIdentifierName(blob.getName())), blob.getProperties().getLastModified().getTime(), blob.getProperties().getLength());
/** * List Logs with well defined time range * * @throws URISyntaxException * @throws StorageException * @throws IOException * @throws InterruptedException */ @Test public void testCloudAnalyticsClientListLogsStartEndTime() throws URISyntaxException, StorageException, IOException { this.container.create(); this.client.LogContainer = this.container.getName(); int numBlobs = 72; Calendar now = new GregorianCalendar(); now.add(GregorianCalendar.DAY_OF_MONTH, -3); List<String> blobNames = AnalyticsTestHelper.CreateLogs(this.container, StorageService.BLOB, 72, now, Granularity.HOUR); assertEquals(numBlobs, blobNames.size()); Calendar start = new GregorianCalendar(); start.add(GregorianCalendar.DAY_OF_MONTH, -2); Calendar end = new GregorianCalendar(); end.add(GregorianCalendar.DAY_OF_MONTH, -1); for (ListBlobItem blob : this.client.listLogBlobs(StorageService.BLOB, start.getTime(), end.getTime(), null, null, null, null)) { assertEquals(CloudBlockBlob.class, blob.getClass()); assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName())); } assertTrue(blobNames.size() == 48); }
/** * List Logs with open ended time range * * @throws URISyntaxException * @throws StorageException * @throws IOException * @throws InterruptedException */ @Test public void testCloudAnalyticsClientListLogsStartTime() throws URISyntaxException, StorageException, IOException { this.container.create(); this.client.LogContainer = this.container.getName(); int numBlobs = 48; Calendar now = new GregorianCalendar(); now.add(GregorianCalendar.DAY_OF_MONTH, -2); List<String> blobNames = AnalyticsTestHelper.CreateLogs(this.container, StorageService.BLOB, 48, now, Granularity.HOUR); assertEquals(numBlobs, blobNames.size()); Calendar start = new GregorianCalendar(); start.add(GregorianCalendar.DAY_OF_MONTH, -1); for (ListBlobItem blob : this.client.listLogBlobs(StorageService.BLOB, start.getTime(), null, null, null, null, null)) { assertEquals(CloudBlockBlob.class, blob.getClass()); assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName())); } assertTrue(blobNames.size() == 24); }
/** * List all logs * * @throws URISyntaxException * @throws StorageException * @throws IOException * @throws InterruptedException */ public void testCloudAnalyticsClientListLogs() throws URISyntaxException, StorageException, IOException { this.container.create(); this.client.LogContainer = this.container.getName(); int numBlobs = 13; Calendar now = new GregorianCalendar(); now.add(GregorianCalendar.MONTH, -13); List<String> blobNames = AnalyticsTestHelper.CreateLogs(this.container, StorageService.BLOB, 13, now, Granularity.MONTH); assertEquals(numBlobs, blobNames.size()); for (ListBlobItem blob : this.client.listLogBlobs(StorageService.BLOB)) { assertEquals(CloudBlockBlob.class, blob.getClass()); assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName())); } assertTrue(blobNames.size() == 0); }
@Test public void testBlobUriOnlyConstructors() throws URISyntaxException, StorageException, InvalidKeyException { URI blobURI = new URI(container.getUri().toString() + "/anonblob"); CloudBlockBlob blob = new CloudBlockBlob(blobURI); assertEquals("anonblob", blob.getName()); assertNotNull(blob.getServiceClient()); assertEquals(StorageCredentialsAnonymous.class, blob.getServiceClient().getCredentials().getClass()); blob = container.getBlockBlobReference("anonblob"); String sas = blob.generateSharedAccessSignature(null, "dummyPolicy"); blobURI = new URI(container.getUri().toString() + "/anonblob?" + sas); blob = new CloudBlockBlob(blobURI); assertEquals("anonblob", blob.getName()); assertNotNull(blob.getServiceClient()); assertEquals(StorageCredentialsSharedAccessSignature.class, blob.getServiceClient().getCredentials().getClass()); }
for (ListBlobItem blob : result.getResults()) { assertEquals(CloudBlockBlob.class, blob.getClass()); assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName()));
for (ListBlobItem blob : this.container.listBlobs("pref", true)) { assertEquals(CloudBlockBlob.class, blob.getClass()); assertTrue(((CloudBlockBlob)blob).getName().startsWith("pref/blob")); count++;
noneContainer.getServiceClient().getCredentials().getClass().toString()); CloudBlockBlob noneBlob = noneContainer.getBlockBlobReference(this.blob.getName()); noneBlob.download(new ByteArrayOutputStream()); fail(); oneContainer.getServiceClient().getCredentials().getClass().toString()); CloudBlockBlob oneBlob = oneContainer.getBlockBlobReference(this.blob.getName()); oneBlob.download(new ByteArrayOutputStream()); allContainer.getServiceClient().getCredentials().getClass().toString()); CloudBlockBlob allBlob = allContainer.getBlockBlobReference(this.blob.getName()); allBlob.download(new ByteArrayOutputStream());
@Test @Category(SlowTests.class) public void testBlobSaS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessBlobPolicy sp = createSharedAccessPolicy( EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST), 3600); BlobContainerPermissions perms = new BlobContainerPermissions(); perms.getSharedAccessPolicies().put("readperm", sp); this.container.uploadPermissions(perms); Thread.sleep(30000); CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?" + this.blob.generateSharedAccessSignature(null, "readperm"))); sasBlob.download(new ByteArrayOutputStream()); // do not give the client and check that the new blob's client has the correct perms CloudBlob blobFromUri = new CloudBlockBlob(PathUtility.addToQuery(this.blob.getStorageUri(), this.blob.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), blobFromUri.getServiceClient() .getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.blob.generateSharedAccessSignature(null, "readperm")); CloudBlobClient bClient = new CloudBlobClient(sasBlob.getServiceClient().getStorageUri(), creds); CloudBlockBlob blobFromClient = bClient.getContainerReference(this.blob.getContainer().getName()) .getBlockBlobReference(this.blob.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), blobFromClient.getServiceClient() .getCredentials().getClass().toString()); assertEquals(bClient, blobFromClient.getServiceClient()); }
.getCredentials().getClass().toString()); CloudBlockBlob blobFromSasContainer = readListContainer.getBlockBlobReference(this.blob.getName()); blobFromSasContainer.download(new ByteArrayOutputStream());
/** * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class }) public void testBlobNamePlusEncodingTest() throws StorageException, URISyntaxException, IOException, InterruptedException { final int length = 1 * 1024; final CloudBlockBlob originalBlob = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "a+b.txt", length, null); final CloudBlockBlob copyBlob = this.container.getBlockBlobReference(originalBlob.getName() + "copyed"); copyBlob.startCopy(originalBlob); BlobTestHelper.waitForCopy(copyBlob); copyBlob.downloadAttributes(); }
@Test public void testBlobAttributesEncryption() throws URISyntaxException, StorageException, IOException { this.blob.downloadAttributes(); assertTrue(this.blob.getProperties().isServerEncrypted()); CloudBlockBlob testBlob = this.container.getBlockBlobReference(this.blob.getName()); testBlob.downloadText(); assertTrue(testBlob.getProperties().isServerEncrypted()); }
/** * Start copying a blob and then abort * * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCopyFromBlobAbortTest() throws StorageException, URISyntaxException, IOException { final int length = 128; CloudBlockBlob originalBlob = (CloudBlockBlob) BlobTestHelper.uploadNewBlob( this.container, BlobType.BLOCK_BLOB, "originalBlob", length, null); CloudBlockBlob copyBlob = this.container.getBlockBlobReference(originalBlob.getName() + "copyed"); copyBlob.startCopy(originalBlob); try { copyBlob.abortCopy(copyBlob.getProperties().getCopyState().getCopyId()); } catch (StorageException e) { if (!e.getErrorCode().contains("NoPendingCopyOperation")) { throw e; } } }
assertEquals(dir1.getServiceClient().getEndpoint().toString(), blockBlob.getServiceClient().getEndpoint() .toString()); assertEquals("Dir1" + delimiter + "BlockBlob", blockBlob.getName()); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/Dir1" + delimiter + "BlockBlob", null, null), blockBlob.getUri()); assertEquals(blockSnapshot.getName(), blockSnapshotDir1.getName()); assertEquals(dir1.getContainer().getName(), blockSnapshotDir1.getContainer().getName()); assertEquals(dir1.getServiceClient().getEndpoint().toString(), blockSnapshotDir1.getServiceClient()
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();
.getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null); sasBlob.exists();