-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathSubmitStormTopologyWindows.ps1
71 lines (63 loc) · 2.58 KB
/
SubmitStormTopologyWindows.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
[CmdletBinding(PositionalBinding=$True)]
Param(
[Parameter(Mandatory = $true)]
[String]$ClusterUrl, # required
[Parameter(Mandatory = $true)]
[String]$ClusterUsername, # required
[Parameter(Mandatory = $true)]
[String]$ClusterPassword, # required
[Parameter(Mandatory = $true)]
[String]$JarPath, # required path of the jar in WASB to submit
[Parameter(Mandatory = $true)]
[String]$ClassName, # required
[String]$AdditionalParams # optional at least include the topology name
)
###########################################################
# Start - Initialization - Invocation, Logging etc
###########################################################
$VerbosePreference = "SilentlyContinue"
$ErrorActionPreference = "Stop"
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path $scriptPath
& "$scriptDir\..\init.ps1"
if(-not $?)
{
throw "Initialization failure."
exit -9999
}
###########################################################
# End - Initialization - Invocation, Logging etc
###########################################################
$clusterUri = new-object Uri($ClusterUrl)
$clusterSubmitJarUri = new-object Uri($clusterUri, "StormDashboard/SubmitWasbJar")
$body = @{
FilePath = $JarPath;
ClassName = $ClassName;
AdditionalParameters = $AdditionalParams;
}
$securePwd = ConvertTo-SecureString $ClusterPassword -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential($ClusterUsername, $securePwd)
Write-InfoLog ("Sending POST request at: " + $clusterSubmitJarUri.AbsoluteUri) (Get-ScriptName) (Get-ScriptLineNumber)
try
{
$response = Invoke-RestMethod -Uri $clusterSubmitJarUri.AbsoluteUri -Method "Post" -Body $body -Credential $creds
if($?)
{
Write-SpecialLog "Successfully submitted topology: $ClassName" (Get-ScriptName) (Get-ScriptLineNumber)
Write-InfoLog ("Response:`r`n" + ($response | Out-String)) (Get-ScriptName) (Get-ScriptLineNumber)
}
else
{
$failure = $true
}
}
catch
{
$failure = $true
Write-ErrorLog "Exception encountered while invoking the [POST] rest method at: $clusterSubmitJarUri" (Get-ScriptName) (Get-ScriptLineNumber) $_
}
if($failure)
{
Write-ErrorLog "Topology submission encountered an error, please check logs for error information." (Get-ScriptName) (Get-ScriptLineNumber)
throw "Topology submission encountered an error, please check logs for error information."
}