-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.ps1
56 lines (48 loc) · 1.33 KB
/
test.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
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[string] $Version,
[Parameter(Mandatory=$false)]
[string] $Timeout = 120
)
$start = [datetime]::UtcNow
$successfull = $false
$ip = docker inspect --format='{{.NetworkSettings.Networks.nat.IPAddress}}' elasticsearch
$ip = $ip.Trim()
if([string]::IsNullOrEmpty($ip))
{
$ip = 'localhost'
}
$baseUrl = "http://$($ip):9200"
Write-Host "Conneting to $baseUrl"
while(!$successfull -and (New-TimeSpan -Start $start -End ([datetime]::UtcNow)).TotalSeconds -le $Timeout)
{
try
{
Write-Host "Getting cluster health..."
$health = Invoke-RestMethod "$baseUrl/_cluster/health" -TimeoutSec 5
Write-Host "Cluster status is $($health.status)"
$successfull = $health.status -eq 'green'
if($successfull)
{
$cluster = Invoke-RestMethod $baseUrl -TimeoutSec 5
Write-Host "Cluster version is $($cluster.version.number)"
if($cluster.version.number -ne $Version)
{
Write-Host "Version does not match, was expecting $Version"
$successfull = $false
break #exit while loop
}
}
}
catch
{
Write-Host $_.Exception.Message
Start-Sleep 5
}
}
if(!$successfull)
{
docker logs elasticsearch
exit(1)
}