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);
        }
Ejemplo n.º 2
0
        private ServiceResource GetNewServiceParameters(string location)
        {
            ServiceResource service = new ServiceResource()
            {
                Tags       = this.Tag?.Cast <DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string),
                Location   = location,
                Properties = new ServiceResourceProperties()
            };

            switch (ParameterSetName)
            {
            case StatelessSingleton:
            case StatelessUniformInt64:
            case StatelessNamed:
                StatelessServiceProperties statelessProperties = new StatelessServiceProperties();
                // Required
                statelessProperties.InstanceCount = this.InstanceCount;

                // Optional
                if (this.IsParameterBound(c => c.MinInstancePercentage))
                {
                    statelessProperties.MinInstancePercentage = this.MinInstancePercentage;
                }
                if (this.IsParameterBound(c => c.MinInstanceCount))
                {
                    statelessProperties.MinInstanceCount = this.MinInstanceCount;
                }

                service.Properties = statelessProperties;
                break;

            case StatefulSingleton:
            case StatefulUniformInt64:
            case StatefulNamed:
                StatefulServiceProperties statefulProperties = new 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;
                }

                service.Properties = statefulProperties;
                break;

            default:
                throw new PSArgumentException("Invalid ParameterSetName");
            }
            SetCommonProperties(service.Properties);

            return(service);
        }