<#
.SYNOPSIS
Copies a file to the primary storage of an HDInsight cluster.
.DESCRIPTION
Copies a file from a local directory to the blob container for
the HDInsight cluster.
.EXAMPLE
Start-HBaseExample -className "com.microsoft.examples.CreateTable"
-clusterName "MyHDInsightCluster"
.EXAMPLE
Start-HBaseExample -className "com.microsoft.examples.SearchByEmail"
-clusterName "MyHDInsightCluster"
-emailRegex "contoso.com"
.EXAMPLE
Start-HBaseExample -className "com.microsoft.examples.SearchByEmail"
-clusterName "MyHDInsightCluster"
-emailRegex "^r" -showErr
#>
function Start-HBaseExample {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
#The class to run
[Parameter(Mandatory = $true)]
[String]$className,
#The name of the HDInsight cluster
[Parameter(Mandatory = $true)]
[String]$clusterName,
#Only used when using SearchByEmail
[Parameter(Mandatory = $false)]
[String]$emailRegex,
#Use if you want to see stderr output
[Parameter(Mandatory = $false)]
[Switch]$showErr
)
Set-StrictMode -Version 3
# Is the Azure module installed?
FindAzure
# Get the login for the HDInsight cluster
$creds=Get-Credential -Message "Enter the login for the cluster" -UserName "admin"
# The JAR
$jarFile = "wasb:///example/jars/hbaseapp-1.0-SNAPSHOT.jar"
# The job definition
$jobDefinition = New-AzHDInsightMapReduceJobDefinition `
-JarFile $jarFile `
-ClassName $className `
-Arguments $emailRegex
# Get the job output
$job = Start-AzHDInsightJob `
-ClusterName $clusterName `
-JobDefinition $jobDefinition `
-HttpCredential $creds
Write-Host "Wait for the job to complete ..." -ForegroundColor Green
Wait-AzHDInsightJob `
-ClusterName $clusterName `
-JobId $job.JobId `
-HttpCredential $creds
if($showErr)
{
Write-Host "STDERR"
Get-AzHDInsightJobOutput `
-Clustername $clusterName `
-JobId $job.JobId `
-HttpCredential $creds `
-DisplayOutputType StandardError
}
Write-Host "Display the standard output ..." -ForegroundColor Green
Get-AzHDInsightJobOutput `
-Clustername $clusterName `
-JobId $job.JobId `
-HttpCredential $creds
}
<#
.SYNOPSIS
Copies a file to the primary storage of an HDInsight cluster.
.DESCRIPTION
Copies a file from a local directory to the blob container for
the HDInsight cluster.
.EXAMPLE
Add-HDInsightFile -localPath "C:\temp\data.txt"
-destinationPath "example/data/data.txt"
-ClusterName "MyHDInsightCluster"
.EXAMPLE
Add-HDInsightFile -localPath "C:\temp\data.txt"
-destinationPath "example/data/data.txt"
-ClusterName "MyHDInsightCluster"
-Container "MyContainer"
#>
function Add-HDInsightFile {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
#The path to the local file.
[Parameter(Mandatory = $true)]
[String]$localPath,
#The destination path and file name, relative to the root of the container.
[Parameter(Mandatory = $true)]
[String]$destinationPath,
#The name of the HDInsight cluster
[Parameter(Mandatory = $true)]
[String]$clusterName,
#If specified, overwrites existing files without prompting
[Parameter(Mandatory = $false)]
[Switch]$force
)
Set-StrictMode -Version 3
# Is the Azure module installed?
FindAzure
# Get authentication for the cluster
$creds=Get-Credential
# Does the local path exist?
if (-not (Test-Path $localPath))
{
throw "Source path '$localPath' does not exist."
}
# Get the primary storage container
$storage = GetStorage -clusterName $clusterName
# Upload file to storage, overwriting existing files if -force was used.
Set-AzStorageBlobContent -File $localPath `
-Blob $destinationPath `
-force:$force `
-Container $storage.container `
-Context $storage.context
}
function FindAzure {
# Is there an active Azure subscription?
$sub = Get-AzSubscription -ErrorAction SilentlyContinue
if(-not($sub))
{
Connect-AzAccount
}
}
function GetStorage {
param(
[Parameter(Mandatory = $true)]
[String]$clusterName
)
$hdi = Get-AzHDInsightCluster -ClusterName $clusterName
# Does the cluster exist?
if (!$hdi)
{
throw "HDInsight cluster '$clusterName' does not exist."
}
# Create a return object for context & container
$return = @{}
$storageAccounts = @{}
# Get storage information
$resourceGroup = $hdi.ResourceGroup
$storageAccountName=$hdi.DefaultStorageAccount.split('.')[0]
$container=$hdi.DefaultStorageContainer
$storageAccountKey=(Get-AzStorageAccountKey `
-Name $storageAccountName `
-ResourceGroupName $resourceGroup)[0].Value
# Get the resource group, in case we need that
$return.resourceGroup = $resourceGroup
# Get the storage context, as we can't depend
# on using the default storage context
$return.context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
# Get the container, so we know where to
# find/store blobs
$return.container = $container
# Return storage accounts to support finding all accounts for
# a cluster
$return.storageAccount = $storageAccountName
$return.storageAccountKey = $storageAccountKey
return $return
}
# Only export the verb-phrase things
export-modulemember *-*