lab3-4 оценка

This commit is contained in:
2026-10-21 13:31:36 +03:00
parent 0ab3a341aa
commit 093602c18b
38 changed files with 3483 additions and 41 deletions
-10
View File
@@ -1,10 +0,0 @@
#!/bin/sh
set -eu
# TODO: copy to restart.sh and implement using YOUR compose/stack services.
# Restart API and ALL used state stores (DB, sessions, S3, broker as applicable).
# Preserve persistent volumes and schema/data; never down -v / flush / re-seed.
# Allow operator unseal if required in lab7; do not print credentials.
# Exit 0 only after the intended action; test waits for API readiness separately.
printf '%s
' 'TODO: implement restart.sh for your infrastructure' >&2
exit 2
+45
View File
@@ -0,0 +1,45 @@
@echo off
setlocal
echo === Rolling Update Test ===
echo.
:: Устанавливаем UTF-8 для Python (ВАЖНО!)
set PYTHONUTF8=1
:: Запускаем нагрузочный тест в фоне
echo Starting load test in background...
start /b python tests/load.py --base-url http://localhost:8080 --duration 60 --concurrency 8 --output metrics-rolling.json
:: Ждём 5 секунд
echo Waiting for load to stabilize...
timeout /t 5 /nobreak >nul
:: Выполняем rolling update
echo.
echo === Performing rolling update ===
docker compose up -d --build api
:: Ждём завершения обновления
echo Waiting for all replicas to become healthy...
:wait_healthy
timeout /t 2 /nobreak >nul
docker compose ps api | findstr "healthy" | find /c "healthy" | findstr "2" >nul
if errorlevel 1 goto :wait_healthy
echo All replicas are healthy!
:: Ждём завершения нагрузочного теста
echo.
echo Waiting for load test to complete...
timeout /t 30 /nobreak >nul
echo.
echo === Rolling update completed ===
if exist metrics-rolling.json (
echo Metrics saved to metrics-rolling.json
type metrics-rolling.json
) else (
echo WARNING: metrics-rolling.json not found!
)
endlocal
+84
View File
@@ -0,0 +1,84 @@
@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
echo === Sequential Replica Stop/Start Test ===
echo.
:: Запускаем нагрузочный тест в фоне с флагом -X utf8 (обходит все проблемы с кодировкой в Windows)
echo Starting load test in background...
start /b python -X utf8 tests/load.py --base-url http://localhost:8080 --duration 60 --concurrency 8 --output metrics-sequential.json
echo Waiting for load to stabilize (5 seconds)...
timeout /t 5 /nobreak >nul
:: Надёжно получаем ID двух разных контейнеров
echo.
echo === Identifying API containers ===
set COUNT=0
for /f "tokens=*" %%i in ('docker compose ps -q api') do (
set /a COUNT+=1
if !COUNT!==1 set CONTAINER_1=%%i
if !COUNT!==2 set CONTAINER_2=%%i
)
if "!COUNT!" LSS "2" (
echo ERROR: Ожидалось 2 API контейнера, найдено !COUNT!.
exit /b 1
)
echo Found Container 1: !CONTAINER_1!
echo Found Container 2: !CONTAINER_2!
:: Останавливаем ПЕРВЫЙ контейнер
echo.
echo === Stopping Container 1 ===
docker stop !CONTAINER_1!
echo Waiting 10 seconds for failover...
timeout /t 10 /nobreak >nul
:: Перезапускаем сервис
echo.
echo === Restarting API service ===
docker compose up -d api
echo Waiting for all replicas to become healthy...
:wait1
timeout /t 2 /nobreak >nul
docker compose ps api | findstr "healthy" | find /c "healthy" | findstr "2" >nul
if errorlevel 1 goto :wait1
echo All replicas are healthy!
timeout /t 5 /nobreak >nul
:: Останавливаем ВТОРОЙ контейнер
echo.
echo === Stopping Container 2 ===
docker stop !CONTAINER_2!
echo Waiting 10 seconds for failover...
timeout /t 10 /nobreak >nul
:: Перезапускаем сервис снова
echo.
echo === Restarting API service ===
docker compose up -d api
echo Waiting for all replicas to become healthy...
:wait2
timeout /t 2 /nobreak >nul
docker compose ps api | findstr "healthy" | find /c "healthy" | findstr "2" >nul
if errorlevel 1 goto :wait2
echo All replicas are healthy!
:: Ждём завершения нагрузочного теста
echo.
echo Waiting for load test to complete (approx 45 seconds)...
timeout /t 45 /nobreak >nul
echo.
echo === Test completed ===
if exist metrics-sequential.json (
echo Metrics saved to metrics-sequential.json:
type metrics-sequential.json
) else (
echo WARNING: metrics-sequential.json not found!
)
endlocal
pause
+13
View File
@@ -0,0 +1,13 @@
@echo off
setlocal
set "CONTAINER_ID="
for /f "delims=" %%i in ('docker compose ps -q api 2^>nul') do (
set "CONTAINER_ID=%%i"
goto :stop_container
)
echo No API container found
exit /b 1
:stop_container
echo Stopping container %CONTAINER_ID%
docker stop "%CONTAINER_ID%"
endlocal