85 lines
4.0 KiB
PowerShell
85 lines
4.0 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]$DockerSSH = "test-docker",
|
|
[string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.226",
|
|
[string]$ResultPath = "artifacts\c18z44-service-channel-rebuild-snapshot-warmup-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
|
|
|
|
function Invoke-ApiGet {
|
|
param([string]$Path, [int]$TimeoutSec = 30)
|
|
Invoke-RestMethod -Method Get -Uri "$ApiBaseUrl$Path" -TimeoutSec $TimeoutSec
|
|
}
|
|
|
|
function Invoke-ApiPost {
|
|
param([string]$Path, [object]$Body, [int]$TimeoutSec = 30)
|
|
Invoke-RestMethod -Method Post -Uri "$ApiBaseUrl$Path" -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 20) -TimeoutSec $TimeoutSec
|
|
}
|
|
|
|
$warmupPayload = @{
|
|
actor_user_id = $ActorUserID
|
|
limit = 10
|
|
stale_after_seconds = 1
|
|
}
|
|
$warmup = (Invoke-ApiPost -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-snapshots/warmup" -Body $warmupPayload -TimeoutSec 30).rebuild_snapshot_warmup
|
|
$schemaStatus = (Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/schema-status?actor_user_id=$ActorUserID" -TimeoutSec 15).fabric_service_channel_schema_status
|
|
$deep = (Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-attempts?actor_user_id=$ActorUserID&limit=3&enrichment=deep" -TimeoutSec 30).rebuild_attempts
|
|
$readiness = (Invoke-ApiGet -Path "/clusters/$ClusterID/fabric/service-channels/readiness?actor_user_id=$ActorUserID&limit=5" -TimeoutSec 30).fabric_service_channel_readiness
|
|
$backendLine = (& ssh $DockerSSH "docker ps --format '{{.Names}} {{.Image}} {{.Status}}' | grep '^rap_test_backend '") | Out-String
|
|
|
|
$deepItems = @($deep)
|
|
$deepWithSnapshots = @($deepItems | Where-Object { [string]$_.correlation_snapshot_at -ne "" })
|
|
|
|
$result = [ordered]@{
|
|
schema_version = "c18z44.service_channel_rebuild_snapshot_warmup_smoke.v1"
|
|
cluster_id = $ClusterID
|
|
passed = [bool](
|
|
$backendLine.Contains($ExpectedBackendImage) -and
|
|
[string]$schemaStatus.status -eq "ready" -and
|
|
[int]$warmup.scanned_count -gt 0 -and
|
|
([int]$warmup.warmed_count + [int]$warmup.already_fresh_count + [int]$warmup.deferred_stale_count) -gt 0 -and
|
|
[int]$warmup.error_count -eq 0 -and
|
|
$deepItems.Count -gt 0 -and
|
|
$deepWithSnapshots.Count -eq $deepItems.Count -and
|
|
[string]$readiness.status -ne ""
|
|
)
|
|
checks = [ordered]@{
|
|
backend_expected_image_deployed = $backendLine.Contains($ExpectedBackendImage)
|
|
schema_ready = ([string]$schemaStatus.status -eq "ready")
|
|
warmup_scanned_attempts = ([int]$warmup.scanned_count -gt 0)
|
|
warmup_touched_or_confirmed = (([int]$warmup.warmed_count + [int]$warmup.already_fresh_count + [int]$warmup.deferred_stale_count) -gt 0)
|
|
warmup_no_errors = ([int]$warmup.error_count -eq 0)
|
|
deep_returns_snapshots = ($deepItems.Count -gt 0 -and $deepWithSnapshots.Count -eq $deepItems.Count)
|
|
readiness_available = ([string]$readiness.status -ne "")
|
|
}
|
|
summary = [ordered]@{
|
|
backend_container = $backendLine.Trim()
|
|
warmup = $warmup
|
|
schema_status = [string]$schemaStatus.status
|
|
deep_count = $deepItems.Count
|
|
deep_with_snapshots = $deepWithSnapshots.Count
|
|
readiness_status = [string]$readiness.status
|
|
}
|
|
}
|
|
|
|
$resultFullPath = Join-Path $repoRoot $ResultPath
|
|
$resultDir = Split-Path -Parent $resultFullPath
|
|
if (-not (Test-Path $resultDir)) {
|
|
New-Item -ItemType Directory -Path $resultDir | Out-Null
|
|
}
|
|
$result | ConvertTo-Json -Depth 100 | Set-Content -Path $resultFullPath -Encoding UTF8
|
|
|
|
if (-not $result.passed) {
|
|
throw "C18Z44 service-channel rebuild snapshot warmup smoke failed. Result: $resultFullPath"
|
|
}
|
|
|
|
Write-Host "C18Z44 service-channel rebuild snapshot warmup smoke passed. Result: $resultFullPath"
|
|
$result
|