Esempio n. 1
0
        public void ICanCallThe_Connect_ClusterHDInsightClusterCmdlet_WithDebug()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                var logWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = logWriter;
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.UseAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName)
                    .WithParameter(CmdletConstants.Debug, null)
                    .Invoke();

                Assert.AreEqual(1, results.Results.Count);
                IAzureHDInsightConnectionSessionManager sessionManager =
                    ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null);
                AzureHDInsightClusterConnection currentCluster = sessionManager.GetCurrentCluster();
                Assert.IsNotNull(currentCluster);
                string expectedLogMessage = "Getting hdinsight clusters for subscriptionid : ";
                ValidateGetCluster(currentCluster.Cluster);
                Assert.IsTrue(logWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();
            }
        }
Esempio n. 2
0
        internal static AzureHDInsightJob RunJobInPowershell(
            IRunspace runspace, AzureHDInsightJobDefinition mapReduceJobDefinition, ClusterDetails cluster, bool debug, string expectedLogMessage)
        {
            IPipelineResult result = null;

            if (debug)
            {
                var logWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = logWriter;
                result =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.StartAzureHDInsightJob)
                    .WithParameter(CmdletConstants.Cluster, cluster.ConnectionUrl)
                    .WithParameter(CmdletConstants.Credential, GetPSCredential(cluster.HttpUserName, cluster.HttpPassword))
                    .WithParameter(CmdletConstants.JobDefinition, mapReduceJobDefinition)
                    .WithParameter(CmdletConstants.Debug, null)
                    .Invoke();

                Assert.IsTrue(logWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();
            }
            else
            {
                result =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.StartAzureHDInsightJob)
                    .WithParameter(CmdletConstants.Cluster, cluster.ConnectionUrl)
                    .WithParameter(CmdletConstants.Credential, GetPSCredential(cluster.HttpUserName, cluster.HttpPassword))
                    .WithParameter(CmdletConstants.JobDefinition, mapReduceJobDefinition)
                    .Invoke();
            }
            Assert.AreEqual(1, result.Results.Count);
            IEnumerable <AzureHDInsightJob> jobCreationCmdletResults = result.Results.ToEnumerable <AzureHDInsightJob>();
            AzureHDInsightJob jobCreationResults = jobCreationCmdletResults.First();

            Assert.IsNotNull(jobCreationResults.JobId, "Should get a non-null jobDetails id");

            return(jobCreationResults);
        }
Esempio n. 3
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();
            }
        }
        public void ICanCallThe_Get_HDInsightJobsCmdlet_WithDebug()
        {
            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                ClusterDetails testCluster = CmdletScenariosTestCaseBase.GetHttpAccessEnabledCluster();
                var            logWriter   = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = logWriter;
                IPipelineResult results =
                    runspace.NewPipeline()
                    .AddCommand(CmdletConstants.GetAzureHDInsightJob)
                    .WithParameter(CmdletConstants.Cluster, testCluster.ConnectionUrl)
                    .WithParameter(CmdletConstants.Credential, GetPSCredential(testCluster.HttpUserName, testCluster.HttpPassword))
                    .WithParameter(CmdletConstants.Debug, null)
                    .Invoke();
                IEnumerable <AzureHDInsightJob> jobHistory = results.Results.ToEnumerable <AzureHDInsightJob>();

                JobList expectedJobHistory = HDInsightGetJobsCommandTests.GetJobHistory(testCluster.ConnectionUrl);
                Assert.AreEqual(expectedJobHistory.Jobs.Count, jobHistory.Count(), "Should have {0} jobs.", expectedJobHistory.Jobs.Count);
                string expectedLogMessage = "Listing jobs";
                Assert.IsTrue(logWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();
            }
        }
Esempio n. 5
0
        public void ICanCreateAClusterUsingPowerShellAndConfig_WithDebug()
        {
            IHDInsightCertificateCredential creds = GetValidCredentials();
            var coreConfig = new Hashtable();

            coreConfig.Add("hadoop.logfile.size", "10000");

            string dnsName = this.GetRandomClusterName();

            using (IRunspace runspace = this.GetPowerShellRunspace())
            {
                var getCommandLogWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = getCommandLogWriter;
                IGetAzureHDInsightClusterCommand getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();
                getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();
                getCommand.CurrentSubscription = GetCurrentSubscription();
                getCommand.Logger = getCommandLogWriter;
                getCommand.EndProcessing();
                int expected = getCommand.Output.Count();

                string expectedLogMessage = "Getting hdinsight clusters for subscriptionid : " + creds.SubscriptionId.ToString();
                Assert.IsTrue(getCommandLogWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();

                var newClusterCommandLogWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = newClusterCommandLogWriter;
                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.AddAzureHDInsightConfigValues)
                    .WithParameter(CmdletConstants.CoreConfig, coreConfig)
                    .AddCommand(CmdletConstants.NewAzureHDInsightCluster)
                    .WithParameter(CmdletConstants.Name, dnsName)
                    .WithParameter(CmdletConstants.Debug, null)
                    .WithParameter(CmdletConstants.Version, TestCredentials.WellKnownCluster.Version)
                    .WithParameter(CmdletConstants.Location, CmdletConstants.EastUs)
                    .WithParameter(CmdletConstants.Credential, GetPSCredential("hadoop", this.GetRandomValidPassword()))
                    .Invoke();

                Assert.AreEqual(1, results.Results.Count);
                Assert.AreEqual(dnsName, results.Results.ToEnumerable <AzureHDInsightCluster>().First().Name);

                expectedLogMessage = string.Format(
                    CultureInfo.InvariantCulture, "Creating cluster '{0}' in location {1}", dnsName, CmdletConstants.EastUs);
                Assert.IsTrue(newClusterCommandLogWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                BufferingLogWriterFactory.Reset();

                getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();
                getCommand.CurrentSubscription = GetCurrentSubscription();
                getCommand.Name = dnsName;

                getCommand.EndProcessing();
                Assert.AreEqual(1, getCommand.Output.Count);
                Assert.AreEqual(dnsName, getCommand.Output.ElementAt(0).Name);
                var deleteClusterCommandLogWriter = new PowershellLogWriter();
                BufferingLogWriterFactory.Instance = deleteClusterCommandLogWriter;
                results = runspace.NewPipeline().AddCommand(CmdletConstants.RemoveAzureHDInsightCluster)
                          .WithParameter(CmdletConstants.Name, dnsName)
                          .WithParameter(CmdletConstants.Debug, null)
                          .Invoke();

                Assert.AreEqual(0, results.Results.Count);
                expectedLogMessage = string.Format(
                    CultureInfo.InvariantCulture, "Deleting cluster '{0}' in location {1}", dnsName, CmdletConstants.EastUs);
                Assert.IsTrue(deleteClusterCommandLogWriter.Buffer.Any(message => message.Contains(expectedLogMessage)));
                getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();
                getCommand.CurrentSubscription = GetCurrentSubscription();

                getCommand.EndProcessing();
                Assert.AreEqual(expected, getCommand.Output.Count);
                BufferingLogWriterFactory.Reset();
            }
        }