Framework/Core/SVT/Services/HDInsight.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
74
75
76
77
78
79
80
81
Set-StrictMode -Version Latest 
class HDInsight: AzSVTBase
{
    hidden [PSObject] $ResourceObject;
    HDInsight([string] $subscriptionId, [SVTResource] $svtResource):
    Base($subscriptionId, $svtResource)
    { 
        $this.PublishCustomMessage("Currently HDInsight contains only cluster level controls. More controls will be added in future releases.", [MessageType]::Warning);
        $this.GetResourceObject();
    }

    hidden [void] GetResourceObject()
    {
        if (-not $this.ResourceObject)
        {
            $this.ResourceObject = Get-AzResource -ResourceId $this.ResourceContext.ResourceId -ExpandProperties
            if(-not $this.ResourceObject)
            {
                throw ([SuppressedException]::new(("Resource '$($this.ResourceContext.ResourceName)' not found under Resource Group '$($this.ResourceContext.ResourceGroupName)'"), [SuppressedExceptionType]::InvalidOperation))
            }

        }
    }

    hidden [ControlResult] CheckClusterVersion([ControlResult] $controlResult)
    {
        if([Helpers]::CheckMember($this.ResourceObject,"Properties.clusterVersion"))
        {
            #Validate if cluster version is below supported or retired version
            if([version]$this.ResourceObject.Properties.clusterVersion -gt [version]$this.ControlSettings.HDInsight.MinSupportedClusterVersion)
            {
                $controlResult.AddMessage([VerificationResult]::Passed,
                                        "Supported HDI cluster version available");
            }
            else
            {
                $controlResult.AddMessage([VerificationResult]::Failed,
                                        "Retired HDI cluster version found: "+$this.ResourceObject.ClusterVersion);
            }
        }
        else
        {
            $controlResult.AddMessage([VerificationResult]::Manual,
                                    "Not able to find HDI cluster version");
        }
        return $controlResult;
    }

    hidden [ControlResult] CheckClusterNetworkProfile([ControlResult] $controlResult)
    {
        if([Helpers]::CheckMember($this.ResourceObject,"Properties.computeProfile.roles"))
        {

            $clusterRoles = $this.ResourceObject.Properties.computeProfile.roles
            $clusterRolesWithoutNetworkProfile = @()
            #Validate if network profile is defined for all cluster roles like head,worker,zookipper nodes
            $clusterRoles | ForEach-Object {
                if(-not [Helpers]::CheckMember($_,"virtualNetworkProfile"))
                {
                    $clusterRolesWithoutNetworkProfile += $_.name
                }
            }
            if($clusterRolesWithoutNetworkProfile.Count -gt 0)
            {
                $controlResult.AddMessage([VerificationResult]::Failed,
                                        "Network profile is not defined for HDI cluster roles", $clusterRolesWithoutNetworkProfile);
            }
            else
            {
                $controlResult.AddMessage([VerificationResult]::Passed,
                                        "Network profile found for all HDI cluster roles");
            }
        }
        else
        {
            $controlResult.AddMessage([VerificationResult]::Manual,
                                    "Not able to find HDI cluster roles");
        }
        return $controlResult;
    }  
}