Skip to content

Commit d0c1f97

Browse files
committed
Merge branch 'PolicyChangesMkherani' into dev1
2 parents cd4b52d + 40b8400 commit d0c1f97

File tree

6 files changed

+213
-1
lines changed

6 files changed

+213
-1
lines changed
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;
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+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesBackupRetentionPolicyObject"), OutputType(typeof(AzureRmRecoveryServicesRetentionPolicyBase))]
27+
class GetAzureRmRecoveryServicesBackupRetentionPolicyObject : RecoveryServicesBackupCmdletBase
28+
{
29+
[Parameter(Mandatory = true, HelpMessage = "Temp Help message. Need to update it")]
30+
[ValidateNotNullOrEmpty]
31+
public WorkloadType WorkloadType { get; set; }
32+
33+
[Parameter(Mandatory = false, HelpMessage = "Temp Help message. Need to update it")]
34+
[ValidateNotNullOrEmpty]
35+
public BackupManagementType BackupManagementType { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>(), HydraAdapter);
44+
45+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType, BackupManagementType);
46+
WriteObject(psBackupProvider.GetDefaultRetentionPolicyObject());
47+
});
48+
}
49+
}
50+
}
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;
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+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesSchedulePolicyObject"), OutputType(typeof(AzureRmRecoveryServicesSchedulePolicyBase))]
27+
class GetAzureRmRecoveryServicesSchedulePolicyObject : RecoveryServicesBackupCmdletBase
28+
{
29+
[Parameter(Mandatory = true, HelpMessage = "Temp Help message. Need to update it")]
30+
[ValidateNotNullOrEmpty]
31+
public WorkloadType WorkloadType { get; set; }
32+
33+
[Parameter(Mandatory = false, HelpMessage = "Temp Help message. Need to update it")]
34+
[ValidateNotNullOrEmpty]
35+
public BackupManagementType BackupManagementType { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>(), HydraAdapter);
44+
45+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType, BackupManagementType);
46+
WriteObject(psBackupProvider.GetDefaultSchedulePolicyObject());
47+
});
48+
}
49+
}
50+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJob.cs" />
7474
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJobDetails.cs" />
7575
<Compile Include="Cmdlets\Jobs\WaitAzureRmRecoveryServicesJob.cs" />
76+
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesBackupRetentionPolicyObject.cs" />
7677
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesPolicy.cs" />
78+
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesSchedulePolicyObject.cs" />
7779
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRMBackupSchedulePolicyObject.cs" />
7880
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRMBackupRetentionPolicyObject.cs" />
7981
<Compile Include="Cmdlets\ProtectionPolicy\PolicyCmdletHelpers.cs" />

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public interface IPsBackupProvider
4444

4545
ProtectionPolicyResponse GetPolicy();
4646

47+
AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject();
48+
49+
AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject();
4750
void DeletePolicy();
4851

4952
List<AzureRmRecoveryServicesContainerBase> ListProtectionContainers();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,15 @@ public void DeletePolicy()
8282
{
8383
throw new NotImplementedException();
8484
}
85+
86+
public AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject()
87+
{
88+
throw new NotImplementedException();
89+
}
90+
91+
public AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject()
92+
{
93+
throw new NotImplementedException();
94+
}
8595
}
8696
}

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

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public List<AzureRmRecoveryServicesJobBase> ModifyPolicy()
245245
{
246246
// poll for AsyncHeader and get the jobsList
247247
// TBD
248-
}
248+
}
249249
else
250250
{
251251
// no datasources attached to policy
@@ -297,6 +297,103 @@ public void DeletePolicy()
297297
throw new NotImplementedException();
298298
}
299299

300+
301+
public AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject()
302+
{
303+
AzureRmRecoveryServicesSimpleSchedulePolicy defaultSchedule = new AzureRmRecoveryServicesSimpleSchedulePolicy();
304+
//Default is daily scedule at 10:30 AM local time
305+
defaultSchedule.ScheduleRunFrequency = ScheduleRunType.Daily;
306+
307+
DateTime scheduleTime = GenerateRandomTime();
308+
defaultSchedule.ScheduleRunTimes = new List<DateTime>();
309+
defaultSchedule.ScheduleRunTimes.Add(scheduleTime);
310+
311+
defaultSchedule.ScheduleRunDays = new List<DayOfWeek>();
312+
defaultSchedule.ScheduleRunDays.Add(DayOfWeek.Sunday);
313+
314+
return defaultSchedule;
315+
}
316+
317+
public AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject()
318+
{
319+
AzureRmRecoveryServicesLongTermRetentionPolicy defaultRetention = new AzureRmRecoveryServicesLongTermRetentionPolicy();
320+
321+
//Default time is 10:30 local time
322+
DateTime retentionTime = GenerateRandomTime();
323+
324+
//Daily Retention policy
325+
defaultRetention.IsDailyScheduleEnabled = true;
326+
defaultRetention.DailySchedule = new Models.DailyRetentionSchedule();
327+
defaultRetention.DailySchedule.RetentionTimes = new List<DateTime>();
328+
defaultRetention.DailySchedule.RetentionTimes.Add(retentionTime);
329+
defaultRetention.DailySchedule.DurationCountInDays = 180; //TBD make it const
330+
331+
//Weekly Retention policy
332+
defaultRetention.IsWeeklyScheduleEnabled = true;
333+
defaultRetention.WeeklySchedule = new Models.WeeklyRetentionSchedule();
334+
defaultRetention.WeeklySchedule.DaysOfTheWeek = new List<DayOfWeek>();
335+
defaultRetention.WeeklySchedule.DaysOfTheWeek.Add(DayOfWeek.Sunday);
336+
defaultRetention.WeeklySchedule.DurationCountInWeeks = 104; //TBD make it const
337+
defaultRetention.WeeklySchedule.RetentionTimes = new List<DateTime>();
338+
defaultRetention.WeeklySchedule.RetentionTimes.Add(retentionTime);
339+
340+
//Monthly retention policy
341+
defaultRetention.IsMonthlyScheduleEnabled = true;
342+
defaultRetention.MonthlySchedule = new Models.MonthlyRetentionSchedule();
343+
defaultRetention.MonthlySchedule.DurationCountInMonths = 60; //tbd: make it const
344+
defaultRetention.MonthlySchedule.RetentionScheduleFormatType = Models.RetentionScheduleFormat.Weekly;
345+
346+
//Initialize day based schedule
347+
defaultRetention.MonthlySchedule.RetentionScheduleDaily = GetDailyRetentionFormat();
348+
349+
//Initialize Week based schedule
350+
defaultRetention.MonthlySchedule.RetentionScheduleWeekly = GetWeeklyRetentionFormat();
351+
352+
//Yearly retention policy
353+
defaultRetention.IsYearlyScheduleEnabled = true;
354+
defaultRetention.YearlySchedule = new Models.YearlyRetentionSchedule();
355+
defaultRetention.YearlySchedule.DurationCountInYears = 10;
356+
defaultRetention.YearlySchedule.RetentionScheduleFormatType = Models.RetentionScheduleFormat.Weekly;
357+
defaultRetention.YearlySchedule.MonthsOfYear = new List<Models.Month>();
358+
defaultRetention.YearlySchedule.MonthsOfYear.Add(Models.Month.January);
359+
defaultRetention.YearlySchedule.RetentionScheduleDaily = GetDailyRetentionFormat();
360+
defaultRetention.YearlySchedule.RetentionScheduleWeekly = GetWeeklyRetentionFormat();
361+
return defaultRetention;
362+
363+
}
364+
365+
private static Models.DailyRetentionFormat GetDailyRetentionFormat()
366+
{
367+
Models.DailyRetentionFormat dailyRetention = new Models.DailyRetentionFormat();
368+
dailyRetention.DaysOfTheMonth = new List<Models.Day>();
369+
Models.Day dayBasedRetention = new Models.Day();
370+
dayBasedRetention.IsLast = false;
371+
dayBasedRetention.Date = 1;
372+
dailyRetention.DaysOfTheMonth.Add(dayBasedRetention);
373+
return dailyRetention;
374+
}
375+
376+
private static Models.WeeklyRetentionFormat GetWeeklyRetentionFormat()
377+
{
378+
Models.WeeklyRetentionFormat weeklyRetention = new Models.WeeklyRetentionFormat();
379+
weeklyRetention.DaysOfTheWeek = new List<DayOfWeek>();
380+
weeklyRetention.DaysOfTheWeek.Add(DayOfWeek.Sunday);
381+
382+
weeklyRetention.WeeksOfTheMonth = new List<WeekOfMonth>();
383+
weeklyRetention.WeeksOfTheMonth.Add(WeekOfMonth.First);
384+
return weeklyRetention;
385+
}
386+
387+
private static DateTime GenerateRandomTime()
388+
{
389+
//Schedule time will be random to avoid the load in service (same is in portal as well)
390+
Random rand = new Random();
391+
int hour = rand.Next(0, 24);
392+
int minute = (rand.Next(0, 2) == 0) ? 0 : 30;
393+
return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, minute, 00);
394+
}
395+
396+
300397
#region private
301398
private void ValidateAzureVMWorkloadType(Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType type)
302399
{

0 commit comments

Comments
 (0)