-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeploy-RiskPro.ps1
More file actions
375 lines (340 loc) · 18.4 KB
/
Deploy-RiskPro.ps1
File metadata and controls
375 lines (340 loc) · 18.4 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#Requires -Version 5.0
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Deploy OneSumX for Risk Management
.DESCRIPTION
Setup and deploy OneSumX for Risk Management
.PARAMETER Action
The action parameter corresponds to the operation to perform.
The following actions are available:
- backup: Take a backup of RiskPro database
- clean-up: Clean-up RiskPro application files
- configure: Configure RiskPro
- deploy: Deploy RiskPro web-application
- extract: Extract RiskPro distribution files
- install: Install and configure RiskPro
- package: Generate RiskPro web-application (WAR file)
- restore: Restore backup of RiskPro database
- show: Display configuration
- undeploy: Un-deploy RiskPro web-application
- uninstall: Uninstall RiskPro
- upgrade: Upgrade RiskPro
.NOTES
File name: Deploy-RiskPro.ps1
Author: Florian CARRIER
Creation date: 27/11/2018
Last modified: 06/02/2020
Dependencies: - PowerShell Tool Kit (PSTK)
- WildFly PowerShell Module (PSWF)
- RiskPro PowerShell Module (PSRP)
- SQL Server PowerShell Module (SQLServer)
.LINK
https://github.com/Akaizoku/rp-deploy
.LINK
https://www.powershellgallery.com/packages/PSTK
.LINK
https://www.powershellgallery.com/packages/PSWF
.LINK
https://www.powershellgallery.com/packages/PSRP
.LINK
https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module
.LINK
http://wolterskluwerfs.com
.LINK
http://www.wolterskluwerfs.com/risk/home.aspx
#>
# ------------------------------------------------------------------------------
# Parameters
# ------------------------------------------------------------------------------
[CmdletBinding (
SupportsShouldProcess = $true
)]
Param (
[Parameter (
Position = 1,
Mandatory = $true,
HelpMessage = "Action to perform"
)]
[ValidateSet (
"backup",
"clean-up",
"configure",
"deploy",
"extract",
"install",
"package",
"restore",
"show",
"test",
"undeploy",
"uninstall",
"upgrade"
)]
[String]
$Action,
[Parameter (
Position = 2,
Mandatory = $false,
HelpMessage = "Specify a single target host from the grid"
)]
[String]
$Target,
[Parameter (
Position = 3,
Mandatory = $false,
HelpMessage = "RiskPro version"
)]
[String]
$Version,
[Parameter (
HelpMessage = "Flag to ignore database"
)]
[Switch]
$SkipDB,
[Parameter (
HelpMessage = "Run script in unattended mode"
)]
[Switch]
$Unattended
)
Begin {
# ----------------------------------------------------------------------------
# Global preferences
# ----------------------------------------------------------------------------
# WARNING Do not enable strict mode to prevent
# Set-StrictMode -Version Latest
# $ErrorActionPreference = "Stop"
$DebugPreference = "Continue"
# ----------------------------------------------------------------------------
# Global variables
# ----------------------------------------------------------------------------
# General
$WorkingDirectory = $PSScriptRoot
$ISOTimeStamp = Get-Date -Format "yyyy-MM-dd_HHmmss"
# Configuration
$LibDirectory = Join-Path -Path $WorkingDirectory -ChildPath "lib"
$ConfDirectory = Join-Path -Path $WorkingDirectory -ChildPath "conf"
$DefaultProperties = Join-Path -Path $ConfDirectory -ChildPath "default.ini"
$CustomProperties = Join-Path -Path $ConfDirectory -ChildPath "custom.ini"
# ----------------------------------------------------------------------------
# Modules
# ----------------------------------------------------------------------------
$Modules = @("PSTK", "PSWF", "PSRP", "SQLServer")
foreach ($Module in $Modules) {
# Workaround for issue RPD-2
$Force = $Module -ne "SQLServer"
try {
# Check if module is installed
Import-Module -Name "$Module" -Force:$Force -ErrorAction "Stop"
Write-Log -Type "CHECK" -Object "The $Module module was successfully loaded."
} catch {
# If module is not installed then check if package is available locally
try {
Import-Module -Name (Join-Path -Path $LibDirectory -ChildPath $Module) -ErrorAction "Stop" -Force:$Force
Write-Log -Type "CHECK" -Object "The $Module module was successfully loaded from the library directory."
} catch {
Throw "The $Module library could not be loaded. Make sure it has been made available on the machine or manually put it in the ""$LibDirectory"" directory"
}
}
}
# ----------------------------------------------------------------------------
# Script configuration
# ----------------------------------------------------------------------------
# General settings
$Properties = Import-Properties -Path $DefaultProperties -Custom $CustomProperties
# Resolve relative paths
$Properties = Get-Path -PathToResolve $Properties.RelativePaths -Hashtable $Properties -Root $WorkingDirectory
$Properties = Set-RelativePath -Path $Properties.ResRelativePaths -Hashtable $Properties -Root $Properties.ResDirectory
$Properties = Set-RelativePath -Path $Properties.ConfRelativePaths -Hashtable $Properties -Root $Properties.ConfDirectory
$Properties = Set-RelativePath -Path $Properties.GridRelativePaths -Hashtable $Properties -Root $Properties.GridDirectory
$Properties = Set-RelativePath -Path $Properties.SQLRelativePaths -Hashtable $Properties -Root $Properties.SQLDirectory
# Resolve boolean values
$BooleanValues = $Properties.BooleanValues.Split(",").Trim()
foreach ($BooleanValue in $BooleanValues) {
$Properties.$BooleanValue = Resolve-Boolean -Value $Properties.$BooleanValue
}
# ----------------------------------------------------------------------------
# Start script
# ----------------------------------------------------------------------------
# Generate transcript
$FormattedAction = Format-String -String $Action -Format "TitleCase"
$Transcript = Join-Path -Path $Properties.LogDirectory -ChildPath "${FormattedAction}-RiskPro_${ISOTimeStamp}.log"
Start-Script -Transcript $Transcript
# Log command line
Write-Log -Type "DEBUG" -Object $PSCmdlet.MyInvocation.Line
# ----------------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------------
# Load PowerShell functions
$Functions = Get-ChildItem -Path $Properties.PSDirectory
foreach ($Function in $Functions) {
Write-Log -Type "DEBUG" -Object "Import $($Function.Name)"
try { . $Function.FullName }
catch { Write-Error -Message "Failed to import function $($Function.FullName): $_" }
}
# ----------------------------------------------------------------------------
# Properties
# ----------------------------------------------------------------------------
# Database properties
$DatabaseProperties = Import-Properties -Path $Properties.DatabaseProperties
# Hosts properties
$WebServers = Import-Properties -Path $Properties.ServerProperties -Section
# Grid configuration & server list
if ($Target) {
$Servers = Import-Csv -Path $Properties.CSVGridConfiguration -Delimiter "," | Where { $_.Hostname -eq $Target }
} else {
$Servers = Import-Csv -Path $Properties.CSVGridConfiguration -Delimiter ","
}
# Check grid configuration
$GridCheck = Test-GridConfiguration -Grid $Servers -Properties $WebServers
if (-Not $GridCheck) {
Write-Log -Type "ERROR" -Object "Invalid grid configuration" -ExitCode 1
}
# Load custom grid configuration
if ($Properties.CustomGridConfiguration -eq $true) {
# General configuration
$Properties.Add("RPConfiguration", (Import-CSVProperties -Path $Properties.CSVConfigurationProperties -Delimiter "," -Key "NAME" -NullValue "NULL"))
# Environment configuration
$Properties.Add("RPEnvironment", (Import-CSVProperties -Path $Properties.CSVEnvironmentProperties -Delimiter "," -Key "NAME" -NullValue "NULL"))
# Job controller properties
$Properties.Add("JobController", (Import-CSVProperties -Path $Properties.CSVJobControllerProperties -Delimiter "," -Key "HOSTNAME" -NullValue "NULL"))
# Staging area properties
$Properties.Add("StagingArea", (Import-CSVProperties -Path $Properties.CSVStagingAreaProperties -Delimiter "," -Key "HOSTNAME" -NullValue "NULL"))
# TESS properties
$Properties.Add("TESS", (Import-CSVProperties -Path $Properties.CSVTESSProperties -Delimiter "," -Key "HOSTNAME" -NullValue "NULL"))
# Calculator properties
$Properties.Add("Calculator", (Import-CSVProperties -Path $Properties.CSVCalculatorProperties -Delimiter "," -Key "NAME" -NullValue "NULL"))
}
# ----------------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------------
# Execution type switch
$Attended = -Not $Unattended
# Version overwrite
if ($PSBoundParameters.ContainsKey("Version")) {
$Properties.RiskProVersion = $Version
}
# (Re)load environment variables
Write-Log -Type "DEBUG" -Object "Load environment variables"
$EnvironmentVariables = @(
$Properties.RiskProHomeVariable,
$Properties.WildFlyHomeVariable,
$Properties.JavaHomeVariable
)
foreach ($EnvironmentVariable in $EnvironmentVariables) {
Sync-EnvironmentVariable -Name $EnvironmentVariable -Scope $Properties.EnvironmentVariableScope | Out-Null
}
# RiskPro
$Properties.RiskProDistribution = "distribution-" + $Properties.RiskProVersion + "-dist.zip"
$RPHome = Get-EnvironmentVariable -Name $Properties.RiskProHomeVariable -Scope $Properties.EnvironmentVariableScope
$Properties.RPHomeDirectory = Join-Path -Path $Properties.InstallationPath -ChildPath ("rp-" + $Properties.RiskProVersion)
# RiskPro migrator tool
$Properties.MigratorDistribution = "migrator-distribution-" + $Properties.RiskProMigratorVersion + ".zip"
# Resolve relative paths
$Properties = Set-RelativePath -Path $Properties.RPRelativePaths -Hashtable $Properties -Root $Properties.RPHomeDirectory
$Properties = Set-RelativePath -Path $Properties.RPBinRelativePaths -Hashtable $Properties -Root $Properties.RPBinDirectory
$Properties = Set-RelativePath -Path $Properties.RPLibRelativePaths -Hashtable $Properties -Root $Properties.RPLibDirectory
$Properties = Set-RelativePath -Path $Properties.RPWebAppRelativePaths -Hashtable $Properties -Root $Properties.RPWebAppDirectory
# WildFly
# TODO Use specified JBOSS_HOME path if EnableEnvironmentVariable is set to 0
if (Test-EnvironmentVariable -Name $Properties.WildFlyHomeVariable -Scope $Properties.EnvironmentVariableScope) {
$JBossHome = Get-EnvironmentVariable -Name $Properties.WildFlyHomeVariable -Scope $Properties.EnvironmentVariableScope
if (Test-Path -Path $JBossHome) {
$Properties.JBossHome = $JBossHome
$Properties.JBossClient = Join-Path -Path $JBossHome -ChildPath "/bin/jboss-cli.ps1"
} else {
Write-Log -Type "ERROR" -Object "$($Properties.WildFlyHomeVariable) path not found ""$JBossHome""" -ExitCode 1
}
} else {
Write-Log -Type "ERROR" -Object "$($Properties.WildFlyHomeVariable) environment variable does not exist" -ExitCode 1
}
# Database properties
if ($DatabaseProperties.DatabaseInstance) {
$DatabaseProperties.Add("DatabaseURL", (Get-ConnectionString -Type $DatabaseProperties.DatabaseType -Hostname $DatabaseProperties.DatabaseHost -PortNumber $DatabaseProperties.DatabasePort -Instance $DatabaseProperties.DatabaseInstance -Database $DatabaseProperties.DatabaseName -Connector "JDBC"))
} else {
$DatabaseProperties.Add("DatabaseURL", (Get-ConnectionString -Type $DatabaseProperties.DatabaseType -Hostname $DatabaseProperties.DatabaseHost -PortNumber $DatabaseProperties.DatabasePort -Database $DatabaseProperties.DatabaseName -Connector "JDBC"))
}
if ($DatabaseProperties.DatabaseInstance) {
$DatabaseProperties.Add("DatabaseServerInstance", $DatabaseProperties.DatabaseHost + "\" + $DatabaseProperties.DatabaseInstance)
} else {
$DatabaseProperties.Add("DatabaseServerInstance", $DatabaseProperties.DatabaseHost)
}
if ($DatabaseProperties.DatabaseType -eq "SQLServer") {
$Properties.Add("DatabaseXML", $Properties.SQLServerXML)
$DatabaseProperties.Add("DatabaseDriver" , $Properties.SQLDriver )
$DatabaseProperties.Add("CommandLine" , $Properties.SQLCommandLine )
$DatabaseProperties.Add("JDBCDriverModule", $Properties.SQLJDBCDriverModule )
$DatabaseProperties.Add("JDBCDriverClass" , $Properties.SQLJDBCDriverClass )
$DatabaseProperties.Add("JDBCDriverPath" , (Join-Path -Path $Properties.RPHomeDirectory -ChildPath $Properties.SQLJDBCDriverPath))
} elseif ($DatabaseProperties.DatabaseType -eq "Oracle") {
$Properties.Add("DatabaseXML", $Properties.OracleXML)
$DatabaseProperties.Add("DatabaseDriver" , $Properties.ORADriver )
$DatabaseProperties.Add("CommandLine" , $Properties.ORACommandLine )
$DatabaseProperties.Add("JDBCDriverModule", $Properties.ORAJDBCDriverModule )
$DatabaseProperties.Add("JDBCDriverClass" , $Properties.ORAJDBCDriverClass )
$DatabaseProperties.Add("JDBCDriverPath" , (Join-Path -Path $Properties.RPHomeDirectory -ChildPath $Properties.ORAJDBCDriverPath))
# Load Oracle Managed Data Access assembly
if ($Properties.OracleManagedDataAccess -And (Test-Path -Path $Properties.OracleManagedDataAccess)) {
Add-Type -Path $Properties.OracleManagedDataAccess
} else {
Write-Log -Type "ERROR" -Object "Oracle.ManagedDataAccess assembly not found" -ExitCode 1
}
}
# Get custom paths
$Properties.CustomProperties = $CustomProperties
$CustomCheck = Import-Properties -Path $Properties.CustomProperties
$CustomPaths = Resolve-Array -Array $Properties.CustomPaths -Delimiter ","
foreach ($CustomPath in $CustomPaths) {
# Check that path has not been specified by user
if ($CustomCheck.$CustomPath -eq $null) {
# Resolve absolute path
$Properties.$CustomPath = Join-Path -Path $Properties.InstallationPath -ChildPath $Properties.$CustomPath
}
}
# Java
if ((-Not $Properties.JavaPath) -Or ($Properties.JavaPath -eq "") -Or ($Properties.JavaPath -eq $null)) {
if (Test-EnvironmentVariable -Name $Properties.JavaHomeVariable -Scope $Properties.EnvironmentVariableScope) {
Write-Log -Type "DEBUG" -Object "Java path not specified. Defaulting to $($Properties.JavaHomeVariable)"
$JavaHome = Get-EnvironmentVariable -Name $Properties.JavaHomeVariable -Scope $Properties.EnvironmentVariableScope
$Properties.JavaPath = Join-Path -Path $JavaHome -ChildPath "bin\java.exe"
} else {
Write-Log -Type "ERROR" -Object "$($Properties.JavaHomeVariable) environment variable does not exist"
Write-Log -Type "WARN" -Object "Please setup $($Properties.JavaHomeVariable) or specify the Java path in the configuration files" -ExitCode 1
}
}
# RiskPro batch client properties
$RiskProMainApplicationServer = Get-MainApplicationServer -Grid $Servers -Criteria "TESS"
$RiskProBatchClientProperties = New-Object -TypeName "System.Collections.Specialized.OrderedDictionary"
$RiskProBatchClientProperties.Add("RiskProBatchClientPath", $Properties.RiskProBatchClient)
$RiskProBatchClientProperties.Add("ServerURI", (Format-String -String (Get-URI -Scheme $WebServers.$RiskProMainApplicationServer.AppServerProtocol -Authority ($WebServers.$RiskProMainApplicationServer.Hostname + ':' + $WebServers.$RiskProMainApplicationServer.HTTPPort) -Path $Properties.RPWebApplication) -Format "lowercase"))
$JavaOptions = New-Object -TypeName "System.Collections.ArrayList"
# WARNING use quotes to avoid parsing issue due to dots ("Could not find or load main class .io.tmpdir")
[Void]$JavaOptions.Add('-D"java.io.tmpdir"="' + $Properties.RPTempDirectory + '"')
# Add heap size if specified
if ($Properties.HeapSize) { [Void]$JavaOptions.Add('-Xmx' + $Properties.HeapSize) }
$RiskProBatchClientProperties.Add("JavaOptions", $JavaOptions)
}
# ------------------------------------------------------------------------------
Process {
switch ($Action) {
"backup" { Invoke-BackupSchema -Properties ($Properties + $DatabaseProperties) -Unattended:$Unattended }
"clean-up" { Clear-RiskPro -Properties $Properties -Unattended:$Unattended }
"configure" { Invoke-ConfigureRiskPro -Properties ($Properties + $DatabaseProperties) -WebServers $WebServers -Servers $Servers -Unattended:$Unattended -SkipDB:$SkipDB }
"deploy" { Invoke-DeployRiskPro -Properties $Properties -WebServers $WebServers -Servers $Servers -Unattended:$Unattended }
"install" { Install-RiskPro -Properties ($Properties + $DatabaseProperties) -WebServers $WebServers -Servers $Servers -Unattended:$Unattended -SkipDB:$SkipDB }
"package" { Invoke-GenerateWebApp -Properties $Properties }
"restore" { Invoke-RestoreSchema -Properties ($Properties + $DatabaseProperties) -Unattended:$Unattended }
"show" { Show-Configuration -Properties $Properties -DatabaseProperties $DatabaseProperties -WebServers $WebServers -Servers $Servers }
"test" { Test-RiskPro -Properties $Properties -RiskProBatchClientProperties $RiskProBatchClientProperties -Unattended:$Unattended }
"undeploy" { Invoke-UndeployRiskPro -Properties $Properties -WebServers $WebServers -Servers $Servers -Unattended:$Unattended }
"uninstall" { Uninstall-RiskPro -Properties ($Properties + $DatabaseProperties) -WebServers $WebServers -Servers $Servers -Unattended:$Unattended -SkipDB:$SkipDB }
"upgrade" { Update-RiskPro -Properties ($Properties + $DatabaseProperties) -WebServers $WebServers -Servers $Servers -Unattended:$Unattended }
default { Write-Log -Type "ERROR" -Object "Unsupported action parameter: ""$Action""" -ExitCode 1 }
}
}
# ------------------------------------------------------------------------------
End {
# End script gracefully
Stop-Script -ExitCode 0
}