Skip to content

Commit 2ac7352

Browse files
author
dragonfly91
committed
Resolved merge conflicts
2 parents 1e0021e + dfc902f commit 2ac7352

31 files changed

+856
-100
lines changed

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal static class Common
3737
public const string Vault = "The Azure Backup vault object which is the parent resource.";
3838
public const string WorkloadType = "Workload type of the resource (for example: AzureVM, WindowsServer).";
3939
public const string BackupManagementType = "Backup Management type of the resource (for example: MAB, DPM).";
40+
public const string ConfirmationMessage = "Don't ask for confirmation.";
4041
}
4142

4243
internal static class Policy
@@ -71,6 +72,7 @@ internal static class Item
7172
public const string ProtectionStatus = "Protection status of Item";
7273
public const string Status = "Status of the data source";
7374
public const string Container = "Container where the item resides";
75+
public const string RemoveProtectionOption = "If this option is used, all the backup data for this item will also be deleted and restoring data will not be possible.";
7476
public const string ExpiryDate = "Retention period for the recovery points created by this backup operaiton";
7577
}
7678

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
24+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
25+
using HydraModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
26+
27+
28+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
29+
{
30+
/// <summary>
31+
/// Enable Azure Backup protection
32+
/// </summary>
33+
[Cmdlet(VerbsLifecycle.Disable, "AzureRmRecoveryServicesProtection"), OutputType(typeof(AzureRmRecoveryServicesJobBase))]
34+
public class DisableAzureRmRecoveryServicesProtection : RecoveryServicesBackupCmdletBase
35+
{
36+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Item.ProtectedItem, ValueFromPipeline = true)]
37+
[ValidateNotNullOrEmpty]
38+
public AzureRmRecoveryServicesItemBase Item { get; set; }
39+
40+
[Parameter(Position = 1, Mandatory = false, HelpMessage = ParamHelpMsg.Item.RemoveProtectionOption)]
41+
public SwitchParameter RemoveRecoveryPoints
42+
{
43+
get { return DeleteBackupData; }
44+
set { DeleteBackupData = value; }
45+
}
46+
47+
[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
48+
public SwitchParameter Force { get; set; }
49+
50+
private bool DeleteBackupData;
51+
52+
public override void ExecuteCmdlet()
53+
{
54+
ConfirmAction(
55+
Force.IsPresent,
56+
string.Format(Resources.DisableProtectionWarning, Item.Name),
57+
Resources.DisableProtectionMessage,
58+
Item.Name, () =>
59+
{
60+
ExecutionBlock(() =>
61+
{
62+
base.ExecuteCmdlet();
63+
64+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
65+
{
66+
67+
{ItemParams.Item, Item},
68+
{ItemParams.DeleteBackupData, this.DeleteBackupData},
69+
}, HydraAdapter);
70+
71+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.WorkloadType, Item.BackupManagementType);
72+
73+
var jobResponse = psBackupProvider.DisableProtection();
74+
75+
// Track Response and display job details
76+
77+
var response = OperationStatusHelper.TrackOperationStatus(jobResponse, HydraAdapter);
78+
79+
if (response.OperationStatus.Status == HydraModel.OperationStatusValues.Succeeded)
80+
{
81+
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
82+
string jobId = jobStatusResponse.JobId;
83+
var job = HydraAdapter.GetJob(jobId);
84+
WriteObject(JobConversions.GetPSJob(job));
85+
}
86+
else if(response.OperationStatus.Status == HydraModel.OperationStatusValues.Failed)
87+
{
88+
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
89+
if(jobStatusResponse != null || !string.IsNullOrEmpty(jobStatusResponse.JobId))
90+
{
91+
string jobId = jobStatusResponse.JobId;
92+
var job = HydraAdapter.GetJob(jobId);
93+
WriteObject(JobConversions.GetPSJob(job));
94+
}
95+
96+
var errorMessage = string.Format(Resources.DisableProtectionOperationFailed,
97+
response.OperationStatus.OperationStatusError.Code,
98+
response.OperationStatus.OperationStatusError.Message);
99+
100+
throw new Exception(errorMessage);
101+
}
102+
});
103+
});
104+
105+
}
106+
}
107+
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Item/EnableAzureRmRecoveryServicesProtection.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
using System.Management.Automation;
2121
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2222
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2324
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
25+
using HydraModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
26+
2427

2528
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2629
{
@@ -30,8 +33,8 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3033
[Cmdlet(VerbsLifecycle.Enable, "AzureRmRecoveryServicesProtection", DefaultParameterSetName = ModifyProtectionParameterSet), OutputType(typeof(AzureRmRecoveryServicesJobBase))]
3134
public class EnableAzureRmRecoveryServicesProtection : RecoveryServicesBackupCmdletBase
3235
{
33-
internal const string AzureVMClassicComputeParameterSet = "AzureVMClassicCompute";
34-
internal const string AzureVMComputeParameterSet = "AzureVMCompute";
36+
internal const string AzureVMClassicComputeParameterSet = "AzureVMClassicComputeEnableProtection";
37+
internal const string AzureVMComputeParameterSet = "AzureVMComputeEnableProtection";
3538
internal const string ModifyProtectionParameterSet = "ModifyProtection";
3639

3740
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
@@ -44,15 +47,15 @@ public class EnableAzureRmRecoveryServicesProtection : RecoveryServicesBackupCmd
4447
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMResourceGroupName)]
4548
public string ResourceGroupName { get; set; }
4649

47-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
48-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
50+
[Parameter(Mandatory = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
51+
[Parameter(Mandatory = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
4952
public WorkloadType WorkLoadType { get; set; }
5053

5154
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Policy.ProtectionPolicy)]
5255
[ValidateNotNullOrEmpty]
5356
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
5457

55-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Item.ProtectedItem, ValueFromPipeline = true)]
58+
[Parameter(Mandatory = true, ParameterSetName = ModifyProtectionParameterSet, HelpMessage = ParamHelpMsg.Item.ProtectedItem, ValueFromPipeline = true)]
5659
[ValidateNotNullOrEmpty]
5760
public AzureRmRecoveryServicesItemBase Item { get; set; }
5861

@@ -81,19 +84,30 @@ public override void ExecuteCmdlet()
8184
// Track Response and display job details
8285
// -- TBD to move it to common helper and remove hard-coded vaules
8386

84-
var response = HydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
85-
while (response.OperationStatus.Status == "InProgress")
86-
{
87-
response = HydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
88-
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
89-
}
87+
var response = OperationStatusHelper.TrackOperationStatus(jobResponse, HydraAdapter);
9088

91-
if(response.OperationStatus.Status == "Completed")
89+
if (response.OperationStatus.Status == HydraModel.OperationStatusValues.Succeeded)
9290
{
93-
// TBD -- Hydra change to add jobId in OperationStatusExtendedInfo
94-
string jobId = ""; //response.OperationStatus.Properties.jobId;
91+
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
92+
string jobId = jobStatusResponse.JobId;
9593
var job = HydraAdapter.GetJob(jobId);
96-
//WriteObject(ConversionHelpers.GetJobModel(job));
94+
WriteObject(JobConversions.GetPSJob(job));
95+
}
96+
else if(response.OperationStatus.Status == HydraModel.OperationStatusValues.Failed)
97+
{
98+
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
99+
if(jobStatusResponse != null || !string.IsNullOrEmpty(jobStatusResponse.JobId))
100+
{
101+
string jobId = jobStatusResponse.JobId;
102+
var job = HydraAdapter.GetJob(jobId);
103+
WriteObject(JobConversions.GetPSJob(job));
104+
}
105+
106+
var errorMessage = string.Format(Resources.EnableProtectionOperationFailed,
107+
response.OperationStatus.OperationStatusError.Code,
108+
response.OperationStatus.OperationStatusError.Message);
109+
110+
throw new Exception(errorMessage);
97111
}
98112
});
99113
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/PolicyCmdletHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class PolicyCmdletHelpers
3333

3434
public static void ValidateProtectionPolicyName(string policyName)
3535
{
36+
if(string.IsNullOrEmpty(policyName))
37+
{
38+
throw new ArgumentException(Resources.PolicyNameIsEmptyOrNull);
39+
}
40+
3641
if (policyName.Length < PolicyConstants.MinPolicyNameLength ||
3742
policyName.Length > PolicyConstants.MaxPolicyNameLength)
3843
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
24+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
25+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
26+
27+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
28+
{
29+
/// <summary>
30+
/// Update existing protection policy
31+
/// </summary>
32+
[Cmdlet(VerbsCommon.Remove, "AzureRmRecoveryServicesProtectionPolicy")]
33+
public class RemoveAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackupCmdletBase
34+
{
35+
[Parameter(Position = 1, Mandatory = true, HelpMessage = ParamHelpMsg.Policy.ProtectionPolicy, ValueFromPipeline = true)]
36+
[ValidateNotNullOrEmpty]
37+
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
38+
39+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Common.ConfirmationMessage)]
40+
public SwitchParameter Force { get; set; }
41+
42+
public override void ExecuteCmdlet()
43+
{
44+
ConfirmAction(
45+
Force.IsPresent,
46+
string.Format(Resources.RemoveProtectionPolicyWarning, Policy.Name),
47+
Resources.RemoveProtectionPolicyMessage,
48+
Policy.Name, () =>
49+
{
50+
ExecutionBlock(() =>
51+
{
52+
base.ExecuteCmdlet();
53+
54+
WriteDebug(Resources.MakingClientCall);
55+
56+
HydraAdapter.RemoveProtectionPolicy(Policy.Name);
57+
WriteDebug(Resources.ProtectionPolicyDeleted);
58+
});
59+
60+
});
61+
}
62+
}
63+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<Compile Include="Cmdlets\Container\GetAzureRmRecoveryServicesContainer.cs" />
8383
<Compile Include="Cmdlets\Container\UnregisterAzureRmBackupManagementServer.cs" />
8484
<Compile Include="Cmdlets\Container\UnregisterAzureRmRecoveryServicesBackupContainer.cs" />
85+
<Compile Include="Cmdlets\Item\DisableAzureRmRecoveryServicesProtection.cs" />
8586
<Compile Include="Cmdlets\Item\BackupAzureRmRecoveryServicesItem.cs" />
8687
<Compile Include="Cmdlets\Item\EnableAzureRmRecoveryServicesProtection.cs" />
8788
<Compile Include="Cmdlets\Item\GetAzureRmRecoveryServicesItem.cs" />
@@ -93,6 +94,7 @@
9394
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesPolicy.cs" />
9495
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesSchedulePolicyObject.cs" />
9596
<Compile Include="Cmdlets\ProtectionPolicy\PolicyCmdletHelpers.cs" />
97+
<Compile Include="Cmdlets\ProtectionPolicy\RemoveAzureRmRecoveryServicesPolicy.cs" />
9698
<Compile Include="Cmdlets\ProtectionPolicy\SetAzureRmRecoveryServicesPolicy.cs" />
9799
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureRmRecoveryServicesPolicy.cs" />
98100
<Compile Include="Constants.cs" />

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Commands.RecoveryServices.Backup.Helpers.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<ItemGroup>
5252
<Compile Include="Conversions\JobConversions.cs" />
5353
<Compile Include="Conversions\RecoveryPointConversions.cs" />
54+
<Compile Include="OperationStatusHelper.cs" />
5455
<Compile Include="Utils.cs" />
5556
<Compile Include="Validations\PolicyValidations.cs" />
5657
<Compile Include="Conversions\SchedulePolicyConversions.cs" />
@@ -64,6 +65,10 @@
6465
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
6566
<Name>Commands.Common</Name>
6667
</ProjectReference>
68+
<ProjectReference Include="..\Commands.RecoveryServices.Backup.HydraAdapter\Commands.RecoveryServices.Backup.HydraAdapter.csproj">
69+
<Project>{b758fec1-35c1-4f93-a954-66dd33f6e0ec}</Project>
70+
<Name>Commands.RecoveryServices.Backup.HydraAdapter</Name>
71+
</ProjectReference>
6772
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Logger\Commands.RecoveryServices.Backup.Logger.csproj">
6873
<Project>{5e675749-6139-464a-904c-59c0ffdfec82}</Project>
6974
<Name>Commands.RecoveryServices.Backup.Logger</Name>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
111111
}
112112

113113
policyModel.Name = hydraResponse.Name;
114+
policyModel.Id = hydraResponse.Id;
114115

115116
return policyModel;
116117
}
@@ -154,7 +155,7 @@ public static AzureRmRecoveryServicesItemBase GetItemModel(ProtectedItemResource
154155
{
155156
if (protectedItem.Properties.GetType().IsSubclassOf(typeof(AzureIaaSVMProtectedItem)))
156157
{
157-
itemModel = new AzureRmRecoveryServicesIaasVmItem((AzureIaaSVMProtectedItem)protectedItem.Properties, container);
158+
itemModel = new AzureRmRecoveryServicesIaasVmItem(protectedItem, container);
158159
}
159160
}
160161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Specialized;
17+
using System.Web;
18+
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
19+
using HydraModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
20+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
24+
{
25+
public class OperationStatusHelper
26+
{
27+
public const double defaultOperationStatusRetryTimeInSec = 5.0;
28+
29+
public static BackUpOperationStatusResponse TrackOperationStatus(BaseRecoveryServicesJobResponse jobResponse, HydraAdapter hydraAdapter)
30+
{
31+
var response = hydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
32+
while (response.OperationStatus.Status == HydraModel.OperationStatusValues.InProgress)
33+
{
34+
response = hydraAdapter.GetProtectedItemOperationStatusByURL(jobResponse.AzureAsyncOperation);
35+
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(defaultOperationStatusRetryTimeInSec));
36+
}
37+
38+
return response;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)