/// <summary> /// <para>Reads the properties of the service type.</para> /// </summary> /// <param name="serviceTypeName"> /// <para>The name of the service type.</para> /// </param> /// <param name="placementConstraints"> /// <para>The constraints to be used.</para> /// </param> /// <param name="loadMetricsList"> /// <para>The type of load metric.</para> /// </param> /// <param name="descriptionExtensionList"> /// <para>The description extension list.</para> /// </param> protected internal unsafe void ReadCommonProperties( IntPtr serviceTypeName, IntPtr placementConstraints, IntPtr loadMetricsList, IntPtr descriptionExtensionList) { this.ServiceTypeName = NativeTypes.FromNativeString(serviceTypeName); this.PlacementConstraints = NativeTypes.FromNativeString(placementConstraints); AppTrace.TraceSource.WriteNoise("ServiceTypeDescription.ReadCommonProperties", "Type {0}", this.ServiceTypeName); bool isStateful = (this.ServiceTypeKind == ServiceDescriptionKind.Stateful); if (loadMetricsList != IntPtr.Zero) { NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION_LIST *nativeMetrics = (NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION_LIST *)loadMetricsList; for (int i = 0; i < nativeMetrics->Count; i++) { this.loadMetrics.Add(ServiceLoadMetricDescription.CreateFromNative(nativeMetrics->Items + (i * Marshal.SizeOf(typeof(NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION))), isStateful)); } } if (descriptionExtensionList != IntPtr.Zero) { NativeTypes.FABRIC_SERVICE_TYPE_DESCRIPTION_EXTENSION_LIST *nativeDescriptions = (NativeTypes.FABRIC_SERVICE_TYPE_DESCRIPTION_EXTENSION_LIST *)descriptionExtensionList; for (int i = 0; i < nativeDescriptions->Count; i++) { Tuple <string, string> extension = DescriptionExtension.CreateFromNative(nativeDescriptions->Items + (i * Marshal.SizeOf(typeof(NativeTypes.FABRIC_SERVICE_TYPE_DESCRIPTION_EXTENSION)))); this.extensions.Add(extension.Item1, extension.Item2); } } }
internal static void CopyFrom(KeyedCollection <string, ServiceLoadMetricDescription> source, KeyedCollection <string, ServiceLoadMetricDescription> target) { if (source != null) { target.Clear(); source.ForEach(m => { ServiceLoadMetricDescription casted; if (m is StatefulServiceLoadMetricDescription) { casted = new StatefulServiceLoadMetricDescription(m as StatefulServiceLoadMetricDescription); } else if (m is StatelessServiceLoadMetricDescription) { casted = new StatelessServiceLoadMetricDescription(m as StatelessServiceLoadMetricDescription); } else { casted = new ServiceLoadMetricDescription(m); } target.Add(casted); }); } }
internal static void Validate(ServiceGroupMemberDescription serviceGroupMemberDescription) { Requires.Argument <Uri>("serviceGroupMemberDescription.Name", serviceGroupMemberDescription.ServiceName).NotNullOrWhiteSpace(); Requires.Argument <string>("serviceGroupMemberDescription.ServiceTypeName", serviceGroupMemberDescription.ServiceTypeName).NotNullOrWhiteSpace(); foreach (var metric in serviceGroupMemberDescription.Metrics) { ServiceLoadMetricDescription.Validate(metric); } }
private void CopyFrom(ServiceTypeDescription other) { // Copy basic types this.PlacementConstraints = other.PlacementConstraints; this.ServiceTypeName = other.ServiceTypeName; // Create copies of reference types this.Policies.AddRange(other.Policies.Select(p => p.GetCopy())); ServiceLoadMetricDescription.CopyFrom(other.LoadMetrics, this.LoadMetrics); this.extensions = other.Extensions == null ? this.extensions : new Dictionary <string, string>(other.Extensions); }
internal static void Validate(ServiceDescription serviceDescription) { Requires.Argument <Uri>("serviceDescription.ServiceName", serviceDescription.ServiceName).NotNullOrWhiteSpace(); Requires.Argument <string>("serviceDescription.ServiceTypeName", serviceDescription.ServiceTypeName).NotNullOrWhiteSpace(); Requires.Argument <PartitionSchemeDescription>("serviceDescription.PartitionSchemeDescription", serviceDescription.PartitionSchemeDescription).NotNull(); foreach (var correlation in serviceDescription.Correlations) { ServiceCorrelationDescription.Validate(correlation); } foreach (var metric in serviceDescription.Metrics) { ServiceLoadMetricDescription.Validate(metric); } }
internal unsafe void ParseLoadMetrics(uint count, IntPtr array) { if (count == 0) { return; } ReleaseAssert.AssertIfNot(array != IntPtr.Zero, StringResources.Error_NullArrayWithNonZeroSize); bool isStateful = (this.Kind == ServiceDescriptionKind.Stateful); var nativeMetrics = (NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION *)array; for (int i = 0; i < count; i++) { var item = ServiceLoadMetricDescription.CreateFromNative((IntPtr)(nativeMetrics + i), isStateful); this.Metrics.Add(item); } }
private void CopyFrom(ServiceDescription other) { // Copy basic types this.PlacementConstraints = other.PlacementConstraints; this.ServiceTypeName = other.ServiceTypeName; this.ApplicationName = other.ApplicationName; this.ServiceName = other.ServiceName; this.InitializationData = other.InitializationData == null ? null : other.InitializationData.ToArray(); this.isDefaultMoveCostSpecified = other.IsDefaultMoveCostSpecified; this.defaultMoveCost = other.defaultMoveCost; this.ServiceDnsName = other.ServiceDnsName; this.ServicePackageActivationMode = other.ServicePackageActivationMode; ServiceLoadMetricDescription.CopyFrom(other.Metrics, this.Metrics); this.correlations.AddRange(other.Correlations.Select(c => new ServiceCorrelationDescription(c))); this.PartitionSchemeDescription = other.PartitionSchemeDescription.GetCopy(); this.placementPolicies.AddRange(other.placementPolicies.Select(p => p.GetCopy())); this.scalingPolicies.AddRange(other.ScalingPolicies.Select(p => ScalingPolicyDescription.GetCopy(p))); }
internal static unsafe ServiceGroupTypeMemberDescription CreateFromNative(IntPtr descriptionPtr, bool isStateful) { NativeTypes.FABRIC_SERVICE_GROUP_TYPE_MEMBER_DESCRIPTION *nativeDescription = (NativeTypes.FABRIC_SERVICE_GROUP_TYPE_MEMBER_DESCRIPTION *)descriptionPtr; ServiceGroupTypeMemberDescription description = new ServiceGroupTypeMemberDescription() { ServiceTypeName = NativeTypes.FromNativeString(nativeDescription->ServiceTypeName) }; NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION_LIST *nativeMetrics = (NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION_LIST *)nativeDescription->LoadMetrics; if (nativeMetrics != null && nativeMetrics->Count > 0) { for (int i = 0; i < nativeMetrics->Count; ++i) { description.loadMetrics.Add(ServiceLoadMetricDescription.CreateFromNative(nativeMetrics->Items + (i * Marshal.SizeOf(typeof(NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION))), isStateful)); } } return(description); }
internal static unsafe ServiceGroupMemberDescription CreateFromNative(IntPtr nativeDescriptionPtr, bool isStateful) { var nativeDescription = (NativeTypes.FABRIC_SERVICE_GROUP_MEMBER_DESCRIPTION *)nativeDescriptionPtr; var description = new ServiceGroupMemberDescription { ServiceName = NativeTypes.FromNativeUri(nativeDescription->ServiceName), ServiceTypeName = NativeTypes.FromNativeString(nativeDescription->ServiceTypeName), InitializationData = NativeTypes.FromNativeBytes(nativeDescription->InitializationData, nativeDescription->InitializationDataSize), }; var nativeMetrics = (NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION *)nativeDescription->Metrics; for (int i = 0; i < (int)nativeDescription->MetricCount; i++) { var item = ServiceLoadMetricDescription.CreateFromNative((IntPtr)(nativeMetrics + i), isStateful); description.Metrics.Add(item); } return(description); }
// Copy ctor internal ServiceLoadMetricDescription(ServiceLoadMetricDescription other) : this(other.Name, other.primaryDefaultLoad, other.secondaryDefaultLoad, other.Weight) { }
internal static void Validate(ServiceLoadMetricDescription serviceLoadMetricDescription) { Requires.Argument <ServiceLoadMetricDescription>("serviceLoadMetricDescription", serviceLoadMetricDescription).NotNull(); Requires.Argument <string>("serviceLoadMetricDescription.Name", serviceLoadMetricDescription.Name).NotNull(); }