Add LandSAR cluster data transport
This commit is contained in:
@@ -52,6 +52,162 @@ function Resolve-PythonPath {
|
||||
throw "Python interpreter not found. Set PYTHON_PATH in .env or pass -PythonPath."
|
||||
}
|
||||
|
||||
function Read-BoolDotEnvValue {
|
||||
param(
|
||||
[string]$Path,
|
||||
[string]$Name,
|
||||
[bool]$DefaultValue
|
||||
)
|
||||
$value = Read-DotEnvValue -Path $Path -Name $Name
|
||||
if (-not $value) {
|
||||
return $DefaultValue
|
||||
}
|
||||
return @("1", "true", "yes", "on") -contains $value.Trim().ToLowerInvariant()
|
||||
}
|
||||
|
||||
function Read-IntDotEnvValue {
|
||||
param(
|
||||
[string]$Path,
|
||||
[string]$Name,
|
||||
[int]$DefaultValue
|
||||
)
|
||||
$value = Read-DotEnvValue -Path $Path -Name $Name
|
||||
if (-not $value) {
|
||||
return $DefaultValue
|
||||
}
|
||||
$parsed = 0
|
||||
if ([int]::TryParse($value.Trim(), [ref]$parsed)) {
|
||||
return $parsed
|
||||
}
|
||||
return $DefaultValue
|
||||
}
|
||||
|
||||
function Test-TcpPort {
|
||||
param(
|
||||
[string]$HostName,
|
||||
[int]$Port
|
||||
)
|
||||
try {
|
||||
$client = [System.Net.Sockets.TcpClient]::new()
|
||||
$async = $client.BeginConnect($HostName, $Port, $null, $null)
|
||||
$ok = $async.AsyncWaitHandle.WaitOne(1000, $false)
|
||||
if ($ok) {
|
||||
$client.EndConnect($async)
|
||||
}
|
||||
$client.Close()
|
||||
return $ok
|
||||
} catch {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Get-LandSARConfigEndpoint {
|
||||
param(
|
||||
[string]$Path
|
||||
)
|
||||
$row = Read-DotEnvValue -Path $Path -Name "LANDSAR_CONFIG_ROW"
|
||||
if ($row) {
|
||||
$parts = $row.Split(",") | ForEach-Object { $_.Trim() }
|
||||
if ($parts.Count -ge 4) {
|
||||
$port = 6666
|
||||
[void][int]::TryParse($parts[3], [ref]$port)
|
||||
return [pscustomobject]@{
|
||||
Mode = $parts[0]
|
||||
Host = $(if ($parts[2]) { $parts[2] } else { "127.0.0.1" })
|
||||
Port = $port
|
||||
}
|
||||
}
|
||||
}
|
||||
return [pscustomobject]@{
|
||||
Mode = $(Read-DotEnvValue -Path $Path -Name "LANDSAR_LICENSE_MODE")
|
||||
Host = $(Read-DotEnvValue -Path $Path -Name "LANDSAR_LICENSE_HOST")
|
||||
Port = $(Read-IntDotEnvValue -Path $Path -Name "LANDSAR_LICENSE_PORT" -DefaultValue 6666)
|
||||
}
|
||||
}
|
||||
|
||||
function Resolve-LandSARAuthServerPath {
|
||||
param(
|
||||
[string]$RepoRoot,
|
||||
[string]$EnvPath
|
||||
)
|
||||
$explicit = Read-DotEnvValue -Path $EnvPath -Name "LANDSAR_AUTH_SERVER_EXE"
|
||||
$candidates = @(
|
||||
$explicit,
|
||||
(Join-Path $RepoRoot "third_party\LandSAR\tools\_portable_release\LandSAR_auth_tools_win64\landsar_net_auth_server.exe"),
|
||||
(Join-Path $RepoRoot "third_party\LandSAR\landsar_net_auth_server.exe")
|
||||
) | Where-Object { $_ -and $_.Trim() } | Select-Object -Unique
|
||||
foreach ($candidate in $candidates) {
|
||||
if (Test-Path -LiteralPath $candidate) {
|
||||
return (Resolve-Path -LiteralPath $candidate).Path
|
||||
}
|
||||
}
|
||||
return $candidates | Select-Object -First 1
|
||||
}
|
||||
|
||||
function Start-LandSARAuthServerIfNeeded {
|
||||
param(
|
||||
[string]$RepoRoot,
|
||||
[string]$EnvPath
|
||||
)
|
||||
$endpoint = Get-LandSARConfigEndpoint -Path $EnvPath
|
||||
$mode = $(if ($endpoint.Mode) { $endpoint.Mode } else { "netVersion" })
|
||||
if ($mode.Trim().ToLowerInvariant() -ne "netversion") {
|
||||
Write-Host "LandSAR auth: skipped for license mode $mode"
|
||||
return
|
||||
}
|
||||
|
||||
$clientHost = $(if ($endpoint.Host) { $endpoint.Host } else { "127.0.0.1" })
|
||||
$clientPort = [int]$endpoint.Port
|
||||
if (Test-TcpPort -HostName $clientHost -Port $clientPort) {
|
||||
Write-Host "LandSAR auth: already listening on $clientHost`:$clientPort"
|
||||
return
|
||||
}
|
||||
|
||||
$autoStart = Read-BoolDotEnvValue -Path $EnvPath -Name "LANDSAR_AUTH_SERVER_AUTO_START" -DefaultValue $true
|
||||
if (-not $autoStart) {
|
||||
throw "LandSAR auth server is not listening on $clientHost`:$clientPort and LANDSAR_AUTH_SERVER_AUTO_START=false."
|
||||
}
|
||||
|
||||
$authExe = Resolve-LandSARAuthServerPath -RepoRoot $RepoRoot -EnvPath $EnvPath
|
||||
if (-not $authExe -or -not (Test-Path -LiteralPath $authExe)) {
|
||||
throw "LandSAR auth server executable not found: $authExe. Set LANDSAR_AUTH_SERVER_EXE in .env."
|
||||
}
|
||||
|
||||
$serverDir = Split-Path -Parent $authExe
|
||||
$memoryBin = Join-Path $serverDir "dongle_0xa0.bin"
|
||||
if (-not (Test-Path -LiteralPath $memoryBin)) {
|
||||
$fallbackBin = Join-Path $RepoRoot "third_party\LandSAR\tools\dongle_0xa0.bin"
|
||||
if (Test-Path -LiteralPath $fallbackBin) {
|
||||
Copy-Item -LiteralPath $fallbackBin -Destination $memoryBin -Force
|
||||
} else {
|
||||
throw "LandSAR auth memory image missing: $memoryBin"
|
||||
}
|
||||
}
|
||||
|
||||
$bindHost = Read-DotEnvValue -Path $EnvPath -Name "LANDSAR_AUTH_SERVER_HOST"
|
||||
if (-not $bindHost) {
|
||||
$bindHost = $clientHost
|
||||
}
|
||||
$bindPort = Read-IntDotEnvValue -Path $EnvPath -Name "LANDSAR_AUTH_SERVER_PORT" -DefaultValue $clientPort
|
||||
|
||||
Write-Host "LandSAR auth: starting $authExe on $bindHost`:$bindPort"
|
||||
Start-Process `
|
||||
-FilePath $authExe `
|
||||
-ArgumentList @("--host", $bindHost, "--port", [string]$bindPort) `
|
||||
-WorkingDirectory $serverDir `
|
||||
-WindowStyle Hidden | Out-Null
|
||||
|
||||
$deadline = (Get-Date).AddSeconds(5)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
if (Test-TcpPort -HostName $clientHost -Port $clientPort) {
|
||||
Write-Host "LandSAR auth: started and reachable on $clientHost`:$clientPort"
|
||||
return
|
||||
}
|
||||
Start-Sleep -Milliseconds 250
|
||||
}
|
||||
throw "LandSAR auth server was started but $clientHost`:$clientPort is not reachable."
|
||||
}
|
||||
|
||||
$RepoRoot = (Resolve-Path -LiteralPath $RepoRoot).Path
|
||||
$envPath = Join-Path $RepoRoot ".env"
|
||||
$templatePath = Join-Path $RepoRoot "config\landsar_cluster_worker.env.example"
|
||||
@@ -76,6 +232,10 @@ $allowedTypes = Read-DotEnvValue -Path $envPath -Name "JOB_WORKER_ALLOWED_TYPES"
|
||||
if (-not $allowedTypes) {
|
||||
$env:JOB_WORKER_ALLOWED_TYPES = "LANDSAR_CLUSTER_ITEM"
|
||||
}
|
||||
$clusterToken = Read-DotEnvValue -Path $envPath -Name "CLUSTER_SHARED_TOKEN"
|
||||
if (-not $clusterToken) {
|
||||
throw "CLUSTER_SHARED_TOKEN is required for LandSAR cluster input download and result upload."
|
||||
}
|
||||
$concurrency = Read-DotEnvValue -Path $envPath -Name "JOB_WORKER_CONCURRENCY"
|
||||
if (-not $concurrency) {
|
||||
$env:JOB_WORKER_CONCURRENCY = "1"
|
||||
@@ -101,6 +261,7 @@ Write-Host "Log: $stdoutLog"
|
||||
Write-Host "Mode: $(if ($Background) { 'background' } else { 'foreground' })"
|
||||
|
||||
Set-Location $RepoRoot
|
||||
Start-LandSARAuthServerIfNeeded -RepoRoot $RepoRoot -EnvPath $envPath
|
||||
|
||||
if ($Background) {
|
||||
if (Test-Path -LiteralPath $pidFile) {
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
param(
|
||||
[string]$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Read-DotEnvValue {
|
||||
param(
|
||||
[string]$Path,
|
||||
[string]$Name
|
||||
)
|
||||
if (-not (Test-Path -LiteralPath $Path)) {
|
||||
return ""
|
||||
}
|
||||
$line = Get-Content -LiteralPath $Path |
|
||||
Where-Object { $_ -match "^\s*$([regex]::Escape($Name))\s*=" } |
|
||||
Select-Object -Last 1
|
||||
if (-not $line) {
|
||||
return ""
|
||||
}
|
||||
$value = ($line -split "=", 2)[1].Trim()
|
||||
if (($value.StartsWith('"') -and $value.EndsWith('"')) -or ($value.StartsWith("'") -and $value.EndsWith("'"))) {
|
||||
$value = $value.Substring(1, $value.Length - 2)
|
||||
}
|
||||
return $value
|
||||
}
|
||||
|
||||
function Add-Check {
|
||||
param(
|
||||
[System.Collections.Generic.List[object]]$Rows,
|
||||
[string]$Name,
|
||||
[bool]$Ok,
|
||||
[string]$Detail
|
||||
)
|
||||
$Rows.Add([pscustomobject]@{
|
||||
Check = $Name
|
||||
Ok = $Ok
|
||||
Detail = $Detail
|
||||
}) | Out-Null
|
||||
}
|
||||
|
||||
$RepoRoot = (Resolve-Path -LiteralPath $RepoRoot).Path
|
||||
$envPath = Join-Path $RepoRoot ".env"
|
||||
$rows = [System.Collections.Generic.List[object]]::new()
|
||||
|
||||
Add-Check $rows "repo_root" (Test-Path -LiteralPath $RepoRoot) $RepoRoot
|
||||
Add-Check $rows "env_file" (Test-Path -LiteralPath $envPath) $envPath
|
||||
Add-Check $rows "worker_script" (Test-Path -LiteralPath (Join-Path $RepoRoot "run_landsar_cluster_worker.py")) (Join-Path $RepoRoot "run_landsar_cluster_worker.py")
|
||||
Add-Check $rows "start_launcher" (Test-Path -LiteralPath (Join-Path $RepoRoot "scripts\start_landsar_cluster_worker.ps1")) (Join-Path $RepoRoot "scripts\start_landsar_cluster_worker.ps1")
|
||||
Add-Check $rows "stop_launcher" (Test-Path -LiteralPath (Join-Path $RepoRoot "scripts\stop_landsar_cluster_worker.ps1")) (Join-Path $RepoRoot "scripts\stop_landsar_cluster_worker.ps1")
|
||||
|
||||
$databaseUrl = Read-DotEnvValue -Path $envPath -Name "DATABASE_URL"
|
||||
$dbHost = ""
|
||||
$dbPort = 5432
|
||||
if ($databaseUrl -match "@(?<host>[^:/]+)(:(?<port>\d+))?/") {
|
||||
$dbHost = $Matches.host
|
||||
if ($Matches.port) {
|
||||
$dbPort = [int]$Matches.port
|
||||
}
|
||||
}
|
||||
Add-Check $rows "database_url" ([bool]$databaseUrl) $databaseUrl
|
||||
if ($dbHost) {
|
||||
$tcpOk = $false
|
||||
try {
|
||||
$tcpOk = [bool](Test-NetConnection -ComputerName $dbHost -Port $dbPort -InformationLevel Quiet -WarningAction SilentlyContinue)
|
||||
} catch {
|
||||
$tcpOk = $false
|
||||
}
|
||||
Add-Check $rows "database_tcp" $tcpOk "$dbHost`:$dbPort"
|
||||
} else {
|
||||
Add-Check $rows "database_tcp" $false "DATABASE_URL host could not be parsed"
|
||||
}
|
||||
|
||||
$pythonPath = Read-DotEnvValue -Path $envPath -Name "PYTHON_PATH"
|
||||
if (-not $pythonPath) {
|
||||
$pythonPath = "C:\ProgramData\anaconda3\envs\InSAR\python.exe"
|
||||
}
|
||||
Add-Check $rows "python_path" (Test-Path -LiteralPath $pythonPath) $pythonPath
|
||||
|
||||
$landsarConsole = Read-DotEnvValue -Path $envPath -Name "LANDSAR_CONSOLE_EXE"
|
||||
if (-not $landsarConsole) {
|
||||
$landsarConsole = "D:\LandSAR\InSAR_Console.exe"
|
||||
}
|
||||
Add-Check $rows "landsar_console" (Test-Path -LiteralPath $landsarConsole) $landsarConsole
|
||||
|
||||
$landsarHome = Read-DotEnvValue -Path $envPath -Name "LANDSAR_HOME"
|
||||
if (-not $landsarHome) {
|
||||
$landsarHome = Split-Path -Parent $landsarConsole
|
||||
}
|
||||
Add-Check $rows "landsar_home" (Test-Path -LiteralPath $landsarHome) $landsarHome
|
||||
|
||||
$landsarExtraHome = Read-DotEnvValue -Path $envPath -Name "LANDSAR_EXTRA_HOME"
|
||||
if (-not $landsarExtraHome) {
|
||||
$landsarExtraHome = Join-Path $RepoRoot "third_party\LandSAR"
|
||||
}
|
||||
Add-Check $rows "landsar_extra_home" (Test-Path -LiteralPath $landsarExtraHome) $landsarExtraHome
|
||||
|
||||
$authExe = Read-DotEnvValue -Path $envPath -Name "LANDSAR_AUTH_SERVER_EXE"
|
||||
if (-not $authExe) {
|
||||
$authExe = Join-Path $RepoRoot "third_party\LandSAR\tools\_portable_release\LandSAR_auth_tools_win64\landsar_net_auth_server.exe"
|
||||
}
|
||||
Add-Check $rows "landsar_auth_exe" (Test-Path -LiteralPath $authExe) $authExe
|
||||
|
||||
$authMemory = Join-Path (Split-Path -Parent $authExe) "dongle_0xa0.bin"
|
||||
$fallbackMemory = Join-Path $RepoRoot "third_party\LandSAR\tools\dongle_0xa0.bin"
|
||||
Add-Check $rows "landsar_auth_memory" ((Test-Path -LiteralPath $authMemory) -or (Test-Path -LiteralPath $fallbackMemory)) "$authMemory or $fallbackMemory"
|
||||
|
||||
$authHost = Read-DotEnvValue -Path $envPath -Name "LANDSAR_AUTH_SERVER_HOST"
|
||||
if (-not $authHost) {
|
||||
$authHost = "127.0.0.1"
|
||||
}
|
||||
$authPortText = Read-DotEnvValue -Path $envPath -Name "LANDSAR_AUTH_SERVER_PORT"
|
||||
$authPort = 6666
|
||||
if ($authPortText) {
|
||||
[void][int]::TryParse($authPortText, [ref]$authPort)
|
||||
}
|
||||
Add-Check $rows "landsar_auth_endpoint" ($authPort -gt 0) "$authHost`:$authPort"
|
||||
|
||||
$demPath = Read-DotEnvValue -Path $envPath -Name "LANDSAR_DEM_PATH"
|
||||
if (-not $demPath) {
|
||||
$demPath = "D:\DEM\SRTMDEM_RSP_SARscape_global_int16.tif"
|
||||
}
|
||||
Add-Check $rows "landsar_dem" (Test-Path -LiteralPath $demPath) $demPath
|
||||
|
||||
$workRoot = Read-DotEnvValue -Path $envPath -Name "LANDSAR_WORK_ROOT"
|
||||
if (-not $workRoot) {
|
||||
$workRoot = "D:\LandSAR_Work"
|
||||
}
|
||||
try {
|
||||
New-Item -ItemType Directory -Force -Path $workRoot | Out-Null
|
||||
$workRootOk = Test-Path -LiteralPath $workRoot
|
||||
} catch {
|
||||
$workRootOk = $false
|
||||
}
|
||||
Add-Check $rows "landsar_work_root" $workRootOk $workRoot
|
||||
|
||||
$allowedTypes = Read-DotEnvValue -Path $envPath -Name "JOB_WORKER_ALLOWED_TYPES"
|
||||
Add-Check $rows "allowed_job_types" ($allowedTypes -eq "LANDSAR_CLUSTER_ITEM") $allowedTypes
|
||||
|
||||
$clusterMainUrl = Read-DotEnvValue -Path $envPath -Name "CLUSTER_MAIN_SERVER_URL"
|
||||
Add-Check $rows "cluster_main_server_url" ([bool]$clusterMainUrl) $clusterMainUrl
|
||||
|
||||
$clusterToken = Read-DotEnvValue -Path $envPath -Name "CLUSTER_SHARED_TOKEN"
|
||||
Add-Check $rows "cluster_shared_token" ([bool]$clusterToken) $(if ($clusterToken) { "configured" } else { "missing" })
|
||||
|
||||
$rows | Format-Table -AutoSize
|
||||
|
||||
$failed = @($rows | Where-Object { -not $_.Ok })
|
||||
if ($failed.Count -gt 0) {
|
||||
Write-Host ""
|
||||
Write-Host "FAILED CHECKS:" -ForegroundColor Red
|
||||
$failed | Format-Table -AutoSize
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "All LandSAR cluster worker checks passed." -ForegroundColor Green
|
||||
Reference in New Issue
Block a user