Record project continuation changes
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
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\c19z-remote-workspace-adapter-readiness-smoke-result.json"
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
|
||||
$sourceResultPath = "artifacts\c19z-remote-workspace-adapter-readiness-source-result.json"
|
||||
$consumerID = "rdp-worker-probe"
|
||||
$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)
|
||||
$workloadStatus = $null
|
||||
$workloadSink = $null
|
||||
$telemetry = $null
|
||||
$telemetrySink = $null
|
||||
$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)
|
||||
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
|
||||
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-Control {
|
||||
param([string]$SessionID)
|
||||
if ([string]::IsNullOrWhiteSpace($SessionID)) { return $null }
|
||||
$url = "$EntryBaseUrl/mesh/v1/remote-workspace/adapter-sessions/$SessionID/control"
|
||||
$body = @{ action = "close"; reason = "c19z adapter readiness close" } | ConvertTo-Json -Compress
|
||||
return Invoke-RestMethod -Method POST -Uri $url -ContentType "application/json" -Body $body -TimeoutSec 30
|
||||
}
|
||||
|
||||
function Test-AdapterReadiness {
|
||||
param(
|
||||
[object]$Sink,
|
||||
[string]$SessionID,
|
||||
[int64]$ResumeSequence,
|
||||
[int]$SkippedCount,
|
||||
[int]$ReturnedCount
|
||||
)
|
||||
if ($null -eq $Sink) { return $false }
|
||||
$readiness = Get-PropertyValue -Item $Sink -Name "adapter_runtime_readiness" -Default $null
|
||||
if ($null -eq $readiness) { return $false }
|
||||
return (
|
||||
[string](Get-PropertyValue -Item $readiness -Name "schema_version" -Default "") -eq "rap.remote_workspace_adapter_runtime_readiness.v1" -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "status" -Default "") -eq "cursor_ready" -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "diagnostic_state" -Default "") -eq "adapter_cursor_ready" -and
|
||||
[bool](Get-PropertyValue -Item $readiness -Name "ready" -Default $false) -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "adapter_session_id" -Default "") -eq $SessionID -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "session_state" -Default "") -eq "probe_bound" -and
|
||||
[int](Get-PropertyValue -Item $readiness -Name "mailbox_depth" -Default 0) -ge 3 -and
|
||||
[int](Get-PropertyValue -Item $readiness -Name "consumer_count" -Default 0) -ge 1 -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "last_consumer_id" -Default "") -eq $consumerID -and
|
||||
[int64](Get-PropertyValue -Item $readiness -Name "last_consumer_ack_sequence" -Default -1) -eq $ResumeSequence -and
|
||||
[int64](Get-PropertyValue -Item $readiness -Name "last_consumer_lag_count" -Default -1) -ge 1 -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "last_resume_from" -Default "") -eq "ack" -and
|
||||
[int64](Get-PropertyValue -Item $readiness -Name "last_resume_sequence" -Default -1) -eq $ResumeSequence -and
|
||||
[string](Get-PropertyValue -Item $readiness -Name "last_resume_consumer_id" -Default "") -eq $consumerID -and
|
||||
[int](Get-PropertyValue -Item $readiness -Name "last_skipped_count" -Default -1) -eq $SkippedCount -and
|
||||
[int](Get-PropertyValue -Item $readiness -Name "last_returned_count" -Default -1) -eq $ReturnedCount
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
$entryNode = Get-NodeByName -Name $EntryNodeName
|
||||
|
||||
$source = & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19x-remote-workspace-mailbox-consumer-resume-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 "")
|
||||
$resumeAck = Get-PropertyValue -Item $sourceResult -Name "resume_ack" -Default $null
|
||||
$resumeAckJson = Get-PropertyValue -Item $resumeAck -Name "json" -Default $null
|
||||
$resumeSequence = [int64](Get-PropertyValue -Item $resumeAckJson -Name "resume_sequence" -Default 0)
|
||||
$skippedCount = [int](Get-PropertyValue -Item $resumeAckJson -Name "skipped_count" -Default 0)
|
||||
$returnedCount = [int](Get-PropertyValue -Item $resumeAckJson -Name "returned_count" -Default 0)
|
||||
|
||||
$observed = $null
|
||||
$deadline = (Get-Date).AddSeconds(90)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
Start-Sleep -Seconds 5
|
||||
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
|
||||
if (
|
||||
(Test-AdapterReadiness -Sink $observed.workload_sink -SessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount) -and
|
||||
(Test-AdapterReadiness -Sink $observed.telemetry_sink -SessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount)
|
||||
) {
|
||||
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}$")
|
||||
resume_ack_shape_visible = ([string](Get-PropertyValue -Item $resumeAckJson -Name "resume_from" -Default "") -eq "ack" -and $resumeSequence -gt 0 -and $skippedCount -eq 1 -and $returnedCount -eq 2)
|
||||
workload_readiness_visible = (Test-AdapterReadiness -Sink $observed.workload_sink -SessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount)
|
||||
telemetry_readiness_visible = (Test-AdapterReadiness -Sink $observed.telemetry_sink -SessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount)
|
||||
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 = "c19z.remote_workspace_adapter_readiness_smoke.v1"
|
||||
source_result_path = $sourceFile
|
||||
cluster_id = $ClusterID
|
||||
entry_node = [ordered]@{ id = $entryNode.id; name = $entryNode.name }
|
||||
adapter_session_id = $adapterSessionID
|
||||
source = $sourceResult
|
||||
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 "C19Z remote workspace adapter readiness smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
|
||||
}
|
||||
|
||||
Write-Host "C19Z remote workspace adapter readiness smoke passed. Result: $fullResultPath"
|
||||
$result
|
||||
Reference in New Issue
Block a user