143 lines
5.7 KiB
PowerShell
143 lines
5.7 KiB
PowerShell
param(
|
|
[string]$ApiBaseUrl = "http://192.168.200.61:18121/api/v1",
|
|
[string]$ClusterID = "cfc0743d-d960-49fb-9de8-96e063d5e4aa",
|
|
[string]$ActorUserID = "f67d943f-5397-4b3a-a229-695fe67ad700",
|
|
[string]$EntryNodeName = "test-1",
|
|
[string]$ResultPath = "artifacts\c18z71-service-channel-adaptive-policy-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
|
|
$c18z67 = Join-Path $scriptDir "c18z67-service-channel-concurrent-qos-live-smoke.ps1"
|
|
|
|
function Invoke-Api {
|
|
param(
|
|
[string]$Method,
|
|
[string]$Path,
|
|
[object]$Body = $null
|
|
)
|
|
$params = @{
|
|
Method = $Method
|
|
Uri = "$ApiBaseUrl$Path"
|
|
TimeoutSec = 30
|
|
}
|
|
if ($null -ne $Body) {
|
|
$params.ContentType = "application/json"
|
|
$params.Body = ($Body | ConvertTo-Json -Depth 30)
|
|
}
|
|
return Invoke-RestMethod @params
|
|
}
|
|
|
|
function Get-PropertyValue {
|
|
param([object]$Item, [string]$Name, [object]$Default = $null)
|
|
if ($null -eq $Item) { return $Default }
|
|
$property = $Item.PSObject.Properties[$Name]
|
|
if ($null -eq $property) { return $Default }
|
|
return $property.Value
|
|
}
|
|
|
|
$policyBody = @{
|
|
actor_user_id = $ActorUserID
|
|
max_parallel_window = 6
|
|
bulk_pressure_channel_threshold = 8
|
|
queue_pressure_high_watermark = 8
|
|
queue_pressure_max_in_flight = 8
|
|
class_windows = @{
|
|
control = 6
|
|
interactive = 6
|
|
reliable = 4
|
|
bulk = 2
|
|
droppable = 1
|
|
}
|
|
}
|
|
$updatedPolicy = (Invoke-Api -Method PUT -Path "/clusters/$ClusterID/fabric/service-channels/adaptive-policy" -Body $policyBody).fabric_service_channel_adaptive_policy
|
|
$expectedFingerprint = [string]$updatedPolicy.fingerprint
|
|
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File $c18z67 | Out-Host
|
|
|
|
$nodes = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes?actor_user_id=$ActorUserID").nodes
|
|
$entryNode = @($nodes | Where-Object { $_.name -eq $EntryNodeName }) | Select-Object -First 1
|
|
if ($null -eq $entryNode) {
|
|
throw "entry node '$EntryNodeName' not found"
|
|
}
|
|
|
|
$flowScheduler = $null
|
|
for ($i = 0; $i -lt 12; $i++) {
|
|
Start-Sleep -Seconds 5
|
|
$heartbeats = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$($entryNode.id)/heartbeats?actor_user_id=$ActorUserID&limit=5").heartbeats
|
|
foreach ($heartbeat in @($heartbeats)) {
|
|
$runtimeReport = Get-PropertyValue -Item (Get-PropertyValue -Item $heartbeat -Name "metadata" -Default $null) -Name "fabric_service_channel_runtime_report" -Default $null
|
|
$ingress = Get-PropertyValue -Item $runtimeReport -Name "ingress" -Default $null
|
|
$candidate = Get-PropertyValue -Item $ingress -Name "flow_scheduler" -Default $null
|
|
if ($null -eq $candidate) { continue }
|
|
if ([string](Get-PropertyValue -Item $candidate -Name "adaptive_policy_fingerprint" -Default "") -eq $expectedFingerprint) {
|
|
$flowScheduler = $candidate
|
|
break
|
|
}
|
|
}
|
|
if ($null -ne $flowScheduler) { break }
|
|
}
|
|
if ($null -eq $flowScheduler) {
|
|
throw "entry node did not report adaptive policy fingerprint '$expectedFingerprint'"
|
|
}
|
|
|
|
$windows = Get-PropertyValue -Item $flowScheduler -Name "recommended_parallel_windows" -Default $null
|
|
$checks = [ordered]@{
|
|
policy_fingerprint_persisted = ($expectedFingerprint.Length -gt 0)
|
|
node_reported_policy_fingerprint = ([string](Get-PropertyValue -Item $flowScheduler -Name "adaptive_policy_fingerprint" -Default "") -eq $expectedFingerprint)
|
|
adaptive_backpressure_active = [bool](Get-PropertyValue -Item $flowScheduler -Name "adaptive_backpressure_active" -Default $false)
|
|
bulk_window_uses_policy = ([int](Get-PropertyValue -Item $windows -Name "bulk" -Default 0) -eq 2)
|
|
droppable_window_uses_policy = ([int](Get-PropertyValue -Item $windows -Name "droppable" -Default 0) -eq 1)
|
|
reliable_window_uses_policy = ([int](Get-PropertyValue -Item $windows -Name "reliable" -Default 0) -le 4)
|
|
interactive_window_uses_policy_ceiling = ([int](Get-PropertyValue -Item $windows -Name "interactive" -Default 0) -eq 6)
|
|
control_window_uses_policy_ceiling = ([int](Get-PropertyValue -Item $windows -Name "control" -Default 0) -eq 6)
|
|
}
|
|
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c18z71.service_channel_adaptive_policy_smoke.v1"
|
|
run_id = "c18z71-" + (Get-Date -Format "yyyyMMdd-HHmmss")
|
|
cluster_id = $ClusterID
|
|
entry_node_id = $entryNode.id
|
|
entry_node_name = $entryNode.name
|
|
passed = ($failed.Count -eq 0)
|
|
checks = $checks
|
|
failed_checks = $failed
|
|
summary = [ordered]@{
|
|
adaptive_policy = $updatedPolicy
|
|
flow_scheduler = $flowScheduler
|
|
}
|
|
}
|
|
|
|
$target = Join-Path $repoRoot $ResultPath
|
|
$result | ConvertTo-Json -Depth 50 | Set-Content -Path $target -Encoding UTF8
|
|
|
|
try {
|
|
Invoke-Api -Method PUT -Path "/clusters/$ClusterID/fabric/service-channels/adaptive-policy" -Body @{
|
|
actor_user_id = $ActorUserID
|
|
max_parallel_window = 4
|
|
bulk_pressure_channel_threshold = 16
|
|
queue_pressure_high_watermark = 16
|
|
queue_pressure_max_in_flight = 16
|
|
class_windows = @{
|
|
control = 4
|
|
interactive = 4
|
|
reliable = 3
|
|
bulk = 1
|
|
droppable = 1
|
|
}
|
|
} | Out-Null
|
|
} catch {
|
|
Write-Warning "failed to restore default adaptive policy after smoke: $($_.Exception.Message)"
|
|
}
|
|
|
|
if (-not $result.passed) {
|
|
throw "C18Z71 adaptive policy smoke failed: $($failed -join ', ')"
|
|
}
|
|
|
|
Write-Host "C18Z71 service-channel adaptive policy smoke passed. Result: $target"
|
|
$result
|