conductor(checkpoint): Checkpoint end of Phase 2 - Aggregator Refactor
This commit is contained in:
@@ -2,55 +2,45 @@ import requests
|
||||
|
||||
def get_cluster_services(consul_url):
|
||||
"""
|
||||
Queries Consul health API for navidrome and replica-navidrome services.
|
||||
Queries Consul health API for all 'navidrome' services.
|
||||
Returns a list of dictionaries with node info.
|
||||
"""
|
||||
services = []
|
||||
|
||||
# Define roles to fetch
|
||||
role_map = {
|
||||
"navidrome": "primary",
|
||||
"replica-navidrome": "replica"
|
||||
}
|
||||
|
||||
for service_name, role in role_map.items():
|
||||
url = f"{consul_url}/v1/health/service/{service_name}"
|
||||
try:
|
||||
response = requests.get(url, timeout=5)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
url = f"{consul_url}/v1/health/service/navidrome"
|
||||
try:
|
||||
response = requests.get(url, timeout=5)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
for item in data:
|
||||
node_name = item["Node"]["Node"]
|
||||
address = item["Node"]["Address"]
|
||||
port = item["Service"]["Port"]
|
||||
|
||||
for item in data:
|
||||
node_name = item["Node"]["Node"]
|
||||
address = item["Node"]["Address"]
|
||||
port = item["Service"]["Port"]
|
||||
|
||||
# Determine overall status from checks and extract output
|
||||
checks = item.get("Checks", [])
|
||||
status = "passing"
|
||||
check_output = ""
|
||||
for check in checks:
|
||||
if check["Status"] != "passing":
|
||||
status = check["Status"]
|
||||
# Determine overall status from checks and extract output
|
||||
checks = item.get("Checks", [])
|
||||
status = "passing"
|
||||
check_output = ""
|
||||
for check in checks:
|
||||
if check["Status"] != "passing":
|
||||
status = check["Status"]
|
||||
check_output = check.get("Output", "")
|
||||
break
|
||||
else:
|
||||
if not check_output:
|
||||
check_output = check.get("Output", "")
|
||||
break
|
||||
else:
|
||||
# Even if passing, store the output of the first check if it's the only one
|
||||
if not check_output:
|
||||
check_output = check.get("Output", "")
|
||||
|
||||
services.append({
|
||||
"node": node_name,
|
||||
"address": address,
|
||||
"port": port,
|
||||
"role": role,
|
||||
"status": status,
|
||||
"service_id": item["Service"]["ID"],
|
||||
"check_output": check_output
|
||||
})
|
||||
except Exception as e:
|
||||
# For now, we just don't add the service if it fails to fetch
|
||||
# In a real script we might want to report the error
|
||||
print(f"Error fetching {service_name}: {e}")
|
||||
|
||||
services.append({
|
||||
"node": node_name,
|
||||
"address": address,
|
||||
"port": port,
|
||||
"role": "primary", # If it's in Consul as 'navidrome', it's intended to be primary
|
||||
"status": status,
|
||||
"service_id": item["Service"]["ID"],
|
||||
"check_output": check_output
|
||||
})
|
||||
except Exception as e:
|
||||
print(f"Error fetching navidrome services from Consul: {e}")
|
||||
|
||||
return services
|
||||
|
||||
Reference in New Issue
Block a user