Skip to content

Webapps undelete commands #7165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 15, 2018

Conversation

nking-1
Copy link

@nking-1 nking-1 commented Sep 7, 2018

Description

Implements the cmdlets Get-AzureRmDeletedWebApp and Restore-AzureRmDeletedWebApp, which allow users to restore a deleted app.

Sisira is working on updating the Websites project to use the new Websites SDK and fix all breaking changes. I will rebase onto her changes once her PR is accepted. I am opening this PR for early feedback since the deadline is coming up very soon.

Cmdlet review:
https://github.com/Azure/azure-powershell-cmdlet-review-pr/issues/128

Checklist

@maddieclayton
Copy link
Contributor

Marking as do not merge until this gets in: #7127

@cormacpayne
Copy link
Member

@Nking92 Hey Nick, for some reason, GitHub isn't letting me pull in the latest changes from preview into your branch, so would you mind doing so to resolve the build failure you're currently seeing?

@nking-1
Copy link
Author

nking-1 commented Sep 12, 2018

I had an SDK update commit on my own preview branch and then branched the webapps-undelete branch off of that. I have rebased everything to be on upstream/preview, so the SDK update is now included as part of this PR, which will hopefully fix the build. Please note that both Sisira and I have updated the SDK separately. We want to take Sisira's update as the "official" one, and I will rebase my branch on top of that once you merge her PR. So basically, the only commit that needs review is 4d3ed08, and the SDK update commit was only there to get my build working.

$deletedApp = Get-AzureRmDeletedWebApp -ResourceGroupName $undeleteRgName -Name $undeleteAppName -Slot "Production"
$deletedSlot = Get-AzureRmDeletedWebApp -ResourceGroupName $undeleteRgName -Name $undeleteAppName -Slot $undeleteSlot
Restore-AzureRmDeletedWebApp $deletedApp -TargetResourceGroupName $rgname -TargetName $wname -Force
Restore-AzureRmDeletedWebApp $deletedSlot -TargetResourceGroupName $rgname -TargetName $wname -TargetSlot $slotName -Force
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some asserts here?

New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier $tier
$deletedApp = Get-AzureRmDeletedWebApp -ResourceGroupName $undeleteRgName -Name $undeleteAppName -Slot "Production"
$job = $deletedApp | Restore-AzureRmDeletedWebApp -TargetResourceGroupName $rgname -TargetAppServicePlanName $whpName -Force -AsJob
$job | Wait-Job
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, please add some asserts here

@@ -95,7 +95,8 @@ CmdletsToExport = 'Get-AzAppServicePlan', 'Set-AzAppServicePlan',
'New-AzWebApp', 'Remove-AzWebAppBackup',
'Reset-AzWebAppPublishingProfile', 'Restart-AzWebApp',
'Set-AzWebApp', 'Start-AzWebApp', 'Stop-AzWebApp',
'Get-AzWebAppSnapshot', 'Restore-AzWebAppSnapshot'
'Get-AzWebAppSnapshot', 'Restore-AzWebAppSnapshot',
'Get-AzDeletedWebApp'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing one of the cmdlets

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow these instructions to create the right aliases for the Az -> AzureRm netcore cmdlets. https://github.com/Azure/azure-powershell/blob/preview/documentation/development-docs/create-alias-mappings.md


namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
{
public class AzureDeletedWebApp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a "PS" prefix to indicate that this is a PowerShell model

/// <summary>
/// Restores a deleted Azure Web App's contents and settings to an existing web app
/// </summary>
[Cmdlet("Restore", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "DeletedWebApp"), OutputType(typeof(void))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do a get here and return the restored web app? I feel like that would be the expected behavior.

{
// Note, there can be multiple deleted web apps with the same name and resource group. Internally each deleted app has a unique ID.
[Parameter(Position = 0, Mandatory = true, HelpMessage = "The deleted Azure Web App.", ValueFromPipeline = true)]
public AzureDeletedWebApp InputObject;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you only did the inputobject parameter set - you need the interactive one as well (as discussed in the design review)

Restore-AzureRmDeletedWebApp -ResourceGroupName <string> -Name <string> [-TargetResourceGroupName <string>] -TargetName <string>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I overlooked that. The problem is that there could be a web app with the same name and resource group that was deleted and re-created multiple times. This is actually a relatively common case. In the backend we've given each deleted app a unique ID to avoid ambiguity.

We could default to restoring the most recent deleted app with the provided name and resource group. Do you think that would be good, or could it be too confusing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I do see your point. I think it would be good to be restore the most recently deleted app, but add a warning message if there were multiple stating that we chose to restore the most recent app. Could you also add a parameter set to accept that unique id? Or do you think that the users would not ever want to use that functionality? Apologies if we've previously discussed this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on adding the option to undelete by deleted site name with your suggestions.

I don't think many people would use a deleted site ID parameter. The ID is a generated integer that's only discoverable by using the Get-AzureRmDeletedWebApp cmdlet. It's easiest to just use the deleted site object directly instead of pulling the ID out of it. The ID is also something we'd prefer to keep somewhat hidden from customers because it's not much use to them.

public AzureDeletedWebApp InputObject;

[Parameter(Position = 1, Mandatory = true, HelpMessage = "The resource group containing the new Azure Web App.", ValueFromPipelineByPropertyName = true)]
public string TargetResourceGroupName { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the design review this was not mandatory - why has this changed? Also, none of these parameters should have ValueFromPipelineByPropertyName = true, please remove from all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to be optional

@maddieclayton
Copy link
Contributor

@Nking92 Is this feature supposed to go in stable or a preview module?

@maddieclayton maddieclayton changed the base branch from preview to release-2018-09-17 September 14, 2018 01:05
@maddieclayton
Copy link
Contributor

@Nking92 Please fix merge conflicts.

@maddieclayton
Copy link
Contributor

@Nking92 In order to get into the Ignite release you will need to update this PR by the end of the day. We are required to hand off to cloudshell by 10am Monday morning.

/// <summary>
/// Restores a deleted Azure Web App's contents and settings to an existing web app
/// </summary>
[Cmdlet("Restore", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "DeletedWebApp"), OutputType(typeof(PSSite))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a DefaultParameterSetName attribute

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please update the changelog at src/Websites/Commands.Websites/Changelog.md

@maddieclayton maddieclayton merged commit a259f88 into Azure:release-2018-09-17 Sep 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants