Skip to content

Commit af92e26

Browse files
committed
added logger wrapper and minor fixes in policy
1 parent 80ce066 commit af92e26

File tree

13 files changed

+185
-23
lines changed

13 files changed

+185
-23
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.Logger.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
75+
Logger.Logger.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.Logger.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
83+
Logger.Logger.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.Logger.WriteDebug(Resources.UpdateToNewAzurePowershellWarning);
102+
Logger.Logger.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
99103
return null;
100104
}
101105

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.Logger</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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using System.Collections.Generic;
6+
7+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Logger
8+
{
9+
public class Logger
10+
{
11+
private static Action<string> WriteWarningAction { get; set; }
12+
13+
private static Action<string> WriteDebugAction { get; set; }
14+
15+
private static Action<string> WriteVerboseAction { get; set; }
16+
17+
public Logger(Action<string> writeWarning,
18+
Action<string> writeDebug,
19+
Action<string> writeVerbose)
20+
{
21+
WriteWarningAction = writeWarning;
22+
WriteDebugAction = writeDebug;
23+
WriteVerboseAction = writeVerbose;
24+
}
25+
26+
public static void WriteVerbose(string text)
27+
{
28+
WriteVerboseAction(text);
29+
}
30+
31+
public static void WriteDebug(string text)
32+
{
33+
WriteDebugAction(text);
34+
}
35+
36+
public static void WriteWarning(string text)
37+
{
38+
WriteWarningAction(text);
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Commands.RecoveryServices.Backup.Logger")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Commands.RecoveryServices.Backup.Logger")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("cac38a0e-a5a2-4473-b2a9-e6f6f49ca63d")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

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/RecoveryServices.Backup.sln

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.ResourceManager.Common", "..\Common\Commands.ResourceManager.Common\Commands.ResourceManager.Common.csproj", "{3819D8A7-C62C-4C47-8DDD-0332D9CE1252}"
57
EndProject
68
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Common", "..\..\Common\Commands.Common\Commands.Common.csproj", "{5EE72C53-1720-4309-B54B-5FB79703195F}"
@@ -23,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.RecoveryServices.B
2325
EndProject
2426
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.ScenarioTests.ResourceManager.Common", "..\Common\Commands.ScenarioTests.ResourceManager.Common\Commands.ScenarioTests.ResourceManager.Common.csproj", "{3436A126-EDC9-4060-8952-9A1BE34CDD95}"
2527
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.RecoveryServices.Backup.Logger", "Commands.RecoveryServices.Backup.Logger\Commands.RecoveryServices.Backup.Logger.csproj", "{5E675749-6139-464A-904C-59C0FFDFEC82}"
29+
EndProject
2630
Global
2731
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2832
Debug|Any CPU = Debug|Any CPU
@@ -69,6 +73,10 @@ Global
6973
{3436A126-EDC9-4060-8952-9A1BE34CDD95}.Debug|Any CPU.Build.0 = Debug|Any CPU
7074
{3436A126-EDC9-4060-8952-9A1BE34CDD95}.Release|Any CPU.ActiveCfg = Release|Any CPU
7175
{3436A126-EDC9-4060-8952-9A1BE34CDD95}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{5E675749-6139-464A-904C-59C0FFDFEC82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{5E675749-6139-464A-904C-59C0FFDFEC82}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{5E675749-6139-464A-904C-59C0FFDFEC82}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{5E675749-6139-464A-904C-59C0FFDFEC82}.Release|Any CPU.Build.0 = Release|Any CPU
7280
EndGlobalSection
7381
GlobalSection(SolutionProperties) = preSolution
7482
HideSolutionNode = FALSE

src/ResourceManager/RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected void InitializeAzureBackupCmdlet()
4040
{
4141
var cloudServicesClient = AzureSession.ClientFactory.CreateClient<CloudServiceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager);
4242
HydraAdapter = new HydraAdapterNS.HydraAdapter(cloudServicesClient.Credentials, cloudServicesClient.BaseUri);
43+
new Logger.Logger(WriteWarning, WriteDebug, WriteVerbose);
4344
}
4445

4546
protected void ExecutionBlock(Action action)

0 commit comments

Comments
 (0)