73 lines
2.3 KiB
PowerShell
73 lines
2.3 KiB
PowerShell
|
function Enable-AlkamiServiceFabricNode {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
State transitions a Service Fabric node to 'Up' and monitors that state transition to
|
||
|
completion (by default).
|
||
|
|
||
|
.PARAMETER Hostname
|
||
|
[string] The host name of the server in the Service Fabric cluster to enable. If not provided, defaults to localhost.
|
||
|
|
||
|
.PARAMETER TimeoutMinutes
|
||
|
[byte] The length of time in minutes to monitor the node for state transition completion before declaring that an error
|
||
|
has occurred. Defaults to 30 minutes.
|
||
|
|
||
|
.PARAMETER SleepIntervalSeconds
|
||
|
[byte] The length of time in seconds to pause between node status queries. Defaults to 15 seconds.
|
||
|
|
||
|
.PARAMETER SkipHealthCheck
|
||
|
[switch] Flag to skip node and cluster health status monitoring post-transition.
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
Param(
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[ValidateNotNullOrEmpty()]
|
||
|
[string]$Hostname = 'localhost',
|
||
|
|
||
|
[Parameter(Mandatory=$false)]
|
||
|
[byte]$TimeoutMinutes = 30,
|
||
|
|
||
|
[Parameter(Mandatory=$false)]
|
||
|
[ValidateRange(1, 120)]
|
||
|
[byte]$SleepIntervalSeconds = 15,
|
||
|
|
||
|
[Parameter(Mandatory=$false)]
|
||
|
[switch]$SkipHealthCheck
|
||
|
)
|
||
|
|
||
|
$loglead = (Get-LogLeadName)
|
||
|
|
||
|
Connect-AlkamiServiceFabricCluster -Hostname $Hostname
|
||
|
|
||
|
if ( $Hostname -eq 'localhost' ) {
|
||
|
|
||
|
$actualHostname = "$env:COMPUTERNAME"
|
||
|
|
||
|
} else {
|
||
|
|
||
|
$actualHostname = $Hostname
|
||
|
}
|
||
|
|
||
|
$curNode = Get-ServiceFabricNode | Where-Object { $_.NodeName -eq $actualHostname } | Select-Object -First 1
|
||
|
if ( ! $curNode ) {
|
||
|
|
||
|
Write-Error "$loglead : Could not retrieve the Service Fabric node for $actualHostname."
|
||
|
return
|
||
|
|
||
|
} else {
|
||
|
|
||
|
$nodeName = $curNode.NodeName
|
||
|
}
|
||
|
|
||
|
Enable-ServiceFabricNode -NodeName $nodeName
|
||
|
|
||
|
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
|
||
|
Wait-AlkamiServiceFabricNodeStatus -DesiredStatus 'Up' -Hostname $nodeName -TimeoutMinutes $TimeoutMinutes -SleepIntervalSeconds $SleepIntervalSeconds -SkipHealthCheck:$SkipHealthCheck
|
||
|
$stopwatch.Stop()
|
||
|
|
||
|
if ( ! $SkipHealthCheck ) {
|
||
|
|
||
|
$timeRemaining = ( $TimeoutMinutes - $stopwatch.Elapsed.TotalMinutes )
|
||
|
Wait-AlkamiServiceFabricClusterHealthy -Hostname $nodeName -TimeoutMinutes $timeRemaining -SleepIntervalSeconds $SleepIntervalSeconds
|
||
|
}
|
||
|
}
|