public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(ResourceId);
                this.ClusterName       = resourceIdentifier.ResourceName;
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
            }

            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ClusterName       = this.InputObject.Name;
                this.ResourceGroupName = this.InputObject.ResourceGroup;
            }

            if (ResourceGroupName == null)
            {
                ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
            }

            if (ShouldProcess(ClusterName))
            {
                AutoscaleConfigurationUpdateParameter parameter = new AutoscaleConfigurationUpdateParameter();
                HDInsightManagementClient.UpdateAutoScaleConfiguration(ResourceGroupName, ClusterName, parameter);

                Cluster cluster = HDInsightManagementClient.Get(ResourceGroupName, ClusterName);
                WriteObject(new AzureHDInsightCluster(cluster));
            }
        }
        public override void ExecuteCmdlet()
        {
            AzureHDInsightAutoscale autoscaleConfiguration = null;

            if (this.IsParameterBound(c => c.InputObject))
            {
                autoscaleConfiguration = InputObject?.ComputeProfile?.Roles?.FirstOrDefault(role => role.Name.Equals("workernode"))?.AutoscaleConfiguration;
            }
            else
            {
                if (this.IsParameterBound(c => c.ResourceId))
                {
                    var resourceIdentifier = new ResourceIdentifier(ResourceId);
                    this.ClusterName       = resourceIdentifier.ResourceName;
                    this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                }

                if (ClusterName != null && ResourceGroupName == null)
                {
                    ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
                }
                var cluster   = HDInsightManagementClient.Get(ResourceGroupName, ClusterName);
                var autoscale = Utils.ExtractWorkerNode(cluster)?.AutoscaleConfiguration;
                autoscaleConfiguration = autoscale != null ? new AzureHDInsightAutoscale(autoscale) : null;
            }

            WriteObject(autoscaleConfiguration);
        }
示例#3
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(ResourceId);
                this.ClusterName       = resourceIdentifier.ResourceName;
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
            }

            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ClusterName       = this.InputObject.Name;
                this.ResourceGroupName = this.InputObject.ResourceGroup;
            }

            if (ClusterName != null && ResourceGroupName == null)
            {
                ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
            }

            var       clusterBeforeUpdate = HDInsightManagementClient.Get(ResourceGroupName, ClusterName);
            Autoscale autoscaleConfig     = Utils.ExtractWorkerNode(clusterBeforeUpdate)?.AutoscaleConfiguration;

            if (autoscaleConfig == null)
            {
                autoscaleConfig = new Autoscale();
            }

            switch (ParameterSetName)
            {
            case LoadAutoscaleByNameParameterSet:
            case LoadAutoscaleByResourceIdParameterSet:
            case LoadAutoscaleByInputObjectParameterSet:
                // override Recurrence to support switch from schedule to load
                autoscaleConfig.Recurrence = null;

                if (autoscaleConfig.Capacity == null)
                {
                    autoscaleConfig.Capacity = new AutoscaleCapacity(MinWorkerNodeCount, MaxWorkerNodeCount);
                }
                else
                {
                    if (this.IsParameterBound(c => c.MinWorkerNodeCount))
                    {
                        autoscaleConfig.Capacity.MinInstanceCount = MinWorkerNodeCount;
                    }

                    if (this.IsParameterBound(c => c.MaxWorkerNodeCount))
                    {
                        autoscaleConfig.Capacity.MaxInstanceCount = MaxWorkerNodeCount;
                    }
                }
                break;

            case ScheduleAutoscaleByNameParameterSet:
            case ScheduleAutoscaleByResourceIdParameterSet:
            case ScheduleAutoscaleByInputObjectParameterSet:
                // override Capacity to support switch from Load to Schedule
                autoscaleConfig.Capacity = null;

                if (autoscaleConfig.Recurrence == null)
                {
                    var schedules = Condition?.Select(conditon => conditon.ToAutoscaleSchedule()).ToList();
                    autoscaleConfig.Recurrence = new AutoscaleRecurrence(TimeZone, schedules);
                }
                else
                {
                    if (this.IsParameterBound(c => c.TimeZone))
                    {
                        autoscaleConfig.Recurrence.TimeZone = TimeZone;
                    }

                    if (this.IsParameterBound(c => c.Condition))
                    {
                        autoscaleConfig.Recurrence.Schedule = Condition?.Select(conditon => conditon.ToAutoscaleSchedule()).ToList();
                    }
                }
                break;

            case AutoscaleConfigurationByNameParameterSet:
            case AutoscaleConfigurationByResourceIdParameterSet:
            case AutoscaleConfigurationByInputObjectParameterSet:
                autoscaleConfig = AutoscaleConfiguration?.ToAutoscale();
                break;

            default:
                break;
            }

            if (ShouldProcess(ClusterName))
            {
                HDInsightManagementClient.UpdateAutoScaleConfiguration(ResourceGroupName, ClusterName, new AutoscaleConfigurationUpdateParameter(autoscaleConfig));

                Cluster cluster = HDInsightManagementClient.Get(ResourceGroupName, ClusterName);
                WriteObject(new AzureHDInsightCluster(cluster));
            }
        }