diff --git a/services/mam-api/src/routes/cluster.js b/services/mam-api/src/routes/cluster.js index 4d81aa5..fdd0fca 100644 --- a/services/mam-api/src/routes/cluster.js +++ b/services/mam-api/src/routes/cluster.js @@ -16,20 +16,19 @@ router.get('/', async (req, res, next) => { ); res.json(r.rows.map(row => ({ ...row, - // online = last heartbeat within 2 minutes online: Number(row.stale_seconds) < 120, }))); } catch (err) { next(err); } }); -// POST /heartbeat – upsert this node's registration +// POST /heartbeat – upsert this node's registration (includes hardware capabilities) router.post('/heartbeat', async (req, res, next) => { try { const { hostname, ip_address, role = 'worker', version, api_url, cpu_usage, mem_used_mb, mem_total_mb, - metadata, + capabilities, metadata, } = req.body; if (!hostname) return res.status(400).json({ error: 'hostname is required' }); @@ -37,8 +36,8 @@ router.post('/heartbeat', async (req, res, next) => { const r = await pool.query( `INSERT INTO cluster_nodes (hostname, ip_address, role, version, api_url, - cpu_usage, mem_used_mb, mem_total_mb, last_seen, metadata) - VALUES ($1,$2,$3,$4,$5,$6,$7,$8,NOW(),$9) + cpu_usage, mem_used_mb, mem_total_mb, last_seen, capabilities, metadata) + VALUES ($1,$2,$3,$4,$5,$6,$7,$8,NOW(),$9,$10) ON CONFLICT (hostname) DO UPDATE SET ip_address = EXCLUDED.ip_address, role = EXCLUDED.role, @@ -48,6 +47,7 @@ router.post('/heartbeat', async (req, res, next) => { mem_used_mb = EXCLUDED.mem_used_mb, mem_total_mb = EXCLUDED.mem_total_mb, last_seen = NOW(), + capabilities = EXCLUDED.capabilities, metadata = EXCLUDED.metadata RETURNING *`, [ @@ -59,6 +59,7 @@ router.post('/heartbeat', async (req, res, next) => { cpu_usage != null ? cpu_usage : null, mem_used_mb != null ? mem_used_mb : null, mem_total_mb != null ? mem_total_mb : null, + capabilities != null ? JSON.stringify(capabilities) : '{}', metadata != null ? JSON.stringify(metadata) : null, ] ); @@ -99,7 +100,7 @@ router.delete('/:id', async (req, res, next) => { 'DELETE FROM cluster_nodes WHERE id = $1 RETURNING id', [req.params.id] ); - if (r.rowCount === 0) return res.status(404).json({ error: 'Node not found' });; + if (r.rowCount === 0) return res.status(404).json({ error: 'Node not found' }); res.json({ ok: true }); } catch (err) { next(err); } });