Migrate Restore-AzStorageBlobRange and ManagementPolicy related cmdlets#14
Migrate Restore-AzStorageBlobRange and ManagementPolicy related cmdlets#14yifanz0 merged 12 commits intowastoresh:track2reviewfrom
Conversation
| using Microsoft.Azure.Management.Storage; | ||
| using Microsoft.Azure.Management.Storage.Models; | ||
| using System.Management.Automation; | ||
| using Azure; |
There was a problem hiding this comment.
Put system and others assemblies in groups. VS sort-usings may help.
src/Storage/Storage.Management/StorageAccount/RestoreAzStorageBlobRange.cs
Outdated
Show resolved
Hide resolved
| } | ||
| else | ||
| { | ||
| WriteWarning(string.Format("Restore blob ranges with Id started. Restore blob ranges time to complete is dependent on the size of the restore.")); |
| } | ||
| else | ||
| { | ||
| WriteWarning(string.Format("Restore blob ranges with Id started. Restore blob ranges time to complete is dependent on the size of the restore.")); |
There was a problem hiding this comment.
may be "without id", since restoreId is not fetched?
There was a problem hiding this comment.
Maybe we should remove "with Id" here. OR jut report error, since it should have the restore ID.
There was a problem hiding this comment.
Per discussion, removed "with id", and simply print a warning of "cannot fetch id" here.
| Uri queueEndpoint = storageAccountResource.Data.PrimaryEndpoints.Queue != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.Queue) : null; | ||
| Uri tableEndpoint = storageAccountResource.Data.PrimaryEndpoints.Table != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.Table) : null; | ||
| Uri fileEndpoint = storageAccountResource.Data.PrimaryEndpoints.File != null ? new Uri(storageAccountResource.Data.PrimaryEndpoints.File) : null; | ||
| string key = storageAccountResource.GetKeys().Value.Keys[0].Value; |
There was a problem hiding this comment.
check: storageAccountResource.GetKeys()?.Value?.Keys != null && storageAccountResource.GetKeys().Value.Keys.Count > 0
| public static IList<Track2Models.BlobRestoreRange> ParseBlobRestoreRanges(PSBlobRestoreRange[] ranges) | ||
| { | ||
| IList<Track2Models.BlobRestoreRange> re = new List<Track2Models.BlobRestoreRange>(); | ||
| if (ranges == null) |
There was a problem hiding this comment.
Do you want to make sure there is at least one item in the list? If so, you need to handle to case when ranges contains 0 item as well.
There was a problem hiding this comment.
Per the PSH design, if user not input "-BlobRestoreRange", will restore all ranges (from " to "" ).
If user input the parameter "-BlobRestoreRange", normally willl input at least 1 range, and we will restore the ranged user specified.
However, there're special way to input an array with 0 range. If this happen, we will just restore with 0 ranges as user input. We have not get customer complain for this behavior before.
| Track2.Models.DateAfterModification dateAfterModification = new Track2.Models.DateAfterModification(); | ||
| dateAfterModification.DaysAfterLastAccessTimeGreaterThan = this.DaysAfterLastAccessTimeGreaterThan; | ||
| dateAfterModification.DaysAfterModificationGreaterThan = this.DaysAfterModificationGreaterThan; | ||
|
|
There was a problem hiding this comment.
missed DaysAfterLastTierChangeGreaterThan
If SDK still not support it, please add a TODO comment for it, and add the left item to the progress track excel.
There was a problem hiding this comment.
Done. It's not supported yet, so added a TODO comment for it
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| using Track2 = Azure.ResourceManager.Storage; | ||
| using Track2Models = Azure.ResourceManager.Storage.Models; |
There was a problem hiding this comment.
Should update Storage.Management.csproj, by remove following line to include the file in az.storage.
<Compile Remove="StorageAccount\RestoreAzStorageBlobRange.cs" />
| WriteObject(new PSBlobRestoreStatus(result)); | ||
| } | ||
| catch (System.AggregateException ex) when (ex.InnerException is CloudException) | ||
| catch (Exception ex) |
There was a problem hiding this comment.
Please catch a specific type exception, instead of all exceptions.
| if (status != null && status.Status == BlobRestoreProgressStatus.Failed) | ||
| Track2.StorageAccountResource account = this.StorageClientTrack2.GetStorageAccount(this.ResourceGroupName, this.StorageAccountName); | ||
| var restoreLro = account.RestoreBlobRanges( | ||
| WaitUntil.Completed, |
There was a problem hiding this comment.
Here might should be "WaitUntil.Started", as it's for when waitForComplete is not specified .
| new Track2Models.BlobRestoreContent( | ||
| this.TimeToRestore.ToUniversalTime(), | ||
| ParseBlobRestoreRanges(this.BlobRestoreRange))); | ||
| if (restoreLro.Value != null && restoreLro.Value.Status != null && restoreLro.Value.Status == Track2Models.BlobRestoreProgressStatus.Failed) |
There was a problem hiding this comment.
This line of code won't work. As can't parse the restore status from the return value when use "WaitUntil.Started".
You might should make the parse rawresponds code to a function, and use it in both place.
There was a problem hiding this comment.
Thanks for catching this! Fixed the implementation to fetch all the information we need from the raw response and create a BlobRestoreStatus.
| /// <summary> | ||
| /// Parse from PSBlobRestoreRange list to BlobRestoreRange list | ||
| /// </summary> | ||
| public static IList<Track2Models.BlobRestoreRange> ParseBlobRestoreRanges(PSBlobRestoreRange[] ranges) |
There was a problem hiding this comment.
This should be a function of class PSBlobRestoreRange.
There was a problem hiding this comment.
Done. Didn't notice there's already a ParseBlobRestoreRanges in PSBlobRestoreRange. Therefore simply removing this duplicated function here.
| Actions = this.Actions is null ? null : this.Actions.ParseManagementPolicyAction(), | ||
| Filters = this.Filters is null ? null : this.Filters.ParseManagementPolicyFilter() | ||
| }; | ||
| Track2.Models.ManagementPolicyAction actions = this.Actions is null ? null : this.Actions.ParseManagementPolicyAction(); |
There was a problem hiding this comment.
Try the syntactic sugar: actions = this.Actions?.ParseManagementPolicyAction();
| }; | ||
| Track2.Models.ManagementPolicyAction actions = this.Actions is null ? null : this.Actions.ParseManagementPolicyAction(); | ||
| Track2.Models.ManagementPolicyDefinition policyDefinition = new Track2.Models.ManagementPolicyDefinition(actions); | ||
| policyDefinition.Filters = this.Filters is null ? null : this.Filters.ParseManagementPolicyFilter(); |
There was a problem hiding this comment.
policyDefinition.Filters = this.Filters?.ParseManagementPolicyFilter();
| Dictionary<string, object> temp = restoreLro.GetRawResponse().Content.ToObjectFromJson() as Dictionary<string, object>; | ||
| object restoreId; | ||
|
|
||
| if (temp != null && temp.TryGetValue("restoreId", out restoreId)) |
There was a problem hiding this comment.
We may return early when this condition is hit, otherwise all the places using temp.*** need a null-check.
There was a problem hiding this comment.
Discussed offline with Wei and changed to throw an exception when temp is null. Thus temp referenced below is definitely not null.
Getting the raw response is a temporary workaround for this SDK issue. We will remove this chunk of code once the issue is fixed, and we should be able to get BlobRestoreStatus object directly with the SDK.
| WriteWarning(string.Format("Could not fetch the status.")); | ||
| } | ||
|
|
||
| temp.TryGetValue("restoreId", out object restoreId); |
There was a problem hiding this comment.
temp.*** is not guarded by the null-check.
There was a problem hiding this comment.
Changed to throw an exception when temp is null
|
|
||
| PSBlobRestoreRange blobRestoreRange = new PSBlobRestoreRange | ||
| { | ||
| StartRange = startRange == null ? null : startRange.ToString(), |
| } | ||
| public DateAfterCreation ParseDateAfterCreation() | ||
| { | ||
| return new DateAfterCreation(this.DaysAfterCreationGreaterThan, this.DaysAfterLastTierChangeGreaterThan); |
There was a problem hiding this comment.
Same comment should be add to code for SDK still not support "DaysAfterLastTierChangeGreaterThan". Like // TODO: DaysAfterLastTierChangeGreaterThan is still not supported by SDK, will add later.
src/Storage/Storage.Management/StorageAccount/StorageAccountBaseCmdlet.cs
Show resolved
Hide resolved
| if (storageAccountResource.GetKeys()?.Value?.Keys != null && storageAccountResource.GetKeys().Value.Keys.Count > 0) | ||
| { | ||
| key = storageAccountResource.GetKeys().Value.Keys[0].Value; | ||
| } else |
| PSBlobRestoreParameters blobRestoreParameters = new PSBlobRestoreParameters(); | ||
| Dictionary<string, object> paramMap = parameters as Dictionary<string, object>; | ||
|
|
||
| paramMap.TryGetValue("timetoRestore", out object timeToRestore); |
There was a problem hiding this comment.
Fixed. Assign null to blobRestoreParameters when paramMap is null
| Dictionary<string, object> paramMap = parameters as Dictionary<string, object>; | ||
|
|
||
| paramMap.TryGetValue("timetoRestore", out object timeToRestore); | ||
| DateTimeOffset.TryParse(timeToRestore.ToString(), out DateTimeOffset parseDate); |
| PSBlobRestoreParameters blobRestoreParameters = new PSBlobRestoreParameters(); | ||
| Dictionary<string, object> paramMap = parameters as Dictionary<string, object>; | ||
|
|
||
| paramMap.TryGetValue("timetoRestore", out object timeToRestore); |
There was a problem hiding this comment.
Double checked the response. Weird but it's timetoRestore (might be a typo on the server side?), so I'm keeping timetoRestore here.
* init add powershell cmdlet * add customization for filedetails * correct readme to include file workspace create * add custom cmdlet for creating and uploading the file * chunking logic for larger files * add error for custom cmdlet when file too big * combined cmdlets * edit custom file upload command to not use default subscriptionid * no default value for subid in custom file upload * separate subscription and no subscription commands * remove comments from combined cmd for file * fix cmd * custom no subscription file upload commands * autogen docs for no sub file upload * hide individual file commands * add back workspace commands * add name as alias for fileworkspacename fileworkspacesnosubscription * remove update files and add alias for nosubscription file commands * tests for get service * tests for problem classification * try adding erroractionpreference = stop * tests for new file workspace * tests for get file workspace * more tests * add tests for new file and upload, removefile name as a parameter * remove new files no subscription * tests for get file * erroraction stop * remove unnecessary comments and print statements * docs for get support service * problem classification docs * add titles * documentation for file workspace commands * documentation for file/file workspace cmdlets * documentation for checkNameAvailability * added tests and documentation for operations, support ticket, communication and chat transcript cmdlets * added examples for operations, support ticket, communication and chat transcript cmdlets * resolve merge conflicts * resolved PR comments * get conflict file changes from grhuang/azsupport-autorest * resolved merge conflict * removed update communication sub and no sub scenarios * Revert "removed update communication sub and no sub scenarios" This reverts commit ccbfdee. * removed update communication sub and no sub scenarios , updated readme * make communiation and support ticket properties required in readme, edit get operation file name, edit calling internal cmdlets for file upload * fix documentation * fix top query * add custom error handler * consolidate list and get communicationsnosubscription and chattranscriptsnosubscription * init changes to allow no subscription recording tests-need to use csp partner account in tenant 2e6a0c9f-986d-480e-ad4b-bdfddc047aba * changes to not create new resources in playback * remove custom error handler csharp * init add changes to split subscription and no subscription tests * update skip * Update recordings * update recordings * add more examples to new-azsupportticket documentation * update documentation and readme * add directive back in * make advanced diagnostic consent required * Add custom error handling for New- and Update- cmdlets to print full details of error (#9) * Add custom error handler * Add default filter to retrieve tickets from the past week for Get-AzSupportTickets and Get-AzSupportTicketsNoSubscription (#10) * add custom filtering for list support ticket if no filter is applied * make transformations in swagger in readme to make enrollment id not readonly and show isTempTicket (#11) * Add argument completer (#12) * add argument completers * add quotes to argument completers * remove repeated time zone * Regenerate powershell module with GA swagger (#13) * Rerecord tests using GA version (#14) * add tests for file size (will add recordings once Ga swagger available) * Regenerate powershell module with GA swagger * Rerecord tests with GA version * Fix documentation * fix url for file upload --------- Co-authored-by: Grace Huang (from Dev Box) <grhuang@microsoft.com> Co-authored-by: grhuangmsft <103289214+grhuangmsft@users.noreply.github.com> Co-authored-by: Shreya Kumar <shreyakumar@microsoft.com> Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com>
Description
Migrate Restore-AzStorageBlobRange and ManagementPolicy related cmdlets
Checklist
CONTRIBUTING.mdChangeLog.mdfile(s) has been updated:ChangeLog.mdfile can be found atsrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md## Upcoming Releaseheader -- no new version header should be added