public URI getUri() { return getBlob().getUri(); }
public URI getUri() { return getBlob().getUri(); }
/** * Returns the absolute URI to the blob, including query string information if the blob is a snapshot. * * @return A <code>java.net.URI</code> object specifying the absolute URI to the blob, * including snapshot query information if the blob is a snapshot. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ public final URI getSnapshotQualifiedUri() throws URISyntaxException, StorageException { if (this.isSnapshot()) { return PathUtility.addToQuery(this.getUri(), String.format("snapshot=%s", this.snapshotID)); } return this.getUri(); }
/** * Returns the absolute URI to the blob, including query string information if the blob is a snapshot. * * @return A <code>java.net.URI</code> object specifying the absolute URI to the blob, * including snapshot query information if the blob is a snapshot. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ public final URI getSnapshotQualifiedUri() throws URISyntaxException, StorageException { if (this.isSnapshot()) { return PathUtility.addToQuery(this.getUri(), String.format("snapshot=%s", this.snapshotID)); } return this.getUri(); }
public static void deleteAllEntries(CloudBlobDirectory directory) throws IOException { Stream<CloudBlob> blobs = getBlobs(directory); blobs.forEach(b -> { try { b.deleteIfExists(); } catch (StorageException e) { log.error("Can't delete blob {}", b.getUri().getPath(), e); } }); }
public static void deleteAllEntries(CloudBlobDirectory directory) throws IOException { Stream<CloudBlob> blobs = getBlobs(directory); blobs.forEach(b -> { try { b.deleteIfExists(); } catch (StorageException e) { log.error("Can't delete blob {}", b.getUri().getPath(), e); } }); }
@Override public boolean delete(String archiveName) { try { getBlobs(archiveName) .forEach(cloudBlob -> { try { cloudBlob.delete(); } catch (StorageException e) { log.error("Can't delete segment {}", cloudBlob.getUri().getPath(), e); } }); return true; } catch (IOException e) { log.error("Can't delete archive {}", archiveName, e); return false; } }
@Override public boolean delete(String archiveName) { try { getBlobs(archiveName) .forEach(cloudBlob -> { try { cloudBlob.delete(); } catch (StorageException e) { log.error("Can't delete segment {}", cloudBlob.getUri().getPath(), e); } }); return true; } catch (IOException e) { log.error("Can't delete archive {}", archiveName, e); return false; } }
@Override public void copyFile(String from, String to) throws IOException { CloudBlobDirectory targetDirectory = getDirectory(to); getBlobs(from) .forEach(cloudBlob -> { try { copyBlob(cloudBlob, targetDirectory); } catch (IOException e) { log.error("Can't copy segment {}", cloudBlob.getUri().getPath(), e); } }); }
@Override public void copyFile(String from, String to) throws IOException { CloudBlobDirectory targetDirectory = getDirectory(to); getBlobs(from) .forEach(cloudBlob -> { try { copyBlob(cloudBlob, targetDirectory); } catch (IOException e) { log.error("Can't copy segment {}", cloudBlob.getUri().getPath(), e); } }); }
/** * Returns the snapshot or shared access signature qualified URI for this blob. * * @deprecated use {@link #getSnapshotQualifiedUri()} instead. * * @return A <code>java.net.URI</code> object that represents the snapshot or shared access signature. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @Deprecated public final URI getQualifiedUri() throws URISyntaxException, StorageException { if (this.isSnapshot()) { return PathUtility.addToQuery(this.getUri(), String.format("snapshot=%s", this.snapshotID)); } return this.blobServiceClient.getCredentials().transformUri(this.getUri()); }
@Override public boolean renameTo(String from, String to) { try { CloudBlobDirectory targetDirectory = getDirectory(to); getBlobs(from) .forEach(cloudBlob -> { try { renameBlob(cloudBlob, targetDirectory); } catch (IOException e) { log.error("Can't rename segment {}", cloudBlob.getUri().getPath(), e); } }); return true; } catch (IOException e) { log.error("Can't rename archive {} to {}", from, to, e); return false; } }
@Override public boolean renameTo(String from, String to) { try { CloudBlobDirectory targetDirectory = getDirectory(to); getBlobs(from) .forEach(cloudBlob -> { try { renameBlob(cloudBlob, targetDirectory); } catch (IOException e) { log.error("Can't rename segment {}", cloudBlob.getUri().getPath(), e); } }); return true; } catch (IOException e) { log.error("Can't rename archive {} to {}", from, to, e); return false; } }
/** * Returns the snapshot or shared access signature qualified URI for this blob. * * @deprecated use {@link #getSnapshotQualifiedUri()} instead. * * @return A <code>java.net.URI</code> object that represents the snapshot or shared access signature. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is invalid. */ @Deprecated public final URI getQualifiedUri() throws URISyntaxException, StorageException { if (this.isSnapshot()) { return PathUtility.addToQuery(this.getUri(), String.format("snapshot=%s", this.snapshotID)); } return this.blobServiceClient.getCredentials().transformUri(this.getUri()); }
public static CloudBlob getConfiguredClient(BlobServiceConfiguration cfg) { CloudBlob client = cfg.getAzureBlobClient(); if (client != null) { Class<?> expectedCls = null; if (cfg.getBlobType() == BlobType.blockblob) { expectedCls = CloudBlockBlob.class; } else if (cfg.getBlobType() == BlobType.appendblob) { expectedCls = CloudAppendBlob.class; } else if (cfg.getBlobType() == BlobType.pageblob) { expectedCls = CloudPageBlob.class; } if (client.getClass() != expectedCls) { throw new IllegalArgumentException("Invalid Client Type"); } if (!client.getUri().equals(prepareStorageBlobUri(cfg))) { throw new IllegalArgumentException("Invalid Client URI"); } } return client; }
private void copyBlob(CloudBlob blob, CloudBlobDirectory newParent) throws IOException { checkArgument(blob instanceof CloudBlockBlob, "Only page blobs are supported for the rename"); try { String blobName = getName(blob); CloudBlockBlob newBlob = newParent.getBlockBlobReference(blobName); newBlob.startCopy(blob.getUri()); boolean isStatusPending = true; while (isStatusPending) { newBlob.downloadAttributes(); if (newBlob.getCopyState().getStatus() == CopyStatus.PENDING) { Thread.sleep(100); } else { isStatusPending = false; } } CopyStatus finalStatus = newBlob.getCopyState().getStatus(); if (newBlob.getCopyState().getStatus() != CopyStatus.SUCCESS) { throw new IOException("Invalid copy status for " + blob.getUri().getPath() + ": " + finalStatus); } } catch (StorageException | InterruptedException | URISyntaxException e) { throw new IOException(e); } }
private void copyBlob(CloudBlob blob, CloudBlobDirectory newParent) throws IOException { checkArgument(blob instanceof CloudBlockBlob, "Only page blobs are supported for the rename"); try { String blobName = getName(blob); CloudBlockBlob newBlob = newParent.getBlockBlobReference(blobName); newBlob.startCopy(blob.getUri()); boolean isStatusPending = true; while (isStatusPending) { newBlob.downloadAttributes(); if (newBlob.getCopyState().getStatus() == CopyStatus.PENDING) { Thread.sleep(100); } else { isStatusPending = false; } } CopyStatus finalStatus = newBlob.getCopyState().getStatus(); if (newBlob.getCopyState().getStatus() != CopyStatus.SUCCESS) { throw new IOException("Invalid copy status for " + blob.getUri().getPath() + ": " + finalStatus); } } catch (StorageException | InterruptedException | URISyntaxException e) { throw new IOException(e); } }
@Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob target = session.getClient().getContainerReference(containerService.getContainer(copy).getName()) .getAppendBlobReference(containerService.getKey(copy)); final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(source).getName()) .getBlobReferenceFromServer(containerService.getKey(source)); final BlobRequestOptions options = new BlobRequestOptions(); options.setStoreBlobContentMD5(PreferencesFactory.get().getBoolean("azure.upload.md5")); final URI s = session.getHost().getCredentials().isTokenAuthentication() ? URI.create(blob.getUri().toString() + session.getHost().getCredentials().getToken()) : blob.getUri(); final String id = target.startCopy(s, AccessCondition.generateEmptyCondition(), AccessCondition.generateEmptyCondition(), options, context); if(log.isDebugEnabled()) { log.debug(String.format("Started copy for %s with copy operation ID %s", copy, id)); } // Copy original file attributes return new Path(copy.getParent(), copy.getName(), copy.getType(), new PathAttributes(source.attributes())); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Cannot copy {0}", e, source); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerSAS() throws StorageException, URISyntaxException, IOException, InvalidKeyException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy(); Calendar now = Calendar.getInstance(); now.add(Calendar.MINUTE, 10); policy.setSharedAccessExpiryTime(now.getTime()); policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ)); String token = this.container.generateSharedAccessSignature(policy, null); CloudBlobContainer containerSAS = new CloudBlobContainer(this.container.getStorageUri(), new StorageCredentialsSharedAccessSignature(token)); CloudBlob blobRef = containerSAS.getBlobReferenceFromServer(blob.getName()); assertEquals(blob.getClass(), blobRef.getClass()); assertEquals(blob.getUri(), blobRef.getUri()); }
public static void assertAreEqual(CloudBlob blob1, CloudBlob blob2) throws URISyntaxException, StorageException { if (blob1 == null) { assertNull(blob2); } else { assertNotNull(blob2); assertEquals(blob1.getClass(), blob2.getClass()); assertEquals(blob1.getUri(), blob2.getUri()); assertEquals(blob1.getSnapshotID(), blob2.getSnapshotID()); assertEquals(blob1.isSnapshot(), blob2.isSnapshot()); assertEquals(blob1.getSnapshotQualifiedStorageUri(), blob2.getSnapshotQualifiedStorageUri()); assertAreEqual(blob1.getProperties(), blob2.getProperties()); assertAreEqual(blob1.getCopyState(), blob2.getCopyState()); } }