public override async Task EndProcessing()
        {
            this.Name.ArgumentNotNullOrEmpty("Name");
            IHDInsightClient client = this.GetClient();
            var cluster             = await client.GetClusterAsync(this.Name);

            var connection = new AzureHDInsightClusterConnection();

            connection.Credential = this.GetSubscriptionCertificateCredentials(this.CurrentSubscription);

            if (cluster == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Failed to connect to cluster :{0}", this.Name));
            }

            connection.Cluster = new AzureHDInsightCluster(cluster);

            if (cluster.State != ClusterState.Running)
            {
                throw new NotSupportedException(
                          string.Format(CultureInfo.InvariantCulture, "Cluster {0} is in an invalid state : {1}", this.Name, cluster.State.ToString()));
            }

            if (string.IsNullOrEmpty(cluster.HttpUserName))
            {
                throw new NotSupportedException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Cluster {0} is not configured for Http Services access.\r\nPlease use the {1} cmdlet to enable Http Services access.",
                              this.Name,
                              GrantHttpAccessCmdletName));
            }

            this.Output.Add(connection);
        }
示例#2
0
        public async Task ICanAddAndDeleteRDPUser()
        {
            IHDInsightSubscriptionCredentials credentials = IntegrationTestBase.GetValidCredentials();
            IHDInsightClient client = HDInsightClient.Connect(credentials);

            ClusterCreateParametersV2 clusterCreationDetails = GetRandomCluster();

            clusterCreationDetails.Version = "1.6";
            ClusterDetails clusterDetails = client.CreateCluster(clusterCreationDetails);

            // add a rdp user - rdp is OFF by default, hence we enable it first
            string userName = "******";
            string password = GetRandomValidPassword();

            client.EnableRdp(clusterDetails.Name, clusterDetails.Location, userName, password, DateTime.UtcNow.AddHours(1));

            ClusterDetails cluster = await client.GetClusterAsync(clusterDetails.Name);

            Assert.AreEqual(userName, cluster.RdpUserName, "Rdp user name has not been updated");

            // now disable the rdp user
            await client.DisableRdpAsync(clusterDetails.Name, clusterDetails.Location);

            cluster = await client.GetClusterAsync(clusterDetails.Name);

            Assert.IsFalse(String.IsNullOrEmpty(cluster.Name), "Cluster user name is empty, maybe cluster was not created.");
            Assert.IsTrue(String.IsNullOrEmpty(cluster.RdpUserName), "Rdp user name has not been cleared");

            // delete the cluster
            if (!string.Equals(clusterDetails.Name, IntegrationTestBase.TestCredentials.WellKnownCluster.DnsName))
            {
                client.DeleteCluster(clusterDetails.Name);
            }
        }
        public List <ClusterList> GetAsync()
        {
            Trace.WriteLine("Entering GetAsync method");
            Trace.TraceInformation("Executing GetAsync method at " + DateTime.Now.ToLongTimeString());


            Guid   subscriptionId = new Guid("44fbb137-edbb-4044-9db9-0e1333e137cf");   //your-subscription-id
            string certName       = "Azdem187U23713U-1-8-2015-credentials";             //your-subscription-management-cert-name

            // Create an HDInsight Client
            X509Store store = new X509Store(StoreName.My);

            store.Open(OpenFlags.ReadOnly);
            X509Certificate2 cert = store.Certificates.Cast <X509Certificate2>().Single(item => item.FriendlyName == certName); //your friendly name
            HDInsightCertificateCredential creds = new HDInsightCertificateCredential(subscriptionId, cert);
            IHDInsightClient client = HDInsightClient.Connect(creds);

            //var c =Task.Run(() => client.ListClusters()).Result;
            var cluster = client.ListClusters();

            var c1 = new List <ClusterList>();

            foreach (var item in cluster)
            {
                c1.Add(new ClusterList()
                {
                    Name = item.Name, Node = item.ClusterSizeInNodes
                });
            }

            Trace.WriteLine("Leaving GetAsync method");
            return(c1);
        }
示例#4
0
        /// <inheritdoc />
        public override async Task EndProcessing()
        {
            this.Name.ArgumentNotNullOrEmpty("Name");
            this.Location.ArgumentNotNullOrEmpty("Location");

            IHDInsightClient client = this.GetClient();

            if (this.Enable)
            {
                this.Credential.ArgumentNotNull("Credential");
                await client.EnableHttpAsync(this.Name, this.Location, this.Credential.UserName, this.Credential.GetCleartextPassword());
            }
            else
            {
                await client.DisableHttpAsync(this.Name, this.Location);
            }

            var getCommand = ServiceLocator.Instance.Locate <IAzureHDInsightCommandFactory>().CreateGet();

            getCommand.CurrentSubscription = this.CurrentSubscription;
            getCommand.Name = this.Name;
            await getCommand.EndProcessing();

            this.Output.AddRange(getCommand.Output);
        }
 public override async Task EndProcessing()
 {
     IHDInsightClient client = this.GetClient();
     client.ClusterProvisioning += this.ClientOnClusterProvisioning;
     ClusterCreateParameters createClusterRequest = this.GetClusterCreateParameters();
     var cluster = await client.CreateClusterAsync(createClusterRequest);
     this.Output.Add(new AzureHDInsightCluster(cluster));
 }
示例#6
0
        private async Task <Dictionary <string, AzureCluster> > ListClusters()
        {
            Dictionary <string, AzureCluster> clusterList = new Dictionary <string, AzureCluster>();

            HDInsightCertificateCredential sCred = new HDInsightCertificateCredential(_guid, _certificate);
            IHDInsightClient sClient             = HDInsightClient.Connect(sCred);

            ICollection <ClusterDetails> clusters = await sClient.ListClustersAsync();

            foreach (ClusterDetails cluster in clusters)
            {
                clusterList.Add(cluster.Name, new AzureCluster(cluster, this));
            }

            return(clusterList);
        }
示例#7
0
        public override async Task EndProcessing()
        {
            IHDInsightClient client = this.GetClient();
            var capabilities        = await client.ListResourceProviderPropertiesAsync();

            capabilities = capabilities.ToList();
            var azureCapabilities = new AzureHDInsightCapabilities(capabilities);

            azureCapabilities.Versions = await client.ListAvailableVersionsAsync();

            azureCapabilities.Locations = await client.ListAvailableLocationsAsync();

            azureCapabilities.ClusterCount    = this.GetIntCapability(capabilities, ContainersCountKey);
            azureCapabilities.CoresUsed       = this.GetIntCapability(capabilities, CoresUsedKey);
            azureCapabilities.MaxCoresAllowed = this.GetIntCapability(capabilities, MaxCoresAllowedKey);
            this.Output.Add(azureCapabilities);
        }
        public override async Task EndProcessing()
        {
            IHDInsightClient client = this.GetClient();

            if (!string.IsNullOrWhiteSpace(this.Name))
            {
                var azureCluster = await client.GetClusterAsync(this.Name);

                if (azureCluster != null)
                {
                    this.Output.Add(new AzureHDInsightCluster(azureCluster));
                }
            }
            else
            {
                this.Output.AddRange(client.ListClusters().Select(c => new AzureHDInsightCluster(c)));
            }
        }
示例#9
0
        /// <summary>
        /// Connects to HDInsight cluster.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="subscription">The subscription.</param>
        /// <param name="clusterName">Name of the cluster.</param>
        /// <param name="storageAccountName">Name of the storage account.</param>
        /// <param name="storageAccountKey">The storage account key.</param>
        public void Connect(string certificate, string subscription, string clusterName, string storageAccountName, string storageAccountKey)
        {
            // Obtain the certificate
            var store = new X509Store();

            store.Open(OpenFlags.ReadOnly);
            var cert = store.Certificates.Cast <X509Certificate2>().FirstOrDefault(item => string.Compare(item.Thumbprint, certificate, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) == 0);

            if (cert == null)
            {
                AvroHdiSample.ReportError("Error: Counld not find the certificate on this machine!");
            }

            // Connect to the cluster using the certificate and the subscription
            try
            {
                this.client = HDInsightClient.Connect(new HDInsightCertificateCredential(new Guid(subscription), cert));
            }
            catch (Exception e)
            {
                AvroHdiSample.ReportError("Error while connecting to HDInsight service\n" + e);
            }

            this.cluster = this.client.GetCluster(clusterName);
            if (this.cluster == null)
            {
                AvroHdiSample.ReportError("Error while connecting to cluster: " + clusterName);
            }

            // Create a job client
            this.job = JobSubmissionClientFactory.Connect(
                new JobSubmissionCertificateCredential(new Guid(subscription), cert, clusterName));

            // Create an Azure storage client
            // We will use this client to upload files to Azure storage account
            // which is used by HDInsight cluster.
            var storageAccount = CloudStorageAccount.Parse(
                "DefaultEndpointsProtocol=https;AccountName=" + storageAccountName + ";AccountKey=" + storageAccountKey);
            var blobClient = storageAccount.CreateCloudBlobClient();

            this.container = blobClient.GetContainerReference(this.cluster.DefaultStorageAccount.Container);
        }
示例#10
0
        public AzureYarnClient(AzureSubscriptions subscriptions, AzureDfsClient dfsClient, Uri baseUri,
                               string ppmHome, string clusterName = null)
        {
            this.dfsClient       = dfsClient;
            this.baseUri         = baseUri;
            this.peloponneseHome = ppmHome;

            IEnumerable <AzureCluster> clusters = subscriptions.GetClustersAsync().Result;

            AzureCluster cluster;

            if (clusterName == null)
            {
                if (clusters.Count() != 1)
                {
                    throw new ArgumentException("A cluster name must be provided if there is not exactly one configured HDInsight cluster.", "clusterName");
                }
                cluster = clusters.Single();
            }
            else
            {
                IEnumerable <AzureCluster> matching = clusters.Where(c => c.Name == clusterName);
                if (matching.Count() == 0)
                {
                    throw new ArgumentException("Cluster " + clusterName + " not attached to a Powershell subscription or specified manuall", "clusterName");
                }
                cluster = matching.First();
            }

            ClusterName    = cluster.Name;
            SubscriptionId = cluster.SubscriptionId;

            Guid subscriptionGuid = new Guid(SubscriptionId);

            HDInsightCertificateCredential sCred = new HDInsightCertificateCredential(subscriptionGuid, cluster.Certificate);
            IHDInsightClient sClient             = HDInsightClient.Connect(sCred);

            credentials = new JobSubmissionCertificateCredential(sCred, ClusterName);
            JobClient   = JobSubmissionClientFactory.Connect(credentials);
        }
示例#11
0
        public override async Task EndProcessing()
        {
            this.Name.ArgumentNotNullOrEmpty("Name");
            IHDInsightClient client = this.GetClient(IgnoreSslErrors);
            var cluster             = await client.GetClusterAsync(this.Name);

            var           connection    = new AzureHDInsightClusterConnection();
            ProfileClient profileClient = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));

            connection.Credential = this.GetSubscriptionCredentials(this.CurrentSubscription,
                                                                    profileClient.GetEnvironmentOrDefault(this.CurrentSubscription.Environment),
                                                                    profileClient.Profile);

            if (cluster == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Failed to connect to cluster :{0}", this.Name));
            }

            connection.Cluster = new AzureHDInsightCluster(cluster);

            if (!(cluster.State == ClusterState.Running || cluster.State == ClusterState.Operational))
            {
                throw new NotSupportedException(
                          string.Format(CultureInfo.InvariantCulture, "Cluster {0} is in an invalid state : {1}", this.Name, cluster.State.ToString()));
            }

            if (string.IsNullOrEmpty(cluster.HttpUserName))
            {
                throw new NotSupportedException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Cluster {0} is not configured for Http Services access.\r\nPlease use the {1} cmdlet to enable Http Services access.",
                              this.Name,
                              GrantHttpAccessCmdletName));
            }

            this.Output.Add(connection);
        }
 public override async Task EndProcessing()
 {
     IHDInsightClient client = this.GetClient();
     await client.DeleteClusterAsync(this.Name);
 }
示例#13
0
        /// <summary>
        /// Connects to HDInsight cluster.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="subscription">The subscription.</param>
        /// <param name="clusterName">Name of the cluster.</param>
        /// <param name="storageAccountName">Name of the storage account.</param>
        /// <param name="storageAccountKey">The storage account key.</param>
        public void Connect(string certificate, string subscription, string clusterName, string storageAccountName, string storageAccountKey)
        {
            // Obtain the certificate
            var store = new X509Store();
            store.Open(OpenFlags.ReadOnly);
            var cert = store.Certificates.Cast<X509Certificate2>().FirstOrDefault(item => string.Compare(item.Thumbprint, certificate, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) == 0);
            if (cert == null)
            {
                AvroHdiSample.ReportError("Error: Counld not find the certificate on this machine!");
            }

            // Connect to the cluster using the certificate and the subscription
            try
            {
                this.client = HDInsightClient.Connect(new HDInsightCertificateCredential(new Guid(subscription), cert));
            }
            catch (Exception e)
            {
                AvroHdiSample.ReportError("Error while connecting to HDInsight service\n" + e);
            }

            this.cluster = this.client.GetCluster(clusterName);
            if (this.cluster == null)
            {
                AvroHdiSample.ReportError("Error while connecting to cluster: " + clusterName);
            }

            // Create a job client
            this.job = JobSubmissionClientFactory.Connect(
                        new JobSubmissionCertificateCredential(new Guid(subscription), cert, clusterName));

            // Create an Azure storage client
            // We will use this client to upload files to Azure storage account
            // which is used by HDInsight cluster.
            var storageAccount = CloudStorageAccount.Parse(
                    "DefaultEndpointsProtocol=https;AccountName=" + storageAccountName + ";AccountKey=" + storageAccountKey);
            var blobClient = storageAccount.CreateCloudBlobClient();
            this.container = blobClient.GetContainerReference(this.cluster.DefaultStorageAccount.Container);
        }