Recovery services simple schedule policy.
Inheritance: SchedulePolicyBase
        public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy retPolicy,
                                                     CmdletModel.SimpleSchedulePolicy schPolicy)
        {
            // schedule runTimes is already validated if in UTC/not during validate()
            // now copy times from schedule to retention policy
            if (retPolicy.IsDailyScheduleEnabled && retPolicy.DailySchedule != null)
            {
                retPolicy.DailySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
            }

            if (retPolicy.IsWeeklyScheduleEnabled && retPolicy.WeeklySchedule != null)
            {
                retPolicy.WeeklySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
            }

            if (retPolicy.IsMonthlyScheduleEnabled && retPolicy.MonthlySchedule != null)
            {
                retPolicy.MonthlySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
            }

            if (retPolicy.IsYearlyScheduleEnabled && retPolicy.YearlySchedule != null)
            {
                retPolicy.YearlySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
            }
        }
Example #2
0
        public void ValidateAzureIaasVMSchedulePolicy(CmdletModel.SchedulePolicyBase policy)
        {
            if (policy.GetType() == typeof(CmdletModel.SimpleSchedulePolicy))
            {
                CmdletModel.SimpleSchedulePolicy simpleSchedulePolicy = (CmdletModel.SimpleSchedulePolicy)policy;

                // Standard hourly is restricted for IaasVM
                if (simpleSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Hourly)
                {
                    throw new ArgumentException(Resources.StandardHourlyPolicyNotSupported);
                }
            }
            else if (policy.GetType() == typeof(CmdletModel.SimpleSchedulePolicyV2))
            {
                CmdletModel.SimpleSchedulePolicyV2 simpleSchedulePolicyV2 = (CmdletModel.SimpleSchedulePolicyV2)policy;
                if (simpleSchedulePolicyV2.ScheduleRunFrequency == ScheduleRunType.Hourly)
                {
                    // throw new ArgumentException("Enhanced Hourly policy is currently not supported for WorkloadType AzureIaasVM. This will be supported soon");
                    List <int> AllowedScheduleIntervals = new List <int> {
                        4, 6, 8, 12
                    };
                    if (!(AllowedScheduleIntervals.Contains((int)simpleSchedulePolicyV2.HourlySchedule.Interval)))
                    {
                        throw new ArgumentException(String.Format(Resources.InvalidScheduleInterval, string.Join(",", AllowedScheduleIntervals.ToArray())));
                    }

                    // duration should be multiple of Interval and less than or equal to 24
                    if (simpleSchedulePolicyV2.HourlySchedule.WindowDuration > 24 || simpleSchedulePolicyV2.HourlySchedule.WindowDuration % simpleSchedulePolicyV2.HourlySchedule.Interval != 0)
                    {
                        throw new ArgumentException("Hourly policy ScheduleWindowDuration should be multiple of ScheduleInterval and less than or equal to 24 Hrs. for WorkloadType AzureVM");
                    }
                }
            }
        }
Example #3
0
        public SchedulePolicyBase GetDefaultSchedulePolicyObject()
        {
            CmdletModel.SimpleSchedulePolicy defaultSchedule = new CmdletModel.SimpleSchedulePolicy();
            defaultSchedule.ScheduleRunFrequency = CmdletModel.ScheduleRunType.Daily;

            DateTime scheduleTime = AzureWorkloadProviderHelper.GenerateRandomScheduleTime();

            defaultSchedule.ScheduleRunTimes = new List <DateTime>();
            defaultSchedule.ScheduleRunTimes.Add(scheduleTime);

            return(defaultSchedule);
        }
        /// <summary>
        /// Constructs the schedule policy object with default inits
        /// </summary>
        /// <returns>Default schedule policy object</returns>
        public SchedulePolicyBase GetDefaultSchedulePolicyObject()
        {
            CmdletModel.SimpleSchedulePolicy defaultSchedule = new CmdletModel.SimpleSchedulePolicy();
            //Default is daily scedule at 10:30 AM local time
            defaultSchedule.ScheduleRunFrequency = ScheduleRunType.Daily;

            DateTime scheduleTime = GenerateRandomTime();

            defaultSchedule.ScheduleRunTimes = new List <DateTime>();
            defaultSchedule.ScheduleRunTimes.Add(scheduleTime);

            defaultSchedule.ScheduleRunDays = new List <DayOfWeek>();
            defaultSchedule.ScheduleRunDays.Add(DayOfWeek.Sunday);

            return(defaultSchedule);
        }
Example #5
0
        public void ValidateAFSSchedulePolicy(CmdletModel.SimpleSchedulePolicy policy)
        {
            if (policy.ScheduleRunFrequency == ScheduleRunType.Hourly)
            {
                List <int> AllowedScheduleIntervals = new List <int> {
                    4, 6, 8, 12
                };
                if (!(AllowedScheduleIntervals.Contains((int)policy.ScheduleInterval)))
                {
                    throw new ArgumentException(String.Format(Resources.InvalidScheduleInterval, string.Join(",", AllowedScheduleIntervals.ToArray())));
                }

                if ((policy.ScheduleWindowDuration < policy.ScheduleInterval) || (policy.ScheduleWindowDuration < PolicyConstants.AfsHourlyWindowDurationMin) ||
                    (policy.ScheduleWindowDuration > PolicyConstants.AfsHourlyWindowDurationMax))
                {
                    throw new ArgumentException(String.Format(Resources.InvalidScheduleWindowDuration, PolicyConstants.AfsHourlyWindowDurationMin, PolicyConstants.AfsHourlyWindowDurationMax));
                }

                DateTime windowStartTime  = (DateTime)policy.ScheduleWindowStartTime;
                DateTime minimumStartTime = new DateTime(windowStartTime.Year, windowStartTime.Month, windowStartTime.Day, 00, 00, 00, 00, DateTimeKind.Utc);
                DateTime maximumStartTime = new DateTime(windowStartTime.Year, windowStartTime.Month, windowStartTime.Day, 19, 30, 00, 00, DateTimeKind.Utc);

                //validate window start time
                if (windowStartTime > maximumStartTime || windowStartTime < minimumStartTime)
                {
                    throw new ArgumentException(String.Format(Resources.ScheduleWindowStartTimeOutOfRange));
                }

                // final backup time can be 23:30:00
                DateTime finalBackupTime = new DateTime(windowStartTime.Year, windowStartTime.Month, windowStartTime.Day, 23, 30, 00, 00, DateTimeKind.Utc);
                TimeSpan diff            = finalBackupTime - windowStartTime;

                // If ScheduleWindowDuration is greator than (23:30 - ScheduleWindowStartTime) then throw exception
                if (diff.TotalHours < policy.ScheduleWindowDuration)
                {
                    throw new ArgumentException(String.Format(Resources.InvalidLastBackupTime));
                }
            }
        }
        /// <summary>
        /// Constructs the schedule policy object with default inits
        /// </summary>
        /// <returns>Default schedule policy object</returns>
        public SchedulePolicyBase GetDefaultSchedulePolicyObject()
        {
            CmdletModel.SimpleSchedulePolicy defaultSchedule = new CmdletModel.SimpleSchedulePolicy();
            //Default is daily scedule at 10:30 AM local time
            defaultSchedule.ScheduleRunFrequency = ScheduleRunType.Daily;

            DateTime scheduleTime = GenerateRandomTime();
            defaultSchedule.ScheduleRunTimes = new List<DateTime>();
            defaultSchedule.ScheduleRunTimes.Add(scheduleTime);

            defaultSchedule.ScheduleRunDays = new List<DayOfWeek>();
            defaultSchedule.ScheduleRunDays.Add(DayOfWeek.Sunday);

            return defaultSchedule;
        }
        // <summary>
        /// Helper function to validate long term rentention policy and simple schedule policy.
        /// </summary>
        public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
            LongTermRetentionPolicy ltrPolicy,
            SimpleSchedulePolicy schPolicy)
        {
            // for daily schedule, daily retention policy is required
            if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Daily &&
               (ltrPolicy.DailySchedule == null || ltrPolicy.IsDailyScheduleEnabled == false))
            {
                throw new ArgumentException(Resources.DailyRetentionScheduleNullException);
            }

            // for weekly schedule, daily retention policy should be NULL
            // AND weekly retention policy is required
            if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
               (ltrPolicy.IsDailyScheduleEnabled != false || ltrPolicy.WeeklySchedule == null || 
               (ltrPolicy.IsWeeklyScheduleEnabled == false)))
            {
                throw new ArgumentException(Resources.WeeklyRetentionScheduleNullException);
            }

            // validate daily retention schedule with schPolicy
            if (ltrPolicy.DailySchedule != null && ltrPolicy.IsDailyScheduleEnabled == true)
            {
                ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.DailySchedule.RetentionTimes);
            }

            // validate weekly retention schedule with schPolicy
            if (ltrPolicy.WeeklySchedule != null && ltrPolicy.IsWeeklyScheduleEnabled == true)
            {
                ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.WeeklySchedule.RetentionTimes);

                if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
                {
                    // count of daysOfWeek should match for weekly schedule
                    if (ltrPolicy.WeeklySchedule.DaysOfTheWeek.Count != schPolicy.ScheduleRunDays.Count)
                    {
                        throw new ArgumentException(Resources.DaysofTheWeekInWeeklyRetentionException);
                    }

                    // validate days of week
                    ValidateRetentionAndScheduleDaysOfWeek(schPolicy.ScheduleRunDays, ltrPolicy.WeeklySchedule.DaysOfTheWeek);
                }
            }

            // validate monthly retention schedule with schPolicy
            if (ltrPolicy.MonthlySchedule != null && ltrPolicy.IsMonthlyScheduleEnabled == true)
            {
                ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.MonthlySchedule.RetentionTimes);

                // if backupSchedule is weekly, then user cannot choose 'Daily Retention format' 
                if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
                    ltrPolicy.MonthlySchedule.RetentionScheduleFormatType == Cmdlets.Models.RetentionScheduleFormat.Daily)
                {
                    throw new ArgumentException(Resources.MonthlyYearlyInvalidDailyRetentionFormatTypeException);
                }

                // for monthly and weeklyFormat, validate days of week
                if (ltrPolicy.MonthlySchedule.RetentionScheduleFormatType == Cmdlets.Models.RetentionScheduleFormat.Weekly &&
                   schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
                {
                    ValidateRetentionAndScheduleDaysOfWeek(schPolicy.ScheduleRunDays,
                                                           ltrPolicy.MonthlySchedule.RetentionScheduleWeekly.DaysOfTheWeek);
                }
            }

            // validate yearly retention schedule with schPolicy
            if (ltrPolicy.YearlySchedule != null && ltrPolicy.IsYearlyScheduleEnabled == true)
            {
                ValidateRetentionAndBackupTimes(schPolicy.ScheduleRunTimes, ltrPolicy.YearlySchedule.RetentionTimes);

                // if backupSchedule is weekly, then user cannot choose 'Daily Retention format' 
                if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly &&
                    ltrPolicy.YearlySchedule.RetentionScheduleFormatType == Cmdlets.Models.RetentionScheduleFormat.Daily)
                {
                    throw new ArgumentException(Resources.MonthlyYearlyInvalidDailyRetentionFormatTypeException);
                }

                // for yearly and weeklyFormat, validate days of week                 
                if (ltrPolicy.YearlySchedule.RetentionScheduleFormatType == Cmdlets.Models.RetentionScheduleFormat.Weekly &&
                    schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
                {
                    ValidateRetentionAndScheduleDaysOfWeek(schPolicy.ScheduleRunDays,
                                                           ltrPolicy.YearlySchedule.RetentionScheduleWeekly.DaysOfTheWeek);
                }
            }
        }
Example #8
0
        public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy retPolicy,
                                                     CmdletModel.SchedulePolicyBase schPolicyBase)
        {
            if (schPolicyBase.GetType() == typeof(CmdletModel.SimpleSchedulePolicy))
            {
                CmdletModel.SimpleSchedulePolicy schPolicy = (CmdletModel.SimpleSchedulePolicy)schPolicyBase;

                // schedule runTimes is already validated if in UTC/not during validate()
                // now copy times from schedule to retention policy
                if (retPolicy.IsDailyScheduleEnabled && retPolicy.DailySchedule != null)
                {
                    retPolicy.DailySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
                }

                if (retPolicy.IsWeeklyScheduleEnabled && retPolicy.WeeklySchedule != null)
                {
                    retPolicy.WeeklySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
                }

                if (retPolicy.IsMonthlyScheduleEnabled && retPolicy.MonthlySchedule != null)
                {
                    retPolicy.MonthlySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
                }

                if (retPolicy.IsYearlyScheduleEnabled && retPolicy.YearlySchedule != null)
                {
                    retPolicy.YearlySchedule.RetentionTimes = schPolicy.ScheduleRunTimes;
                }
            }
            else if (schPolicyBase.GetType() == typeof(CmdletModel.SimpleSchedulePolicyV2))
            {
                CmdletModel.SimpleSchedulePolicyV2 schPolicyV2 = (CmdletModel.SimpleSchedulePolicyV2)schPolicyBase;

                // schedule runTimes is already validated if in UTC/not during validate()
                // now copy times from schedule to retention policy

                List <DateTime> hourlyWindowStartTime = (schPolicyV2.HourlySchedule != null) ? new List <DateTime> {
                    (DateTime)schPolicyV2.HourlySchedule.WindowStartTime
                } : null;

                if (retPolicy.IsDailyScheduleEnabled && retPolicy.DailySchedule != null)
                {
                    retPolicy.DailySchedule.RetentionTimes = (schPolicyV2.DailySchedule != null) ? schPolicyV2.DailySchedule.ScheduleRunTimes : hourlyWindowStartTime;
                }

                if (retPolicy.IsWeeklyScheduleEnabled && retPolicy.WeeklySchedule != null)
                {
                    retPolicy.WeeklySchedule.RetentionTimes = (schPolicyV2.DailySchedule != null) ? schPolicyV2.DailySchedule.ScheduleRunTimes : ((schPolicyV2.WeeklySchedule != null) ? schPolicyV2.WeeklySchedule.ScheduleRunTimes : hourlyWindowStartTime);
                }

                if (retPolicy.IsMonthlyScheduleEnabled && retPolicy.MonthlySchedule != null)
                {
                    retPolicy.MonthlySchedule.RetentionTimes = (schPolicyV2.DailySchedule != null) ? schPolicyV2.DailySchedule.ScheduleRunTimes : ((schPolicyV2.WeeklySchedule != null) ? schPolicyV2.WeeklySchedule.ScheduleRunTimes : hourlyWindowStartTime);
                }

                if (retPolicy.IsYearlyScheduleEnabled && retPolicy.YearlySchedule != null)
                {
                    retPolicy.YearlySchedule.RetentionTimes = (schPolicyV2.DailySchedule != null) ? schPolicyV2.DailySchedule.ScheduleRunTimes : ((schPolicyV2.WeeklySchedule != null) ? schPolicyV2.WeeklySchedule.ScheduleRunTimes : hourlyWindowStartTime);
                }
            }
        }