private static boolean waitForCopy(CloudBlob blob) throws StorageException, InterruptedException { boolean continueLoop = true; CopyStatus status = CopyStatus.PENDING; while (continueLoop) { blob.downloadAttributes(); status = blob.getCopyState().getStatus(); continueLoop = status == CopyStatus.PENDING; // Sleep if retry is needed if (continueLoop) { Thread.sleep(500); } } return status == CopyStatus.SUCCESS; }
@Override public void renameFile(String from, String to, String pp) throws IOException { while (from.startsWith(File.separator)) from = from.substring(1); while (to.startsWith(File.separator)) to = to.substring(1); String fn = EncyptUtils.encString(from, Main.chunkStoreEncryptionEnabled); String tn = EncyptUtils.encString(to, Main.chunkStoreEncryptionEnabled); try { CloudBlockBlob sblob = container.getBlockBlobReference(pp + "/" + fn); CloudBlockBlob tblob = container.getBlockBlobReference(pp + "/" + tn); tblob.startCopy(sblob); while (tblob.getCopyState().getStatus() == CopyStatus.PENDING) { Thread.sleep(10); } if (tblob.getCopyState().getStatus() == CopyStatus.SUCCESS) { sblob.delete(); } else { throw new IOException( "unable to rename file " + fn + " because " + tblob.getCopyState().getStatus().name() + " : " + tblob.getCopyState().getStatusDescription()); } } catch (Exception 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); } }
private void waitForCopyToComplete(CloudBlobWrapper blob, OperationContext opContext){ boolean copyInProgress = true; while (copyInProgress) { try { blob.downloadAttributes(opContext); } catch (StorageException se){ } // test for null because mocked filesystem doesn't know about copystates yet. copyInProgress = (blob.getCopyState() != null && blob.getCopyState().getStatus() == CopyStatus.PENDING); if (copyInProgress) { try { Thread.sleep(1000); } catch (InterruptedException ie){ //ignore } } } }
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); } }
public static void waitForCopy(CloudBlob blob) throws StorageException, InterruptedException { boolean copyInProgress = true; while (copyInProgress) { blob.downloadAttributes(); copyInProgress = (blob.getCopyState().getStatus() == CopyStatus.PENDING) || (blob.getCopyState().getStatus() == CopyStatus.ABORTED); // One second sleep if retry is needed if (copyInProgress) { Thread.sleep(1000); } } }
public static void assertAreEqual(CopyState copy1, CopyState copy2) { if (copy1 == null) { assertNull(copy2); } else { assertNotNull(copy2); assertEquals(copy1.getBytesCopied(), copy2.getBytesCopied()); assertEquals(copy1.getCompletionTime(), copy2.getCompletionTime()); assertEquals(copy1.getCopyId(), copy2.getCopyId()); assertEquals(copy1.getSource(), copy2.getSource()); assertEquals(copy1.getStatus(), copy2.getStatus()); assertEquals(copy1.getTotalBytes(), copy2.getTotalBytes()); } } }
BlobTestHelper.waitForCopy(copy); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath()); assertEquals(buffer.length, copy.getCopyState().getTotalBytes().intValue());
copy.download(copyStream); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(copyStream.toByteArray())); assertEquals(copyId, copy.getProperties().getCopyState().getCopyId());
BlobTestHelper.waitForCopy(copy); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState() .getSource().getPath());
copy.download(copyStream); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream( copyStream.toByteArray()));
BlobTestHelper.waitForCopy(copy); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath()); assertEquals(buffer.length, copy.getCopyState().getTotalBytes().intValue());
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(sourceUri.getSchemeSpecificPart(), copy.getCopyState().getSource().getSchemeSpecificPart()); assertTrue(buffer.length == copy.getCopyState().getTotalBytes());
assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), destination.getCopyState().getSource().getPath()); assertEquals(data.length(), destination.getCopyState().getTotalBytes().intValue());
BlobTestHelper.waitForCopy(copy); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath()); assertEquals(data.length(), copy.getCopyState().getTotalBytes().intValue());
BlobTestHelper.waitForCopy(copy); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState() .getSource().getPath());
destination.downloadAttributes(); assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getServiceClient().getCredentials().transformUri(source.getUri()).getPath(), destination.getCopyState().getSource().getPath());
assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getServiceClient().getCredentials().transformUri(source.getUri()).getPath(), destination.getCopyState().getSource().getPath());
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(data, copy.downloadText(Constants.UTF8_CHARSET, null, null, null)); assertEquals(copyId, copy.getProperties().getCopyState().getCopyId());