###################################################################
# Get node count difference according to capacity #
###################################################################
Function GetNodesToHibernate($currentCapacity, $targetCapacity, $totalCount)
{
if ($currentCapacity -ge $targetCapacity)
{
return [int](($currentCapacity - $targetCapacity) * $totalCount / 100)
}
else
{
return [System.Math]::Floor(($currentCapacity - $targetCapacity) * $totalCount / 100)
}
}
###################################################################
# Hibernate nodes #
###################################################################
Function Hibernate($onlineNodes, $hibernatedNodes, $countToHibernate)
{
$targets = New-Object System.Collections.ArrayList
$counters = $onlineNodes | Get-HpcMetricValue -Name HPCCoresInUse -EA:SilentlyContinue
$freeNodes = @{}
$counters | % {
if ($_.Value -eq 0)
{
$freeNodes.Add($_.NodeName, $null) # use as an set
}
}
foreach ($node in $onlineNodes)
{
if ($targets.Count -ge $countToHibernate)
{
break
}
if ((-not $node.IsHeadNode) -and (-not ([string]$node.NodeRole).Contains("BrokerNode")) -and ($freeNodes.ContainsKey($node.NetBiosName))) # installed as cn and is free
{
$targets.Add($node.NetBiosName)
}
}
foreach ($op in $workitem.Operations)
{
if ($op.State -ne 'Committed')
{
$offline = $false
break
}
}
if (-not $offline) # failed to offline or timeout
{
Write-EventLog -LogName $eventLogName -Source $eventLogSource -EventId $timeoutEvent -EntryType Warning -Message "Consumption based power management rule: Nodes are not offline within the time limit. Operations will be canceled."
$nodes = Get-HpcNode -Name $nodesToWakeup -State Offline -HealthState OK, Warning -Scheduler $clusterName -EA:SilentlyContinue
if ($nodes -ne $null) # some nodes need to be brought online
{
$error.Clear()
$nodes | Set-HpcNodeState -State Online -Scheduler $clusterName
$errorMsg = $error
if ($error)
{
$nodes = Get-HpcNode -Name $targets -State Offline -HealthState OK, Warning -Scheduler $clusterName -EA:SilentlyContinue
if ($nodes -ne $null) # some nodes failed to be brought online even after retrial
{
$message = @"
Some nodes failed to be brought online by consumption based power management rule. These nodes include:
"@
$nodes | % {
$message += $_.NetBiosName + " "
$nodesToHibernate.Add($_.NetBiosName)
}
$message += @"