Skip to content

Commit 4ca08b4

Browse files
author
dragonfly91
committed
Merge branch 'dev1' into anudeeb-dev1
2 parents c349d27 + 0d90486 commit 4ca08b4

File tree

16 files changed

+241
-74
lines changed

16 files changed

+241
-74
lines changed

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,7 @@ public override void ExecuteCmdlet()
7272

7373
// Track Response and display job details
7474

75-
WriteDebug(Resources.TrackingOperationStatusURLForCompletion +
76-
itemResponse.AzureAsyncOperation);
77-
78-
var response = WaitForOperationCompletionUsingStatusLink(
79-
itemResponse.AzureAsyncOperation,
80-
HydraAdapter.GetProtectedItemOperationStatusByURL);
81-
82-
WriteDebug(Resources.FinalOperationStatus + response.OperationStatus.Status);
83-
84-
if (response.OperationStatus.Properties != null &&
85-
((HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties).JobId != null)
86-
{
87-
var jobStatusResponse = (HydraModel.OperationStatusJobExtendedInfo)response.OperationStatus.Properties;
88-
WriteObject(GetJobObject(jobStatusResponse.JobId));
89-
}
90-
91-
if (response.OperationStatus.Status == HydraModel.OperationStatusValues.Failed)
92-
{
93-
var errorMessage = string.Format(Resources.DisableProtectionOperationFailed,
94-
response.OperationStatus.OperationStatusError.Code,
95-
response.OperationStatus.OperationStatusError.Message);
96-
throw new Exception(errorMessage);
97-
}
75+
HandleCreatedJob(itemResponse, Resources.DisableProtectionOperation);
9876
});
9977
});
10078

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public class EnableAzureRmRecoveryServicesProtection : RecoveryServicesBackupCmd
4141
[ValidateNotNullOrEmpty]
4242
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
4343

44-
[Parameter(Position = 2, Mandatory = true, ParameterSetName = ModifyProtectionParameterSet, HelpMessage = ParamHelpMsg.Item.ProtectedItem, ValueFromPipeline = true)]
45-
[ValidateNotNullOrEmpty]
46-
public AzureRmRecoveryServicesItemBase Item { get; set; }
47-
4844
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMClassicComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
4945
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Item.AzureVMName)]
5046
public string Name { get; set; }
@@ -59,6 +55,10 @@ public class EnableAzureRmRecoveryServicesProtection : RecoveryServicesBackupCmd
5955
[Parameter(Position = 4, Mandatory = true, ParameterSetName = AzureVMComputeParameterSet, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
6056
public WorkloadType WorkLoadType { get; set; }
6157

58+
[Parameter(Position = 5, Mandatory = true, ParameterSetName = ModifyProtectionParameterSet, HelpMessage = ParamHelpMsg.Item.ProtectedItem, ValueFromPipeline = true)]
59+
[ValidateNotNullOrEmpty]
60+
public AzureRmRecoveryServicesItemBase Item { get; set; }
61+
6262
public override void ExecuteCmdlet()
6363
{
6464
ExecutionBlock(() =>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
<Compile Include="Cmdlets\Container\UnregisterAzureRmBackupManagementServer.cs" />
8484
<Compile Include="Cmdlets\Container\UnregisterAzureRmRecoveryServicesBackupContainer.cs" />
8585
<Compile Include="Cmdlets\Item\DisableAzureRmRecoveryServicesProtection.cs" />
86-
<Compile Include="Cmdlets\Backup\BackupAzureRmRecoveryServicesItem.cs" />
8786
<Compile Include="Cmdlets\Item\EnableAzureRmRecoveryServicesProtection.cs" />
8887
<Compile Include="Cmdlets\Item\GetAzureRmRecoveryServicesItem.cs" />
8988
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJob.cs" />
@@ -104,7 +103,9 @@
104103
<Compile Include="RecoveryServicesBackupCmdletBase.cs" />
105104
<Compile Include="CmdletParameterHelpMessages.cs" />
106105
</ItemGroup>
107-
<ItemGroup />
106+
<ItemGroup>
107+
<Folder Include="Cmdlets\Backup\" />
108+
</ItemGroup>
108109
<ItemGroup>
109110
<ProjectReference Include="..\..\Common\Commands.Common.Authentication\Commands.Common.Authentication.csproj">
110111
<Project>{d3804b64-c0d3-48f8-82ec-1f632f833c9e}</Project>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Utils.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Text.RegularExpressions;
56
using System.Threading.Tasks;
7+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
8+
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
69

710
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
811
{
@@ -39,5 +42,90 @@ public static List<string> GetStringListFromEnumList<T>(IList<T> enumList)
3942

4043
return ret;
4144
}
45+
46+
/// <summary>
47+
/// Helper function to parse resource id which in format of "[\{Key}\{value}]*"
48+
/// </summary>
49+
/// <param name="id">Id of the resource</param>
50+
/// <returns>dictionary of UriEnum as key and value as value of corresponding URI enum</returns>
51+
public static Dictionary<CmdletModel.UriEnums, string> ParseUri(string id)
52+
{
53+
Dictionary<CmdletModel.UriEnums, string> keyValuePairDict = new Dictionary<CmdletModel.UriEnums, string>();
54+
if (!string.IsNullOrEmpty(id))
55+
{
56+
string idPattern = @"/[a-zA-Z]*/[a-zA-Z0-9-;.]*";
57+
string uriPattern = @"/";
58+
Regex reg = new Regex(idPattern, RegexOptions.IgnoreCase);
59+
60+
// Match the regular expression pattern against a uri string.
61+
Match match = reg.Match(id);
62+
63+
while (match.Success)
64+
{
65+
string[] keyValuePair = match.Value.Split(new string[] { uriPattern }, StringSplitOptions.RemoveEmptyEntries);
66+
CmdletModel.UriEnums key;
67+
CmdletModel.UriEnums value;
68+
if (keyValuePair.Length == 2)
69+
{
70+
if (Enum.TryParse<CmdletModel.UriEnums>(keyValuePair[0], true, out key) &&
71+
!Enum.TryParse<CmdletModel.UriEnums>(keyValuePair[1], true, out value))
72+
{
73+
keyValuePairDict.Add(key, keyValuePair[1]);
74+
}
75+
}
76+
match = match.NextMatch();
77+
}
78+
}
79+
return keyValuePairDict;
80+
}
81+
82+
public static string GetContainerUri(Dictionary<CmdletModel.UriEnums, string> keyValuePairDict, string id)
83+
{
84+
string containerUri = string.Empty;
85+
86+
if (keyValuePairDict.ContainsKey(CmdletModel.UriEnums.ProtectionContainers))
87+
{
88+
containerUri = keyValuePairDict[CmdletModel.UriEnums.ProtectionContainers];
89+
}
90+
else
91+
{
92+
throw new ArgumentException(string.Format(Resources.URIValueNotFound,
93+
CmdletModel.UriEnums.ProtectionContainers.ToString(), id));
94+
}
95+
return containerUri;
96+
}
97+
98+
public static string GetProtectedItemUri(Dictionary<CmdletModel.UriEnums, string> keyValuePairDict, string id)
99+
{
100+
string itemUri = string.Empty;
101+
102+
if (keyValuePairDict.ContainsKey(CmdletModel.UriEnums.ProtectedItems))
103+
{
104+
itemUri = keyValuePairDict[CmdletModel.UriEnums.ProtectedItems];
105+
}
106+
else
107+
{
108+
throw new ArgumentException(string.Format(Resources.URIValueNotFound,
109+
CmdletModel.UriEnums.ProtectedItems.ToString(), id));
110+
}
111+
return itemUri;
112+
}
113+
114+
public static string GetProtectableItemUri(Dictionary<CmdletModel.UriEnums, string> keyValuePairDict, string id)
115+
{
116+
string protectableItemUri = string.Empty;
117+
118+
if (keyValuePairDict.ContainsKey(CmdletModel.UriEnums.ProtectableItems))
119+
{
120+
protectableItemUri = keyValuePairDict[CmdletModel.UriEnums.ProtectableItems];
121+
}
122+
else
123+
{
124+
throw new ArgumentException(string.Format(Resources.URIValueNotFound,
125+
CmdletModel.UriEnums.ProtectableItems.ToString(), id));
126+
}
127+
return protectableItemUri;
128+
}
129+
42130
}
43131
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/ClientProxyBase.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Threading;
2121
using System.Threading.Tasks;
2222
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2324

2425
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
2526
{
@@ -60,16 +61,28 @@ public string GetClientRequestId()
6061

6162
public string GetResourceName()
6263
{
64+
if (string.IsNullOrEmpty(PSRecoveryServicesClient.arsVault.Name))
65+
{
66+
throw new ArgumentException(Resources.SetVaultContextFirst);
67+
}
6368
return PSRecoveryServicesClient.arsVault.Name;
6469
}
6570

6671
public string GetResourceGroupName()
6772
{
73+
if (string.IsNullOrEmpty(PSRecoveryServicesClient.arsVault.ResouceGroupName))
74+
{
75+
throw new ArgumentException(Resources.SetVaultContextFirst);
76+
}
6877
return PSRecoveryServicesClient.arsVault.ResouceGroupName;
6978
}
7079

7180
public string GetResourceLocation()
7281
{
82+
if (string.IsNullOrEmpty(PSRecoveryServicesClient.arsVault.Location))
83+
{
84+
throw new ArgumentException(Resources.SetVaultContextFirst);
85+
}
7386
return PSRecoveryServicesClient.arsVault.Location;
7487
}
7588
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/AzureVmModels/AzureRmRecoveryServicesAzureVmPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AzureRmRecoveryServicesIaasVmPolicy : AzureRmRecoveryServicesPolicy
2626

2727
public AzureRmRecoveryServicesRetentionPolicyBase RetentionPolicy { get; set; }
2828

29-
public virtual void Validate()
29+
public override void Validate()
3030
{
3131
base.Validate();
3232

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<AutoGen>True</AutoGen>
6262
<DesignTime>True</DesignTime>
6363
</Compile>
64+
<Compile Include="UriEnums.cs" />
6465
</ItemGroup>
6566
<ItemGroup>
6667
<EmbeddedResource Include="Properties\Resources.resx">

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public override string ToString()
295295
base.ToString(),
296296
RetentionScheduleDaily == null ? "NULL" : RetentionScheduleDaily.ToString(),
297297
RetentionScheduleWeekly == null ? "NULL" : RetentionScheduleWeekly.ToString(),
298-
MonthsOfYear.ToString(), base.ToString());
298+
TraceUtils.GetEnumsString<Month>(MonthsOfYear), base.ToString());
299299
}
300300
}
301301

@@ -365,7 +365,7 @@ public override string ToString()
365365
{
366366
return string.Format("DaysOfTheWeek:{0}, WeeksOfTheMonth:{1}",
367367
TraceUtils.GetString(DaysOfTheWeek),
368-
WeeksOfTheMonth.ToString());
368+
TraceUtils.GetEnumsString<WeekOfMonth>(WeeksOfTheMonth));
369369
}
370370
}
371371

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public static string GetString(IEnumerable<Object> objList)
4747
return (objList == null) ? "null" : "{" + string.Join("}, {", objList) + "}";
4848
}
4949

50+
public static string GetEnumsString<T>(List<T> objList)
51+
{
52+
return (objList == null) ? "null" : "{" + string.Join(",", Enum.GetNames(typeof(T))) +"}";
53+
}
54+
5055
public static string GetString(IEnumerable<DateTime> objList)
5156
{
5257
return (objList == null) ? "null" : "{" + string.Join("}, {", objList) + "}";

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 31 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ Please contact Microsoft for further assistant.</value>
347347
<data name="DisableProtectionWarning" xml:space="preserve">
348348
<value>Are you sure you want to disable protection for the item '{0}'</value>
349349
</data>
350-
<data name="DisableProtectionOperationFailed" xml:space="preserve">
351-
<value>Disable Protection OperationFailed with error code: {0} , and error Message: {1}</value>
350+
<data name="DisableProtectionOperation" xml:space="preserve">
351+
<value>Disable Protection Operation</value>
352352
</data>
353353
<data name="FinalOperationStatus" xml:space="preserve">
354354
<value>Final operation status:</value>
@@ -368,4 +368,13 @@ Please contact Microsoft for further assistant.</value>
368368
<data name="TriggerBackupOperation" xml:space="preserve">
369369
<value>Trigger Backup Operation</value>
370370
</data>
371+
<data name="URIValueNotFound" xml:space="preserve">
372+
<value>{0} Uri value not found in Id {1}</value>
373+
</data>
374+
<data name="SetVaultContextFirst" xml:space="preserve">
375+
<value>Set vault context first using cmdlet Set-AzureRmRecoveryServicesVaultContext</value>
376+
</data>
377+
<data name="VirtualMachineIdIsEmptyOrNull" xml:space="preserve">
378+
<value>VirtualMachineId is NULL or Empty. Please enter valid VirtualMachineId</value>
379+
</data>
371380
</root>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
22+
{
23+
public enum UriEnums
24+
{
25+
Subscriptions,
26+
ResourceGroups,
27+
Providers,
28+
Vaults,
29+
BackupFabrics,
30+
ProtectionContainers,
31+
ProtectableItems,
32+
ProtectedItems,
33+
RecoveryPoints,
34+
BackupJobs,
35+
OperationResults,
36+
BackupPolicies,
37+
Operations,
38+
OperationsStatus
39+
}
40+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1615
using System;
1716
using System.Collections.Generic;
1817
using System.Linq;

0 commit comments

Comments
 (0)