use of com.azure.storage.blob.models.BlobCopyInfo in project bulk-scan-processor by hmcts.
the class BlobManager method copyToRejectedContainer.
private void copyToRejectedContainer(BlobClient sourceBlob, BlobClient targetBlob) {
String sasToken = sourceBlob.generateSas(new BlobServiceSasSignatureValues(OffsetDateTime.of(LocalDateTime.now().plus(5, ChronoUnit.MINUTES), ZoneOffset.UTC), new BlobContainerSasPermission().setReadPermission(true)));
var start = System.nanoTime();
SyncPoller<BlobCopyInfo, Void> poller = null;
try {
poller = targetBlob.beginCopy(sourceBlob.getBlobUrl() + "?" + sasToken, META_DATA_MAP, null, null, null, null, Duration.ofSeconds(2));
PollResponse<BlobCopyInfo> pollResponse = poller.waitForCompletion(Duration.ofMinutes(5));
targetBlob.setMetadata(null);
log.info("Moved to rejected container from {}. Poll response: {}, Copy status: {} ,Takes {} second", sourceBlob.getBlobUrl(), pollResponse.getStatus(), pollResponse.getValue().getCopyStatus(), TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start));
} catch (Exception ex) {
log.error("Copy Error, for {} to rejected container", sourceBlob.getBlobUrl(), ex);
if (poller != null) {
try {
targetBlob.abortCopyFromUrl(poller.poll().getValue().getCopyId());
} catch (Exception exc) {
log.error("Abort Copy From Url got Error, From {} to rejected container", sourceBlob.getBlobUrl(), exc);
}
}
throw ex;
}
}
use of com.azure.storage.blob.models.BlobCopyInfo in project bulk-scan-processor by hmcts.
the class BlobManagerTest method mockBeginCopy.
private void mockBeginCopy(String url, String sasToken) {
given(inputBlobClient.getBlobUrl()).willReturn(url);
given(inputBlobClient.generateSas(any())).willReturn(sasToken);
SyncPoller syncPoller = mock(SyncPoller.class);
given(rejectedBlobClient.beginCopy(url + "?" + sasToken, BlobManager.META_DATA_MAP, null, null, null, null, Duration.ofSeconds(2))).willReturn(syncPoller);
var pollResponse = mock(PollResponse.class);
var blobCopyInfo = mock(BlobCopyInfo.class);
given(syncPoller.waitForCompletion(Duration.ofMinutes(5))).willReturn(pollResponse);
given(pollResponse.getValue()).willReturn(mock(BlobCopyInfo.class));
given(pollResponse.getValue()).willReturn(blobCopyInfo);
}
Aggregations