Skip to content

Commit 96894ab

Browse files
committed
[Storage Dataplane] - Remove Validation Set and move to track2 SDK for
accesstier
1 parent 7c135d8 commit 96894ab

File tree

9 files changed

+84
-106
lines changed

9 files changed

+84
-106
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Removed the ValidateSet of StandardBlobTier parameter
22+
- `Copy-AzStorageBlob`
23+
- `Set-AzStorageBlobContent`
24+
- `Start-AzStorageBlobCopy`
2125

2226
## Version 5.3.0
23-
* Return ListBlobProperties in blob list result
27+
* Returned ListBlobProperties in blob list result
2428
- `Get-AzStorageBlob`
25-
* Output AllowedCopyScope in get account result
29+
* Returned AllowedCopyScope in get account result
2630
- `Get-AzStorageAccount`
2731

2832
## Version 5.2.0

src/Storage/Storage.Management/help/Copy-AzStorageBlob.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ C:\PS> $blob = Copy-AzStorageBlob -SrcContainer $containerName -SrcBlob $blobnam
7171

7272
This command update a block blob encryption scope by copy it to itself with a new encryption scope.
7373

74-
### Example 5: Copy a blob to a new append blob
74+
### Example 5: Copy a blob to a new append blob
7575
```
7676
C:\PS> $srcBlob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
7777
C:\PS> $destBlob = Copy-AzStorageBlob -SrcContainer "sourcecontainername" -SrcBlob "srcblobname" -DestContainer "destcontainername" -DestBlob "destblobname" -DestBlobType "Append" -DestContext $destCtx
@@ -325,7 +325,6 @@ See detail in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-
325325
Type: System.String
326326
Parameter Sets: (All)
327327
Aliases:
328-
Accepted values: Hot, Cool, Archive
329328

330329
Required: False
331330
Position: Named

src/Storage/Storage.Management/help/Set-AzStorageBlobContent.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ The blob includes the metadata stored in $Metadata, and has PremiumPageBlobTier
9494

9595
### Example 6: Upload a file to blob with specified blob properties, and set StandardBlobTier as Cool
9696
<!-- Skip: Output cannot be splitted from code -->
97+
98+
9799
```
98100
PS C:\> $filepath = "c:\temp\index.html"
99101
PS C:\> Set-AzStorageBlobContent -File $filepath -Container "contosouploads" -Properties @{"ContentType" = [System.Web.MimeMapping]::GetMimeMapping($filepath); "ContentMD5" = "i727sP7HigloQDsqadNLHw=="} -StandardBlobTier Cool
@@ -110,6 +112,8 @@ This command gets ContentType value set to blob properties by [System.Web.MimeMa
110112

111113
### Example 7: Upload a file to a blob with Encryption Scope
112114
<!-- Skip: Output cannot be splitted from code -->
115+
116+
113117
```
114118
PS C:\> $blob = Set-AzStorageBlobContent -File "mylocalfile" -Container "mycontainer" -Blob "myblob" -EncryptionScope "myencryptscope"
115119
@@ -419,7 +423,6 @@ See detail in https://docs.microsoft.com/azure/storage/blobs/storage-blob-storag
419423
Type: System.String
420424
Parameter Sets: (All)
421425
Aliases:
422-
Accepted values: Hot, Cool, Archive
423426

424427
Required: False
425428
Position: Named
@@ -492,7 +495,7 @@ Accept wildcard characters: False
492495
```
493496
494497
### CommonParameters
495-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
498+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
496499
497500
## INPUTS
498501

src/Storage/Storage.Management/help/Start-AzStorageBlobCopy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ See detail in https://docs.microsoft.com/azure/storage/blobs/storage-blob-storag
614614
Type: System.String
615615
Parameter Sets: (All)
616616
Aliases:
617-
Accepted values: Hot, Cool, Archive
618617

619618
Required: False
620619
Position: Named

src/Storage/Storage/Blob/Cmdlet/CopyAzureStorageBlob.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
1818
using Azure.Commands.Common.Authentication.Abstractions;
1919
using Commands.Common.Storage.ResourceModel;
2020
using global::Azure.Storage.Blobs;
21+
using global::Azure.Storage.Blobs.Models;
2122
using global::Azure.Storage.Blobs.Specialized;
2223
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2324
using Microsoft.Azure.Storage.Blob;
@@ -99,28 +100,30 @@ public string SrcContainer
99100
public string DestBlobType { get; set; }
100101

101102
[Parameter(HelpMessage = "Block Blob Tier, valid values are Hot/Cool/Archive. See detail in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers", Mandatory = false)]
103+
[ValidateNotNullOrEmpty]
102104
[PSArgumentCompleter("Hot", "Cool", "Archive")]
103-
[ValidateSet("Hot", "Cool", "Archive", IgnoreCase = true)]
104105
public string StandardBlobTier
105106
{
106107
get
107108
{
108-
return standardBlobTier is null ? null : standardBlobTier.Value.ToString();
109+
return accesstier?.ToString();
109110
}
110111

111112
set
112113
{
113114
if (value != null)
114115
{
115-
standardBlobTier = ((StandardBlobTier)Enum.Parse(typeof(StandardBlobTier), value, true));
116+
accesstier = new AccessTier(value);
117+
isBlockBlobAccessTier = true;
116118
}
117119
else
118120
{
119-
standardBlobTier = null;
121+
accesstier = null;
120122
}
121123
}
122124
}
123-
private StandardBlobTier? standardBlobTier = null;
125+
private bool? isBlockBlobAccessTier = null;
126+
private AccessTier? accesstier = null;
124127

125128
[Parameter(HelpMessage = "Block Blob RehydratePriority. Indicates the priority with which to rehydrate an archived blob. Valid values are High/Standard.", Mandatory = false)]
126129
[ValidateSet("Standard", "High", IgnoreCase = true)]
@@ -372,7 +375,11 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
372375

373376
if (destBlobType != null)
374377
{
375-
ValidateBlobTier(Util.convertBlobType_Track2ToTrack1(destBlobType), null, standardBlobTier, rehydratePriority);
378+
ValidateBlobTier(Util.convertBlobType_Track2ToTrack1(destBlobType), null, isBlockBlobAccessTier, rehydratePriority);
379+
if (this.rehydratePriority != null && this.accesstier == null)
380+
{
381+
throw new ArgumentException("RehydratePriority should only be specified when StandardBlobTier is specified.");
382+
}
376383
}
377384

378385
if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
@@ -483,9 +490,9 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
483490
Track2Models.BlobCopyFromUriOptions options = new Track2Models.BlobCopyFromUriOptions();
484491

485492
// The Blob Type and Blob Tier must match, since already checked before
486-
if (standardBlobTier != null || rehydratePriority != null)
493+
if (accesstier != null || rehydratePriority != null)
487494
{
488-
options.AccessTier = Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier);
495+
options.AccessTier = accesstier;
489496
options.RehydratePriority = Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority);
490497
}
491498
options.SourceConditions = this.BlobRequestConditions;
@@ -495,10 +502,10 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
495502
destBlobClient.SyncCopyFromUri(srcUri, options, this.CmdletCancellationToken);
496503

497504
// Set rehydrate priority
498-
if (rehydratePriority != null)
505+
if (rehydratePriority != null && accesstier != null)
499506
{
500-
destBlobClient.SetAccessTier(Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier) == null ? null : (Track2Models.AccessTier)Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier),
501-
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
507+
destBlobClient.SetAccessTier(accesstier.Value,
508+
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
502509
}
503510
break;
504511
}
@@ -510,9 +517,9 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
510517
commitBlockListOptions.Metadata = srcProperties.Metadata;
511518
commitBlockListOptions.Tags = blobTags ?? null;
512519

513-
if (standardBlobTier != null)
520+
if (accesstier != null)
514521
{
515-
commitBlockListOptions.AccessTier = Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier);
522+
commitBlockListOptions.AccessTier = accesstier;
516523
}
517524

518525
long blockLength = GetBlockLength(srcProperties.ContentLength);
@@ -534,10 +541,10 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
534541
destBlockBlob.CommitBlockList(blockIDs, commitBlockListOptions, this.CmdletCancellationToken);
535542

536543
// Set rehydrate priority
537-
if (rehydratePriority != null)
544+
if (rehydratePriority != null && accesstier != null)
538545
{
539-
destBlockBlob.SetAccessTier(Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier) == null ? null : (Track2Models.AccessTier)Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier),
540-
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
546+
destBlockBlob.SetAccessTier(accesstier.Value,
547+
rehydratePriority: Util.ConvertRehydratePriority_Track1ToTrack2(rehydratePriority), cancellationToken: this.CmdletCancellationToken);
541548
}
542549
break;
543550
}

src/Storage/Storage/Blob/Cmdlet/SetAzureStorageBlobContent.cs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,30 @@ public PremiumPageBlobTier PremiumPageBlobTier
180180
private PremiumPageBlobTier? pageBlobTier = null;
181181

182182
[Parameter(HelpMessage = "Block Blob Tier, valid values are Hot/Cool/Archive. See detail in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers", Mandatory = false)]
183+
[ValidateNotNullOrEmpty]
183184
[PSArgumentCompleter("Hot", "Cool", "Archive")]
184-
[ValidateSet("Hot", "Cool", "Archive", IgnoreCase = true)]
185185
public string StandardBlobTier
186186
{
187187
get
188188
{
189-
return standardBlobTier is null ? null : standardBlobTier.Value.ToString();
189+
return accesstier?.ToString();
190190
}
191191

192192
set
193193
{
194194
if (value != null)
195195
{
196-
standardBlobTier = ((StandardBlobTier)Enum.Parse(typeof(StandardBlobTier), value, true));
196+
accesstier = new AccessTier(value);
197+
isBlockBlobAccessTier = true;
197198
}
198199
else
199200
{
200-
standardBlobTier = null;
201+
accesstier = null;
201202
}
202203
}
203204
}
204-
private StandardBlobTier? standardBlobTier = null;
205+
private bool? isBlockBlobAccessTier = null;
206+
private AccessTier? accesstier = null;
205207

206208
[Parameter(HelpMessage = "Encryption scope to be used when making requests to the blob.",
207209
Mandatory = false)]
@@ -220,6 +222,10 @@ protected override bool UseTrack2Sdk()
220222
{
221223
return true;
222224
}
225+
if (accesstier != null && accesstier.Value != AccessTier.Archive && accesstier.Value != AccessTier.Cool && accesstier.Value != AccessTier.Hot)
226+
{
227+
return true;
228+
}
223229
return false;
224230
}
225231

@@ -286,9 +292,9 @@ await DataMovementTransferHelper.DoTransfer(() =>
286292
data.Record,
287293
this.OutputStream).ConfigureAwait(false);
288294

289-
if (this.pageBlobTier != null || this.standardBlobTier != null)
295+
if (this.pageBlobTier != null || this.accesstier != null)
290296
{
291-
await this.SetBlobTier(localChannel, blob, pageBlobTier, standardBlobTier).ConfigureAwait(false);
297+
await this.SetBlobTier(localChannel, blob, pageBlobTier, accesstier).ConfigureAwait(false);
292298
}
293299

294300
try
@@ -409,10 +415,10 @@ protected override void DoEndProcessing()
409415
/// <param name="localChannel">IStorageBlobManagement channel object</param>
410416
/// <param name="blob">CloudBlob object</param>
411417
/// <param name="pageBlobTier">Page Blob Tier</param>
412-
/// <param name="standardBlobTier">Access condition to source if it's file/blob in azure.</param>
413-
private async Task SetBlobTier(IStorageBlobManagement localChannel, StorageBlob.CloudBlob blob, PremiumPageBlobTier? pageBlobTier = null, StandardBlobTier? standardBlobTier = null)
418+
/// <param name="accessTier">Access condition to source if it's file/blob in azure.</param>
419+
private async Task SetBlobTier(IStorageBlobManagement localChannel, StorageBlob.CloudBlob blob, PremiumPageBlobTier? pageBlobTier = null, AccessTier? accessTier = null)
414420
{
415-
if (pageBlobTier == null && standardBlobTier == null)
421+
if (pageBlobTier == null && accessTier == null)
416422
{
417423
return;
418424
}
@@ -424,10 +430,9 @@ private async Task SetBlobTier(IStorageBlobManagement localChannel, StorageBlob.
424430
{
425431
await Channel.SetPageBlobTierAsync((CloudPageBlob)blob, pageBlobTier.Value, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
426432
}
427-
if (standardBlobTier != null)
433+
if (accessTier != null)
428434
{
429-
AccessCondition accessCondition = null;
430-
await Channel.SetStandardBlobTierAsync((CloudBlockBlob)blob, accessCondition, standardBlobTier.Value, null, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
435+
AzureStorageBlob.GetTrack2BlobClient(blob, localChannel.StorageContext, ClientOptions).SetAccessTier(accesstier.Value, cancellationToken: this.CmdletCancellationToken);
431436
}
432437
}
433438

@@ -450,7 +455,11 @@ internal virtual async Task UploadBlobwithSdk(long taskId, IStorageBlobManagemen
450455
BlobHttpHeaders blobHttpHeaders = CreateBlobHttpHeaders(BlobProperties);
451456
IDictionary<string, string> metadata = new Dictionary<string, string>();
452457
SetBlobMeta_Track2(metadata, this.Metadata);
453-
AccessTier? accesstier = GetAccessTier_Track2(this.standardBlobTier, this.pageBlobTier);
458+
AccessTier? accesstierToSet = this.accesstier;
459+
if (accesstierToSet == null)
460+
{
461+
accesstierToSet = Util.ConvertAccessTier_Track1ToTrack2(this.pageBlobTier);
462+
}
454463

455464
//Prepare progress handler
456465
long fileSize = new FileInfo(ResolvedFileName).Length;
@@ -485,7 +494,7 @@ internal virtual async Task UploadBlobwithSdk(long taskId, IStorageBlobManagemen
485494
uploadOptions.Metadata = metadata;
486495
uploadOptions.HttpHeaders = blobHttpHeaders;
487496
uploadOptions.Conditions = this.BlobRequestConditions;
488-
uploadOptions.AccessTier = accesstier;
497+
uploadOptions.AccessTier = accesstierToSet;
489498
uploadOptions.ProgressHandler = progressHandler;
490499
uploadOptions.TransferOptions = trasnferOption;
491500

@@ -580,9 +589,9 @@ internal virtual async Task UploadBlobwithSdk(long taskId, IStorageBlobManagemen
580589
offset += readoutcount;
581590
progressHandler.Report(offset);
582591
}
583-
if (string.Equals(blobType, PageBlobType, StringComparison.InvariantCultureIgnoreCase) && accesstier != null)
592+
if (string.Equals(blobType, PageBlobType, StringComparison.InvariantCultureIgnoreCase) && accesstierToSet != null)
584593
{
585-
await pageblobClient.SetAccessTierAsync(accesstier.Value, cancellationToken: CmdletCancellationToken).ConfigureAwait(false);
594+
await pageblobClient.SetAccessTierAsync(accesstierToSet.Value, cancellationToken: CmdletCancellationToken).ConfigureAwait(false);
586595
}
587596
}
588597
else
@@ -613,9 +622,9 @@ protected override void OnTaskSuccessful(DataMovementUserData data)
613622
AccessCondition accessCondition = null;
614623
StorageBlob.BlobRequestOptions requestOptions = RequestOptions;
615624

616-
if (this.pageBlobTier != null || this.standardBlobTier != null)
625+
if (this.pageBlobTier != null || this.accesstier != null)
617626
{
618-
this.SetBlobTier(localChannel, blob, pageBlobTier, standardBlobTier).Wait();
627+
this.SetBlobTier(localChannel, blob, pageBlobTier, accesstier).Wait();
619628
}
620629

621630
try
@@ -683,7 +692,7 @@ public override void ExecuteCmdlet()
683692
{
684693
type = StorageBlob.BlobType.Unspecified;
685694
}
686-
ValidateBlobTier(type, pageBlobTier, standardBlobTier);
695+
ValidateBlobTier(type, pageBlobTier, this.isBlockBlobAccessTier);
687696

688697
if (BlobProperties != null)
689698
{

0 commit comments

Comments
 (0)