internal static unsafe ChaosSchedule FromNative(IntPtr pointer)
        {
            var      nativeSchedule = *(NativeTypes.FABRIC_CHAOS_SCHEDULE *)pointer;
            DateTime startDate      = NativeTypes.FromNativeFILETIME(nativeSchedule.StartDate);
            DateTime expiryDate     = NativeTypes.FromNativeFILETIME(nativeSchedule.ExpiryDate);
            Dictionary <string, ChaosParameters> chaosParametersDictionary = new Dictionary <string, ChaosParameters>();

            var chaosParametersMap = *(NativeTypes.FABRIC_CHAOS_SCHEDULE_CHAOS_PARAMETERS_MAP *)nativeSchedule.ChaosParametersMap;
            var nativechaosParametersMapArrayPtr = (NativeTypes.FABRIC_CHAOS_SCHEDULE_CHAOS_PARAMETERS_MAP_ITEM *)chaosParametersMap.Items;

            for (int i = 0; i < chaosParametersMap.Count; i++)
            {
                var nativeItem = *(nativechaosParametersMapArrayPtr + i);
                var name       = NativeTypes.FromNativeString(nativeItem.Name);
                var parameters = ChaosParameters.CreateFromNative(nativeItem.Parameters);

                chaosParametersDictionary.Add(name, parameters);
            }

            List <ChaosScheduleJob> jobs = new List <ChaosScheduleJob>();
            var nativeJobsList           = *(NativeTypes.FABRIC_CHAOS_SCHEDULE_JOB_LIST *)nativeSchedule.Jobs;
            var nativeJobsArrayPtr       = (NativeTypes.FABRIC_CHAOS_SCHEDULE_JOB *)nativeJobsList.Items;

            for (int i = 0; i < nativeJobsList.Count; ++i)
            {
                var nativeItem       = (nativeJobsArrayPtr + i);
                ChaosScheduleJob job = ChaosScheduleJob.FromNative(nativeItem);
                jobs.Add(job);
            }

            return(new ChaosSchedule(startDate, expiryDate, chaosParametersDictionary, jobs));
        }
        /// <summary>
        /// Assumes the unique internal ctor is always called and populate the public properties that have not been set in that ctor
        /// </summary>
        /// <param name="source">The object from which to take the values of the ramaining public properties.</param>
        public void RehydratePropertiesNotInCtorFrom(ChaosParameters source)
        {
            if (source == null)
            {
                return;
            }

            var uniqueInternalConstructor = typeof(ChaosParameters).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault();

            ChaosUtility.ThrowOrAssertIfTrue(
                ChaosConstants.UnexpectedNumberOfInternalChaosParametersCtor_TelemetryId,
                uniqueInternalConstructor.Equals(default(ConstructorInfo)),
                StringResources.ChaosError_ChaosParametersContructionNotComplete);

            HashSet <string> constructorParameterNameSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            uniqueInternalConstructor.GetParameters()?.ForEach(p => constructorParameterNameSet.Add(p.Name));

            HashSet <PropertyInfo> publicPropertySet = new HashSet <PropertyInfo>();

            typeof(ChaosParameters).GetProperties(BindingFlags.Public | BindingFlags.Instance)?.ForEach(p => publicPropertySet.Add(p));

            var publicPropertiesNotSetFromCtor = new List <PropertyInfo>();

            publicPropertySet.Where(p => !constructorParameterNameSet.Contains(p.Name)).ForEach(p => publicPropertiesNotSetFromCtor.Add(p));

            foreach (var unsetProperty in publicPropertiesNotSetFromCtor)
            {
                this.SetPublicProperty(unsetProperty, source);
            }
        }
Exemple #3
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="System.Fabric.Chaos.DataStructures.ChaosDescription" /> class.</para>
 /// </summary>
 /// <param name="chaosStatus">The status of Chaos. Can be Stopped, Running or Invalid</param>
 /// <param name="chaosParameters">The parameters that Chaos runs with if Chaos is currently running or the parameters if Chaos was running with if Chaos was running. If Chaos has never ran before, then the value here does not have a meaning.</param>
 /// <param name="chaosScheduleStatus">The state of the schedule.</param>
 public ChaosDescription(
     ChaosStatus chaosStatus,
     ChaosParameters chaosParameters,
     ChaosScheduleStatus chaosScheduleStatus)
 {
     this.Status          = chaosStatus;
     this.ChaosParameters = chaosParameters;
     this.ScheduleStatus  = chaosScheduleStatus;
 }
Exemple #4
0
        internal static unsafe ChaosReport FromNative(IntPtr pointer)
        {
            var nativeReport      = *(NativeTypes.FABRIC_CHAOS_REPORT *)pointer;
            var chaosParameters   = ChaosParameters.CreateFromNative(nativeReport.ChaosParameters);
            var status            = (ChaosStatus)nativeReport.Status;
            var continuationToken = NativeTypes.FromNativeString(nativeReport.ContinuationToken);
            var history           = FromNativeHistory(nativeReport.History);

            return(new ChaosReport(chaosParameters, status, history, continuationToken));
        }
Exemple #5
0
        internal static unsafe ChaosDescription FromNative(IntPtr pointer)
        {
            var nativeDescription = *(NativeTypes.FABRIC_CHAOS_DESCRIPTION *)pointer;
            var chaosParameters   = ChaosParameters.CreateFromNative(nativeDescription.ChaosParameters);

            var chaosStatus         = (ChaosStatus)nativeDescription.Status;
            var chaosScheduleStatus = (ChaosScheduleStatus)nativeDescription.ScheduleStatus;

            return(new ChaosDescription(chaosStatus, chaosParameters, chaosScheduleStatus));
        }
Exemple #6
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="System.Fabric.Chaos.DataStructures.ChaosReport" /> class.</para>
 /// </summary>
 /// <param name="chaosParameters">Parameters with which Chaos was started</param>
 /// <param name="status">If Chaos is currently running or stopped.</param>
 /// <param name="history">The list of ChaosEvent's that match the ChaosReportFilter in ChaosParameters</param>
 /// <param name="continuationToken">If too many events match the ChaosReportFilter, those will be returned in multiple batches, the batches are linked by this token.</param>
 public ChaosReport(
     ChaosParameters chaosParameters,
     ChaosStatus status,
     List <ChaosEvent> history,
     string continuationToken)
 {
     this.ChaosParameters   = chaosParameters;
     this.Status            = status;
     this.History           = history;
     this.ContinuationToken = continuationToken;
 }
        internal ChaosParameters(
            ChaosParameters other)
        {
            this.ValidateArguments(other.MaxConcurrentFaults, other.Context, other.MaxClusterStabilizationTimeout, other.TimeToRun, other.WaitTimeBetweenIterations, other.WaitTimeBetweenFaults);

            this.MaxClusterStabilizationTimeout = other.MaxClusterStabilizationTimeout;

            this.WaitTimeBetweenIterations = other.WaitTimeBetweenIterations;

            this.ActionGeneratorParameters = new ActionGeneratorParameters {
                MaxConcurrentFaults = other.MaxConcurrentFaults
            };

            // Set default values for action generator parameters.

            this.EnableMoveReplicaFaults = other.EnableMoveReplicaFaults;

            // This is disable start/stop node
            this.ActionGeneratorParameters.NodeFaultActionsParameters.RestartNodeFaultWeight   = other.ActionGeneratorParameters.NodeFaultActionsParameters.RestartNodeFaultWeight;
            this.ActionGeneratorParameters.NodeFaultActionsParameters.StartStopNodeFaultWeight = other.ActionGeneratorParameters.NodeFaultActionsParameters.StartStopNodeFaultWeight;

            this.ActionGeneratorParameters.NodeFaultActionWeight    = other.ActionGeneratorParameters.NodeFaultActionWeight;
            this.ActionGeneratorParameters.ServiceFaultActionWeight = other.ActionGeneratorParameters.ServiceFaultActionWeight;

            this.ActionGeneratorParameters.ServiceFaultActionsParameters.RemoveReplicaFaultWeight      = other.ActionGeneratorParameters.ServiceFaultActionsParameters.RemoveReplicaFaultWeight;
            this.ActionGeneratorParameters.ServiceFaultActionsParameters.RestartReplicaFaultWeight     = other.ActionGeneratorParameters.ServiceFaultActionsParameters.RestartReplicaFaultWeight;
            this.ActionGeneratorParameters.ServiceFaultActionsParameters.RestartCodePackageFaultWeight = other.ActionGeneratorParameters.ServiceFaultActionsParameters.RestartCodePackageFaultWeight;

            this.ActionGeneratorParameters.ServiceFaultActionsParameters.MovePrimaryFaultWeight   = other.ActionGeneratorParameters.ServiceFaultActionsParameters.MovePrimaryFaultWeight;
            this.ActionGeneratorParameters.ServiceFaultActionsParameters.MoveSecondaryFaultWeight = other.ActionGeneratorParameters.ServiceFaultActionsParameters.MoveSecondaryFaultWeight;

            this.MaxConcurrentFaults = other.MaxConcurrentFaults;

            this.TimeToRun = other.TimeToRun;

            this.WaitTimeBetweenIterations = other.WaitTimeBetweenIterations;
            this.WaitTimeBetweenFaults     = other.WaitTimeBetweenFaults;

            this.requestTimeoutFactor = other.RequestTimeoutFactor;
            this.OperationTimeout     = other.OperationTimeout;

            this.populated = true;

            this.Context = other.Context;

            this.ClusterHealthPolicy = other.ClusterHealthPolicy ?? ChaosConstants.ClusterHealthPolicyDefault;

            this.ApplyUpdatesFromContextIfAvailable(other.Context);

            this.ChaosTargetFilter = other.ChaosTargetFilter;
        }
        /// <summary>
        /// Reads the state of this object from byte array.
        /// </summary>
        /// <param name="br">A BinaryReader object</param>
        /// <exception cref="EndOfStreamException">The end of the stream is reached. </exception>
        /// <exception cref="IOException">An I/O error occurs. </exception>
        public override void Read(BinaryReader br)
        {
            decimal objectVersion = br.ReadDecimal();

            if (objectVersion >= ChaosConstants.ApiVersion62)
            {
                this.StartDate = DateTime.ParseExact(
                    br.ReadString(),
                    ChaosConstants.DateTimeFormat_ISO8601,
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.AdjustToUniversal);

                this.ExpiryDate = DateTime.ParseExact(
                    br.ReadString(),
                    ChaosConstants.DateTimeFormat_ISO8601,
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.AdjustToUniversal);


                int keyValuePairCount = br.ReadInt32();

                for (int i = 0; i < keyValuePairCount; i++)
                {
                    string tempKey = br.ReadString();

                    ChaosParameters tempVal = new ChaosParameters();
                    tempVal.Read(br);
                    this.ChaosParametersDictionary.Add(tempKey, tempVal);
                }

                int jobsCount = br.ReadInt32();

                for (int i = 0; i < jobsCount; i++)
                {
                    ChaosScheduleJob job = new ChaosScheduleJob();
                    job.Read(br);
                    this.Jobs.Add(job);
                }
            }
            else
            {
                TestabilityTrace.TraceSource.WriteError(TraceComponent, "Attempting to read a version of object below lowest version. Saw {0}. Expected >=6.2", objectVersion);
                ReleaseAssert.Fail("Failed to read byte serialization of ChaosSchedule");
            }
        }
        internal static unsafe ChaosParameters CreateFromNative(IntPtr nativeRaw)
        {
            NativeTypes.FABRIC_CHAOS_PARAMETERS native = *(NativeTypes.FABRIC_CHAOS_PARAMETERS *)nativeRaw;

            TimeSpan maxClusterStabilizationTimeout =
                TimeSpan.FromSeconds(native.MaxClusterStabilizationTimeoutInSeconds);

            var maxConcurrentFaults = native.MaxConcurrentFaults;

            TimeSpan waitTimeBetweenIterations = TimeSpan.FromSeconds(native.WaitTimeBetweenIterationsInSeconds);

            TimeSpan waitTimeBetweenFaults = TimeSpan.FromSeconds(native.WaitTimeBetweenFaultsInSeconds);

            TimeSpan timeToRun = TimeSpan.FromSeconds(native.TimeToRunInSeconds);

            var enabledMoveReplicaFaults = NativeTypes.FromBOOLEAN(native.EnableMoveReplicaFaults);

            var contextMap = new Dictionary <string, string>();

            if (native.Context != IntPtr.Zero)
            {
                var nativeMapPtr = (NativeTypes.FABRIC_EVENT_CONTEXT_MAP *)native.Context;
                var bytesPerItem = Marshal.SizeOf(typeof(NativeTypes.FABRIC_EVENT_CONTEXT_MAP_ITEM));
                for (int i = 0; i < nativeMapPtr->Count; ++i)
                {
                    var nativeItemPtr    = nativeMapPtr->Items + (i * bytesPerItem);
                    var nativeMapItemPtr = (NativeTypes.FABRIC_EVENT_CONTEXT_MAP_ITEM *)nativeItemPtr;

                    contextMap.Add(
                        NativeTypes.FromNativeString(nativeMapItemPtr->Key),
                        NativeTypes.FromNativeString(nativeMapItemPtr->Value));
                }
            }

            var parameters = new ChaosParameters(
                maxClusterStabilizationTimeout,
                maxConcurrentFaults,
                enabledMoveReplicaFaults,
                timeToRun,
                contextMap,
                waitTimeBetweenIterations,
                waitTimeBetweenFaults);

            if (native.Reserved != IntPtr.Zero)
            {
                var ex1 = *((NativeTypes.FABRIC_CHAOS_PARAMETERS_EX1 *)native.Reserved);

                if (ex1.ClusterHealthPolicy != IntPtr.Zero)
                {
                    parameters.ClusterHealthPolicy = ClusterHealthPolicy.FromNative(ex1.ClusterHealthPolicy);
                }

                if (ex1.Reserved != IntPtr.Zero)
                {
                    var ex2 = *(NativeTypes.FABRIC_CHAOS_PARAMETERS_EX2 *)ex1.Reserved;
                    parameters.ChaosTargetFilter = ChaosTargetFilter.FromNative(ex2.ChaosTargetFilter);
                }
            }

            return(parameters);
        }
Exemple #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="timeStamp"></param>
 /// <param name="chaosParameters"></param>
 public StartedEvent(DateTime timeStamp, ChaosParameters chaosParameters)
     : base("Started", timeStamp)
 {
     this.ChaosParameters = chaosParameters;
 }