Fix cluster nodes API to show actual worker counts

- Get real worker process information from cluster master instead of placeholder data
- Display correct number of workers and their actual backends
- Improve accuracy of cluster node statistics
parent 4907cef6
......@@ -482,28 +482,49 @@ def api_cluster_nodes():
'workers': [] # Will collect worker details
}
# For now, we don't have worker details in database, so we'll use placeholder
# In a full implementation, you'd store worker info in database too
# For now, assume standard workers based on available backends
workers = []
for backend in available_backends:
workers.extend([
{
'type': 'analysis',
'backend': backend,
'weight': 10,
'model': 'default',
'status': 'active'
},
{
'type': 'training',
'backend': backend,
'weight': 5,
'model': 'default',
'status': 'active'
}
])
node_map[node_key]['workers'] = workers
# Get actual worker processes from cluster master
from .cluster_master import cluster_master
client_id = None
for cid, client_info in cluster_master.clients.items():
if client_info['token'] == token:
client_id = cid
break
if client_id:
# Get registered processes for this client
workers = []
for proc_key, proc_info in cluster_master.processes.items():
if proc_info['client_id'] == client_id:
worker_info = {
'type': proc_info['name'].split('_')[0], # analysis or training
'backend': proc_info['name'].split('_')[1] if '_' in proc_info['name'] else 'unknown',
'weight': proc_info.get('weight', 10),
'model': proc_info.get('model', 'default'),
'status': proc_info.get('status', 'active')
}
workers.append(worker_info)
node_map[node_key]['workers'] = workers
else:
# Fallback: assume standard workers based on available_backends
workers = []
for backend in available_backends:
workers.extend([
{
'type': 'analysis',
'backend': backend,
'weight': 10,
'model': 'default',
'status': 'active'
},
{
'type': 'training',
'backend': backend,
'weight': 5,
'model': 'default',
'status': 'active'
}
])
node_map[node_key]['workers'] = workers
# Convert node_map to nodes list
for node_key, node_data in node_map.items():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment