Implement lab3 replicated API and experiment evidence

This commit is contained in:
Polusikkkk
2026-10-29 20:20:13 +03:00
parent 0ab3a341aa
commit 5847952e76
48 changed files with 4013 additions and 33 deletions
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT"
docker compose -p mtusi2026lab3 restart postgres redis api lb
+42
View File
@@ -0,0 +1,42 @@
#!/bin/sh
set -eu
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT"
if [ -z "${TARGET_INSTANCE_ID:-}" ]; then
echo "TARGET_INSTANCE_ID is required" >&2
exit 2
fi
TARGET_CONTAINER=""
MATCHES=0
for container in $(docker compose -p mtusi2026lab3 ps -q api); do
instance_id=$(
docker exec "$container" python -c '
import urllib.request
with urllib.request.urlopen(
"http://127.0.0.1:8080/health/live",
timeout=2,
) as response:
print(response.headers.get("X-Instance-Id", ""))
' 2>/dev/null
) || continue
if [ "$instance_id" = "$TARGET_INSTANCE_ID" ]; then
TARGET_CONTAINER="$container"
MATCHES=$((MATCHES + 1))
fi
done
if [ "$MATCHES" -ne 1 ]; then
echo "Expected exactly one matching API container; found $MATCHES" >&2
exit 1
fi
echo "Stopping API instance: $TARGET_INSTANCE_ID"
docker stop --time 10 "$TARGET_CONTAINER" >/dev/null
echo "Target API container stopped"