Created
October 7, 2015 23:28
-
-
Save gbellmann/6e7748cedf059bbf182c to your computer and use it in GitHub Desktop.
Create a basic Hadoop cluster in HDInsight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography.X509Certificates; | |
using Microsoft.WindowsAzure.Management.HDInsight; | |
namespace Hdinsight | |
{ | |
public static class Helpers | |
{ | |
private static readonly Guid SubscriptionId = new Guid("<subscription id>"); | |
private const string CertThumbprint = "<certificate thumbprint>"; | |
private const string ClusterName = "<cluster name>"; | |
private const string ClusterLocation = "<cluster location>"; // should be the same as the storage account below | |
private const string StorageAccountName = "<storage account name>.blob.core.windows.net"; | |
private const string StorageAccountKey = "<storage account key>"; | |
private const string StorageContainer = "<container name>"; | |
private const string AdminUserName = "<cluster admin name>"; | |
private const string AdminPassword = "<cluster admin password>"; | |
private const int NodeCount = <node count>; | |
public static void CreateCluster() | |
{ | |
var cert = GetCertificateFromStore(CertThumbprint, StoreLocation.CurrentUser); | |
var creds = new HDInsightCertificateCredential(SubscriptionId, cert); | |
var client = HDInsightClient.Connect(creds); | |
var clusterInfo = new ClusterCreateParametersV2 | |
{ | |
Name = ClusterName, | |
Location = ClusterLocation, | |
DefaultStorageAccountName = StorageAccountName, | |
DefaultStorageAccountKey = StorageAccountKey, | |
DefaultStorageContainer = StorageContainer, | |
UserName = AdminUserName, | |
Password = AdminPassword, | |
ClusterSizeInNodes = NodeCount, | |
Version = "3.1" // default | |
}; | |
client.CreateCluster(clusterInfo); | |
} | |
private static X509Certificate2 GetCertificateFromStore(string thumbprint, StoreLocation storeLocation) | |
{ | |
var store = new X509Store(StoreName.My, storeLocation); | |
try | |
{ | |
store.Open(OpenFlags.ReadOnly); | |
var certCollection = store.Certificates; | |
var currentCerts = certCollection.Find(X509FindType.FindByTimeValid, DateTime.Now, false); | |
var signingCert = currentCerts.Find(X509FindType.FindByThumbprint, thumbprint, false); | |
return signingCert.Count != 0 ? signingCert[0] : null; | |
} | |
finally | |
{ | |
store.Close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment