Get-HDIClonerClusterConfig.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<#
.Synopsis
    .
.DESCRIPTION
    
        
.EXAMPLE
     
     
.EXAMPLE
     
.LINK
    https://github.com/mabushaireh/HDICloner
#>


function Get-HDIClonerClusterConfig {
    
    [CmdletBinding()]
    param 
    (
        [Parameter(Mandatory = $true, ParameterSetName = "Main", HelpMessage = "Source Cluster Dns Name")]
        [string] $SourceCluster,

        [Parameter(Mandatory = $false, ParameterSetName = "Main", HelpMessage = "Source Cluster Subscription Id, if not provided will locate the cluster in the cueect azure account context")]
        [string] $SourceSubId,

        [Parameter(Mandatory = $true, ParameterSetName = "Main", HelpMessage = "Ambari Username")]
        [string]
        $Username,

        [Parameter(Mandatory = $true, ParameterSetName = "Main", HelpMessage = "Ambari Password")]
        [string]
        $Password
    )


    Show-Info "Getting Azure Resources for Cluster $SourceCluster"

    $dependencies = Ger-AzureUtilsHdiDependencies $SourceCluster

    $subId = (Get-AzContext).Subscription.Id
    $ArmPath = Get-PathFor -SubscriptionId $subId -ClusterDnsName $SourceCluster -ConfigArea ARM

    Export-AzureUtilsResource -ResourceName $SourceCluster -Path $ArmPath

    #Export Storage

    $storageName =  $dependencies.Storage.substring(0, $dependencies.Storage.IndexOf("."))
    Export-AzureUtilsResource -ResourceName $storageName -Path $ArmPath


    #get ambari configs

    $configs = Get-AmbariUtilsConfig -ClustDnsName $sourceCluster -Username $Username -Password $Password

    $path = Get-PathFor -SubscriptionId $subId -ClusterDnsName $SourceCluster -ConfigArea HDP

    foreach ($config in $configs.Keys) {
        $folder = ""
        if ($config -like "*log4j*"){
            $folder = "Log4j"
        } elseif ($config -like "*env"){
            $folder = "ENV"
        } else {
            $folder = "CONFIG"
        }

        Show-Debug ("Writing to path: [$path\$folder\$config.json]")
        $configs[$config] | Set-Content "$path\$folder\$config.json"
    }

}