-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from ONSdigital/BLAIS5-4087
Promote from BLAIS5-4087 to main
- Loading branch information
Showing
12 changed files
with
251 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,62 @@ | ||
function ConfigureCmaServerpark{ | ||
function ServerParkExists { | ||
param( | ||
[string] $ServerParkName, | ||
[string] $ManagementNode, | ||
[string] $ConnectionPort, | ||
[string] $BlaiseUserName, | ||
[string] $BlaisePassword | ||
[string] $ServerParkName | ||
) | ||
|
||
If ([string]::IsNullOrEmpty($ServerParkName)) { | ||
throw [System.IO.ArgumentException] "No server park name argument provided" | ||
} | ||
|
||
If ([string]::IsNullOrEmpty($ManagementNode)) { | ||
throw [System.IO.ArgumentException] "No management node argument provided" | ||
$exists = c:\blaise5\bin\servermanager -listserverparks ` | ||
-server:$env:ENV_BLAISE_SERVER_HOST_NAME ` | ||
-binding:http ` | ||
-port:$env:ENV_BLAISE_CONNECTION_PORT ` | ||
-user:$env:ENV_BLAISE_ADMIN_USER ` | ||
-password:$env:ENV_BLAISE_ADMIN_PASSWORD ` | ||
| findstr -i "cma" | ||
|
||
If ([string]::IsNullOrEmpty($exists)) { | ||
return $false | ||
} | ||
|
||
If ([string]::IsNullOrEmpty($ConnectionPort)) { | ||
throw [System.IO.ArgumentException] "No Blaise connection port argument provided" | ||
} | ||
|
||
If ([string]::IsNullOrEmpty($BlaiseUserName)) { | ||
throw [System.IO.ArgumentException] "No Blaise username argument provided" | ||
} | ||
return $true | ||
} | ||
function AddServerpark{ | ||
param( | ||
[string] $ServerParkName | ||
) | ||
|
||
If ([string]::IsNullOrEmpty($BlaisePassword)) { | ||
throw [System.IO.ArgumentException] "No Blaise Admin Password argument provided" | ||
If ([string]::IsNullOrEmpty($ServerParkName)) { | ||
throw [System.IO.ArgumentException] "No server park name argument provided" | ||
} | ||
|
||
Write-Host "Add and/or configure server park '$ServerParkName' to run in disconnected mode with sync surveys set to true" | ||
|
||
#if the serverpark exists this will update the existing one | ||
c:\blaise5\bin\servermanager -addserverpark:$ServerParkName -runmode:disconnected -server:$managementNode -syncsurveyswhenconnected:true -binding:http -port:$connectionPort -user:$blaiseUserName -password:$blaisePassword | ||
c:\blaise5\bin\servermanager -addserverpark:$ServerParkName ` | ||
-runmode:disconnected ` | ||
-server:$env:ENV_BLAISE_SERVER_HOST_NAME ` | ||
-syncsurveyswhenconnected:true ` | ||
-binding:http ` | ||
-port:$env:ENV_BLAISE_CONNECTION_PORT ` | ||
-user:$env:ENV_BLAISE_ADMIN_USER ` | ||
-password:$env:ENV_BLAISE_ADMIN_PASSWORD | ||
|
||
Write-Host "Configured server park '$ServerParkName'" | ||
} | ||
|
||
try{ | ||
$BlaiseCmaServerPark = $env:CmaServerParkName | ||
Write-Host "server park - $($BlaiseCmaServerPark)" | ||
$ManagementNode = $env:ENV_BLAISE_SERVER_HOST_NAME | ||
Write-Host "server - $($ManagementNode)" | ||
$ConnectionPort = $env:ENV_BLAISE_CONNECTION_PORT | ||
Write-Host "port - $($ConnectionPort)" | ||
$BlaisePassword = $env:ENV_BLAISE_ADMIN_PASSWORD | ||
$BlaiseUserName = $env:ENV_BLAISE_ADMIN_USER | ||
|
||
ConfigureCmaServerpark -ServerParkName:$BlaiseCmaServerPark -ManagementNode:$ManagementNode -ConnectionPort:$ConnectionPort -BlaiseUserName:$BlaiseUserName -BlaisePassword:$BlaisePassword | ||
if(ServerParkExists -ServerParkName:$env:CmaServerParkName) { | ||
Write-Host "Serverpark $env:CmaServerParkName already exists" | ||
} | ||
else { | ||
Write-Host "Adding and/or configuring CMA server park $env:CmaServerParkName" | ||
AddServerpark -ServerParkName:$env:CmaServerParkName | ||
} | ||
|
||
exit 0 | ||
} | ||
catch{ | ||
Write-Host "Adding and/or configuring CMA server park(s) failed: $($_.ScriptStackTrace)" | ||
Write-Host "Adding and/or configuring CMA server park $env:CmaServerParkName failed: $($_.ScriptStackTrace)" | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
$CmaInstrumentPath = $env:CmaInstrumentPath | ||
$CmaMultiPackage = $env:CmaMultiPackage | ||
$CmaServerParkName = $env:CmaServerParkName | ||
|
||
$BlaiseConnectionPort = $env:ENV_BLAISE_CONNECTION_PORT | ||
$BlaiseAdminUser = $env:ENV_BLAISE_ADMIN_USER | ||
$BlaiseAdminPassword = $env:ENV_BLAISE_ADMIN_PASSWORD | ||
|
||
function Test-InstrumentInstalled { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$ServerParkName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$InstrumentName | ||
) | ||
|
||
$IsInstrumentInstalled = & "C:\blaise5\bin\servermanager.exe" -listsurveys ` | ||
-serverpark:$ServerParkName ` | ||
-binding:http ` | ||
-port:$BlaiseConnectionPort ` | ||
-user:$BlaiseAdminUser ` | ||
-password:$BlaiseAdminPassword | Select-String -Pattern $InstrumentName -SimpleMatch | ||
|
||
return ($null -ne $IsInstrumentInstalled) | ||
} | ||
|
||
function Test-FileExists { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$FilePath | ||
) | ||
|
||
return (Test-Path -Path $FilePath -PathType Leaf) | ||
} | ||
|
||
function Expand-ZipFile { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$FilePath, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$DestinationPath | ||
) | ||
|
||
if (-not (Test-FileExists -FilePath $FilePath)) { | ||
throw "File '$FilePath' does not exist." | ||
} | ||
|
||
Write-Host "Expanding zip file '$FilePath' to '$DestinationPath'" | ||
Expand-Archive -LiteralPath $FilePath -DestinationPath $DestinationPath -Force | ||
} | ||
|
||
function Install-PackageViaServerManager { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$ServerParkName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$FilePath | ||
) | ||
|
||
if (-not (Test-FileExists -FilePath $FilePath)) { | ||
throw "File '$FilePath' does not exist." | ||
} | ||
|
||
Write-Host "Installing package '$FilePath' into server park '$ServerParkName' via Server Manager" | ||
& "C:\blaise5\bin\servermanager.exe" -installsurvey:$FilePath ` | ||
-serverpark:$ServerParkName ` | ||
-binding:http ` | ||
-port:$BlaiseConnectionPort ` | ||
-user:$BlaiseAdminUser ` | ||
-password:$BlaiseAdminPassword | ||
} | ||
|
||
function Install-PackageViaBlaiseCli { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$ServerParkName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$FilePath | ||
) | ||
|
||
if (-not (Test-FileExists -FilePath $FilePath)) { | ||
throw "File '$FilePath' does not exist." | ||
} | ||
|
||
$InstrumentName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath) | ||
Write-Host "Installing package '$InstrumentName' from '$FilePath' into server park '$ServerParkName' via Blaise CLI" | ||
& "C:\BlaiseServices\BlaiseCli\blaise.cli.exe" questionnaireinstall -s $ServerParkName -q $InstrumentName -f $FilePath | ||
} | ||
|
||
try { | ||
Write-Host "Unzipping CMA multi-package '$CmaMultiPackage'" | ||
Expand-ZipFile -FilePath "$CmaInstrumentPath\$CmaMultiPackage" -DestinationPath $CmaInstrumentPath | ||
|
||
# Install the "CMA" package via Server Manager as it does not use a data interface / database | ||
Install-PackageViaServerManager -ServerParkName $CmaServerParkName -FilePath "$CmaInstrumentPath\CMA.bpkg" | ||
|
||
# Install remaining CMA instruments using Blaise CLI for MySQL data interface database configuration | ||
$InstrumentList = 'CMA_Attempts', 'CMA_ContactInfo', 'CMA_Launcher', 'CMA_Logging' | ||
foreach ($Instrument in $InstrumentList) { | ||
if (Test-InstrumentInstalled -ServerParkName $CmaServerParkName -InstrumentName $Instrument) { | ||
Write-Host "Instrument '$Instrument' already installed on server park '$CmaServerParkName' - skipping installation" | ||
} | ||
else { | ||
Install-PackageViaBlaiseCli -ServerParkName $CmaServerParkName -FilePath "$CmaInstrumentPath\$Instrument.bpkg" | ||
} | ||
} | ||
|
||
Write-Host "Removing CMA working folder '$CmaInstrumentPath'" | ||
Remove-Item -LiteralPath $CmaInstrumentPath -Force -Recurse | ||
} | ||
catch { | ||
Write-Error "Installing CMA packages failed: $($_.Exception.Message)" | ||
Write-Error "$($_.ScriptStackTrace)" | ||
exit 1 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
steps: | ||
- task: PowerShell@2 | ||
displayName: Add CMA server park to run in disconnected mode | ||
inputs: | ||
filePath: '$(Agent.BuildDirectory)/s/scripts/Blaise/add_cma_blaise_serverpark.ps1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
steps: | ||
- task: DownloadSecureFile@1 | ||
displayName: 'Download GCP Key' | ||
name: gcpkey | ||
inputs: | ||
secureFile: 'ons-blaise-v2-shared-221e50eb36c7.json' | ||
|
||
|
||
- task: PowerShell@2 | ||
displayName: Download cma packages | ||
inputs: | ||
targetType: 'inline' | ||
script: | | ||
Write-Host "Authenticating GCP with shared project service account" | ||
gcloud auth activate-service-account $env:ENV_SHARED_SERVICE_ACCOUNT --key-file=$(gcpkey.secureFilePath) | ||
Write-Host "Downloading CMA multi package" | ||
gsutil cp gs://$env:ENV_SHARED_BUCKET/CMA.mbpkg c:\CMA\CMA-MULTI.zip | ||
Write-Host "Reverting GCP authentication back to VM service account" | ||
gcloud config set account $env:ENV_VM_SERVICEACCOUNT |
Oops, something went wrong.