parent
3fd611eebb
commit
993c2350e5
8 changed files with 182 additions and 97 deletions
@ -0,0 +1,108 @@ |
||||
import assert from 'assert'; |
||||
|
||||
import { query } from '../../accessModule'; |
||||
import { stderr } from '../../shell'; |
||||
|
||||
const buildHostStateMessage = (postfix = 2) => `message_022${postfix}`; |
||||
|
||||
export const buildAnvilSummary = async ({ |
||||
anvils, |
||||
anvilUuid, |
||||
hosts, |
||||
}: { |
||||
anvils: AnvilDataAnvilListHash; |
||||
anvilUuid: string; |
||||
hosts: AnvilDataHostListHash; |
||||
}) => { |
||||
const { |
||||
anvil_uuid: { [anvilUuid]: ainfo }, |
||||
} = anvils; |
||||
|
||||
if (!ainfo) |
||||
throw new Error(`Anvil information not found with UUID ${anvilUuid}`); |
||||
|
||||
const { |
||||
anvil_name: aname, |
||||
anvil_node1_host_uuid: n1uuid, |
||||
anvil_node2_host_uuid: n2uuid, |
||||
} = ainfo; |
||||
|
||||
const result: AnvilDetailSummary = { |
||||
anvil_name: aname, |
||||
anvil_state: 'optimal', |
||||
anvil_uuid: anvilUuid, |
||||
hosts: [], |
||||
}; |
||||
|
||||
for (const huuid of [n1uuid, n2uuid]) { |
||||
const { |
||||
host_uuid: { |
||||
[huuid]: { host_status: hstatus, short_host_name: hname }, |
||||
}, |
||||
} = hosts; |
||||
|
||||
const { hosts: rhosts } = result; |
||||
|
||||
const hsummary: AnvilDetailHostSummary = { |
||||
host_name: hname, |
||||
host_uuid: huuid, |
||||
maintenance_mode: false, |
||||
state: 'offline', |
||||
state_message: buildHostStateMessage(), |
||||
state_percent: 0, |
||||
}; |
||||
|
||||
rhosts.push(hsummary); |
||||
|
||||
if (hstatus !== 'online') continue; |
||||
|
||||
let rows: [ |
||||
inCcm: NumberBoolean, |
||||
crmdMember: NumberBoolean, |
||||
clusterMember: NumberBoolean, |
||||
maintenanceMode: NumberBoolean, |
||||
][]; |
||||
|
||||
try { |
||||
rows = await query(`SELECT
|
||||
scan_cluster_node_in_ccm, |
||||
scan_cluster_node_crmd_member, |
||||
scan_cluster_node_cluster_member, |
||||
scan_cluster_node_maintenance_mode |
||||
FROM |
||||
scan_cluster_nodes |
||||
WHERE |
||||
scan_cluster_node_host_uuid = '${huuid}';`);
|
||||
|
||||
assert.ok(rows.length, 'No node cluster info'); |
||||
} catch (error) { |
||||
stderr(`Failed to get node ${huuid} cluster status; CAUSE: ${error}`); |
||||
|
||||
continue; |
||||
} |
||||
|
||||
const [[ccm, crmd, cluster, maintenance]] = rows; |
||||
|
||||
hsummary.maintenance_mode = Boolean(maintenance); |
||||
|
||||
if (cluster) { |
||||
hsummary.state = 'online'; |
||||
hsummary.state_message = buildHostStateMessage(3); |
||||
hsummary.state_percent = 100; |
||||
} else if (crmd) { |
||||
hsummary.state = 'crmd'; |
||||
hsummary.state_message = buildHostStateMessage(4); |
||||
hsummary.state_percent = 75; |
||||
} else if (ccm) { |
||||
hsummary.state = 'in_ccm'; |
||||
hsummary.state_message = buildHostStateMessage(5); |
||||
hsummary.state_percent = 50; |
||||
} else { |
||||
hsummary.state = 'booted'; |
||||
hsummary.state_message = buildHostStateMessage(6); |
||||
hsummary.state_percent = 25; |
||||
} |
||||
} |
||||
|
||||
return result; |
||||
}; |
@ -0,0 +1,33 @@ |
||||
import { RequestHandler } from 'express'; |
||||
|
||||
import { getAnvilData, getHostData } from '../../accessModule'; |
||||
import { buildAnvilSummary } from './buildAnvilSummary'; |
||||
import { stderr } from '../../shell'; |
||||
|
||||
export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async ( |
||||
request, |
||||
response, |
||||
) => { |
||||
let anvils: AnvilDataAnvilListHash; |
||||
let hosts: AnvilDataHostListHash; |
||||
|
||||
try { |
||||
anvils = await getAnvilData(); |
||||
hosts = await getHostData(); |
||||
} catch (error) { |
||||
stderr(`Failed to get anvil and/or host data; CAUSE: ${error}`); |
||||
|
||||
return response.status(500).send(); |
||||
} |
||||
|
||||
const { anvil_uuid: alist } = anvils; |
||||
const result: AnvilSummary = { anvils: [] }; |
||||
|
||||
for (const auuid of Object.keys(alist)) { |
||||
result.anvils.push( |
||||
await buildAnvilSummary({ anvils, anvilUuid: auuid, hosts }), |
||||
); |
||||
} |
||||
|
||||
response.json(result); |
||||
}; |
Loading…
Reference in new issue