Files
getDomain/domain-api/deploy/multi-region/check_temp_topology.sh
Your Name bd6bcb240f debug
2026-04-17 16:17:19 +08:00

127 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
MAINLAND_BASE_URL="${1:-http://127.0.0.1:8100}"
OVERSEAS_BASE_URL="${2:-http://152.53.37.118:8100}"
PYTHON_BIN="${PYTHON_BIN:-python3}"
echo "[1/5] mainland runtime cluster"
MAINLAND_CLUSTER="$(curl -fsS "${MAINLAND_BASE_URL}/api/v1/runtime/cluster")"
echo "${MAINLAND_CLUSTER}"
echo
echo
echo "[2/5] mainland runtime readiness"
MAINLAND_READINESS="$(curl -fsS "${MAINLAND_BASE_URL}/api/v1/runtime/readiness")"
echo "${MAINLAND_READINESS}"
echo
echo
echo "[3/5] mainland worker participation"
PARTICIPATION_JSON="$(/www/server/pgsql/bin/psql -U postgres -d domain -At <<'SQL'
with latest_job as (
select id, job_code, status
from detect_jobs
where status in ('pending','running')
order by id desc
limit 1
),
node_stats as (
select
node_code,
role,
status,
coalesce(metadata_json->>'worker_online', '') as worker_online,
coalesce(metadata_json->>'detect_participating', '') as detect_participating
from detect_worker_nodes
),
item_stats as (
select
coalesce(claimed_by, '') as claimed_by,
status,
count(*) as cnt
from detect_job_items
where job_id = (select id from latest_job)
group by claimed_by, status
)
select json_build_object(
'job', (
select json_build_object(
'job_code', coalesce(job_code, ''),
'status', coalesce(status, '')
)
from latest_job
),
'online_nodes', (
select coalesce(json_agg(json_build_object(
'node_code', node_code,
'role', role,
'status', status,
'worker_online', worker_online,
'detect_participating', detect_participating
) order by node_code), '[]'::json)
from node_stats
where status in ('online', 'busy')
),
'claimed_distribution', (
select coalesce(json_agg(json_build_object(
'claimed_by', claimed_by,
'status', status,
'count', cnt
) order by claimed_by, status), '[]'::json)
from item_stats
)
);
SQL
)"
echo "${PARTICIPATION_JSON}"
echo
echo
echo "[4/5] overseas runtime cluster"
OVERSEAS_CLUSTER="$(curl -fsS "${OVERSEAS_BASE_URL}/api/v1/runtime/cluster")"
echo "${OVERSEAS_CLUSTER}"
echo
echo
echo "[5/5] condensed summary"
"${PYTHON_BIN}" - <<'PY' "$MAINLAND_CLUSTER" "$MAINLAND_READINESS" "$PARTICIPATION_JSON" "$OVERSEAS_CLUSTER"
import json
import sys
mainland_cluster = json.loads(sys.argv[1]).get("data", {})
mainland_readiness = json.loads(sys.argv[2]).get("data", {})
participation = json.loads(sys.argv[3])
overseas_cluster = json.loads(sys.argv[4]).get("data", {})
mainland_summary = mainland_cluster.get("summary") or {}
overseas_summary = overseas_cluster.get("summary") or {}
def node_codes(cluster):
return [str(item.get("node_code") or "") for item in (cluster.get("nodes") or [])]
print(
json.dumps(
{
"mainland": {
"readiness_status": mainland_readiness.get("status", ""),
"readiness_summary": mainland_readiness.get("summary", ""),
"online_worker_nodes": mainland_summary.get("online_worker_nodes", 0),
"dedicated_online_worker_nodes": mainland_summary.get("dedicated_online_worker_nodes", 0),
"online_control_nodes": mainland_summary.get("online_control_nodes", 0),
"node_codes": node_codes(mainland_cluster),
},
"participation": participation,
"overseas": {
"online_worker_nodes": overseas_summary.get("online_worker_nodes", 0),
"dedicated_online_worker_nodes": overseas_summary.get("dedicated_online_worker_nodes", 0),
"online_control_nodes": overseas_summary.get("online_control_nodes", 0),
"node_codes": node_codes(overseas_cluster),
},
},
ensure_ascii=False,
indent=2,
)
)
PY