private IHDInsightCertificateCredential Create(IHDInsightCertificateCredential ignoreCreds) { return new HDInsightCertificateCredential() { Certificate = new X509Certificate2(this.creds.Certificate), Endpoint = new Uri(this.creds.Endpoint), DeploymentNamespace = this.creds.CloudServiceName, SubscriptionId = this.creds.SubscriptionId }; }
private IHDInsightCertificateCredential Create(IHDInsightCertificateCredential credentials) { credentials.ArgumentNotNull("credentials"); return new HDInsightCertificateCredential() { Certificate = credentials.Certificate, DeploymentNamespace = credentials.DeploymentNamespace, Endpoint = credentials.Endpoint, SubscriptionId = credentials.SubscriptionId }; }
public RdfeServiceRestSimulatorClient(IHDInsightCertificateCredential credentials, IAbstractionContext context) { var validCreds = IntegrationTestBase.GetValidCredentials() as IHDInsightCertificateCredential; if (validCreds == null || (credentials.Certificate.SubjectName != validCreds.Certificate.SubjectName && credentials.SubscriptionId != validCreds.SubscriptionId)) { throw new HttpLayerException(HttpStatusCode.Unauthorized, "User " + validCreds.SubscriptionId + " is not authorized"); } this.context = context; this.credentials = credentials; this.PollInterval = TimeSpan.FromMilliseconds(10); }
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(); }
public SubscriptionRegistrationSimulatorClient(IHDInsightCertificateCredential creds, IAbstractionContext context) { this.context = context; lock (locker) { if (subcriptions == null) { subcriptions = new Dictionary<Guid, List<string>>(); subcriptions.Add(IntegrationTestBase.GetValidCredentials().SubscriptionId, new List<string> { "East US 2" }); } } this.credentials = creds; }
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)); }
private static AzureHDInsightCluster GetClusterWithHttpAccessDisabled(IHDInsightCertificateCredential creds) { IGetAzureHDInsightClusterCommand client = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateGet(); client.CurrentSubscription = GetCurrentSubscription(); client.EndProcessing(); List<AzureHDInsightCluster> clusters = client.Output.ToList(); AzureHDInsightCluster containerWithHttpAccessDisabled = clusters.FirstOrDefault(cluster => cluster.HttpUserName.IsNullOrEmpty()); if (containerWithHttpAccessDisabled == null) { containerWithHttpAccessDisabled = clusters.Last(); DisableHttpAccessToCluster(creds, containerWithHttpAccessDisabled); } return containerWithHttpAccessDisabled; }
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 ICannotDeleteANonExistantClusterUsingPowerShell() { IHDInsightCertificateCredential creds = GetValidCredentials(); string invalidClusterName = Guid.NewGuid().ToString(); using (IRunspace runspace = this.GetPowerShellRunspace()) { try { runspace.NewPipeline() .AddCommand(CmdletConstants.RemoveAzureHDInsightCluster) .WithParameter(CmdletConstants.Name, invalidClusterName) .Invoke(); Assert.Fail("test failed"); } catch (CmdletInvocationException invokeException) { var invalidOperationException = invokeException.GetBaseException() as InvalidOperationException; Assert.IsNotNull(invalidOperationException); Assert.AreEqual("The cluster '" + invalidClusterName + "' doesn't exist.", invalidOperationException.Message); } } }
public void CanCallTheExecHiveCommand_UploadsFile() { IHDInsightCertificateCredential creds = GetValidCredentials(); using (IRunspace runspace = this.GetPowerShellRunspace()) { AzureHDInsightClusterConnection connection = ConnectToCluster(runspace, creds); var storageHandlerSimulator = new AzureHDInsightStorageHandlerSimulator(); AzureHDInsightStorageHandlerSimulatorFactory.Instance = storageHandlerSimulator; IInvokeHiveCommand execHiveCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateInvokeHive(); execHiveCommand.JobDefinition = new AzureHDInsightHiveJobDefinition { Query = "show tables", JobName = "show tables" }; execHiveCommand.CurrentSubscription = GetCurrentSubscription(); execHiveCommand.Connection = connection; execHiveCommand.EndProcessing(); string destinationPath = string.Format( CultureInfo.InvariantCulture, "http://{0}/{1}/user/{2}/", connection.Cluster.DefaultStorageAccount.StorageAccountName, connection.Cluster.DefaultStorageAccount.StorageContainerName, connection.Cluster.HttpUserName); string outputContent = execHiveCommand.Output.Last(); Assert.IsNotNull(storageHandlerSimulator.UploadedStream); storageHandlerSimulator.UploadedStream.Seek(0, SeekOrigin.Begin); string contents = new StreamReader(storageHandlerSimulator.UploadedStream).ReadToEnd(); Assert.AreEqual("show tables", contents); Assert.IsFalse(string.IsNullOrEmpty(storageHandlerSimulator.Path.OriginalString)); Assert.IsTrue(storageHandlerSimulator.Path.OriginalString.StartsWith(destinationPath, StringComparison.OrdinalIgnoreCase)); Assert.AreEqual(5, execHiveCommand.Output.Count()); Assert.AreEqual("hivesampletable", outputContent); } }
public async Task ICanHandleA_CancellationToken_Using_HttpClientAbstraction() { // Given I want to use an X509 Cert for authentication IHDInsightCertificateCredential credentials = IntegrationTestBase.GetValidCredentials(); // And I have a CancelationToken var token = new CancellationToken(true); // And I know when we started the request. var start = DateTime.Now; // And I have an Http Client try { using (var client = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>().Create(credentials.Certificate, new AbstractionContext(token), false)) { // And I set the uri for a http that will take 30 sec to complete client.RequestUri = new Uri("http://httpbin.org/delay/30000"); client.RequestHeaders.Add("x-ms-version", "2012-08-01"); client.RequestHeaders.Add("accept", "application/xml"); // And I set the client timeout to a value << 30 sec client.Timeout = TimeSpan.FromSeconds(32); // The call Client.SendAsync to trigger exception var responseTask = client.SendAsync(); var response = await responseTask; Console.WriteLine(response.Content); Console.WriteLine(response.ToString()); Console.WriteLine(response.StatusCode); } } catch (OperationCanceledException ex) { Assert.IsTrue(DateTime.Now - start < TimeSpan.FromSeconds(30)); Assert.IsTrue(ex.Message.Contains("operation was canceled at the users request")); } }
public async Task NegativeTest_RepeatedAsvConfig_Using_PocoClientAbstraction() { IHDInsightCertificateCredential credentials = IntegrationTestBase.GetValidCredentials(); var cluster = GetRandomCluster(); cluster.AdditionalStorageAccounts.Add(new WabStorageAccountConfiguration(cluster.DefaultStorageAccountName, cluster.DefaultStorageAccountKey)); try { await ServiceLocator.Instance.Locate <IHDInsightManagementPocoClientFactory>().Create(credentials, GetAbstractionContext(), false).CreateContainer(cluster); } catch (InvalidOperationException e) { Console.WriteLine("THIS TEST SUCCEDED because the expected negative result was found"); Console.WriteLine("ASV Validation failed. Details: {0}", e.ToString()); return; } catch (Exception e) { Assert.Fail("Expected exception 'InvalidOperationException'; found '{0}'. Message:{1}", e.GetType(), e.Message); } Assert.Fail("ASV Validation should have failed."); }
public void CanCallTheGetHDInsightPropertiesCmdletWithVersionsSwitch() { IHDInsightCertificateCredential creds = GetValidCredentials(); using (IRunspace runspace = this.GetPowerShellRunspace()) { IPipelineResult results = runspace.NewPipeline() .AddCommand(CmdletConstants.GetAzureHDInsightProperties) .WithParameter(CmdletConstants.Versions, null) .Invoke(); List <HDInsightVersion> versionsFromPowerShell = results.Results.ToEnumerable <IEnumerable <HDInsightVersion> >().SelectMany(ver => ver.ToList()).ToList(); var versions = new Collection <HDInsightVersion>(); versions.Add(new HDInsightVersion { Version = "1.2", VersionStatus = VersionStatus.Obsolete }); versions.Add(new HDInsightVersion { Version = "1.5", VersionStatus = VersionStatus.Obsolete }); versions.Add(new HDInsightVersion { Version = "1.6", VersionStatus = VersionStatus.Compatible }); versions.Add(new HDInsightVersion { Version = "2.1", VersionStatus = VersionStatus.Compatible }); foreach (HDInsightVersion version in versions) { Assert.IsTrue( versionsFromPowerShell.Any(capVersion => string.Equals(version.Version, capVersion.Version, StringComparison.Ordinal)), "unable to find version '{0}' in capabilities", version.Version); } } }
[Timeout(5 * 60 * 1000)] // ms public async Task ICanPerformA_CreateDeleteContainers_Using_RestClient_ManualEnvironment() { var creds = IntegrationTestBase.GetCredentialsForEnvironmentType(EnvironmentType.Current); if (creds == null) { Assert.Inconclusive("Alternative Azure Endpoint wasn't set up"); } IHDInsightCertificateCredential certCreds = IntegrationTestBase.GetValidCredentials() as IHDInsightCertificateCredential; IHDInsightAccessTokenCredential tokenCreds = IntegrationTestBase.GetValidCredentials() as IHDInsightAccessTokenCredential; IHDInsightSubscriptionCredentials tempCredentials = null; if (certCreds != null) { tempCredentials = new HDInsightCertificateCredential() { SubscriptionId = creds.SubscriptionId, Certificate = certCreds.Certificate }; } else if (tokenCreds != null) { tempCredentials = new HDInsightAccessTokenCredential() { SubscriptionId = creds.SubscriptionId, AccessToken = tokenCreds.AccessToken }; } IHDInsightSubscriptionCredentials credentials = new AlternativeEnvironmentIHDInsightSubscriptionCertificateCredentialsFactory().Create(tempCredentials); var client = new HDInsightManagementRestClient(credentials, GetAbstractionContext(), false); var dnsName = GetRandomClusterName(); var location = "East US"; var subscriptionId = credentials.SubscriptionId; var createPayload = String.Format(CreateContainerGenericRequest, dnsName, location, subscriptionId, Guid.NewGuid()); var xmlReader = new XmlTextReader(new StringReader(createPayload)); var resource = new Resource() { IntrinsicSettings = new[] { new XmlDocument().ReadNode(xmlReader) } }; var result = await client.ListCloudServices(); Assert.IsTrue(!this.ContainsContainer(dnsName, result.Content)); await client.CreateContainer(dnsName, location, resource.SerializeToXml()); result = await client.ListCloudServices(); bool containsContiner = false; while (!containsContiner) { result = await client.ListCloudServices(); containsContiner = this.ContainsContainer(dnsName, result.Content); await Task.Delay(100); } await client.DeleteContainer(dnsName, location); containsContiner = true; while (containsContiner) { result = await client.ListCloudServices(); containsContiner = this.ContainsContainer(dnsName, result.Content); await Task.Delay(100); } }
internal static AzureHDInsightCluster GetCluster( IHDInsightCertificateCredential connectionCredentials, string clusterName, IRunspace runspace) { IPipelineResult results = runspace.NewPipeline() .AddCommand(CmdletConstants.GetAzureHDInsightCluster) .WithParameter(CmdletConstants.Name, clusterName) .Invoke(); List<AzureHDInsightCluster> clusters = results.Results.ToEnumerable<AzureHDInsightCluster>().ToList(); return clusters.FirstOrDefault(); }
public RdfeServiceRestSimulatorClient(IHDInsightAccessTokenCredential credentials, IAbstractionContext context) { this.context = context; this.credentials = IntegrationTestBase.GetValidCredentials() as IHDInsightCertificateCredential; this.PollInterval = TimeSpan.FromMilliseconds(10); }
private static AzureHDInsightClusterConnection ConnectToCluster(IRunspace runspace, IHDInsightCertificateCredential creds) { IUseAzureHDInsightClusterCommand connectCommand = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateUseCluster(); connectCommand.CurrentSubscription = GetCurrentSubscription(); connectCommand.Name = TestCredentials.WellKnownCluster.DnsName; connectCommand.EndProcessing(); Assert.AreEqual(1, connectCommand.Output.Count); AzureHDInsightClusterConnection currentCluster = connectCommand.Output.First(); ValidateGetCluster(currentCluster.Cluster); return currentCluster; }
protected static void DeleteClustersWithVersion(IHDInsightCertificateCredential credentials, string version) { var client = HDInsightClient.Connect(new HDInsightCertificateCredential(credentials.SubscriptionId, credentials.Certificate)); var clusters = client.ListClusters().Where(cluster => cluster.Version == version).ToList(); Parallel.ForEach(clusters, cluster => client.DeleteCluster(cluster.Name)); }
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(); } }
private static AzureHDInsightClusterConnection ConnectToCluster(IRunspace runspace, IHDInsightCertificateCredential creds) { IUseAzureHDInsightClusterCommand connectCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateUseCluster(); connectCommand.CurrentSubscription = GetCurrentSubscription(); connectCommand.Name = TestCredentials.WellKnownCluster.DnsName; connectCommand.EndProcessing(); Assert.AreEqual(1, connectCommand.Output.Count); AzureHDInsightClusterConnection currentCluster = connectCommand.Output.First(); ValidateGetCluster(currentCluster.Cluster); return(currentCluster); }
public void ICanCreateAClusterUsingPowerShellAndConfig() { IHDInsightCertificateCredential creds = GetValidCredentials(); var coreConfig = new Hashtable(); coreConfig.Add("hadoop.logfile.size", "10000"); var yarnConfig = new Hashtable(); yarnConfig.Add("yarn.fakevalue", "12345"); var hbaseConfig = new Hashtable(); hbaseConfig.Add("hbase.blob.size", "12345"); var hbaseServiceConfig = new AzureHDInsightHBaseConfiguration { Configuration = hbaseConfig, AdditionalLibraries = new AzureHDInsightDefaultStorageAccount { StorageAccountKey = Guid.NewGuid().ToString(), StorageAccountName = Guid.NewGuid().ToString(), StorageContainerName = Guid.NewGuid().ToString() } }; string dnsName = this.GetRandomClusterName(); using (IRunspace runspace = this.GetPowerShellRunspace()) { IGetAzureHDInsightClusterCommand getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet(); getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet(); getCommand.CurrentSubscription = GetCurrentSubscription(); getCommand.EndProcessing(); int expected = getCommand.Output.Count(); IPipelineResult results = runspace.NewPipeline() .AddCommand(CmdletConstants.NewAzureHDInsightClusterConfig) .WithParameter(CmdletConstants.ClusterSizeInNodes, 3) .WithParameter(CmdletConstants.HeadNodeVMSize, NodeVMSize.Large) .WithParameter(CmdletConstants.ClusterType, ClusterType.HBase) .WithParameter(CmdletConstants.VirtualNetworkId, Guid.NewGuid().ToString()) .WithParameter(CmdletConstants.SubnetName, "fakeSubnet") .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) .WithParameter(CmdletConstants.YarnConfig, yarnConfig) .WithParameter(CmdletConstants.HBaseConfig, hbaseServiceConfig) .AddCommand(CmdletConstants.NewAzureHDInsightCluster) // Ensure that the subscription Id can be accepted as a guid as well as a string. .WithParameter(CmdletConstants.Name, dnsName) .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); 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); results = runspace.NewPipeline().AddCommand(CmdletConstants.RemoveAzureHDInsightCluster) // Ensure that subscription id can be accepted as a sting as well as a guid. .WithParameter(CmdletConstants.Name, dnsName) .Invoke(); Assert.AreEqual(0, results.Results.Count); getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet(); getCommand.CurrentSubscription = GetCurrentSubscription(); getCommand.EndProcessing(); Assert.AreEqual(expected, getCommand.Output.Count); } }
public void ICanAddMultipleStorageAccountsUsingPowerShell() { IHDInsightCertificateCredential creds = GetValidCredentials(); string dnsName = this.GetRandomClusterName(); using (IRunspace runspace = this.GetPowerShellRunspace()) { var additionalStorageAccount = new WabStorageAccountConfiguration( TestCredentials.Environments[0].AdditionalStorageAccounts[0].Name, TestCredentials.Environments[0].AdditionalStorageAccounts[0].Key); 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, additionalStorageAccount.Name) .WithParameter(CmdletConstants.StorageAccountKey, additionalStorageAccount.Key) .AddCommand(CmdletConstants.NewAzureHDInsightCluster) .WithParameter(CmdletConstants.Name, dnsName) .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); IGetAzureHDInsightClusterCommand 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); List <AzureHDInsightStorageAccount> storageAccounts = getCommand.Output.Last().StorageAccounts.ToList(); Assert.AreEqual(storageAccounts.Count, 1); AzureHDInsightStorageAccount additionalStorageAccountFromOutput = storageAccounts.FirstOrDefault(acc => acc.StorageAccountName == additionalStorageAccount.Name); Assert.IsNotNull(additionalStorageAccountFromOutput); Assert.AreEqual(additionalStorageAccount.Key, additionalStorageAccountFromOutput.StorageAccountKey); results = runspace.NewPipeline().AddCommand(CmdletConstants.RemoveAzureHDInsightCluster) // Ensure that subscription id can be accepted as a sting as well as a guid. .WithParameter(CmdletConstants.Name, dnsName) .Invoke(); Assert.AreEqual(0, results.Results.Count); getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet(); getCommand.CurrentSubscription = GetCurrentSubscription(); getCommand.Name = dnsName; getCommand.EndProcessing(); Assert.AreEqual(0, getCommand.Output.Count); } }
public RdfeServiceRestSimulatorClient(IHDInsightAccessTokenCredential credentials, IAbstractionContext context) { this.context = context; this.credentials = IntegrationTestBase.GetValidCredentials() as IHDInsightCertificateCredential; this.PollInterval = TimeSpan.FromMilliseconds(10); }
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 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); }
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(); }
public void ICanNotSubmitAJobWithTheIncorectCredintials() { IHDInsightCertificateCredential hdInsightCredentials = IntegrationTestBase.GetValidCredentials(); var client = ServiceLocator.Instance.Locate <IHDInsightClientFactory>().Create(new HDInsightCertificateCredential(hdInsightCredentials.SubscriptionId, hdInsightCredentials.Certificate)); var manager = ServiceLocator.Instance.Locate <IHDInsightManagementPocoClientFactory>(); var pocoClient = manager.Create(hdInsightCredentials, GetAbstractionContext(), false); var clusterDetails = GetRandomCluster(); client.CreateCluster(clusterDetails); try { ClusterDetails cluster = pocoClient.ListContainer(clusterDetails.Name).WaitForResult(); BasicAuthCredential hadoopCredentials = new BasicAuthCredential() { Server = GatewayUriResolver.GetGatewayUri(cluster.ConnectionUrl), UserName = clusterDetails.UserName, Password = clusterDetails.Password }; var hadoopClient = JobSubmissionClientFactory.Connect(hadoopCredentials); var mapReduceJob = new MapReduceJobCreateParameters() { ClassName = "pi", JobName = "pi estimation jobDetails", JarFile = "/example/hadoop-examples.jar", StatusFolder = "/piresults" }; mapReduceJob.Arguments.Add("16"); mapReduceJob.Arguments.Add("10000"); var jobCreationDetails = hadoopClient.CreateMapReduceJob(mapReduceJob); var id = pocoClient.DisableHttp(clusterDetails.Name, clusterDetails.Location).WaitForResult(); while (!pocoClient.IsComplete(cluster.Name, cluster.Location, id).WaitForResult()) { Thread.Sleep(500); } // now add a user string userName = "******"; string password = GetRandomValidPassword(); id = pocoClient.EnableHttp(clusterDetails.Name, clusterDetails.Location, userName, password).WaitForResult(); while (!pocoClient.IsComplete(cluster.Name, cluster.Location, id).WaitForResult()) { Thread.Sleep(500); } jobCreationDetails = hadoopClient.CreateMapReduceJob(mapReduceJob); Assert.Fail("This test expected an exception but did not receive one."); } catch (UnauthorizedAccessException ex) { Help.DoNothing(ex); } finally { // delete the cluster client.DeleteCluster(clusterDetails.Name); } }