Beispiel #1
0
 private static void ValidateGetCluster(AzureHDInsightCluster expected, AzureHDInsightCluster actual)
 {
     Assert.AreEqual(expected.Name, actual.Name);
     Assert.AreEqual(expected.Version, actual.Version);
     Assert.AreEqual(expected.HttpUserName, actual.HttpUserName);
     Assert.AreEqual(expected.HttpPassword, actual.HttpPassword);
 }
        public void CanGrantAccessToHttpServices()
        {
            IHDInsightCertificateCredential creds       = GetValidCredentials();
            AzureHDInsightCluster           testCluster = GetClusterWithHttpAccessDisabled(creds);
            AzureHDInsightCluster           cluster     = EnableHttpAccessToCluster(
                creds, testCluster, TestCredentials.AzureUserName, TestCredentials.AzurePassword);

            Assert.IsNotNull(cluster);
            Assert.AreEqual(cluster.HttpUserName, TestCredentials.AzureUserName);
            Assert.AreEqual(cluster.HttpPassword, TestCredentials.AzurePassword);
        }
        public void CanGrantHDInsightRdpAccess()
        {
            var rdpUserName = "******";
            IHDInsightCertificateCredential creds       = GetValidCredentials();
            AzureHDInsightCluster           testCluster = GetClusterWithRdpAccessDisabled(creds);
            AzureHDInsightCluster           cluster     = EnableRdpAccessToCluster(
                creds, testCluster, rdpUserName, TestCredentials.AzurePassword, DateTime.UtcNow.AddDays(6));

            Assert.NotNull(cluster);
            Assert.Equal(cluster.RdpUserName, rdpUserName);
        }
        public void CanRevokeAccessToRdpServices()
        {
            IHDInsightCertificateCredential creds       = GetValidCredentials();
            AzureHDInsightCluster           testCluster = GetClusterWithRdpAccessDisabled(creds);

            EnableRdpAccessToCluster(creds, testCluster, TestCredentials.AzureUserName, TestCredentials.AzurePassword,
                                     DateTime.UtcNow.AddDays(6));
            AzureHDInsightCluster cluster = DisableRdpAccessToCluster(creds, testCluster);

            Assert.NotNull(cluster);
            Assert.True(string.IsNullOrEmpty(cluster.RdpUserName));
        }
        public void CanRevokeAccessToHttpServices()
        {
            IHDInsightCertificateCredential creds       = GetValidCredentials();
            AzureHDInsightCluster           testCluster = GetClusterWithHttpAccessDisabled(creds);

            EnableHttpAccessToCluster(creds, testCluster, TestCredentials.AzureUserName, TestCredentials.AzurePassword);
            AzureHDInsightCluster cluster = DisableHttpAccessToCluster(creds, testCluster);

            Assert.IsNotNull(cluster);
            Assert.IsTrue(string.IsNullOrEmpty(cluster.HttpUserName));
            Assert.IsTrue(string.IsNullOrEmpty(cluster.HttpPassword));
        }
        private static AzureHDInsightCluster EnableHttpAccessToCluster(
            IHDInsightCertificateCredential creds, AzureHDInsightCluster containerWithHttpAccessDisabled, string httpUserName, string httpPassword)
        {
            IManageAzureHDInsightHttpAccessCommand httpManagementClient =
                ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateManageHttpAccess();

            httpManagementClient.CurrentSubscription = GetCurrentSubscription();
            httpManagementClient.Credential          = GetPSCredential(httpUserName, httpPassword);
            httpManagementClient.Name     = containerWithHttpAccessDisabled.Name;
            httpManagementClient.Location = containerWithHttpAccessDisabled.Location;
            httpManagementClient.Enable   = true;
            httpManagementClient.EndProcessing();
            return(httpManagementClient.Output.First());
        }
        private static AzureHDInsightCluster DisableRdpAccessToCluster(
            IHDInsightCertificateCredential creds, AzureHDInsightCluster containerWithRdpAccessDisabled)
        {
            IManageAzureHDInsightRdpAccessCommand rdpManagementClient =
                ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateManageRdpAccess();

            rdpManagementClient.CurrentSubscription = GetCurrentSubscription();
            rdpManagementClient.RdpCredential       = GetAzurePsCredentials();
            rdpManagementClient.Name     = containerWithRdpAccessDisabled.Name;
            rdpManagementClient.Location = containerWithRdpAccessDisabled.Location;
            rdpManagementClient.Enable   = false;
            rdpManagementClient.EndProcessing();
            return(rdpManagementClient.Output.First());
        }
        internal static void RevokeHttpAccessToCluster(
            IHDInsightCertificateCredential connectionCredentials, AzureHDInsightCluster cluster, IRunspace runspace)
        {
            IPipelineResult results =
                runspace.NewPipeline()
                        .AddCommand(CmdletConstants.RevokeAzureHDInsightHttpAccess)
                        .WithParameter(CmdletConstants.Location, cluster.Location)
                        .WithParameter(CmdletConstants.Name, cluster.Name)
                        .Invoke();

            AzureHDInsightCluster accessRevokedCluster = GetCluster(connectionCredentials, cluster.Name, runspace);
            Assert.IsNotNull(accessRevokedCluster);
            Assert.IsTrue(string.IsNullOrEmpty(accessRevokedCluster.HttpUserName));
            Assert.IsTrue(string.IsNullOrEmpty(accessRevokedCluster.HttpPassword));
        }
        internal static void RevokeRdpAccessToCluster(
            IHDInsightCertificateCredential connectionCredentials, AzureHDInsightCluster cluster, IRunspace runspace)
        {
            IPipelineResult results =
                runspace.NewPipeline()
                .AddCommand(CmdletConstants.RevokeAzureHDInsightRdpAccess)
                .WithParameter(CmdletConstants.Location, cluster.Location)
                .WithParameter(CmdletConstants.Name, cluster.Name)
                .Invoke();

            AzureHDInsightCluster accessRevokedCluster = GetCluster(connectionCredentials, cluster.Name, runspace);

            Assert.NotNull(accessRevokedCluster);
            Assert.True(string.IsNullOrEmpty(accessRevokedCluster.RdpUserName));
        }
Beispiel #10
0
        public void ICanCallThe_Get_ClusterHDInsightClusterCmdlet()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GetAzureHDInsightCluster)
                    .Invoke();

                IEnumerable <AzureHDInsightCluster> clusters = results.Results.ToEnumerable <AzureHDInsightCluster>();
                AzureHDInsightCluster wellKnownCluster       = clusters.FirstOrDefault(cluster => cluster.Name == TestCredentials.WellKnownCluster.DnsName);
                Assert.IsNotNull(wellKnownCluster);
            }
        }
Beispiel #11
0
        public void ICanCallThe_Get_ClusterHDInsightClusterCmdlet_WithADnsName()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GetAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName)
                    .Invoke();
                Assert.AreEqual(1, results.Results.Count);
                AzureHDInsightCluster cluster = results.Results.ToEnumerable <AzureHDInsightCluster>().Last();
                ValidateGetCluster(cluster);
            }
        }
        private static AzureHDInsightCluster EnableRdpAccessToCluster(
            IHDInsightCertificateCredential creds, AzureHDInsightCluster containerWithRdpAccessDisabled, string rdpUserName, string rdpPassword, DateTime expiry)
        {
            IManageAzureHDInsightRdpAccessCommand rdpManagementClient =
                ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateManageRdpAccess();

            rdpManagementClient.CurrentSubscription = GetCurrentSubscription();
            rdpManagementClient.RdpCredential       = GetPSCredential(rdpUserName, rdpPassword);
            rdpManagementClient.Name            = containerWithRdpAccessDisabled.Name;
            rdpManagementClient.Location        = containerWithRdpAccessDisabled.Location;
            rdpManagementClient.RdpAccessExpiry = expiry;
            rdpManagementClient.Enable          = true;

            rdpManagementClient.EndProcessing();
            return(rdpManagementClient.Output.First());
        }
Beispiel #13
0
        public void ICanCreateAClusterWithThreeOrMoreAsvAccountsUsingPowerShell()
        {
            string dnsName         = this.GetRandomClusterName();
            var    storageAccounts = GetWellKnownStorageAccounts().ToList();

            Assert.IsTrue(storageAccounts.Count >= 3);

            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.NewAzureHDInsightClusterConfig)
                    .WithParameter(CmdletConstants.ClusterSizeInNodes, 3)
                    .AddCommand(CmdletConstants.SetAzureHDInsightDefaultStorage)
                    .WithParameter(CmdletConstants.StorageAccountName, TestCredentials.Environments[0].DefaultStorageAccount.Name)
                    .WithParameter(CmdletConstants.StorageAccountKey, TestCredentials.Environments[0].DefaultStorageAccount.Key)
                    .WithParameter(CmdletConstants.StorageContainerName, TestCredentials.Environments[0].DefaultStorageAccount.Container)
                    .AddCommand(CmdletConstants.AddAzureHDInsightStorage)
                    .WithParameter(CmdletConstants.StorageAccountName, storageAccounts[0].Name)
                    .WithParameter(CmdletConstants.StorageAccountKey, storageAccounts[0].Key)
                    .AddCommand(CmdletConstants.AddAzureHDInsightStorage)
                    .WithParameter(CmdletConstants.StorageAccountName, storageAccounts[1].Name)
                    .WithParameter(CmdletConstants.StorageAccountKey, storageAccounts[1].Key)
                    .AddCommand(CmdletConstants.AddAzureHDInsightStorage)
                    .WithParameter(CmdletConstants.StorageAccountName, storageAccounts[2].Name)
                    .WithParameter(CmdletConstants.StorageAccountKey, storageAccounts[2].Key)
                    .AddCommand(CmdletConstants.NewAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Name, dnsName)
                    .WithParameter(CmdletConstants.Location, CmdletConstants.EastUs)
                    .WithParameter(CmdletConstants.Credential, GetPSCredential("hadoop", this.GetRandomValidPassword()))
                    .Invoke();

                AzureHDInsightCluster clusterFromPowershell = results.Results.ToEnumerable <AzureHDInsightCluster>().First();
                List <AzureHDInsightStorageAccount> storageAccountsFromPowershell = clusterFromPowershell.StorageAccounts.ToList();
                Assert.AreEqual(3, storageAccountsFromPowershell.Count);

                foreach (WabStorageAccountConfiguration storageAccount in storageAccounts)
                {
                    AzureHDInsightStorageAccount additionalStorageAccountFromOutput =
                        storageAccountsFromPowershell.FirstOrDefault(acc => acc.StorageAccountName == storageAccount.Name);
                    Assert.IsNotNull(additionalStorageAccountFromOutput, "Storage account " + storageAccount.Name + " was not found");
                    Assert.AreEqual(storageAccount.Key, additionalStorageAccountFromOutput.StorageAccountKey);
                }
            }
        }
        private static AzureHDInsightCluster GetClusterWithRdpAccessDisabled(IHDInsightCertificateCredential creds)
        {
            IGetAzureHDInsightClusterCommand client = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();

            client.CurrentSubscription = GetCurrentSubscription();
            client.EndProcessing();
            List <AzureHDInsightCluster> clusters = client.Output.ToList();
            AzureHDInsightCluster        containerWithRdpAccessDisabled = clusters.FirstOrDefault(cluster => cluster.RdpUserName.IsNullOrEmpty());

            if (containerWithRdpAccessDisabled == null)
            {
                containerWithRdpAccessDisabled = clusters.Last();
                DisableRdpAccessToCluster(creds, containerWithRdpAccessDisabled);
            }

            return(containerWithRdpAccessDisabled);
        }
Beispiel #15
0
        private static void ValidateGetCluster(AzureHDInsightCluster cluster)
        {
            Assert.AreEqual(TestCredentials.WellKnownCluster.DnsName, cluster.Name);
            Assert.AreEqual(TestCredentials.WellKnownCluster.Version, cluster.Version);
            WabStorageAccountConfiguration defaultStorageAccount = GetWellKnownStorageAccounts().First();

            Assert.AreEqual(defaultStorageAccount.Key, cluster.DefaultStorageAccount.StorageAccountKey);
            Assert.AreEqual(defaultStorageAccount.Name, cluster.DefaultStorageAccount.StorageAccountName);
            Assert.AreEqual(defaultStorageAccount.Container, cluster.DefaultStorageAccount.StorageContainerName);
            foreach (WabStorageAccountConfiguration account in GetWellKnownStorageAccounts().Skip(1))
            {
                AzureHDInsightStorageAccount deserializedAccount =
                    cluster.StorageAccounts.FirstOrDefault(acc => acc.StorageAccountName == account.Name);
                Assert.IsNotNull(deserializedAccount, account.Name);
                Assert.AreEqual(account.Key, deserializedAccount.StorageAccountKey);
            }
        }
        internal static AzureHDInsightCluster GetClusterWithHttpAccessDisabled(IRunspace runspace)
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();
            IPipelineResult results =
                runspace.NewPipeline()
                .AddCommand(CmdletConstants.GetAzureHDInsightCluster)
                .Invoke();

            List <AzureHDInsightCluster> testClusters = results.Results.ToEnumerable <AzureHDInsightCluster>().ToList();
            AzureHDInsightCluster        testCluster  = testClusters.FirstOrDefault(cluster => cluster.HttpUserName.IsNullOrEmpty());

            if (testCluster == null)
            {
                testCluster = testClusters.Last();
                RevokeHttpAccessToCluster(creds, testCluster, runspace);
            }

            return(testCluster);
        }
        public void CanGrantHttpAccessToHDInsightCluster()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                AzureHDInsightCluster cluster = GetClusterWithHttpAccessDisabled(runspace);
                IPipelineResult       results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GrantAzureHDInsightHttpAccess)
                    .WithParameter(CmdletConstants.Location, cluster.Location)
                    .WithParameter(CmdletConstants.Name, cluster.Name)
                    .WithParameter(CmdletConstants.Credential, GetAzurePsCredentials())
                    .Invoke();

                AzureHDInsightCluster accessgrantedCluster = GetCluster(creds, cluster.Name, runspace);
                Assert.IsNotNull(accessgrantedCluster);
                Assert.AreEqual(accessgrantedCluster.HttpUserName, TestCredentials.AzureUserName);
                Assert.AreEqual(accessgrantedCluster.HttpPassword, TestCredentials.AzurePassword);
            }
        }
        public void CanGrantRdpAccessToHDInsightCluster()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                AzureHDInsightCluster cluster = GetClusterWithRdpAccessDisabled(runspace);
                IPipelineResult       results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GrantAzureHDInsightRdpAccess)
                    .WithParameter(CmdletConstants.Location, cluster.Location)
                    .WithParameter(CmdletConstants.Name, cluster.Name)
                    .WithParameter(CmdletConstants.RdpCredential, GetAzurePsCredentials())
                    .WithParameter(CmdletConstants.RdpAccessExpiry, DateTime.UtcNow.AddDays(6))
                    .Invoke();

                AzureHDInsightCluster accessgrantedCluster = GetCluster(creds, cluster.Name, runspace);
                Assert.NotNull(accessgrantedCluster);
                Assert.Equal(accessgrantedCluster.RdpUserName, TestCredentials.AzureUserName);
            }
        }
Beispiel #19
0
        private static void ValidateGetCluster(AzureHDInsightCluster cluster)
        {
            Assert.AreEqual(TestCredentials.WellKnownCluster.DnsName, cluster.Name);
            Assert.AreEqual(TestCredentials.HadoopUserName, cluster.HttpUserName);
            Assert.AreEqual(TestCredentials.AzurePassword, cluster.HttpPassword);
            Assert.AreEqual(ClusterState.Running, cluster.State);
            Assert.IsFalse(string.IsNullOrEmpty(cluster.ConnectionUrl));
            Assert.AreEqual(VersionStatus.Compatible.ToString(), cluster.VersionStatus);
            Assert.AreEqual(TestCredentials.WellKnownCluster.Version, cluster.Version);
            WabStorageAccountConfiguration defaultStorageAccount = GetWellKnownStorageAccounts().First();

            Assert.AreEqual(defaultStorageAccount.Key, cluster.DefaultStorageAccount.StorageAccountKey);
            Assert.AreEqual(defaultStorageAccount.Name, cluster.DefaultStorageAccount.StorageAccountName);
            Assert.AreEqual(defaultStorageAccount.Container, cluster.DefaultStorageAccount.StorageContainerName);
            foreach (WabStorageAccountConfiguration account in GetWellKnownStorageAccounts().Skip(1))
            {
                AzureHDInsightStorageAccount deserializedAccount =
                    cluster.StorageAccounts.FirstOrDefault(acc => acc.StorageAccountName == account.Name);
                Assert.IsNotNull(deserializedAccount, account.Name);
                Assert.AreEqual(account.Key, deserializedAccount.StorageAccountKey);
            }
        }
Beispiel #20
0
        public void ICanCallThe_Get_ClusterHDInsightClusterCmdlet_WithDebug()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                var logWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = logWriter;
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GetAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Debug, null)
                    .Invoke();
                IEnumerable <AzureHDInsightCluster> clusters = results.Results.ToEnumerable <AzureHDInsightCluster>();
                AzureHDInsightCluster wellKnownCluster       = clusters.FirstOrDefault(cluster => cluster.Name == TestCredentials.WellKnownCluster.DnsName);
                Assert.IsNotNull(wellKnownCluster);
                ValidateGetCluster(wellKnownCluster);

                string expectedLogMessage = "Getting hdinsight clusters for subscriptionid : ";
                Assert.IsTrue(logWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();
            }
        }
        protected string GetClusterConnection(string resourceGroupName, string clusterName)
        {
            if (clusterName.Contains("."))
            {
                return(clusterName);
            }
            var cluster = HDInsightManagementClient.GetCluster(resourceGroupName, clusterName);

            if (cluster.First() == null)
            {
                throw new NullReferenceException(string.Format("Could not find cluster {0} in resource group {1}",
                                                               clusterName, resourceGroupName));
            }
            var azurecluster = new AzureHDInsightCluster(cluster.First());
            var state        = azurecluster.ClusterState;

            if (
                !(state.Equals("Running", StringComparison.OrdinalIgnoreCase) ||
                  state.Equals("Operational", StringComparison.OrdinalIgnoreCase)))
            {
                throw new NotSupportedException(
                          string.Format("The cluster {0} is in the {1} state and canot be used at this time.", clusterName,
                                        state));
            }

            var httpEndpoint = azurecluster.HttpEndpoint;

            if (httpEndpoint == null)
            {
                throw new NotSupportedException(
                          string.Format(
                              "Cannot use cluster {0} because HTTP is not enabled on it. Please use the {1} cmdlet to HTTP and try again.",
                              azurecluster.Name, "Grant-" + Constants.CommandNames.AzureHDInsightHttpServicesAccess));
            }
            return(httpEndpoint);
        }
 private static void ValidateGetCluster(AzureHDInsightCluster cluster)
 {
     Assert.AreEqual(TestCredentials.WellKnownCluster.DnsName, cluster.Name);
     Assert.AreEqual(TestCredentials.HadoopUserName, cluster.HttpUserName);
     Assert.AreEqual(TestCredentials.AzurePassword, cluster.HttpPassword);
     Assert.AreEqual(ClusterState.Running, cluster.State);
     Assert.IsFalse(string.IsNullOrEmpty(cluster.ConnectionUrl));
     Assert.AreEqual(VersionStatus.Compatible.ToString(), cluster.VersionStatus);
     Assert.AreEqual(TestCredentials.WellKnownCluster.Version, cluster.Version);
     WabStorageAccountConfiguration defaultStorageAccount = GetWellKnownStorageAccounts().First();
     Assert.AreEqual(defaultStorageAccount.Key, cluster.DefaultStorageAccount.StorageAccountKey);
     Assert.AreEqual(defaultStorageAccount.Name, cluster.DefaultStorageAccount.StorageAccountName);
     Assert.AreEqual(defaultStorageAccount.Container, cluster.DefaultStorageAccount.StorageContainerName);
     foreach (WabStorageAccountConfiguration account in GetWellKnownStorageAccounts().Skip(1))
     {
         AzureHDInsightStorageAccount deserializedAccount =
             cluster.StorageAccounts.FirstOrDefault(acc => acc.StorageAccountName == account.Name);
         Assert.IsNotNull(deserializedAccount, account.Name);
         Assert.AreEqual(account.Key, deserializedAccount.StorageAccountKey);
     }
 }
 private static AzureHDInsightCluster DisableHttpAccessToCluster(
     IHDInsightCertificateCredential creds, AzureHDInsightCluster containerWithHttpAccessDisabled)
 {
     IManageAzureHDInsightHttpAccessCommand httpManagementClient =
         ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateManageHttpAccess();
     httpManagementClient.CurrentSubscription = GetCurrentSubscription();
     httpManagementClient.Credential = GetAzurePsCredentials();
     httpManagementClient.Name = containerWithHttpAccessDisabled.Name;
     httpManagementClient.Location = containerWithHttpAccessDisabled.Location;
     httpManagementClient.Enable = false;
     httpManagementClient.EndProcessing();
     return httpManagementClient.Output.First();
 }
Beispiel #24
0
        protected override void EndProcessing()
        {
            this.WriteWarning(string.Format(AzureHdInsightPowerShellConstants.AsmWarning, "Set-AzureRmHDInsightClusterSize"));
            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();
        }
 private static void ValidateGetCluster(AzureHDInsightCluster expected, AzureHDInsightCluster actual)
 {
     Assert.AreEqual(expected.Name, actual.Name);
     Assert.AreEqual(expected.Version, actual.Version);
     Assert.AreEqual(expected.HttpUserName, actual.HttpUserName);
     Assert.AreEqual(expected.HttpPassword, actual.HttpPassword);
 }
 private static void ValidateGetCluster(AzureHDInsightCluster cluster)
 {
     Assert.AreEqual(TestCredentials.WellKnownCluster.DnsName, cluster.Name);
     Assert.AreEqual(TestCredentials.WellKnownCluster.Version, cluster.Version);
     WabStorageAccountConfiguration defaultStorageAccount = GetWellKnownStorageAccounts().First();
     Assert.AreEqual(defaultStorageAccount.Key, cluster.DefaultStorageAccount.StorageAccountKey);
     Assert.AreEqual(defaultStorageAccount.Name, cluster.DefaultStorageAccount.StorageAccountName);
     Assert.AreEqual(defaultStorageAccount.Container, cluster.DefaultStorageAccount.StorageContainerName);
     foreach (WabStorageAccountConfiguration account in GetWellKnownStorageAccounts().Skip(1))
     {
         AzureHDInsightStorageAccount deserializedAccount =
             cluster.StorageAccounts.FirstOrDefault(acc => acc.StorageAccountName == account.Name);
         Assert.IsNotNull(deserializedAccount, account.Name);
         Assert.AreEqual(account.Key, deserializedAccount.StorageAccountKey);
     }
 }