-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_hpc_headnode.ps1
186 lines (151 loc) · 7.42 KB
/
install_hpc_headnode.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function New-HPC-Job-Template {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)] [string] $ComputeNodeGroup,
[Parameter(Mandatory = $true)] [string] $JobTemplate,
[Parameter(Mandatory = $true)] [string] $TmpFolder
)
# this is where the document will be saved
$Path = "$($TmpFolder)\HpcJobTemplate-$($JobTemplate).xml"
$Encoding = [System.Text.Encoding]::UTF8
# get an XmlTextWriter to create the XML
$XmlWriter = New-Object System.XMl.XmlTextWriter($Path, $Encoding)
# choose a pretty formatting
$xmlWriter.Formatting = 'Indented'
$xmlWriter.Indentation = 1
$XmlWriter.IndentChar = "`t"
# write the header
$xmlWriter.WriteStartDocument()
$xmlWriter.WriteStartElement('JobTemplate')
$XmlWriter.WriteAttributeString('Name', $JobTemplate)
$XmlWriter.WriteAttributeString('Description', "Job Template")
$XmlWriter.WriteAttributeString('CreateTime', "" )
$xmlWriter.WriteStartElement('TemplateItem')
$XmlWriter.WriteAttributeString('PropertyName', "NodeGroups")
$XmlWriter.WriteAttributeString('Default', $ComputeNodeGroup)
$XmlWriter.WriteAttributeString('ValueRange', "")
$XmlWriter.WriteAttributeString('RequiredValues', $ComputeNodeGroup)
$xmlWriter.WriteEndElement()
$xmlWriter.WriteStartElement('TemplateItem')
$XmlWriter.WriteAttributeString('PropertyName', "NodeGroupOp")
$XmlWriter.WriteAttributeString('Default', "Union")
$XmlWriter.WriteAttributeString('ValueRange', "")
$xmlWriter.WriteEndElement()
#finalize JobTemplate
$xmlWriter.WriteEndElement()
# finalize the document
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
return $Path
}
. "C:\ProgramData\WriteToLog.ps1"
LogWrite "Starting installing headnode"
LogWrite "Computer $env:computername"
LogWrite "UserName $env:username"
# if already installed using the hpc scheduler service installed in this script
if (Get-Service HpcScheduler -ErrorAction SilentlyContinue)
{
LogWrite "HPC Pack allready installed, skipping.."
}
else
{
$dnsname = aws ssm get-parameter --name " /Vpc/Default/PrivateDns/Name" --query "Parameter.Value" --output text --region eu-central-1
$certificate_password = aws ssm get-parameter --name "/certificate/hpc/password" --query "Parameter.Value" --with-decryption --output text --region eu-central-1
$sql_password = aws ssm get-parameter --name "/sql-server/service-account/password" --query "Parameter.Value" --with-decryption --output text --region eu-central-1
$sql_user = aws ssm get-parameter --name "/sql-server/service-account/username" --query "Parameter.Value" --with-decryption --output text --region eu-central-1
$tgtdir = "C:\ProgramData\HPC\2016\"
$certpath = "C:\ProgramData\HPCCertificate.pfx"
$ClusterName = "headnode.$dnsname"
$SQLServerInstance = "mssql.$dnsname"
$TmpFolder = $env:TEMP
# use the pfx generated by the script
$setupArg = "-unattend -HeadNode -SkipComponent:rras,dhcp,wds -ClusterName:$ClusterName -SSLPfxFilePath:$certpath -SSLPfxFilePassword:$certificate_password"
$secinfo = "Integrated Security=False;User ID=$sql_user;Password=$sql_password"
$mgmtConstr = "Data Source=$SQLServerInstance;Initial Catalog=HpcManagement;$secinfo"
$schdConstr = "Data Source=$SQLServerInstance;Initial Catalog=HpcScheduler;$secinfo"
$monConstr = "Data Source=$SQLServerInstance;Initial Catalog=HPCMonitoring;$secinfo"
$rptConstr = "Data Source=$SQLServerInstance;Initial Catalog=HPCReporting;$secinfo"
$diagConstr = "Data Source=$SQLServerInstance;Initial Catalog=HPCDiagnostics;$secinfo"
$setupArg = "$setupArg -MGMTDBCONSTR:`"$mgmtConstr`" -SCHDDBCONSTR:`"$schdConstr`" -RPTDBCONSTR:`"$rptConstr`" -DIAGDBCONSTR:`"$diagConstr`" -MONDBCONSTR:`"$monConstr`""
while($true)
{
LogWrite "Installing HPC Pack Head Node"
$p = Start-Process -FilePath "$tgtdir\setup.exe" -ArgumentList $setupArg -PassThru -Wait
if($p.ExitCode -eq 0)
{
LogWrite "Succeed to Install HPC Pack Head Node"
break
}
if($p.ExitCode -eq 3010)
{
LogWrite "Succeed to Install HPC Pack Head Node, a reboot is required."
break
}
if($retry++ -lt $maxRetryTimes)
{
$retryInterval = [System.Math]::Min($maxRetryInterval, $retry * 10)
LogWrite "Failed to Install HPC Pack Head Node (errCode=$($p.ExitCode)), retry after $retryInterval seconds..."
Clear-DnsClientCache
Start-Sleep -Seconds $retryInterval
}
else
{
if($p.ExitCode -eq 13818)
{
throw "Failed to Install HPC Pack Head Node (errCode=$($p.ExitCode)): the certificate doesn't meet the requirements."
}
else
{
throw "Failed to Install HPC Pack Head Node (errCode=$($p.ExitCode))"
}
}
}
}
LogWrite "Done"
LogWrite "Configuring HPC Pack 2016..."\
Add-PSSnapin Microsoft.HPC
LogWrite "Checking if HPC Scheduler service is running."
$status = (Get-Service -Name HpcScheduler -ErrorAction SilentlyContinue -ErrorVariable StErr | Select-Object -ExpandProperty Status)
LogWrite "HPC Scheduler service has status $status"
# cluster admin to complete
# auto scaling group has two ipc adresses, we just need one
$NIC = Get-HpcNetworkInterface -ErrorAction Stop
LogWrite "Get-HpcNetworkInterface done..."
Set-HpcNetwork -Topology Enterprise -Enterprise $NIC.Name[0] -EnterpriseFirewall $null
LogWrite "Set-HpcNetwork done..."
$ServiceAccount = aws ssm get-parameter --name "/service-account/username" --query "Parameter.Value" --with-decryption --output text --region eu-central-1
$password = aws ssm get-parameter --name "/service-account/password" --query "Parameter.Value" --with-decryption --output text --region eu-central-1
$password = $password | ConvertTo-SecureString -AsPlainText -Force
$domain_name = "DOMAIN"
$username = $domain_name.ToUpper() + "\" + $ServiceAccount
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Set-HpcJobCredential -Credential $credential
Set-HpcClusterProperty -InstallCredential $credential
Set-HpcClusterProperty -NodeNamingSeries "HPCCN%0001%"
LogWrite "Set-HpcClusterProperty done..."
# New-HpcNodeTemplate -Name "Default ComputeNode Template" -Type ComputeNode
LogWrite "New-HpcNodeTemplate done..."
foreach ($item in $HpcServiceAccount) {
Add-HpcMember -Name $item -Role JobAdministrator -ErrorVariable Err -ErrorAction Stop -WarningAction Stop
}
}
if ($HpcAdmins) {
foreach ($item in $HpcAdmins) {
Add-HpcMember -Name $item -Role administrator -ErrorVariable Err -ErrorAction Stop -WarningAction Stop
}
}
if ($HpcUsers) {
foreach ($item in $HpcUsers) {
Add-HpcMember -Name $item -Role user -ErrorVariable Err -ErrorAction Stop -WarningAction Stop
}
}
foreach($item in $JobTemplates)
{
New-HpcGroup -Name "$($item)Nodes" -Description "$($item)Nodes node group" -ErrorVariable Err -ErrorAction Stop -WarningAction Stop
$templateXML = New-HPC-Job-Template -ComputeNodeGroup "$($item)Nodes" -JobTemplate $item -TmpFolder $TmpFolder -ErrorVariable Err
Import-HpcJobtemplate -name $item -Path $templateXML -ErrorVariable Err -ErrorAction Stop -WarningAction Stop
}
Set-HpcNode -Name $env:COMPUTERNAME -Role BrokerNode
Set-HpcNodeState -Name $env:COMPUTERNAME -State online
LogWrite "Done"