示例#1
0
        /// <summary>
        /// Create a schedule that runs chaos 24/7 using a particular ChaosParameters. This is useful for create schedules that simulate the old StartChaos
        /// </summary>
        /// <param name="chaosParameters">Parameteres to run chaos with.</param>
        /// <param name="startTime">Time for schedule to become active</param>
        /// <param name="endTime">Time for schedule to expire</param>
        /// <returns>A 24/7 schedule that uses one set of ChaosParameters.</returns>
        public static ChaosSchedule Create247Schedule(ChaosParameters chaosParameters, DateTime startTime, DateTime endTime)
        {
            var chaosParametersDictionary = new Dictionary <string, ChaosParameters>();

            chaosParametersDictionary.Add(ChaosConstants.ChaosScheduler_DefaultParameterKey, chaosParameters);

            List <ChaosScheduleTimeRangeUtc> times = new List <ChaosScheduleTimeRangeUtc>()
            {
                ChaosScheduleTimeRangeUtc.WholeDay
            };
            var everyDay = new HashSet <DayOfWeek>()
            {
                DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday
            };
            ChaosScheduleJobActiveDays activeEveryday = new ChaosScheduleJobActiveDays(everyDay);
            ChaosScheduleJob           job            = new ChaosScheduleJob(ChaosConstants.ChaosScheduler_DefaultParameterKey, activeEveryday, times);
            var chaosScheduleJobs = new List <ChaosScheduleJob>()
            {
                job
            };

            ChaosSchedule schedule = new ChaosSchedule(startTime, endTime, chaosParametersDictionary, chaosScheduleJobs);

            return(schedule);
        }
示例#2
0
        private static void VerifyChaosScheduleJob(ChaosScheduleJob job)
        {
            if (job.Days == null)
            {
                throw new System.ArgumentNullException("Days", StringResources.ChaosScheduler_ScheduleJobDaysIsNull);
            }

            if (job.Days.NoActiveDays())
            {
                throw new System.ArgumentException(StringResources.ChaosScheduler_ScheduleJobNoDaysSet, "Days");
            }

            if (job.Times == null)
            {
                throw new System.ArgumentNullException("Times", StringResources.ChaosScheduler_ScheduleJobTimesIsNull);
            }

            if (job.Times.Count < 1)
            {
                throw new System.ArgumentException(StringResources.ChaosScheduler_ScheduleJobEndTimeAfterEndOfDay, "Times");
            }

            foreach (var time in job.Times)
            {
                ChaosSchedulerUtil.VerifyChaosScheduleTimeRangeUtc(time);
            }
        }
示例#3
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, ChaosScheduleJob obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            if (obj.ChaosParameters != null)
            {
                writer.WriteProperty(obj.ChaosParameters, "ChaosParameters", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.Days != null)
            {
                writer.WriteProperty(obj.Days, "Days", ChaosScheduleJobActiveDaysOfWeekConverter.Serialize);
            }

            if (obj.Times != null)
            {
                writer.WriteEnumerableProperty(obj.Times, "Times", TimeRangeConverter.Serialize);
            }

            writer.WriteEndObject();
        }