Exemplo n.º 1
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="System.Fabric.Health.ApplicationHealthPolicy" /> class.</para>
 /// </summary>
 /// <remarks>The default application health policy doesn't tolerate any errors or warnings.</remarks>
 public ApplicationHealthPolicy()
 {
     this.ConsiderWarningAsError = false;
     this.MaxPercentUnhealthyDeployedApplications = 0;
     this.defaultServiceTypeHealthPolicy          = null;
     this.serviceTypeHealthPolicyMap = new Dictionary <string, ServiceTypeHealthPolicy>();
 }
Exemplo n.º 2
0
        internal static bool AreEqual(ApplicationHealthPolicy current, ApplicationHealthPolicy other)
        {
            if ((current != null) && (other != null))
            {
                if ((current.ConsiderWarningAsError != other.ConsiderWarningAsError) ||
                    (current.MaxPercentUnhealthyDeployedApplications != other.MaxPercentUnhealthyDeployedApplications) ||
                    (!ServiceTypeHealthPolicy.AreEqualWithNullAsDefault(current.DefaultServiceTypeHealthPolicy, other.DefaultServiceTypeHealthPolicy)) ||
                    (current.ServiceTypeHealthPolicyMap.Count != other.ServiceTypeHealthPolicyMap.Count))
                {
                    return(false);
                }

                foreach (var currentItem in current.ServiceTypeHealthPolicyMap)
                {
                    ServiceTypeHealthPolicy otherValue;
                    var success = other.ServiceTypeHealthPolicyMap.TryGetValue(currentItem.Key, out otherValue);

                    if (!success)
                    {
                        return(false);
                    }

                    if (!ServiceTypeHealthPolicy.AreEqual(currentItem.Value, otherValue))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                return((current == null) && (other == null));
            }
        }
        internal static bool AreEqualWithNullAsDefault(ServiceTypeHealthPolicy current, ServiceTypeHealthPolicy other)
        {
            if ((current == null) && (other == null))
            {
                return(true);
            }

            var currentOrDefault = (current == null) ? new ServiceTypeHealthPolicy() : current;
            var otherOrDefault   = (other == null) ? new ServiceTypeHealthPolicy() : other;

            return(AreEqual(currentOrDefault, otherOrDefault));
        }
 internal static bool AreEqual(ServiceTypeHealthPolicy current, ServiceTypeHealthPolicy other)
 {
     if ((current != null) && (other != null))
     {
         return((current.MaxPercentUnhealthyServices == other.MaxPercentUnhealthyServices) &&
                (current.MaxPercentUnhealthyPartitionsPerService == other.MaxPercentUnhealthyPartitionsPerService) &&
                (current.MaxPercentUnhealthyReplicasPerPartition == other.MaxPercentUnhealthyReplicasPerPartition));
     }
     else
     {
         return((current == null) && (other == null));
     }
 }
Exemplo n.º 5
0
        internal unsafe IntPtr ToNative(PinCollection pin)
        {
            var nativeApplicationHealthPolicy = new NativeTypes.FABRIC_APPLICATION_HEALTH_POLICY();

            nativeApplicationHealthPolicy.ConsiderWarningAsError = NativeTypes.ToBOOLEAN(this.ConsiderWarningAsError);

            nativeApplicationHealthPolicy.MaxPercentUnhealthyDeployedApplications = this.MaxPercentUnhealthyDeployedApplications;

            if (this.DefaultServiceTypeHealthPolicy != null)
            {
                nativeApplicationHealthPolicy.DefaultServiceTypeHealthPolicy = this.DefaultServiceTypeHealthPolicy.ToNative(pin);
            }

            nativeApplicationHealthPolicy.ServiceTypeHealthPolicyMap = ServiceTypeHealthPolicy.ToNativeMap(pin, this.ServiceTypeHealthPolicyMap);

            return(pin.AddBlittable(nativeApplicationHealthPolicy));
        }
        internal static unsafe ServiceTypeHealthPolicy FromNative(IntPtr nativeServiceTypeHealthPolicyPtr)
        {
            if (nativeServiceTypeHealthPolicyPtr == IntPtr.Zero)
            {
                return(null);
            }

            var nativeServiceTypeHealthPolicy = (NativeTypes.FABRIC_SERVICE_TYPE_HEALTH_POLICY *)nativeServiceTypeHealthPolicyPtr;

            var serviceTypeHealthPolicy = new ServiceTypeHealthPolicy();

            serviceTypeHealthPolicy.MaxPercentUnhealthyServices             = nativeServiceTypeHealthPolicy->MaxPercentUnhealthyServices;
            serviceTypeHealthPolicy.MaxPercentUnhealthyPartitionsPerService = nativeServiceTypeHealthPolicy->MaxPercentUnhealthyPartitionsPerService;
            serviceTypeHealthPolicy.MaxPercentUnhealthyReplicasPerPartition = nativeServiceTypeHealthPolicy->MaxPercentUnhealthyReplicasPerPartition;

            return(serviceTypeHealthPolicy);
        }
        internal static unsafe void FromNativeMap(IntPtr nativeServiceTypeHealthPolicyMapPtr, IDictionary <string, ServiceTypeHealthPolicy> map)
        {
            if (nativeServiceTypeHealthPolicyMapPtr == IntPtr.Zero)
            {
                return;
            }

            var nativeServiceTypeHealthPolicyMap = (NativeTypes.FABRIC_SERVICE_TYPE_HEALTH_POLICY_MAP *)nativeServiceTypeHealthPolicyMapPtr;
            var offset = Marshal.SizeOf(typeof(NativeTypes.FABRIC_SERVICE_TYPE_HEALTH_POLICY_MAP_ITEM));

            for (int i = 0; i < nativeServiceTypeHealthPolicyMap->Count; i++)
            {
                var nativeMapItemPtr = nativeServiceTypeHealthPolicyMap->Items + (i * offset);
                var nativeMapItem    = (NativeTypes.FABRIC_SERVICE_TYPE_HEALTH_POLICY_MAP_ITEM *)nativeMapItemPtr;

                var serviceTypeName         = NativeTypes.FromNativeString(nativeMapItem->ServiceTypeName);
                var serviceTypeHealthPolicy = ServiceTypeHealthPolicy.FromNative(nativeMapItem->ServiceTypeHealthPolicy);

                map.Add(serviceTypeName, serviceTypeHealthPolicy);
            }
        }
Exemplo n.º 8
0
        internal static unsafe ApplicationHealthPolicy FromNative(IntPtr nativeApplicationHealthPolicyPtr)
        {
            var applicationHealthPolicy = new ApplicationHealthPolicy();

            if (nativeApplicationHealthPolicyPtr == IntPtr.Zero)
            {
                return(applicationHealthPolicy);
            }

            var nativeApplicationHealthPolicy = (NativeTypes.FABRIC_APPLICATION_HEALTH_POLICY *)nativeApplicationHealthPolicyPtr;

            applicationHealthPolicy.ConsiderWarningAsError = NativeTypes.FromBOOLEAN(nativeApplicationHealthPolicy->ConsiderWarningAsError);

            applicationHealthPolicy.MaxPercentUnhealthyDeployedApplications = nativeApplicationHealthPolicy->MaxPercentUnhealthyDeployedApplications;

            applicationHealthPolicy.DefaultServiceTypeHealthPolicy =
                ServiceTypeHealthPolicy.FromNative(nativeApplicationHealthPolicy->DefaultServiceTypeHealthPolicy);

            ServiceTypeHealthPolicy.FromNativeMap(
                nativeApplicationHealthPolicy->ServiceTypeHealthPolicyMap,
                applicationHealthPolicy.ServiceTypeHealthPolicyMap);

            return(applicationHealthPolicy);
        }