Database Reference
In-Depth Information
.First(item => item.Thumbprint == Constants.thumbprint);
var creds = new HDInsightCertificateCredential(Constants.subscriptionId, cert);
var client = HDInsightClient.Connect(creds);
var clusters = client.ListClusters();
foreach (var item in clusters)
{
Console.WriteLine("Cluster: {0}, Nodes: {1}", item.Name, item.ClusterSizeInNodes);
}
}
Following are the first two lines of code. They connect to the X509 certificate store in read-only mode.
var store = new X509Store();
store.Open(OpenFlags.ReadOnly);
Next is a statement to load the Azure certificate based on the thumbprint:
var cert = store.Certificates.Cast<X509Certificate2>().First(item =>
item.Thumbprint == Constants.thumbprint);
After loading the certificate, our next step is to create a client object based on the credentials obtained from the
subscription ID and the certificate. We do that using the following statement:
var creds = new HDInsightCertificateCredential(Constants.subscriptionId, cert);
var client = HDInsightClient.Connect(creds);
Then we enumerate the HDInsight clusters under the subscription. The following lines grab the cluster collection
and loops through each item in the collection:
var clusters = client.ListClusters();
foreach (var item in clusters)
{
Console.WriteLine("Cluster: {0}, Nodes: {1}",
item.Name, item.ClusterSizeInNodes);
}
The WriteLine call within the loop prints the name of each cluster and its respective nodes.
You can run this code to list out your existing clusters in a console window. You need to add a call to this
ListClusters() function in your Main() method and run the application. Because I have a couple of clusters
deployed, I see the output shown in Figure 4-6 when I execute the preceding code.
 
Search WWH ::




Custom Search