Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

treat commit id as the optional parameter in stop-copy cmdlet

  • Loading branch information...
commit 65db198be69a9f642ed0c7b796d571bc11436a0d 1 parent c2870c9
@xmbms xmbms authored
View
8 WindowsAzurePowershell/src/Management.Storage.Test/Blob/Cmdlet/GetAzureStorageBlobContentTest.cs
@@ -66,10 +66,10 @@ public void OnProgressTest()
Assert.AreEqual(12, pr.PercentComplete);
command.OnTaskProgress(pr, 5.6, 12.8);
Assert.AreEqual(12, pr.PercentComplete);
- command.OnTaskProgress(pr, 5.6, 112.8);
- Assert.AreEqual(100, pr.PercentComplete);
- command.OnTaskProgress(pr, 5.6, -112.8);
- Assert.AreEqual(0, pr.PercentComplete);
+ command.OnTaskProgress(pr, 5.6, 2.8);
+ Assert.AreEqual(2, pr.PercentComplete);
+ command.OnTaskProgress(pr, 5.6, 1.8);
+ Assert.AreEqual(1, pr.PercentComplete);
command.OnTaskProgress(pr, 5.6, 5);
Assert.AreEqual(5, pr.PercentComplete);
}
View
8 WindowsAzurePowershell/src/Management.Storage.Test/Blob/Cmdlet/SetAzureStorageBlobContentTest.cs
@@ -67,10 +67,10 @@ public void OnProgressTest()
Assert.AreEqual(12, pr.PercentComplete);
command.OnTaskProgress(pr, 5.6, 12.8);
Assert.AreEqual(12, pr.PercentComplete);
- command.OnTaskProgress(pr, 5.6, 112.8);
- Assert.AreEqual(100, pr.PercentComplete);
- command.OnTaskProgress(pr, 5.6, -112.8);
- Assert.AreEqual(0, pr.PercentComplete);
+ command.OnTaskProgress(pr, 5.6, 11);
+ Assert.AreEqual(11, pr.PercentComplete);
+ command.OnTaskProgress(pr, 5.6, 12.8);
+ Assert.AreEqual(12, pr.PercentComplete);
command.OnTaskProgress(pr, 5.6, 5);
Assert.AreEqual(5, pr.PercentComplete);
}
View
10 WindowsAzurePowershell/src/Management.Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs
@@ -100,6 +100,16 @@ public SwitchParameter CheckMd5
}
private bool checkMd5;
+ /// <summary>
+ /// Amount of concurrent async tasks to run per available core.
+ /// </summary>
+ [Parameter(HelpMessage = "The total amount of concurrent async tasks. The default value is ProcessorCount * 8")]
+ public int ConcurrentTaskCount
+ {
+ get { return concurrentTaskCount; }
+ set { concurrentTaskCount = value; }
+ }
+
private AzureToFileSystemFileNameResolver fileNameResolver;
/// <summary>
View
10 WindowsAzurePowershell/src/Management.Storage/Blob/Cmdlet/SetAzureStorageBlobContent.cs
@@ -148,6 +148,16 @@ public Hashtable Metadata
private Hashtable BlobMetadata = null;
/// <summary>
+ /// Amount of concurrent async tasks to run per available core.
+ /// </summary>
+ [Parameter(HelpMessage = "The total amount of concurrent async tasks. The default value is ProcessorCount * 8")]
+ public int ConcurrentTaskCount
+ {
+ get { return concurrentTaskCount; }
+ set { concurrentTaskCount = value; }
+ }
+
+ /// <summary>
/// the root dir for sending file
/// make sure the root dir is lower case.
/// </summary>
View
61 WindowsAzurePowershell/src/Management.Storage/Blob/Cmdlet/StopCopyAzureStorageBlob.cs
@@ -23,7 +23,7 @@ namespace Microsoft.WindowsAzure.Management.Storage.Blob.Cmdlet
using System.Management.Automation;
using System.Security.Permissions;
- [Cmdlet(VerbsLifecycle.Stop, StorageNouns.CopyBlob, DefaultParameterSetName = NameParameterSet),
+ [Cmdlet(VerbsLifecycle.Stop, StorageNouns.CopyBlob, ConfirmImpact = ConfirmImpact.High, DefaultParameterSetName = NameParameterSet),
OutputType(typeof(AzureStorageBlob))]
public class StopCopyAzureStorageBlob : StorageCloudBlobCmdletBase
{
@@ -77,7 +77,7 @@ public SwitchParameter Force
}
private bool force = false;
- [Parameter(HelpMessage = "Copy Id", Mandatory = true)]
+ [Parameter(HelpMessage = "Copy Id", Mandatory = false)]
[ValidateNotNullOrEmpty]
public string CopyId
{
@@ -155,6 +155,16 @@ private void StopCopyBlob(CloudBlobContainer container, string blobName, string
}
/// <summary>
+ /// confirm to abort copy operation
+ /// </summary>
+ /// <param name="msg">Confirmation message</param>
+ /// <returns>True if the opeation is confirmed, otherwise return false</returns>
+ internal virtual bool ConfirmAbort(string msg)
+ {
+ return ShouldProcess(msg);
+ }
+
+ /// <summary>
/// Stop copy operation by ICloudBlob object
/// </summary>
/// <param name="blob">ICloudBlob object</param>
@@ -172,18 +182,51 @@ private void StopCopyBlob(ICloudBlob blob, string copyId)
throw new ArgumentException(String.Format(Resources.ObjectCannotBeNull, typeof(ICloudBlob).Name));
}
- if (Force)
+ string specifiedCopyId = copyId;
+
+ if (string.IsNullOrEmpty(specifiedCopyId))
{
- if (blob.CopyState == null)
+ if (blob.CopyState != null)
{
- //Use default retry policy for FetchBlobAttributes
- BlobRequestOptions options = null;
- Channel.FetchBlobAttributes(blob, accessCondition, options, OperationContext);
+ specifiedCopyId = blob.CopyState.CopyId;
}
+ }
+
+ string abortCopyId = string.Empty;
+
+ if (string.IsNullOrEmpty(specifiedCopyId) || Force)
+ {
+ //Make sure we use the correct copy id to abort
+ //Use default retry policy for FetchBlobAttributes
+ BlobRequestOptions options = null;
+ Channel.FetchBlobAttributes(blob, accessCondition, options, OperationContext);
- if (blob.CopyState != null && !String.IsNullOrEmpty(blob.CopyState.CopyId))
+ if (blob.CopyState == null || String.IsNullOrEmpty(blob.CopyState.CopyId))
+ {
+ throw new ArgumentException(String.Format(Resources.CopyTaskNotFound, blob.Name, blob.Container.Name));
+ }
+ else
+ {
+ abortCopyId = blob.CopyState.CopyId;
+ }
+ }
+
+ if (!Force)
+ {
+ if (String.IsNullOrEmpty(specifiedCopyId))
+ {
+ string confirmation = String.Format(Resources.ConfirmAbortCopyOperation, blob.Name, blob.Container.Name, abortCopyId);
+
+ if(!ConfirmAbort(confirmation))
+ {
+ string cancelMessage = String.Format(Resources.StopCopyOperationCancelled, blob.Name, blob.Container.Name);
+ WriteObject(cancelMessage);
+ return;
+ }
+ }
+ else if(specifiedCopyId != abortCopyId)
{
- copyId = blob.CopyState.CopyId;
+ throw new ArgumentException(String.Format(Resources.CopyIdMismatch, blob.Name, blob.Container.Name));
}
}
View
8 WindowsAzurePowershell/src/Management.Storage/Blob/StorageDataMovementCmdletBase.cs
@@ -25,13 +25,7 @@ public class StorageDataMovementCmdletBase : StorageCloudBlobCmdletBase, IDispos
/// <summary>
/// Amount of concurrent async tasks to run per available core.
/// </summary>
- [Parameter(HelpMessage = "The total amount of concurrent async tasks. The default value is ProcessorCount * 8")]
- public int ConcurrentTaskCount
- {
- get { return concurrentTaskCount; }
- set { concurrentTaskCount = value; }
- }
- private int concurrentTaskCount = 0;
+ protected int concurrentTaskCount = 0;
/// <summary>
/// whether the transfer progress finished
View
27 WindowsAzurePowershell/src/Management.Storage/Resources.Designer.cs
@@ -169,6 +169,15 @@ internal class Resources {
}
/// <summary>
+ /// Looks up a localized string similar to Are you sure to abort the copy operation on blob &apos;{0}&apos; in container &apos;{1}&apos; with copy id {2}..
+ /// </summary>
+ internal static string ConfirmAbortCopyOperation {
+ get {
+ return ResourceManager.GetString("ConfirmAbortCopyOperation", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The blob &apos;{0}&apos; in container &apos;{1}&apos; has snapshots. Are you sure to remove blob and its snapshots?.
/// </summary>
internal static string ConfirmRemoveBlobWithSnapshot {
@@ -286,6 +295,15 @@ internal class Resources {
}
/// <summary>
+ /// Looks up a localized string similar to Copy Id mismatch on blob &apos;{0}&apos; in container &apos;{1}&apos;..
+ /// </summary>
+ internal static string CopyIdMismatch {
+ get {
+ return ResourceManager.GetString("CopyIdMismatch", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Can not find copy task on specified blob &apos;{0}&apos; in container &apos;{1}&apos;..
/// </summary>
internal static string CopyTaskNotFound {
@@ -898,6 +916,15 @@ internal class Resources {
}
/// <summary>
+ /// Looks up a localized string similar to The stop copy operation on blob &apos;{0}&apos; in container &apos;{1}&apos; is cancelled..
+ /// </summary>
+ internal static string StopCopyOperationCancelled {
+ get {
+ return ResourceManager.GetString("StopCopyOperationCancelled", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to {0} stop processing, Use {1} remote calls. Elapsed time {2:0.00} ms. Client operation id: {3}..
/// </summary>
internal static string StopProcessingLog {
View
12 WindowsAzurePowershell/src/Management.Storage/Resources.resx
@@ -475,4 +475,16 @@
<value>Your copy blob request to blob '{0}' in container '{1}' has already scheduled. However the destination blob still didn't create. Please try to mintor it later.</value>
<comment>0 for blob name, 1 for container name.</comment>
</data>
+ <data name="ConfirmAbortCopyOperation" xml:space="preserve">
+ <value>Are you sure to abort the copy operation on blob '{0}' in container '{1}' with copy id {2}.</value>
+ <comment>0 for blob name, 1 for container name, 2 for copy id.</comment>
+ </data>
+ <data name="CopyIdMismatch" xml:space="preserve">
+ <value>Copy Id mismatch on blob '{0}' in container '{1}'.</value>
+ <comment>0 for blob name, 1 for container name.</comment>
+ </data>
+ <data name="StopCopyOperationCancelled" xml:space="preserve">
+ <value>The stop copy operation on blob '{0}' in container '{1}' is cancelled.</value>
+ <comment>0 for blob name, 1 for container name.</comment>
+ </data>
</root>
Please sign in to comment.
Something went wrong with that request. Please try again.