171 lines
8.2 KiB
PowerShell
171 lines
8.2 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]$ExitNodeName = "test-2",
|
|
[string]$EntryBaseUrl = "http://192.168.200.61:19131",
|
|
[string]$ResultPath = "artifacts\c19z14-remote-workspace-mailbox-preflight-repeated-attention-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
|
|
$sourceResultPath = "artifacts\c19z14-remote-workspace-mailbox-preflight-repeated-attention-source-result.json"
|
|
$adapterSessionID = ""
|
|
|
|
function Invoke-Api {
|
|
param([string]$Method, [string]$Path, [object]$Body = $null)
|
|
$uri = "$ApiBaseUrl$Path"
|
|
if ($null -eq $Body) { return Invoke-RestMethod -Method $Method -Uri $uri -TimeoutSec 30 }
|
|
return Invoke-RestMethod -Method $Method -Uri $uri -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 80) -TimeoutSec 30
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
function Get-NodeByName {
|
|
param([string]$Name)
|
|
$nodes = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes?actor_user_id=$ActorUserID").nodes
|
|
$node = @($nodes | Where-Object { $_.name -eq $Name }) | Select-Object -First 1
|
|
if ($null -eq $node) { throw "Node '$Name' was not found in cluster $ClusterID" }
|
|
return $node
|
|
}
|
|
|
|
function Get-RemoteWorkspaceSinkReports {
|
|
param([string]$NodeID)
|
|
$statuses = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/workloads/status?actor_user_id=$ActorUserID").workload_statuses
|
|
$workloadStatus = @($statuses | Where-Object { $_.service_type -eq "rdp-worker" } | Select-Object -First 1)
|
|
$workloadSink = $null
|
|
if ($null -ne $workloadStatus) {
|
|
$workloadSink = Get-PropertyValue -Item $workloadStatus.status_payload -Name "remote_workspace_adapter_sink" -Default $null
|
|
}
|
|
$telemetryItems = @((Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/telemetry?actor_user_id=$ActorUserID&limit=10").telemetry)
|
|
$telemetry = $telemetryItems | Select-Object -First 1
|
|
$telemetrySink = $null
|
|
if ($null -ne $telemetry) {
|
|
$telemetryPayload = Get-PropertyValue -Item $telemetry -Name "payload" -Default $null
|
|
$telemetrySink = Get-PropertyValue -Item $telemetryPayload -Name "remote_workspace_adapter_sink_report" -Default $null
|
|
}
|
|
return [ordered]@{
|
|
workload_status = $workloadStatus
|
|
workload_sink = $workloadSink
|
|
telemetry = $telemetry
|
|
telemetry_sink = $telemetrySink
|
|
}
|
|
}
|
|
|
|
function Invoke-Preflight {
|
|
param([string]$SessionID)
|
|
$url = "$EntryBaseUrl/mesh/v1/remote-workspace/adapter-sessions/$SessionID/mailbox/preflight?consumer_id=rdp-worker-probe&resume_from=ack&limit=3"
|
|
$response = Invoke-WebRequest -Method GET -Uri $url -TimeoutSec 35
|
|
$json = $null
|
|
if ($response.Content) { $json = $response.Content | ConvertFrom-Json }
|
|
return [ordered]@{ status_code = [int]$response.StatusCode; body = $response.Content; json = $json }
|
|
}
|
|
|
|
function Invoke-Control {
|
|
param([string]$SessionID)
|
|
if ([string]::IsNullOrWhiteSpace($SessionID)) { return $null }
|
|
$url = "$EntryBaseUrl/mesh/v1/remote-workspace/adapter-sessions/$SessionID/control"
|
|
$body = @{ action = "close"; reason = "c19z14 repeated preflight close" } | ConvertTo-Json -Compress
|
|
return Invoke-RestMethod -Method POST -Uri $url -ContentType "application/json" -Body $body -TimeoutSec 30
|
|
}
|
|
|
|
function Test-RepeatedAttention {
|
|
param([object]$Sink, [string]$SessionID)
|
|
if ($null -eq $Sink) { return $false }
|
|
$readiness = Get-PropertyValue -Item $Sink -Name "adapter_runtime_readiness" -Default $null
|
|
$rollup = Get-PropertyValue -Item $readiness -Name "last_preflight" -Default $null
|
|
if ($null -eq $rollup) { return $false }
|
|
$statusCounts = Get-PropertyValue -Item $rollup -Name "operator_status_counts" -Default $null
|
|
$severityCounts = Get-PropertyValue -Item $rollup -Name "operator_severity_counts" -Default $null
|
|
return (
|
|
[string](Get-PropertyValue -Item $readiness -Name "adapter_session_id" -Default "") -eq $SessionID -and
|
|
[string](Get-PropertyValue -Item $readiness -Name "preflight_attention_status" -Default "") -eq "repeated_resync_required" -and
|
|
[string](Get-PropertyValue -Item $rollup -Name "preflight_attention_status" -Default "") -eq "repeated_resync_required" -and
|
|
[int64](Get-PropertyValue -Item $statusCounts -Name "resync_required" -Default 0) -ge 2 -and
|
|
[int64](Get-PropertyValue -Item $severityCounts -Name "warn" -Default 0) -ge 2
|
|
)
|
|
}
|
|
|
|
try {
|
|
$entryNode = Get-NodeByName -Name $EntryNodeName
|
|
$source = & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19z3-remote-workspace-mailbox-stale-preflight-smoke.ps1") `
|
|
-ApiBaseUrl $ApiBaseUrl `
|
|
-ClusterID $ClusterID `
|
|
-ActorUserID $ActorUserID `
|
|
-EntryNodeName $EntryNodeName `
|
|
-ExitNodeName $ExitNodeName `
|
|
-EntryBaseUrl $EntryBaseUrl `
|
|
-ResultPath $sourceResultPath `
|
|
-SkipClose
|
|
|
|
$sourceFile = Join-Path $repoRoot $sourceResultPath
|
|
$sourceResult = Get-Content -Raw -Path $sourceFile | ConvertFrom-Json
|
|
$adapterSessionID = [string](Get-PropertyValue -Item $sourceResult -Name "adapter_session_id" -Default "")
|
|
$secondPreflight = Invoke-Preflight -SessionID $adapterSessionID
|
|
|
|
$observed = $null
|
|
$deadline = (Get-Date).AddSeconds(90)
|
|
while ((Get-Date) -lt $deadline) {
|
|
Start-Sleep -Seconds 5
|
|
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
|
|
if (
|
|
(Test-RepeatedAttention -Sink $observed.workload_sink -SessionID $adapterSessionID) -and
|
|
(Test-RepeatedAttention -Sink $observed.telemetry_sink -SessionID $adapterSessionID)
|
|
) {
|
|
break
|
|
}
|
|
}
|
|
if ($null -eq $observed) {
|
|
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
|
|
}
|
|
$control = Invoke-Control -SessionID $adapterSessionID
|
|
|
|
$checks = [ordered]@{
|
|
source_smoke_passed = ([bool]$sourceResult.passed)
|
|
adapter_session_id_present = ($adapterSessionID -match "^rap-rw-adapter-session-[0-9a-f]{24}$")
|
|
second_preflight_stale = ([int]$secondPreflight.status_code -eq 200 -and [string]$secondPreflight.json.operator_status -eq "resync_required" -and [string]$secondPreflight.json.operator_severity -eq "warn")
|
|
workload_repeated_attention_visible = (Test-RepeatedAttention -Sink $observed.workload_sink -SessionID $adapterSessionID)
|
|
telemetry_repeated_attention_visible = (Test-RepeatedAttention -Sink $observed.telemetry_sink -SessionID $adapterSessionID)
|
|
close_accepted = ([bool]$control.accepted -and [string]$control.session_state -eq "closed")
|
|
}
|
|
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c19z14.remote_workspace_mailbox_preflight_repeated_attention_smoke.v1"
|
|
source_result_path = $sourceFile
|
|
cluster_id = $ClusterID
|
|
adapter_session_id = $adapterSessionID
|
|
second_preflight = $secondPreflight
|
|
observed = $observed
|
|
control = $control
|
|
checks = $checks
|
|
failed_checks = $failed
|
|
passed = ($failed.Count -eq 0)
|
|
}
|
|
} finally {
|
|
if ($adapterSessionID) {
|
|
try { [void](Invoke-Control -SessionID $adapterSessionID) } catch {}
|
|
}
|
|
}
|
|
|
|
$fullResultPath = Join-Path $repoRoot $ResultPath
|
|
$resultDir = Split-Path -Parent $fullResultPath
|
|
if ($resultDir) { New-Item -ItemType Directory -Force -Path $resultDir | Out-Null }
|
|
$result | ConvertTo-Json -Depth 100 | Set-Content -Encoding UTF8 -Path $fullResultPath
|
|
|
|
if (-not $result.passed) {
|
|
throw "C19Z14 remote workspace mailbox preflight repeated-attention smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
|
|
}
|
|
|
|
Write-Host "C19Z14 remote workspace mailbox preflight repeated-attention smoke passed. Result: $fullResultPath"
|
|
$result
|