forked from mtusi2026/mtusi2026lab3
Implement lab3 load balancing and idempotent messaging
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0.."
|
||||
docker compose --env-file .env stop --timeout 5 lb api1 api2 redis postgres
|
||||
if errorlevel 1 exit /b 1
|
||||
docker compose --env-file .env up -d --wait postgres redis
|
||||
if errorlevel 1 exit /b 1
|
||||
docker compose --env-file .env up -d --no-deps api1 api2 lb
|
||||
if errorlevel 1 exit /b 1
|
||||
python scripts\wait_ready.py
|
||||
exit /b %ERRORLEVEL%
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
# Preserve named volumes. Restart all state stores and both API processes.
|
||||
docker compose --env-file .env stop --timeout 5 lb api1 api2 redis postgres
|
||||
docker compose --env-file .env up -d --wait postgres redis
|
||||
docker compose --env-file .env up -d --no-deps api1 api2 lb
|
||||
python - <<'PY'
|
||||
import time, urllib.request
|
||||
for i in range(120):
|
||||
try:
|
||||
with urllib.request.urlopen('http://localhost:8080/health/ready', timeout=2) as response:
|
||||
if response.status == 200:
|
||||
print('[restart] all services ready')
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(.5)
|
||||
else:
|
||||
raise SystemExit('[restart] health timeout')
|
||||
PY
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
# Run tests/load.py in a second terminal while this script recreates API instances.
|
||||
for replica in api1 api2; do
|
||||
docker compose --env-file .env up -d --no-deps --force-recreate "$replica"
|
||||
docker compose --env-file .env exec -T "$replica" python - <<'PY'
|
||||
import time,urllib.request
|
||||
for _ in range(40):
|
||||
try:
|
||||
if urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2).status==200:break
|
||||
except Exception:pass
|
||||
time.sleep(.5)
|
||||
else:raise SystemExit('replica did not recover')
|
||||
PY
|
||||
sleep 3
|
||||
done
|
||||
@@ -0,0 +1,10 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0.."
|
||||
if "%TARGET_INSTANCE_ID%"=="api1" goto stop
|
||||
if "%TARGET_INSTANCE_ID%"=="api2" goto stop
|
||||
echo Unexpected TARGET_INSTANCE_ID 1>&2
|
||||
exit /b 2
|
||||
:stop
|
||||
docker compose --env-file .env stop --timeout 1 %TARGET_INSTANCE_ID%
|
||||
exit /b %ERRORLEVEL%
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# The public failover test sets TARGET_INSTANCE_ID from the actual response header.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
case "${TARGET_INSTANCE_ID:?missing TARGET_INSTANCE_ID}" in
|
||||
api1|api2) docker compose --env-file .env stop --timeout 1 "$TARGET_INSTANCE_ID" ;;
|
||||
*) echo 'Unexpected instance alias' >&2; exit 2 ;;
|
||||
esac
|
||||
@@ -0,0 +1,14 @@
|
||||
"""Operator-facing readiness wait after container replacement."""
|
||||
import time
|
||||
import urllib.request
|
||||
for _ in range(120):
|
||||
try:
|
||||
with urllib.request.urlopen("http://localhost:8080/health/ready", timeout=2) as response:
|
||||
if response.status == 200:
|
||||
print("[restart] all services ready")
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(.5)
|
||||
else:
|
||||
raise SystemExit("[restart] health timeout")
|
||||
Reference in New Issue
Block a user