Skip to content

Commit

Permalink
Merge pull request #131 from ONSdigital/BLAIS5-4087
Browse files Browse the repository at this point in the history
Promote from BLAIS5-4087 to main
  • Loading branch information
Riceyo authored Mar 25, 2024
2 parents 5051df9 + 532a8bc commit 07a722a
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 54 deletions.
37 changes: 35 additions & 2 deletions pipelines/configure_blaise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ stages:
- template: /templates/configure_blaise_steps.yml
parameters:
BlaiseLicenseKey: $(ENV_BLAISE_LICENSE_KEY)
BlaiseActivationKey: $(ENV_BLAISE_ACTIVATION_CODE)
BlaiseActivationKey: $(ENV_BLAISE_ACTIVATION_CODE)
- template: /templates/configure_node_roles_steps.yml
- template: /templates/firewall_rule_steps.yml
parameters:
Expand All @@ -84,11 +84,12 @@ stages:
steps:
- checkout: self
- template: /templates/blaise_management_steps.yml
- template: /templates/add_cma_serverpark.yml

- deployment: RegisterDataEntryNodes
condition: eq(variables.ENV_MULTI_NODE, true)
displayName: Register Data Entry Node
dependsOn: InstallBlaise
dependsOn: ManagementSetup
environment:
name: ${{parameters.Environment}}
resourceType: virtualMachine
Expand All @@ -99,6 +100,38 @@ stages:
steps:
- checkout: self
- template: /templates/register_node_steps.yml

- deployment: InstallCmaPackagesOnMultiNode
condition: eq(variables.ENV_MULTI_NODE, true)
displayName: Install CMA Packages on multi node
dependsOn: RegisterDataEntryNodes
environment:
name: ${{parameters.Environment}}
resourceType: virtualMachine
tags: mgmt
strategy:
runOnce:
deploy:
steps:
- checkout: self
- template: /templates/download_cma_packages.yml
- template: /templates/install_cma_packages.yml

- deployment: InstallCmaPackagesOnSingleNode
condition: eq(variables.ENV_MULTI_NODE, false)
displayName: Install CMA Packages on single node
dependsOn: ManagementSetup
environment:
name: ${{parameters.Environment}}
resourceType: virtualMachine
tags: mgmt
strategy:
runOnce:
deploy:
steps:
- checkout: self
- template: /templates/download_cma_packages.yml
- template: /templates/install_cma_packages.yml

- deployment: ConfigureBlaisesDatabases
displayName: Configure Blaises Sql Databases
Expand Down
67 changes: 38 additions & 29 deletions scripts/Blaise/add_cma_blaise_serverpark.ps1
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
}
129 changes: 129 additions & 0 deletions scripts/Blaise/install_cma_packages.ps1
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
}

16 changes: 10 additions & 6 deletions scripts/Blaise/register_blaise_node.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function RegisterNode{
param(
[string] $ServerPark,
[string] $CurrentNode = $(hostname),
[string] $ManagementNode = $env:ENV_BLAISE_SERVER_HOST_NAME,
[string] $ConnectionPort = $env:ENV_BLAISE_CONNECTION_PORT,
[string] $BlaisePassword = $env:ENV_BLAISE_ADMIN_PASSWORD,
[string] $BlaiseServerPark = $env:ENV_BLAISE_SERVER_PARK_NAME,
[string] $BlaiseUserName = $env:ENV_BLAISE_ADMIN_USER
)

Expand All @@ -20,23 +20,27 @@ function RegisterNode{
throw [System.IO.ArgumentException] "No Blaise Admin Password argument provided"
}

If ([string]::IsNullOrEmpty($BlaiseServerPark)) {
If ([string]::IsNullOrEmpty($ServerPark)) {
throw [System.IO.ArgumentException] "No Blaise server park argument provided"
}

If ([string]::IsNullOrEmpty($BlaiseUserName)) {
throw [System.IO.ArgumentException] "No Blaise username argument provided"
}

Write-Host "Registering $currentNode on management node $managementNode"
Write-Host "Registering $currentNode on management node $managementNode for server park $ServerPark"

c:\blaise5\bin\servermanager -addserverparkserver:$currentNode -server:$managementNode -binding:http -port:$connectionPort -user:$blaiseUserName -password:$blaisePassword -serverpark:$blaiseServerPark -serverport:$connectionPort -serverbinding:http -masterhostname:$managementNode -logicalroot:default -server:$managementNode -binding:http -port:$connectionPort
c:\blaise5\bin\servermanager -addserverparkserver:$currentNode -server:$managementNode -user:$blaiseUserName -password:$blaisePassword -serverpark:$ServerPark -serverport:$connectionPort -serverbinding:http -masterhostname:$managementNode -logicalroot:default -binding:http -port:$connectionPort

Write-Host "$currentNode registered"
Write-Host "$currentNode registered for server park $ServerPark"
}

try{
RegisterNode
# reguster for gusty
RegisterNode -ServerPark:$env:ENV_BLAISE_SERVER_PARK_NAME

#register for cma
RegisterNode -ServerPark:$env:CmaServerParkName
}
catch{
Write-Host "Nodes have not been registered: $($_.ScriptStackTrace)"
Expand Down
1 change: 1 addition & 0 deletions scripts/UserRoles/UserRoles.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Deployment.ServerParkManagement",
"Deployment.InstrumentManagement",
"AppManagement",
"Apps",
"Apps.Appfeatures",
"Appfeatures.login",
"Appfeatures.getlistofinstruments",
Expand Down
8 changes: 0 additions & 8 deletions scripts/helpers/download_test_instrument.ps1

This file was deleted.

5 changes: 5 additions & 0 deletions templates/add_cma_serverpark.yml
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'
7 changes: 1 addition & 6 deletions templates/blaise_management_steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ steps:
- task: PowerShell@2
displayName: Configure gusty server park to run in disconnected mode
inputs:
filePath: '$(Agent.BuildDirectory)/s/scripts/Blaise/configure_blaise_serverpark.ps1'

- 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'
filePath: '$(Agent.BuildDirectory)/s/scripts/Blaise/configure_blaise_serverpark.ps1'
21 changes: 21 additions & 0 deletions templates/download_cma_packages.yml
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
Loading

0 comments on commit 07a722a

Please sign in to comment.