Cleanup of unused code

This commit is contained in:
Justin Donnelly
2020-10-21 09:14:17 +00:00
parent c72ddc81c0
commit 09b12873ca
7 changed files with 141 additions and 86 deletions

View File

@@ -1,24 +1,15 @@
#!/usr/bin/env pwsh
#
# Installing Qlik-CLI
# Write-Host "Downloading Qlik-Cli from Github and importing the Module"
# Invoke-WebRequest "https://raw.githubusercontent.com/ahaydon/Qlik-Cli/master/Qlik-Cli.psm1" -OutFile $temp\Qlik-Cli.psm1
# New-Item -ItemType directory -Path C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Qlik-Cli -force
# Move-Item $temp\Qlik-Cli.psm1 C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Qlik-Cli\ -force
# Import-Module Qlik-Cli.psm1
# Export-QlikCertificate -machineNames rim -includeSecretsKey -exportFormat Windows
if ($env:computername -like "central-*") {
exit 0
}
# $deploy_path = "E:\deploy"
Write-Host "------------------------------------------------------------"
Write-Host " Adding Rim to Cluster "
Write-Host "------------------------------------------------------------"
# $centralNode = ($env:COMPUTERNAME).ToLower()
# $config = (Get-Coantent $deploy_path\scripts\config.json | ConvertFrom-Json)
$config = ( Read-GcsObject -Bucket "qliksense" -ObjectName "scripts/config.json" | ConvertFrom-Json )
#-OutFile $deploy_path\certs\rim\client.pfx -Force
# $centralNode = "central-84fe"
$centralNode = $config.cenName
@@ -39,32 +30,28 @@ Invoke-Command -Session $qsConn -ScriptBlock { Get-ChildItem -Path cert:\Current
# Read-GcsObject -Bucket "qliksense" -ObjectName "certs/rim/client.pfx" -OutFile $deploy_path\certs\rim\client.pfx -Force
# Import-PfxCertificate -FilePath $deploy_path\certs\rim\client.pfx -CertStoreLocation Cert:\CurrentUser\My -Exportable
# Connect to Qlik Sense
# Get-ChildItem -Path cert:\CurrentUser\My | Where-Object {$_.Issuer -like "*$centralNode*"} | Connect-Qlik -computername https://"$centralNode":4242 -Username $qlikID | Out-Null
Invoke-Command -Session $qsConn -ScriptBlock { `
$proxyId = (Get-QlikVirtualProxy -full `
| Where-Object description -like "Central*").id | Out-Null
}
$proxyId = (Get-QlikVirtualProxy -full | Where-Object description -like "Central*").id}
#TODO: Read existing whitelist as array, add new node to list and then re-write new list.
Invoke-Command -Session $qsConn -ScriptBlock { `
Update-QlikVirtualProxy -id $proxyId -websocketCrossOriginWhiteList "$using:newNode", "$using:centralNode" | Out-Null
}
# Invoke-Command -Session $qsConn -ScriptBlock { `
# Invoke-Command -ComputerName $using:newNode -ScriptBlock { Invoke-WebRequest `
# -Uri "http://localhost:4570/certificateSetup" -Method Post -Body $foo } -credential $using:Cred }
Invoke-Command -Session $qsConn -ScriptBlock { `
$password = New-QlikNode -hostname $using:newNode -name $using:newNode -nodePurpose Both -engineEnabled -proxyEnabled; `
$password = New-QlikNode -hostname $using:newNode -name $using:newNode -nodePurpose Both -engineEnabled -proxyEnabled;
$foo = @{__pwd = "$password" }
}
$foo = Invoke-Command -Session $qsConn -ScriptBlock { $foo }
Invoke-WebRequest -Uri "http://localhost:4570/certificateSetup" -Method Post -Body $Using:foo -credential $secCred
Invoke-WebRequest -Uri "http://localhost:4570/certificateSetup" -Method Post -Body $foo -credential $secCred
# Works if run on Cen
# Invoke-Command -ComputerName $newNode -ScriptBlock { Invoke-WebRequest -Uri "http://localhost:4570/certificateSetup" -Method Post -Body $Using:foo } -credential $secCred
# Config Engine for better NFS Support, restart Engine to read new value
Set-Content -Path C:\ProgramData\Qlik\Sense\Engine\Settings.ini -Value "[Settings 7]`r`nMapNetworkDrives=1"
Restart-Service QlikSenseEngineService -Force
Set-GceInstance -Name ($env:computername).ToLower() -Zone $config.zone -AddTag "joinedCluster"
# Tag the GCE metadata that the Node has been in initialized.
Set-GceInstance -Name ($env:computername).ToLower() -Zone $config.zone -AddTag "joined-cluster"
# Close the remote PS session
Remove-PSSession $qsConn

View File

@@ -80,19 +80,28 @@ Write-Host "------------------------------------------------------------"
Write-Host " Import PS Modules "
Write-Host "------------------------------------------------------------"
# Installing Qlik-CLI
# Write-Host "Downloading Qlik-Cli from Github and importing the Module"
# Invoke-WebRequest "https://raw.githubusercontent.com/ahaydon/Qlik-Cli/master/Qlik-Cli.psm1" -OutFile $temp\Qlik-Cli.psm1
# New-Item -ItemType directory -Path C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Qlik-Cli -force
# Move-Item $temp\Qlik-Cli.psm1 C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Qlik-Cli\ -force
# Import-Module Qlik-Cli.psm1
# Export-QlikCertificate -machineNames rim -includeSecretsKey -exportFormat Windows
Get-PackageProvider -Name NuGet -ForceBootstrap
# Install-Module PSDscResources -Force
Install-Module Qlik-CLI -Force
Write-Host "------------------------------------------------------------"
Write-Host " Deploy PS7 | VSCode | Firefox "
Write-Host " Deploy VSCode | Firefox "
Write-Host "------------------------------------------------------------"
Expand-Archive -Path $deploy_path\binaries\ps7.zip -DestinationPath $deploy_path\binaries\ps7 -Force
Start-Sleep -Seconds 120
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\vscode_stable.exe" -verb runAs -ArgumentList "/VERYSILENT /NORESTART /MERGETASKS=!runcode" -Wait -PassThru } | Out-Null
# Expand-Archive -Path $deploy_path\binaries\ps7.zip -DestinationPath $deploy_path\binaries\ps7 -Force
# Start-Sleep -Seconds 120
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\firefox_latest.exe" -verb runAs -ArgumentList "/s" -Wait -PassThru } | Out-Null
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\vscode_stable.exe" -verb runAs -ArgumentList "/VERYSILENT /NORESTART /MERGETASKS=!runcode" -Wait -PassThru } | Out-Null
Write-Host "------------------------------------------------------------"
Write-Host " Create QSEoW FW Rule "
Write-Host "------------------------------------------------------------"

View File

@@ -2,14 +2,14 @@
{
"dbUserName": "qliksenserepository",
"dbUserPassword": "Qlik1234!",
"dbInstanceIp": "10.54.242.47",
"dbInstanceIp": "10.54.242.53",
"dbPort": "5432",
"fsInstanceIp": "10.219.178.210",
"fsInstanceIp": "10.169.26.66",
"fsShareName": "qlikshare",
"deployPath": "E:\\deploy",
"cenName": "central-6c9a",
"cenName": "central-bd1c",
"qsAdminUser": "qlikadmin",
"qsSvcUser": "qservice",
"zone": "europe-west1-d"
}
]
]

View File

@@ -18,22 +18,85 @@ Function waitProxy {
while ($StatusCode -ne 200) {
try { $statusCode = (Invoke-WebRequest https://$($env:COMPUTERNAME)/qps/user -usebasicParsing).statusCode }
Catch {
Write-Host "Proxy unavailable - retrying in 15s"
Start-Sleep -s 15
Write-Host "Proxy unavailable - retrying in 30s"
Start-Sleep -s 30
}
}
Write-Host "Proxy responding on $env:COMPUTERNAME, status code: $statusCode"
}
# TODO: Archive XMLs to GCS Bucket?
Function writeXmlCen {
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
$filePath = "$deploy_path\scripts\cen.xml" # Set the File Name
$xml = [System.XML.XmlWriter]::Create($filePath, $Null) # Create The Document
$xml.WriteStartDocument() # Write the XML Decleration
$xml.WriteStartElement("SharedPersistenceConfiguration") # Write Root Element
$xml.WriteAttributeString("xmlns", "xsi", "", "http://www.w3.org/2001/XMLSchema-instance")
$xml.WriteAttributeString("xmlns", "xsd", "", "http://www.w3.org/2001/XMLSchema")
$xml.WriteElementString("DbUserName", "$($config.dbUserName)") # <-- Begin writing the XML file
$xml.WriteElementString("DbUserPassword", "$($config.dbUserPassword)")
$xml.WriteElementString("DbHost", "$($config.dbInstanceIp)")
$xml.WriteElementString("DbPort", "$($config.dbPort)")
$xml.WriteElementString("RootDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)")
$xml.WriteElementString("StaticContentRootDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\StaticContent")
$xml.WriteElementString("ArchivedLogsDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\ArchivedLogs")
$xml.WriteElementString("AppsDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\Apps")
$xml.WriteElementString("CreateCluster", "true")
$xml.WriteElementString("InstallLocalDb", "false")
$xml.WriteElementString("ConfigureDbListener", "false")
$xml.WriteElementString("ListenAddresses", "*")
$xml.WriteElementString("IpRange", "0.0.0.0/0")
$xml.WriteEndElement | Out-Null # <-- Closing RootElement
$xml.WriteEndDocument() | Out-Null # End the XML Document
$xml.Finalize | Out-Null # Finish The Document
$xml.Flush | Out-Null
$xml.Close() | Out-Null
}
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Function writeXmlRim {
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
$filePath = "$deploy_path\scripts\rim.xml" # Set the File Name
$xml = [System.XML.XmlWriter]::Create($filePath, $Null) # Create The Document
$xml.WriteStartDocument() # Write the XML Decleration
$xml.WriteStartElement("SharedPersistenceConfiguration") # Write Root Element
$xml.WriteAttributeString("xmlns", "xsi", "", "http://www.w3.org/2001/XMLSchema-instance")
$xml.WriteAttributeString("xmlns", "xsd", "", "http://www.w3.org/2001/XMLSchema")
$xml.WriteElementString("DbUserName", "$($config.dbUserName)") # <-- Begin writing the XML file
$xml.WriteElementString("DbUserPassword", "$($config.dbUserPassword)")
$xml.WriteElementString("DbHost", "$($config.dbInstanceIp)")
$xml.WriteElementString("DbPort", "$($config.dbPort)")
$xml.WriteElementString("RootDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)")
$xml.WriteElementString("StaticContentRootDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\StaticContent")
$xml.WriteElementString("ArchivedLogsDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\ArchivedLogs")
$xml.WriteElementString("AppsDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\Apps")
$xml.WriteElementString("JoinCluster", "true")
$xml.WriteElementString("InstallLocalDb", "false")
$xml.WriteElementString("ConfigureDbListener", "false")
$xml.WriteElementString("ListenAddresses", "*")
$xml.WriteElementString("IpRange", "0.0.0.0/0")
$xml.WriteEndElement | Out-Null # <-- Closing RootElement
$xml.WriteEndDocument() | Out-Null # End the XML Document
$xml.Finalize | Out-Null # Finish The Document
$xml.Flush | Out-Null
$xml.Close() | Out-Null
}
#### Launch silent install
Write-Host "------------------------------------------------------------"
Write-Host " Installing QSEoW "
Write-Host "------------------------------------------------------------"
if ($env:computername -like "central-*") {
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\Qlik_Sense_setup.exe" -ArgumentList "-s -log $deploy_path\deploy.log accepteula=1 skipvalidation=1 installdir=$deploy_path\Qlik dbpassword=Qlik1234! hostname=$($env:computername) userwithdomain=$($env:computername)\qservice password=Qlik1234! bundleinstall=dashboard,visualization spc=$deploy_path\scripts\cen.xml" -Wait -PassThru } | Out-Null
# Do other Stuff
writeXmlCen
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\Qlik_Sense_setup.exe" -ArgumentList "-s -log $deploy_path\deploy.log accepteula=1 skipvalidation=1 installdir=$deploy_path\Qlik dbpassword=Qlik1234! hostname=$($env:computername) userwithdomain=$($env:computername)\qservice password=Qlik1234! bundleinstall=dashboard,visualization spc=$deploy_path\scripts\cen.xml" -Wait -PassThru } | Out-Null
Set-Item WSMan:localhost\client\trustedhosts -value * -Force
@@ -50,16 +113,10 @@ if ($env:computername -like "central-*") {
Write-Host " Installing QSEoW Patch "
Write-Host "------------------------------------------------------------"
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\Qlik_Sense_Update.exe" -ArgumentList "install" -Wait -Passthru } | Out-Null
### Restarting services
Get-Service Qlik* | Where-Object { $_.Name -ne 'QlikLoggingService' } | Start-Service
Get-Service Qlik* | Where-Object { $_.Name -eq 'QlikSenseServiceDispatcher' } | Stop-Service
Get-Service Qlik* | Where-Object { $_.Name -eq 'QlikSenseServiceDispatcher' } | Start-Service
waitProxy
}
# Config Engine for better NFS Support, restart Engine to read new value
Add-Content -Path C:\ProgramData\Qlik\Sense\Engine\Settings.ini -Value "MapNetworkDrives=1"
Set-Content -Path C:\ProgramData\Qlik\Sense\Engine\Settings.ini -Value "[Settings 7]`r`nMapNetworkDrives=1"
Restart-Service QlikSenseEngineService -Force
# Tag the GCE metadata that the Node has been in initialized.
@@ -68,6 +125,8 @@ if ($env:computername -like "central-*") {
else {
writeXmlRim
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\Qlik_Sense_setup.exe" -ArgumentList "-s -log $deploy_path\deploy.log accepteula=1 skipvalidation=1 installdir=$deploy_path\Qlik dbpassword=Qlik1234! hostname=$($env:computername) userwithdomain=$($env:computername)\qservice password=Qlik1234! bundleinstall=dashboard,visualization spc=$deploy_path\scripts\rim.xml" -Wait -PassThru } | Out-Null
Set-Item WSMan:localhost\client\trustedhosts -value * -Force
@@ -77,21 +136,12 @@ else {
Write-Host " Installing QSEoW Patch "
Write-Host "------------------------------------------------------------"
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\binaries\Qlik_Sense_Update.exe" `
-ArgumentList "install" -Wait -Passthru } | Out-Null
### Restarting services
Get-Service Qlik* | Where-Object { $_.Name -ne 'QlikLoggingService' } | Start-Service
Get-Service Qlik* | Where-Object { $_.Name -eq 'QlikSenseServiceDispatcher' } | Stop-Service
Get-Service Qlik* | Where-Object { $_.Name -eq 'QlikSenseServiceDispatcher' } | Start-Service
waitProxy
-ArgumentList "install" -Wait -Passthru } | Out-Null
}
Write-Host "------------------------------------------------------------"
Write-Host " Adding Rim to Cluster "
Write-Host "------------------------------------------------------------"
Invoke-Command -ScriptBlock { Start-Process -FilePath "$deploy_path\scripts\addRim.ps1" -Wait -PassThru } | Out-Null
Invoke-Command -ScriptBlock { Start-Process C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe "-noprofile -sta -WindowStyle Hidden -executionpolicy unrestricted -file $deploy_path\scripts\addRim.ps1" -Wait -PassThru } | Out-Null
# Tag the GCE metadata that the Node has been initialized into the cluster
Set-GceInstance -Name ($env:computername).ToLower() -Zone $config.zone -AddTag "qseInstalled"
Set-GceInstance -Name ($env:computername).ToLower() -Zone $config.zone -AddTag "qse-installed"
}

View File

@@ -1,30 +1,39 @@
function Edit-XmlNodes {
param (
[xml] $doc = $(throw "doc is a required parameter"),
[string] $xpath = $(throw "xpath is a required parameter"),
[string] $value = $(throw "value is a required parameter"),
[bool] $condition = $true
)
if ($condition -eq $true) {
$nodes = $doc.SelectNodes($xpath)
foreach ($node in $nodes) {
if ($node -ne $null) {
if ($node.NodeType -eq "Element") {
$node.InnerXml = $value
}
else {
$node.Value = $value
}
}
}
}
$config = ( Read-GcsObject -Bucket "qliksense" -ObjectName "scripts/config.json" | ConvertFrom-Json )
$qsAdminUser = $config.qsAdminUser
$centralNode = ($env:COMPUTERNAME).ToLower()
$qlikID = "$centralNode\$qsAdminUser"
$deploy_path = $config.deployPath
#### Functions
Function writeXmlCen {
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
$filePath = "$deploy_path\scripts\cen.xml" # Set the File Name
$xml = [System.XML.XmlWriter]::Create($filePath, $Null) # Create The Document
$xml.WriteStartDocument() # Write the XML Decleration
$xml.WriteStartElement("SharedPersistenceConfiguration") # Write Root Element
$xml.WriteAttributeString("xmlns", "xsi", "", "http://www.w3.org/2001/XMLSchema-instance")
$xml.WriteAttributeString("xmlns", "xsd", "", "http://www.w3.org/2001/XMLSchema")
$xml.WriteElementString("DbUserName", "$($config.dbUserName)") # <-- Begin writing the XML file
$xml.WriteElementString("DbUserPassword", "$($config.dbUserPassword)")
$xml.WriteElementString("DbHost", "$($config.dbInstanceIp)")
$xml.WriteElementString("DbPort", "$($config.dbPort)")
$xml.WriteElementString("RootDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)")
$xml.WriteElementString("StaticContentRootDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\StaticContent")
$xml.WriteElementString("ArchivedLogsDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\ArchivedLogs")
$xml.WriteElementString("AppsDir", "$("\\" + $config.fsInstanceIp + "\" + $config.fsShareName)" + "\Apps")
$xml.WriteElementString("CreateCluster", "true")
$xml.WriteElementString("InstallLocalDb", "false")
$xml.WriteElementString("ConfigureDbListener", "false")
$xml.WriteElementString("ListenAddresses", "*")
$xml.WriteElementString("IpRange", "0.0.0.0/0")
$xml.WriteEndElement | Out-Null # <-- Closing RootElement
$xml.WriteEndDocument() | Out-Null # End the XML Document
$xml.Finalize | Out-Null # Finish The Document
$xml.Flush | Out-Null
$xml.Close() | Out-Null
}
$xml = [xml](Get-Content "./cen.xml")
# <file><foo attribute="bar" attribute2="bar" attribute3="bar" /></file>
Edit-XmlNodes $xml -xpath "/cen/foo[@attribute='bar']/@attribute" -value "new value"
$xml.save("c:\my\file.xml")
# <file><foo attribute="new value" attribute2="bar" attribute3="bar" /></file>
writeXmlCen