/// <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, SingletonPartitionSchemeDescription obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.PartitionScheme, "PartitionScheme", PartitionSchemeConverter.Serialize); writer.WriteEndObject(); }
protected override void ProcessRecord() { PartitionSchemeDescription partitionSchemeDescription; ServiceDescription serviceDescription; var client = new ServiceFabricClientBuilder().ConnectAsync(ClusterEndPoint, ThumbPrint).Result; if (PartitionSchemeUniformInt64) { partitionSchemeDescription = new UniformInt64RangePartitionSchemeDescription(PartitionCount, LowKey.ToString(), HighKey.ToString()); } else if (PartitionSchemeNamed) { partitionSchemeDescription = new NamedPartitionSchemeDescription(PartitionCount, PartitionNames); } else { partitionSchemeDescription = new SingletonPartitionSchemeDescription(); } if (Stateless.IsPresent) { serviceDescription = new StatelessServiceDescription(new ServiceName(ServiceName), ServiceType, partitionSchemeDescription, InstanceCount, initializationData: InitializationData); } else { serviceDescription = new StatefulServiceDescription(new ServiceName(ServiceName), ServiceType, partitionSchemeDescription, TargetReplicaSetSize, MinReplicaSetSize, PersistedState, initializationData: InitializationData); } client.Services.CreateServiceAsync(ApplicationId, serviceDescription).Wait(); }
/// <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, SingletonPartitionSchemeDescription obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.PartitionScheme.ToString(), "PartitionScheme", JsonWriterExtensions.WriteStringValue); writer.WriteEndObject(); }
public void Singleton_Test() { var expected = HelperInstance.CreateDefaultDescription(); using (var pc = new PinCollection()) { var actual = SingletonPartitionSchemeDescription.CreateFromNative(expected.ToNative(pc)); HelperInstance.Compare(expected, actual); } }
private bool TryCreatePartitionDescription(out PartitionSchemeDescription psd) { psd = null; if (this.control.Package.Data.ContainsKey("PartitionSingleton")) { psd = new SingletonPartitionSchemeDescription(); return(true); } if (this.control.Package.Data.ContainsKey("PartitionNamed")) { NamedPartitionSchemeDescription d = new NamedPartitionSchemeDescription(); string nameListValue; if (!this.control.Package.Data.TryGetValue("PartitionNamedList", out nameListValue)) { log.Error("named partition specified, but no named list was found"); return(false); } string[] names = nameListValue.Split(PackageSettings.NamedPartitionSplitChar); for (int i = 0; i < names.Length; i++) { d.PartitionNames.Add(names[i]); } psd = d; return(true); } if (this.control.Package.Data.ContainsKey("PartitionUniform")) { UniformInt64RangePartitionSchemeDescription d = new UniformInt64RangePartitionSchemeDescription(); long low; long high; int count; if (!this.TryGetData("PartitionUniformLowKey", out low) || !this.TryGetData("PartitionUniformHighKey", out high) || !this.TryGetData("PartitionUniformCount", out count)) { return(false); } d.LowKey = low; d.HighKey = high; d.PartitionCount = count; psd = d; return(true); } return(false); }
/// <inheritdoc/> protected override void ProcessRecordInternal() { PartitionSchemeDescription partitionSchemeDescription = null; if (this.Named.IsPresent) { partitionSchemeDescription = new NamedPartitionSchemeDescription( count: this.Count, names: this.Names); } else if (this.Singleton.IsPresent) { partitionSchemeDescription = new SingletonPartitionSchemeDescription(); } else if (this.UniformInt64Range.IsPresent) { partitionSchemeDescription = new UniformInt64RangePartitionSchemeDescription( count: this.Count, lowKey: this.LowKey, highKey: this.HighKey); } ServiceDescription serviceDescription = null; if (this.Stateful.IsPresent) { serviceDescription = new StatefulServiceDescription( serviceName: this.ServiceName, serviceTypeName: this.ServiceTypeName, partitionDescription: partitionSchemeDescription, targetReplicaSetSize: this.TargetReplicaSetSize, minReplicaSetSize: this.MinReplicaSetSize, hasPersistedState: this.HasPersistedState, applicationName: this.ApplicationName, initializationData: this.InitializationData, placementConstraints: this.PlacementConstraints, correlationScheme: this.CorrelationScheme, serviceLoadMetrics: this.ServiceLoadMetrics, servicePlacementPolicies: this.ServicePlacementPolicies, defaultMoveCost: this.DefaultMoveCost, isDefaultMoveCostSpecified: this.IsDefaultMoveCostSpecified, servicePackageActivationMode: this.ServicePackageActivationMode, serviceDnsName: this.ServiceDnsName, scalingPolicies: this.ScalingPolicies, tagsRequiredToPlace: this.TagsRequiredToPlace, tagsRequiredToRun: this.TagsRequiredToRun, flags: this.Flags, replicaRestartWaitDurationSeconds: this.ReplicaRestartWaitDurationSeconds, quorumLossWaitDurationSeconds: this.QuorumLossWaitDurationSeconds, standByReplicaKeepDurationSeconds: this.StandByReplicaKeepDurationSeconds, servicePlacementTimeLimitSeconds: this.ServicePlacementTimeLimitSeconds, dropSourceReplicaOnMove: this.DropSourceReplicaOnMove, replicaLifecycleDescription: this.ReplicaLifecycleDescription, auxiliaryReplicaCount: this.AuxiliaryReplicaCount); } else if (this.Stateless.IsPresent) { serviceDescription = new StatelessServiceDescription( serviceName: this.ServiceName, serviceTypeName: this.ServiceTypeName, partitionDescription: partitionSchemeDescription, instanceCount: this.InstanceCount, applicationName: this.ApplicationName, initializationData: this.InitializationData, placementConstraints: this.PlacementConstraints, correlationScheme: this.CorrelationScheme, serviceLoadMetrics: this.ServiceLoadMetrics, servicePlacementPolicies: this.ServicePlacementPolicies, defaultMoveCost: this.DefaultMoveCost, isDefaultMoveCostSpecified: this.IsDefaultMoveCostSpecified, servicePackageActivationMode: this.ServicePackageActivationMode, serviceDnsName: this.ServiceDnsName, scalingPolicies: this.ScalingPolicies, tagsRequiredToPlace: this.TagsRequiredToPlace, tagsRequiredToRun: this.TagsRequiredToRun, minInstanceCount: this.MinInstanceCount, minInstancePercentage: this.MinInstancePercentage, flags: this.Flags, instanceCloseDelayDurationSeconds: this.InstanceCloseDelayDurationSeconds, instanceLifecycleDescription: this.InstanceLifecycleDescription, instanceRestartWaitDurationSeconds: this.InstanceRestartWaitDurationSeconds); } this.ServiceFabricClient.Services.CreateServiceAsync( applicationId: this.ApplicationId, serviceDescription: serviceDescription, serverTimeout: this.ServerTimeout, cancellationToken: this.CancellationToken).GetAwaiter().GetResult(); Console.WriteLine("Success!"); }
private bool TryCreatePartitionDescription(out PartitionSchemeDescription psd) { psd = null; if (this.control.Package.Data.ContainsKey("PartitionSingleton")) { psd = new SingletonPartitionSchemeDescription(); return true; } if (this.control.Package.Data.ContainsKey("PartitionNamed")) { NamedPartitionSchemeDescription d = new NamedPartitionSchemeDescription(); string nameListValue; if (!this.control.Package.Data.TryGetValue("PartitionNamedList", out nameListValue)) { log.Error("named partition specified, but no named list was found"); return false; } string[] names = nameListValue.Split(PackageSettings.NamedPartitionSplitChar); for (int i = 0; i < names.Length; i++) { d.PartitionNames.Add(names[i]); } psd = d; return true; } if (this.control.Package.Data.ContainsKey("PartitionUniform")) { UniformInt64RangePartitionSchemeDescription d = new UniformInt64RangePartitionSchemeDescription(); long low; long high; int count; if (!this.TryGetData("PartitionUniformLowKey", out low) || !this.TryGetData("PartitionUniformHighKey", out high) || !this.TryGetData("PartitionUniformCount", out count)) { return false; } d.LowKey = low; d.HighKey = high; d.PartitionCount = count; psd = d; return true; } return false; }
private ServiceDescription CreateServiceDescription(ServiceOperationDescription serviceOperationDescription) { string errorMessage; ServiceDescription serviceDescription; switch (serviceOperationDescription.ServiceKind) { case ArmServiceKind.Stateful: if (!this.ValidObjectType <StatefulServiceOperationDescription>(serviceOperationDescription, out errorMessage)) { throw new InvalidCastException(errorMessage); } var statefulOperation = (StatefulServiceOperationDescription)serviceOperationDescription; serviceDescription = new StatefulServiceDescription() { HasPersistedState = statefulOperation.HasPersistedState, MinReplicaSetSize = statefulOperation.MinReplicaSetSize, TargetReplicaSetSize = statefulOperation.TargetReplicaSetSize, QuorumLossWaitDuration = statefulOperation.QuorumLossWaitDuration, ReplicaRestartWaitDuration = statefulOperation.ReplicaRestartWaitDuration, StandByReplicaKeepDuration = statefulOperation.StandByReplicaKeepDuration }; break; case ArmServiceKind.Stateless: if (!this.ValidObjectType <StatelessServiceOperationDescription>(serviceOperationDescription, out errorMessage)) { throw new InvalidCastException(errorMessage); } var statelessOperation = (StatelessServiceOperationDescription)serviceOperationDescription; serviceDescription = new StatelessServiceDescription() { InstanceCount = statelessOperation.InstanceCount }; break; default: throw new ArgumentOutOfRangeException( nameof(serviceOperationDescription.ServiceKind), serviceOperationDescription.ServiceKind, $"{this.TraceType}: Unexpected ArmServiceKind"); } serviceDescription.ApplicationName = serviceOperationDescription.ApplicationName; serviceDescription.ServiceName = serviceOperationDescription.ServiceName; if (serviceOperationDescription.DefaultMoveCost.HasValue) { serviceDescription.DefaultMoveCost = (MoveCost)Enum.Parse( typeof(MoveCost), serviceOperationDescription.DefaultMoveCost.Value.ToString()); } serviceDescription.PlacementConstraints = serviceOperationDescription.PlacementConstraints; serviceDescription.ServiceTypeName = serviceOperationDescription.ServiceTypeName; if (serviceOperationDescription.CorrelationScheme != null) { foreach (var scheme in serviceOperationDescription.CorrelationScheme) { serviceDescription.Correlations.Add(this.GetServiceCorrelationDescription(scheme)); } } if (serviceOperationDescription.ServiceLoadMetrics != null) { foreach (var metric in serviceOperationDescription.ServiceLoadMetrics) { serviceDescription.Metrics.Add(this.GetServiceLoadMetricDescription(metric)); } } if (serviceOperationDescription.ServicePlacementPolicies != null) { foreach (var policy in serviceOperationDescription.ServicePlacementPolicies) { serviceDescription.PlacementPolicies.Add(this.GetServicePlacementPolicyDescription(policy)); } } PartitionSchemeDescription partitionSchemeDescription; switch (serviceOperationDescription.PartitionDescription.PartitionScheme) { case ArmPartitionScheme.Named: if (!this.ValidObjectType <ArmNamedPartitionDescription>(serviceOperationDescription.PartitionDescription, out errorMessage)) { throw new InvalidCastException(errorMessage); } var namedOperation = (ArmNamedPartitionDescription)serviceOperationDescription.PartitionDescription; partitionSchemeDescription = new NamedPartitionSchemeDescription(namedOperation.Names); break; case ArmPartitionScheme.Singleton: partitionSchemeDescription = new SingletonPartitionSchemeDescription(); break; case ArmPartitionScheme.UniformInt64Range: if (!this.ValidObjectType <ArmUniformInt64PartitionDescription>(serviceOperationDescription.PartitionDescription, out errorMessage)) { throw new InvalidCastException(errorMessage); } var uniformOperation = (ArmUniformInt64PartitionDescription)serviceOperationDescription.PartitionDescription; partitionSchemeDescription = new UniformInt64RangePartitionSchemeDescription() { HighKey = uniformOperation.HighKey, LowKey = uniformOperation.LowKey, PartitionCount = uniformOperation.Count }; break; default: throw new ArgumentOutOfRangeException( nameof(serviceOperationDescription.PartitionDescription.PartitionScheme), serviceOperationDescription.PartitionDescription.PartitionScheme, $"{this.TraceType}: Unexpected ArmPartitionScheme"); } serviceDescription.PartitionSchemeDescription = partitionSchemeDescription; return(serviceDescription); }