############################################################################################################################## # Author : Romain Casteres # Blog : http://pulsweb.fr/ # Date : 31/12/2013 # This Script PowerShell is used to creat new HDInsight Services Cluster ############################################################################################################################## $DebugPreference ='Continue' $configvalues = new-object 'Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects.AzureHDInsightHiveConfiguration' $mySubName = "MonAbonnementAzure" $myStoreAcct = "MonStockageAzure" $blobstorage = "MonStockageAzure.blob.core.windows.net" $containerdefault = "MonStockageAzure" $clustername = "MonCluster" $location = "North Europe" $numbernodes = 6 $username = "MonLogin" $password = ConvertTo-SecureString "MonMotDePasse" -AsPlainText -Force $clusterCredentials = New-Object System.Management.Automation.PSCredential ($username, $password) $subid = Get-AzureSubscription $mySubName | %{ $_.SubscriptionId } $cert = Get-AzureSubscription $mySubName | %{ $_.Certificate } $key1 = Get-AzureStorageKey $myStoreAcct | %{ $_.Primary } $configvalues.AdditionalLibraries = new-object 'Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects.AzureHDInsightDefaultStorageAccount' $configvalues.AdditionalLibraries.StorageAccountName = $blobstorage $configvalues.AdditionalLibraries.StorageAccountKey = $Key1 $configvalues.AdditionalLibraries.StorageContainerName = "MonCountainerUDF" Write-Host "Creating '$numbernodes' Node Cluster named: $clustername" -f yellow New-AzureHDInsightClusterConfig -ClusterSizeInNodes $numbernodes ` | Set-AzureHDInsightDefaultStorage -StorageAccountName $blobstorage -StorageAccountKey $Key1 -StorageContainerName $containerdefault ` | Add-AzureHDInsightConfigValues -Hive $configvalues ` | New-AzureHDInsightCluster -Subscription $SubID -Location $Location -Name $ClusterName -Credential $clusterCredentials Write-Host "Executing HiveQL Jobs" -f yellow Use-AzureHDInsightCluster hadooprcatest (Get-AzureSubscription -Current).SubscriptionId $clustername = "MonCluster" $clusterSubscriptionId = (Get-AzureSubscription -Current).SubscriptionId $clusterAdmin = 'MonLogin' $clusterPassword = 'MonMotDePasse' $passwd = ConvertTo-SecureString $clusterPassword -AsPlainText -Force $clusterCredentials = New-Object System.Management.Automation.PSCredential ($clusterAdmin, $passwd) $ScriptFolder = "wasb://MonContainer@MonStorage.blob.core.windows.net/MonScript.hql" $hiveJobVT = New-AzureHDInsightHiveJobDefinition -JobName "MyJobHQL" -File $ScriptFolder $startedHiveJobVT03 = $hiveJobVT | Start-AzureHDInsightJob -Credential $clusterCredentials -Cluster $clusterName $startedHiveJobVT03 | Wait-AzureHDInsightJob -Credential $clusterCredentials Get-AzureHDInsightJobOutput -StandardError -StandardOutput -JobId $startedHiveJobVT03.JobId -TaskSummary -Subscription $clusterSubscriptionId -Cluster $clusterName Write-Host "Deleting Cluster : '$clustername'" -f yellow Remove-AzureHDInsightCluster -Name $ClusterName -Subscription $mySubName