Skip to content

Commit 530d150

Browse files
committed
Merge pull request #204 from MabOneSdk/dev1-sudreddy
Added logger wrapper and minor fixes in policy
2 parents 80ce066 + 1101b8e commit 530d150

File tree

16 files changed

+222
-30
lines changed

16 files changed

+222
-30
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public class GetAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackup
3737
protected const string NoParamSet = "NoParamSet";
3838
protected const string WorkloadBackupMangementTypeParamSet = "WorkloadBackupManagementTypeParamSet";
3939

40-
[Parameter(ParameterSetName = PolicyNameParamSet, Mandatory = true, HelpMessage = ParamHelpMsg.Policy.Name)]
40+
[Parameter(ParameterSetName = PolicyNameParamSet, Position = 1, Mandatory = true, HelpMessage = ParamHelpMsg.Policy.Name)]
4141
[ValidateNotNullOrEmpty]
4242
public string Name { get; set; }
4343

44-
[Parameter(ParameterSetName = WorkloadParamSet, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
45-
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
44+
[Parameter(ParameterSetName = WorkloadParamSet, Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
45+
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
4646
[ValidateNotNullOrEmpty]
4747
public WorkloadType WorkloadType { get; set; }
4848

49-
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Mandatory = false, HelpMessage = ParamHelpMsg.Common.BackupManagementType)]
49+
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Position = 3, Mandatory = true, HelpMessage = ParamHelpMsg.Common.BackupManagementType)]
5050
[ValidateNotNullOrEmpty]
5151
public BackupManagementType BackupManagementType { get; set; }
5252

@@ -75,8 +75,7 @@ public override void ExecuteCmdlet()
7575
}
7676
else
7777
{
78-
string hydraProviderType = null;
79-
string hydraDataSourceType = null;
78+
string hydraProviderType = null;
8079

8180
switch (this.ParameterSetName)
8281
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3232
[Cmdlet(VerbsCommon.New, "AzureRmRecoveryServicesProtectionPolicy"), OutputType(typeof(AzureRmRecoveryServicesPolicyBase))]
3333
public class NewAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackupCmdletBase
3434
{
35-
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Policy.Name)]
35+
[Parameter(Position = 1, Mandatory = true, HelpMessage = ParamHelpMsg.Policy.Name)]
3636
[ValidateNotNullOrEmpty]
3737
public string Name { get; set; }
3838

39-
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType, ValueFromPipelineByPropertyName = true)]
39+
[Parameter(Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType, ValueFromPipelineByPropertyName = true)]
4040
[ValidateNotNullOrEmpty]
4141
public WorkloadType WorkloadType { get; set; }
4242

43-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Common.BackupManagementType, ValueFromPipelineByPropertyName = true)]
43+
[Parameter(Position = 3, Mandatory = false, HelpMessage = ParamHelpMsg.Common.BackupManagementType, ValueFromPipelineByPropertyName = true)]
4444
[ValidateNotNullOrEmpty]
4545
public BackupManagementType BackupManagementType { get; set; }
4646

47-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Policy.RetentionPolicy, ValueFromPipelineByPropertyName = true)]
47+
[Parameter(Position = 4, Mandatory = false, HelpMessage = ParamHelpMsg.Policy.RetentionPolicy, ValueFromPipelineByPropertyName = true)]
4848
[ValidateNotNullOrEmpty]
4949
public AzureRmRecoveryServicesRetentionPolicyBase RetentionPolicy { get; set; }
5050

51-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Policy.SchedulePolicy, ValueFromPipelineByPropertyName = true)]
51+
[Parameter(Position = 5, Mandatory = false, HelpMessage = ParamHelpMsg.Policy.SchedulePolicy, ValueFromPipelineByPropertyName = true)]
5252
[ValidateNotNullOrEmpty]
5353
public AzureRmRecoveryServicesSchedulePolicyBase SchedulePolicy { get; set; }
5454

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
3232
[Cmdlet(VerbsCommon.Set, "AzureRmRecoveryServicesProtectionPolicy"), OutputType(typeof(List<AzureRmRecoveryServicesJobBase>))]
3333
public class SetAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackupCmdletBase
3434
{
35-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Policy.RetentionPolicy)]
35+
[Parameter(Position = 1, Mandatory = true, HelpMessage = ParamHelpMsg.Policy.ProtectionPolicy, ValueFromPipeline = true)]
3636
[ValidateNotNullOrEmpty]
37-
public AzureRmRecoveryServicesRetentionPolicyBase RetentionPolicy { get; set; }
37+
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
3838

39-
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Policy.SchedulePolicy)]
39+
[Parameter(Position = 2, Mandatory = false, HelpMessage = ParamHelpMsg.Policy.RetentionPolicy)]
4040
[ValidateNotNullOrEmpty]
41-
public AzureRmRecoveryServicesSchedulePolicyBase SchedulePolicy { get; set; }
41+
public AzureRmRecoveryServicesRetentionPolicyBase RetentionPolicy { get; set; }
4242

43-
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Policy.ProtectionPolicy, ValueFromPipeline=true)]
43+
[Parameter(Position = 3, Mandatory = false, HelpMessage = ParamHelpMsg.Policy.SchedulePolicy)]
4444
[ValidateNotNullOrEmpty]
45-
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
46-
45+
public AzureRmRecoveryServicesSchedulePolicyBase SchedulePolicy { get; set; }
46+
4747
public override void ExecuteCmdlet()
4848
{
4949
ExecutionBlock(() =>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
<Project>{b758fec1-35c1-4f93-a954-66dd33f6e0ec}</Project>
112112
<Name>Commands.RecoveryServices.Backup.HydraAdapter</Name>
113113
</ProjectReference>
114+
<ProjectReference Include="Commands.RecoveryServices.Backup.Logger\Commands.RecoveryServices.Backup.Logger.csproj">
115+
<Project>{5e675749-6139-464a-904c-59c0ffdfec82}</Project>
116+
<Name>Commands.RecoveryServices.Backup.Logger</Name>
117+
</ProjectReference>
114118
<ProjectReference Include="Commands.RecoveryServices.Backup.Models\Commands.RecoveryServices.Backup.Models.csproj">
115119
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
116120
<Name>Commands.RecoveryServices.Backup.Models</Name>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ProjectGuid>{0E1D3F36-E6C8-4764-8C7D-6F9EE537490C}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>Helpers</RootNamespace>
11-
<AssemblyName>Helpers</AssemblyName>
10+
<RootNamespace>Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers</RootNamespace>
11+
<AssemblyName>Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
</PropertyGroup>
@@ -60,6 +60,10 @@
6060
<Compile Include="Properties\AssemblyInfo.cs" />
6161
</ItemGroup>
6262
<ItemGroup>
63+
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Logger\Commands.RecoveryServices.Backup.Logger.csproj">
64+
<Project>{5e675749-6139-464a-904c-59c0ffdfec82}</Project>
65+
<Name>Commands.RecoveryServices.Backup.Logger</Name>
66+
</ProjectReference>
6367
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Models\Commands.RecoveryServices.Backup.Models.csproj">
6468
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
6569
<Name>Commands.RecoveryServices.Backup.Models</Name>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
7171
if(((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).RetentionPolicy.GetType() !=
7272
typeof(LongTermRetentionPolicy))
7373
{
74-
// unsupported by old powershell - trace warning and return null
74+
Logger.Instance.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
75+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
7576
return null;
7677
}
7778

7879
if (((AzureIaaSVMProtectionPolicy)hydraResponse.Properties).SchedulePolicy.GetType() !=
7980
typeof(SimpleSchedulePolicy))
8081
{
81-
// unsupported by old powershell - trace warning and return null
82+
Logger.Instance.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
83+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
8284
return null;
8385
}
8486

@@ -93,9 +95,11 @@ public static AzureRmRecoveryServicesPolicyBase GetPolicyModel(ProtectionPolicyR
9395
}
9496
else
9597
{
96-
// TBD - trace warning message, ignore and return
98+
// trace warning message, ignore and return
9799
// we will enter this case when service supports new workload and customer
98-
// still using old version of powershell
100+
// still using old version of azure powershell
101+
Logger.Instance.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
102+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
99103
return null;
100104
}
101105

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ProjectGuid>{B758FEC1-35C1-4F93-A954-66DD33F6E0EC}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>Adapter</RootNamespace>
11-
<AssemblyName>Adapter</AssemblyName>
10+
<RootNamespace>Microsoft.Azure.Commands.RecoveryServices.Backup.HydraAdapter</RootNamespace>
11+
<AssemblyName>Microsoft.Azure.Commands.RecoveryServices.Backup.HydraAdapter</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{5E675749-6139-464A-904C-59C0FFDFEC82}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Microsoft.Azure.Commands.RecoveryServices.Backup</RootNamespace>
11+
<AssemblyName>Microsoft.Azure.Commands.RecoveryServices.Backup.Logger</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Xml" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="Logger.cs" />
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
46+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
47+
Other similar extension points exist, see Microsoft.Common.targets.
48+
<Target Name="BeforeBuild">
49+
</Target>
50+
<Target Name="AfterBuild">
51+
</Target>
52+
-->
53+
</Project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup
22+
{
23+
public class Logger
24+
{
25+
private Action<string> writeWarningAction;
26+
27+
private Action<string> writeDebugAction;
28+
29+
private Action<string> writeVerboseAction;
30+
31+
public static Logger Instance { get; set; }
32+
33+
public Logger(Action<string> writeWarning,
34+
Action<string> writeDebug,
35+
Action<string> writeVerbose)
36+
{
37+
writeWarningAction = writeWarning;
38+
writeDebugAction = writeDebug;
39+
writeVerboseAction = writeVerbose;
40+
}
41+
42+
public void WriteVerbose(string text)
43+
{
44+
writeVerboseAction(text);
45+
}
46+
47+
public void WriteDebug(string text)
48+
{
49+
writeDebugAction(text);
50+
}
51+
52+
public void WriteWarning(string text)
53+
{
54+
writeWarningAction(text);
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.Reflection;
16+
using System.Runtime.CompilerServices;
17+
using System.Runtime.InteropServices;
18+
19+
// General Information about an assembly is controlled through the following
20+
// set of attributes. Change these attribute values to modify the information
21+
// associated with an assembly.
22+
[assembly: AssemblyTitle("Commands.RecoveryServices.Backup.Logger")]
23+
[assembly: AssemblyDescription("")]
24+
[assembly: AssemblyConfiguration("")]
25+
[assembly: AssemblyCompany("")]
26+
[assembly: AssemblyProduct("Commands.RecoveryServices.Backup.Logger")]
27+
[assembly: AssemblyCopyright("Copyright © 2016")]
28+
[assembly: AssemblyTrademark("")]
29+
[assembly: AssemblyCulture("")]
30+
31+
// Setting ComVisible to false makes the types in this assembly not visible
32+
// to COM components. If you need to access a type in this assembly from
33+
// COM, set the ComVisible attribute to true on that type.
34+
[assembly: ComVisible(false)]
35+
36+
// The following GUID is for the ID of the typelib if this project is exposed to COM
37+
[assembly: Guid("cac38a0e-a5a2-4473-b2a9-e6f6f49ca63d")]
38+
39+
// Version information for an assembly consists of the following four values:
40+
//
41+
// Major Version
42+
// Minor Version
43+
// Build Number
44+
// Revision
45+
//
46+
// You can specify all the values or you can default the Build and Revision Numbers
47+
// by using the '*' as shown below:
48+
// [assembly: AssemblyVersion("1.0.*")]
49+
[assembly: AssemblyVersion("1.0.0.0")]
50+
[assembly: AssemblyFileVersion("1.0.0.0")]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Microsoft.Azure.Commands.RecoveryServices.Backup</RootNamespace>
11-
<AssemblyName>Models</AssemblyName>
11+
<AssemblyName>Microsoft.Azure.Commands.RecoveryServices.Backup.Models</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
</PropertyGroup>

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

Lines changed: 9 additions & 0 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,7 @@
261261
<data name="MonthlyYearlyRetentionWeeklySchedulePolicyNULLException" xml:space="preserve">
262262
<value>In Monthly/Yearly retention schedule, if RetentionScheduleFormatType=Weekly then RetentionScheduleWeekly should NOT be null</value>
263263
</data>
264+
<data name="UpdateToNewAzurePowershellWarning" xml:space="preserve">
265+
<value>Data truncated. Please upgrade to latest version of Azure Powershell</value>
266+
</data>
264267
</root>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ProjectGuid>{02234E90-BCDE-4B20-B1F5-01B1005821DB}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>ProviderModel</RootNamespace>
11-
<AssemblyName>ProviderModel</AssemblyName>
10+
<RootNamespace>Microsoft.Azure.Commands.RecoveryServices.Backup.Providers</RootNamespace>
11+
<AssemblyName>Microsoft.Azure.Commands.RecoveryServices.Backup.Providers</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
</PropertyGroup>

0 commit comments

Comments
 (0)