run_lobster_phase2_java.ps1 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # One-click Phase2: rebuild fs-saas-company, restart, Java migrate + smoke + verify
  2. # Usage:
  3. # cd d:\ylrz_saas_new\java\scripts
  4. # .\run_lobster_phase2_java.ps1 -TenantId 1 -CompanyId 1
  5. param(
  6. [string]$ApiBase = "http://127.0.0.1:8006",
  7. [int]$TenantId = 1,
  8. [int]$CompanyId = 1,
  9. [string]$OpsSecret = "lobster-dev-ops",
  10. [switch]$SkipBuild,
  11. [switch]$SkipRestart
  12. )
  13. $ErrorActionPreference = "Stop"
  14. $javaHome = "D:\AICALL\jdk-17.0.12+7"
  15. $mvn = "D:\maven\apache-maven-3.9.15\bin\mvn.cmd"
  16. $jarDir = "d:\ylrz_saas_new\java\fs-saas-company"
  17. $jarPath = "$jarDir\target\fs-saas-company.jar"
  18. $logPath = "d:\ylrz_saas_new\java\fs-saas-company-phase2-run.log"
  19. $headers = @{
  20. "Content-Type" = "application/json"
  21. "X-Lobster-Ops-Secret" = $OpsSecret
  22. }
  23. $qs = "tenantId=$TenantId"
  24. function Invoke-Phase2 {
  25. param([string]$Method, [string]$Path)
  26. $uri = "$($ApiBase.TrimEnd('/'))$Path" + "?$qs"
  27. if ($Method -eq "GET") {
  28. return Invoke-RestMethod -Uri $uri -Method GET -Headers $headers -TimeoutSec 120
  29. }
  30. return Invoke-RestMethod -Uri $uri -Method POST -Headers $headers -TimeoutSec 180
  31. }
  32. Write-Host "=== Phase2 Java ops pipeline ===" -ForegroundColor Cyan
  33. if (-not $SkipBuild) {
  34. Write-Host "[1/4] mvn package fs-saas-company ..." -ForegroundColor Yellow
  35. $env:JAVA_HOME = $javaHome
  36. $env:PATH = "$javaHome\bin;$env:PATH"
  37. Push-Location "d:\ylrz_saas_new\java"
  38. & $mvn -pl fs-saas-company -am package -DskipTests -q
  39. if ($LASTEXITCODE -ne 0) { throw "Maven build failed" }
  40. Pop-Location
  41. }
  42. if (-not $SkipRestart) {
  43. Write-Host "[2/4] restart fs-saas-company :8006 ..." -ForegroundColor Yellow
  44. Get-NetTCPConnection -LocalPort 8006 -ErrorAction SilentlyContinue |
  45. ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }
  46. Start-Sleep -Seconds 2
  47. $env:JAVA_HOME = $javaHome
  48. Start-Process -FilePath "$javaHome\bin\java.exe" `
  49. -ArgumentList @("-jar", $jarPath, "--spring.profiles.active=dev") `
  50. -WorkingDirectory $jarDir `
  51. -RedirectStandardOutput $logPath `
  52. -RedirectStandardError "${logPath}.err" `
  53. -WindowStyle Hidden
  54. $deadline = (Get-Date).AddMinutes(5)
  55. do {
  56. Start-Sleep -Seconds 3
  57. try {
  58. $r = Invoke-WebRequest -Uri "$ApiBase/" -UseBasicParsing -TimeoutSec 5 -SkipHttpErrorCheck
  59. if ($r.StatusCode -ge 200 -and $r.StatusCode -lt 600) { break }
  60. } catch {
  61. if ((Get-Date) -gt $deadline) { throw "Service not up on $ApiBase" }
  62. }
  63. } while ((Get-Date) -lt $deadline)
  64. Write-Host " service is up" -ForegroundColor Green
  65. } else {
  66. Write-Host "[2/4] skip restart" -ForegroundColor DarkGray
  67. }
  68. Write-Host "[3/4] POST run-all (migrate + smoke x2 + verify) ..." -ForegroundColor Yellow
  69. $result = Invoke-Phase2 -Method POST -Path "/api/lobster/admin/phase2/run-all/$CompanyId"
  70. $result | ConvertTo-Json -Depth 6
  71. Write-Host "[4/4] summary" -ForegroundColor Yellow
  72. $smoke = $result.smoke
  73. if ($smoke.passed -eq $true) {
  74. Write-Host "PASS replay_buffer increased by $($smoke.delta) ($($smoke.hotReplayRowsBefore) -> $($smoke.hotReplayRowsAfter))" -ForegroundColor Green
  75. exit 0
  76. } else {
  77. Write-Host "FAIL smoke check: $($smoke | ConvertTo-Json -Compress)" -ForegroundColor Red
  78. exit 2
  79. }