コード例 #1
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, ServiceResourceProperties obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.OsType, "osType", OperatingSystemTypesConverter.Serialize);
            writer.WriteEnumerableProperty(obj.CodePackages, "codePackages", ContainerCodePackagePropertiesConverter.Serialize);
            writer.WriteProperty(obj.HealthState, "healthState", HealthStateConverter.Serialize);
            writer.WriteProperty(obj.Status, "status", ServiceResourceStatusConverter.Serialize);
            if (obj.NetworkRefs != null)
            {
                writer.WriteEnumerableProperty(obj.NetworkRefs, "networkRefs", NetworkRefConverter.Serialize);
            }

            if (obj.Diagnostics != null)
            {
                writer.WriteProperty(obj.Diagnostics, "diagnostics", DiagnosticsRefConverter.Serialize);
            }

            if (obj.Description != null)
            {
                writer.WriteProperty(obj.Description, "description", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ReplicaCount != null)
            {
                writer.WriteProperty(obj.ReplicaCount, "replicaCount", JsonWriterExtensions.WriteIntValue);
            }

            writer.WriteEndObject();
        }
コード例 #2
0
        private void SetCommonProperties(ServiceResourceProperties properties)
        {
            // Required
            properties.ServiceTypeName      = this.Type;
            properties.PartitionDescription = SetPartitionDescription();

            // Optional
            if (this.IsParameterBound(c => c.ServicePackageActivationMode))
            {
                properties.ServicePackageActivationMode = this.ServicePackageActivationMode.ToString();
            }
            if (this.IsParameterBound(c => c.DefaultMoveCost))
            {
                properties.DefaultMoveCost = this.DefaultMoveCost.ToString();
            }
            if (this.IsParameterBound(c => c.PlacementConstraint))
            {
                properties.PlacementConstraints = this.PlacementConstraint;
            }
            if (this.IsParameterBound(c => c.Metric))
            {
                properties.ServiceLoadMetrics = this.Metric;
            }
            if (this.IsParameterBound(c => c.Correlation))
            {
                properties.CorrelationScheme = this.Correlation;
            }
        }
コード例 #3
0
 private void SetCommonProperties(ServiceResourceProperties properties)
 {
     if (this.IsParameterBound(c => c.ServicePackageActivationMode))
     {
         properties.ServicePackageActivationMode = this.ServicePackageActivationMode.ToString();
     }
     if (this.IsParameterBound(c => c.DefaultMoveCost))
     {
         properties.DefaultMoveCost = this.DefaultMoveCost.ToString();
     }
     if (this.IsParameterBound(c => c.PlacementConstraint))
     {
         properties.PlacementConstraints = this.PlacementConstraint;
     }
     if (this.IsParameterBound(c => c.Metric))
     {
         properties.ServiceLoadMetrics = this.Metric;
     }
     if (this.IsParameterBound(c => c.Correlation))
     {
         properties.CorrelationScheme = this.Correlation;
     }
     if (this.IsParameterBound(c => c.ServiceDnsName))
     {
         properties.ServiceDnsName = this.ServiceDnsName;
     }
 }
        /// <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, ServiceResourceProperties obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.OsType, "osType", OperatingSystemTypeConverter.Serialize);
            writer.WriteEnumerableProperty(obj.CodePackages, "codePackages", ContainerCodePackagePropertiesConverter.Serialize);
            writer.WriteProperty(obj.Status, "status", ResourceStatusConverter.Serialize);
            writer.WriteProperty(obj.HealthState, "healthState", HealthStateConverter.Serialize);
            if (obj.NetworkRefs != null)
            {
                writer.WriteEnumerableProperty(obj.NetworkRefs, "networkRefs", NetworkRefConverter.Serialize);
            }

            if (obj.Diagnostics != null)
            {
                writer.WriteProperty(obj.Diagnostics, "diagnostics", DiagnosticsRefConverter.Serialize);
            }

            if (obj.Description != null)
            {
                writer.WriteProperty(obj.Description, "description", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ReplicaCount != null)
            {
                writer.WriteProperty(obj.ReplicaCount, "replicaCount", JsonWriterExtensions.WriteIntValue);
            }

            if (obj.ExecutionPolicy != null)
            {
                writer.WriteProperty(obj.ExecutionPolicy, "executionPolicy", ExecutionPolicyConverter.Serialize);
            }

            if (obj.AutoScalingPolicies != null)
            {
                writer.WriteEnumerableProperty(obj.AutoScalingPolicies, "autoScalingPolicies", AutoScalingPolicyConverter.Serialize);
            }

            if (obj.StatusDetails != null)
            {
                writer.WriteProperty(obj.StatusDetails, "statusDetails", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.UnhealthyEvaluation != null)
            {
                writer.WriteProperty(obj.UnhealthyEvaluation, "unhealthyEvaluation", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.IdentityRefs != null)
            {
                writer.WriteEnumerableProperty(obj.IdentityRefs, "identityRefs", ServiceIdentityConverter.Serialize);
            }

            if (obj.DnsName != null)
            {
                writer.WriteProperty(obj.DnsName, "dnsName", JsonWriterExtensions.WriteStringValue);
            }

            writer.WriteEndObject();
        }
        private ServiceResource GetUpdatedServiceParams(PSManagedService inputObject = null)
        {
            ServiceResource currentService;

            if (inputObject == null)
            {
                currentService = SafeGetResource(() =>
                                                 this.SfrpMcClient.Services.Get(
                                                     this.ResourceGroupName,
                                                     this.ClusterName,
                                                     this.ApplicationName,
                                                     this.Name),
                                                 false);

                if (currentService == null)
                {
                    WriteError(new ErrorRecord(new InvalidOperationException($"Managed Service '{this.Name}' does not exist."),
                                               "ResourceDoesNotExist", ErrorCategory.InvalidOperation, null));
                    return(currentService);
                }
            }
            else
            {
                currentService = inputObject.ToServiceResource();
            }

            WriteVerbose($"Updating managed service '{this.Name}.'");

            if (this.IsParameterBound(c => c.Tag))
            {
                currentService.Tags = this.Tag?.Cast <DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string);
            }
            ServiceResourceProperties properties = currentService.Properties;

            if (this.Stateless.ToBool())
            {
                StatelessServiceProperties statelessProperties = properties as  StatelessServiceProperties;

                if (this.IsParameterBound(c => c.InstanceCount))
                {
                    statelessProperties.InstanceCount = this.InstanceCount;
                }

                if (this.IsParameterBound(c => c.MinInstancePercentage))
                {
                    statelessProperties.MinInstancePercentage = this.MinInstancePercentage;
                }
                if (this.IsParameterBound(c => c.MinInstanceCount))
                {
                    statelessProperties.MinInstanceCount = this.MinInstanceCount;
                }
            }
            else if (this.Stateful.ToBool())
            {
                StatefulServiceProperties statefulProperties = properties as StatefulServiceProperties;
                if (this.IsParameterBound(c => c.ServicePlacementTimeLimit))
                {
                    statefulProperties.ServicePlacementTimeLimit = this.ServicePlacementTimeLimit.ToString();
                }
                if (this.IsParameterBound(c => c.StandByReplicaKeepDuration))
                {
                    statefulProperties.StandByReplicaKeepDuration = this.StandByReplicaKeepDuration.ToString();
                }
                if (this.IsParameterBound(c => c.QuorumLossWaitDuration))
                {
                    statefulProperties.QuorumLossWaitDuration = this.QuorumLossWaitDuration.ToString();
                }
                if (this.IsParameterBound(c => c.ReplicaRestartWaitDuration))
                {
                    statefulProperties.ReplicaRestartWaitDuration = this.ReplicaRestartWaitDuration.ToString();
                }
                if (this.IsParameterBound(c => c.HasPersistedState))
                {
                    statefulProperties.HasPersistedState = this.HasPersistedState.ToBool();
                }
                if (this.IsParameterBound(c => c.MinReplicaSetSize))
                {
                    statefulProperties.MinReplicaSetSize = this.MinReplicaSetSize;
                }
                if (this.IsParameterBound(c => c.TargetReplicaSetSize))
                {
                    statefulProperties.TargetReplicaSetSize = this.TargetReplicaSetSize;
                }
            }
            SetCommonProperties(properties);

            return(currentService);
        }
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from, reader must be placed at first property.</param>
        /// <returns>The object Value.</returns>
        internal static ServiceResourceProperties GetFromJsonProperties(JsonReader reader)
        {
            var osType              = default(OperatingSystemType?);
            var codePackages        = default(IEnumerable <ContainerCodePackageProperties>);
            var networkRefs         = default(IEnumerable <NetworkRef>);
            var diagnostics         = default(DiagnosticsRef);
            var description         = default(string);
            var replicaCount        = default(int?);
            var autoScalingPolicies = default(IEnumerable <AutoScalingPolicy>);
            var status              = default(ResourceStatus?);
            var statusDetails       = default(string);
            var healthState         = default(HealthState?);
            var unhealthyEvaluation = default(string);

            do
            {
                var propName = reader.ReadPropertyName();
                if (string.Compare("osType", propName, StringComparison.Ordinal) == 0)
                {
                    osType = OperatingSystemTypeConverter.Deserialize(reader);
                }
                else if (string.Compare("codePackages", propName, StringComparison.Ordinal) == 0)
                {
                    codePackages = reader.ReadList(ContainerCodePackagePropertiesConverter.Deserialize);
                }
                else if (string.Compare("networkRefs", propName, StringComparison.Ordinal) == 0)
                {
                    networkRefs = reader.ReadList(NetworkRefConverter.Deserialize);
                }
                else if (string.Compare("diagnostics", propName, StringComparison.Ordinal) == 0)
                {
                    diagnostics = DiagnosticsRefConverter.Deserialize(reader);
                }
                else if (string.Compare("description", propName, StringComparison.Ordinal) == 0)
                {
                    description = reader.ReadValueAsString();
                }
                else if (string.Compare("replicaCount", propName, StringComparison.Ordinal) == 0)
                {
                    replicaCount = reader.ReadValueAsInt();
                }
                else if (string.Compare("autoScalingPolicies", propName, StringComparison.Ordinal) == 0)
                {
                    autoScalingPolicies = reader.ReadList(AutoScalingPolicyConverter.Deserialize);
                }
                else if (string.Compare("status", propName, StringComparison.Ordinal) == 0)
                {
                    status = ResourceStatusConverter.Deserialize(reader);
                }
                else if (string.Compare("statusDetails", propName, StringComparison.Ordinal) == 0)
                {
                    statusDetails = reader.ReadValueAsString();
                }
                else if (string.Compare("healthState", propName, StringComparison.Ordinal) == 0)
                {
                    healthState = HealthStateConverter.Deserialize(reader);
                }
                else if (string.Compare("unhealthyEvaluation", propName, StringComparison.Ordinal) == 0)
                {
                    unhealthyEvaluation = reader.ReadValueAsString();
                }
                else
                {
                    reader.SkipPropertyValue();
                }
            }while (reader.TokenType != JsonToken.EndObject);

            var serviceResourceProperties = new ServiceResourceProperties(
                osType: osType,
                codePackages: codePackages,
                networkRefs: networkRefs,
                diagnostics: diagnostics,
                description: description,
                replicaCount: replicaCount,
                autoScalingPolicies: autoScalingPolicies);

            serviceResourceProperties.Status              = status;
            serviceResourceProperties.StatusDetails       = statusDetails;
            serviceResourceProperties.HealthState         = healthState;
            serviceResourceProperties.UnhealthyEvaluation = unhealthyEvaluation;
            return(serviceResourceProperties);
        }