public void ICanCallThe_Connect_ClusterHDInsightClusterCmdlet_MoreThanOnce() { IHDInsightCertificateCredential creds = GetValidCredentials(); using (IRunspace runspace = this.GetPowerShellRunspace()) { IHDInsightCertificateCredential credentials = GetValidCredentials(); IPipelineResult clusterResults = runspace.NewPipeline() .AddCommand(CmdletConstants.GetAzureHDInsightCluster) .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName) .Invoke(); IEnumerable <AzureHDInsightCluster> clusters = clusterResults.Results.ToEnumerable <AzureHDInsightCluster>(); foreach (AzureHDInsightCluster cluster in clusters) { IPipelineResult results = runspace.NewPipeline() .AddCommand(CmdletConstants.UseAzureHDInsightCluster) .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName) .Invoke(); Assert.AreEqual(1, results.Results.Count); IAzureHDInsightConnectionSessionManager sessionManager = ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null); AzureHDInsightClusterConnection currentCluster = sessionManager.GetCurrentCluster(); Assert.IsNotNull(currentCluster); ValidateGetCluster(cluster, currentCluster.Cluster); } } }
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(); } }
private static void ConnectToCluster(IRunspace runspace, IHDInsightCertificateCredential creds) { IPipelineResult results = runspace.NewPipeline() .AddCommand(CmdletConstants.UseAzureHDInsightCluster) .WithParameter(CmdletConstants.Name, TestCredentials.WellKnownCluster.DnsName) .Invoke(); Assert.AreEqual(1, results.Results.Count); IAzureHDInsightConnectionSessionManager sessionManager = ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(null); AzureHDInsightClusterConnection currentCluster = sessionManager.GetCurrentCluster(); ValidateGetCluster(currentCluster.Cluster); }
public static AzureHDInsightClusterConnection AssertValidConnection(this PSCmdlet cmdlet) { IAzureHDInsightConnectionSessionManager sessionManager = ServiceLocator.Instance.Locate <IAzureHDInsightConnectionSessionManagerFactory>().Create(cmdlet.SessionState); AzureHDInsightClusterConnection currentConnection = sessionManager.GetCurrentCluster(); if (currentConnection == null) { cmdlet.ThrowTerminatingError( new ErrorRecord( new NotSupportedException("Please connect to a valid Azure HDInsight cluster before calling this cmdlet."), "1024", ErrorCategory.ConnectionError, cmdlet)); } return(currentConnection); }