Ejemplo n.º 1
0
        protected override void EndProcessing()
        {
            if (Cluster != null)
            {
                Name = Cluster.Name;
            }
            Name.ArgumentNotNull("Name");
            if (ClusterSizeInNodes < 1)
            {
                throw new ArgumentOutOfRangeException("ClusterSizeInNodes", "The requested ClusterSizeInNodes must be at least 1.");
            }
            try
            {
                command.Logger = Logger;
                var currentSubscription = GetCurrentSubscription(Subscription, Certificate);
                command.CurrentSubscription = currentSubscription;
                Func <Task> action = () => command.EndProcessing();
                var         token  = command.CancellationToken;

                //get cluster
                AzureHDInsightCluster cluster = Cluster;
                if (cluster == null)
                {
                    var getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();
                    getCommand.CurrentSubscription = currentSubscription;
                    getCommand.Name = Name;
                    var getTask = getCommand.EndProcessing();
                    this.WriteObject("This operation may take several minutes...");
                    while (!getTask.IsCompleted)
                    {
                        WriteDebugLog();
                        getTask.Wait(1000, token);
                    }
                    if (getTask.IsFaulted)
                    {
                        throw new AggregateException(getTask.Exception);
                    }
                    if (getCommand.Output == null || getCommand.Output.Count == 0)
                    {
                        throw new InvalidOperationException(string.Format("Could not find cluster {0}", Name));
                    }
                    cluster = getCommand.Output.First();
                }

                //prep cluster resize operation
                command.Location = cluster.Location;
                if (ClusterSizeInNodes < cluster.ClusterSizeInNodes)
                {
                    Task task;
                    if (cluster.ClusterType == ClusterType.Hadoop)
                    {
                        task = ConfirmSetAction(
                            "You are requesting a cluster size that is less than the current cluster size. We recommend not running jobs till the operation is complete as all running jobs will fail at end of resize operation and may impact the health of your cluster. Do you want to continue?",
                            "Continuing with set cluster operation.",
                            ClusterSizeInNodes.ToString(CultureInfo.InvariantCulture),
                            action);
                    }
                    else
                    {
                        task = action();
                    }
                    if (task == null)
                    {
                        throw new OperationCanceledException("The change cluster size operation was aborted.");
                    }
                    while (!task.IsCompleted)
                    {
                        WriteDebugLog();
                        task.Wait(1000, token);
                    }
                    if (task.IsFaulted)
                    {
                        throw new AggregateException(task.Exception);
                    }
                }
                else
                {
                    var task = action();
                    while (!task.IsCompleted)
                    {
                        WriteDebugLog();
                        task.Wait(1000, token);
                    }
                    if (task.IsFaulted)
                    {
                        throw new AggregateException(task.Exception);
                    }
                }
                //print cluster details
                foreach (var output in command.Output)
                {
                    WriteObject(output);
                }
                WriteDebugLog();
            }
            catch (Exception ex)
            {
                var type = ex.GetType();
                Logger.Log(Severity.Error, Verbosity.Normal, FormatException(ex));
                WriteDebugLog();
                if (type == typeof(AggregateException) || type == typeof(TargetInvocationException) ||
                    type == typeof(TaskCanceledException))
                {
                    ex.Rethrow();
                }
                else
                {
                    throw;
                }
            }

            WriteDebugLog();
        }