resources/node.ps1
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 |
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, [ValidateSet("Production", "Development", "Both", "ProductionAndDevelopment")] [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 { $conf = @{ configuration=@{ name=$name; hostName=$hostname; } } If ($engineEnabled) { $conf.configuration.engineEnabled = $engineEnabled.IsPresent; } If ($proxyEnabled) { $conf.configuration.proxyEnabled = $proxyEnabled.IsPresent; } If ($schedulerEnabled) { $conf.configuration.schedulerEnabled = $schedulerEnabled.IsPresent; } If ($printingEnabled) { $conf.configuration.printingEnabled = $printingEnabled.IsPresent; } If ($failoverCandidate) { $conf.configuration.failoverCandidate = $failoverCandidate.IsPresent; } If( $nodePurpose ) { $conf.configuration.nodePurpose = switch($nodePurpose) { Production { 0 } Development { 1 } ProductionAndDevelopment { 2 } Both { 2 } } } $json = ($conf | 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(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 if ($password) { $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", "ProductionAndDevelopment")] [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 } ProductionAndDevelopment { $node.nodePurpose = 2 } Both { $node.nodePurpose = 2 } } } if ($PSBoundParameters.ContainsKey("customProperties")) { $node.customProperties = @(GetCustomProperties $customProperties) } if ($PSBoundParameters.ContainsKey("tags")) { $node.tags = @(GetTags $tags) } If( $psBoundParameters.ContainsKey("engineEnabled") ) { $node.engineEnabled = $engineEnabled.IsPresent } If( $psBoundParameters.ContainsKey("proxyEnabled") ) { $node.proxyEnabled = $proxyEnabled.IsPresent } If( $psBoundParameters.ContainsKey("schedulerEnabled") ) { $node.schedulerEnabled = $schedulerEnabled.IsPresent } If( $psBoundParameters.ContainsKey("printingEnabled") ) { $node.printingEnabled = $printingEnabled.IsPresent } If( $psBoundParameters.ContainsKey("failoverCandidate") ) { $node.failoverCandidate = $failoverCandidate.IsPresent } $json = $node | ConvertTo-Json -Compress -Depth 10 return Invoke-QlikPut "/qrs/servernodeconfiguration/$id" $json } } |