resources/node.ps1
function Get-QlikNode { [CmdletBinding()] param ( [parameter(Position=0)] [string]$id, [string]$filter, [switch]$count, [switch]$full, [switch]$raw ) PROCESS { $path = "/qrs/servernodeconfiguration" If( $id ) { $path += "/$id" } If( $full ) { $path += "/full" } If( $count -And (-not ($id -And $full)) ) { $path += "/count" } If( $raw ) { $rawOutput = $true } return Invoke-QlikGet $path $filter } } function New-QlikNode { [CmdletBinding()] param ( [parameter(Mandatory=$true,Position=0)] [string]$hostname, [string]$name = $hostname, [string]$nodePurpose, [string[]]$customProperties, [string[]]$tags, [alias("engine")] [switch]$engineEnabled, [alias("proxy")] [switch]$proxyEnabled, [alias("scheduler")] [switch]$schedulerEnabled, [alias("printing")] [switch]$printingEnabled, [alias("failover")] [switch]$failoverCandidate ) PROCESS { $json = (@{ configuration=@{ name=$name; hostName=$hostname; engineEnabled=$engineEnabled.IsPresent; proxyEnabled=$proxyEnabled.IsPresent; schedulerEnabled=$schedulerEnabled.IsPresent; printingEnabled=$printingEnabled.IsPresent; failoverCandidate=$failoverCandidate.IsPresent; } } | ConvertTo-Json -Compress -Depth 10) $container = Invoke-QlikPost "/qrs/servernodeconfiguration/container" $json #Write-Host "http://localhost:4570/certificateSetup" return Invoke-QlikGet "/qrs/servernoderegistration/start/$($container.configuration.id)" } } function Register-QlikNode { [CmdletBinding()] param ( [parameter(Mandatory=$true,Position=0)] [string]$hostname = $($env:computername), [string]$name = $hostname, [string]$nodePurpose, [string[]]$customProperties, [string[]]$tags, [alias("engine")] [switch]$engineEnabled, [alias("proxy")] [switch]$proxyEnabled, [alias("scheduler")] [switch]$schedulerEnabled, [alias("printing")] [switch]$printingEnabled, [alias("failover")] [switch]$failoverCandidate ) PROCESS { If( !$psBoundParameters.ContainsKey("hostname") ) { $psBoundParameters.Add( "hostname", $hostname ) } If( !$psBoundParameters.ContainsKey("name") ) { $psBoundParameters.Add( "name", $name ) } $password = New-QlikNode @psBoundParameters $postParams = @{__pwd="$password"} Invoke-WebRequest -Uri "http://localhost:4570/certificateSetup" -Method Post -Body $postParams -UseBasicParsing > $null } } function Remove-QlikNode { [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelinebyPropertyName=$true,Position=0)] [string]$id ) PROCESS { return Invoke-QlikDelete "/qrs/servernodeconfiguration/$id" } } function Update-QlikNode { [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True,Position=0)] [string]$id, [string]$name, [ValidateSet("Production", "Development", "Both")] [string]$nodePurpose, [string[]]$customProperties, [string[]]$tags, [switch]$engineEnabled, [switch]$proxyEnabled, [switch]$schedulerEnabled, [switch]$printingEnabled, [switch]$failoverCandidate ) PROCESS { $node = Get-QlikNode $id -raw If( $name ) { $node.name = $name } If( $nodePurpose ) { switch($nodePurpose) { Production { $node.nodePurpose = 0 } Development { $node.nodePurpose = 1 } Both { $node.nodePurpose = 2 } } } If( $customProperties ) { $prop = @( $customProperties | foreach { $val = $_ -Split "=" $p = Get-QlikCustomProperty -filter "name eq '$($val[0])'" @{ value = ($p.choiceValues -eq $val[1])[0] definition = $p } } ) $node.customProperties = $prop } If( $tags ) { $node.tags = $tags } If( $psBoundParameters.ContainsKey("engineEnabled") ) { $node.engineEnabled = $engineEnabled } If( $psBoundParameters.ContainsKey("proxyEnabled") ) { $node.proxyEnabled = $proxyEnabled } If( $psBoundParameters.ContainsKey("schedulerEnabled") ) { $node.schedulerEnabled = $schedulerEnabled } If( $psBoundParameters.ContainsKey("printingEnabled") ) { $node.printingEnabled = $printingEnabled } If( $psBoundParameters.ContainsKey("failoverCandidate") ) { $node.failoverCandidate = $failoverCandidate } $json = $node | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut "/qrs/servernodeconfiguration/$id" $json } } |