fix(striker-ui-api): add get all anvil node pair summary

main
Tsu-ba-me 2 years ago
parent 3fd611eebb
commit 993c2350e5
  1. 108
      striker-ui-api/src/lib/request_handlers/anvil/buildAnvilSummary.ts
  2. 93
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilDetail.ts
  3. 33
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilSummary.ts
  4. 1
      striker-ui-api/src/lib/request_handlers/anvil/index.ts
  5. 2
      striker-ui-api/src/routes/anvil.ts
  6. 9
      striker-ui-api/src/types/ApiAn.d.ts
  7. 3
      striker-ui-api/src/types/GetAnvilDataFunction.d.ts

@ -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;
};

@ -1,14 +1,12 @@
import assert from 'assert';
import { RequestHandler } from 'express';
import { getAnvilData, getHostData, query } from '../../accessModule';
import { getAnvilData, getHostData } from '../../accessModule';
import { stderr } from '../../shell';
const buildHostStateMessage = (postfix = 2) => `message_022${postfix}`;
import { buildAnvilSummary } from './buildAnvilSummary';
export const getAnvilDetail: RequestHandler<
AnvilDetailParamsDictionary,
AnvilDetail,
AnvilDetailSummary,
undefined
> = async (request, response) => {
const {
@ -27,85 +25,20 @@ export const getAnvilDetail: RequestHandler<
return response.status(500).send();
}
const {
anvil_uuid: {
[anvilUuid]: {
anvil_node1_host_uuid: n1uuid,
anvil_node2_host_uuid: n2uuid,
},
},
} = anvils;
const result: AnvilDetail = { anvil_state: 'optimal', 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,
][];
let result: AnvilDetailSummary;
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');
result = await buildAnvilSummary({
anvils,
anvilUuid,
hosts,
});
} catch (error) {
stderr(`Failed to get node ${huuid} cluster status; CAUSE: ${error}`);
continue;
}
stderr(
`Failed to get summary of anvil node pair ${anvilUuid}; CAUSE: ${error}`,
);
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 response.status(500).send();
}
response.status(200).send(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);
};

@ -4,3 +4,4 @@ export * from './getAnvilDetail';
export * from './getAnvilMemory';
export * from './getAnvilNetwork';
export * from './getAnvilStore';
export * from './getAnvilSummary';

@ -3,6 +3,7 @@ import express from 'express';
import {
getAnvil,
getAnvilCpu,
getAnvilSummary,
getAnvilDetail,
getAnvilMemory,
getAnvilNetwork,
@ -13,6 +14,7 @@ const router = express.Router();
router
.get('/', getAnvil)
.get('/summary', getAnvilSummary)
.get('/:anvilUuid/cpu', getAnvilCpu)
.get('/:anvilUuid/memory', getAnvilMemory)
.get('/:anvilUuid/network', getAnvilNetwork)

@ -71,11 +71,18 @@ type AnvilDetailHostSummary = {
state_percent: number;
};
type AnvilDetail = {
type AnvilDetailSummary = {
anvil_name: string;
anvil_state: string;
anvil_uuid: string;
hosts: AnvilDetailHostSummary[];
};
/**
* @deprecated
*/
type AnvilSummary = { anvils: AnvilDetailSummary[] };
type AnvilDetailForProvisionServer = {
anvilDescription: string;
anvilName: string;

@ -7,9 +7,10 @@ type AnvilDataAnvilListHash = {
[uuid: string]: {
anvil_description: string;
anvil_dr1_host_uuid?: string;
anvil_name: string;
anvil_node1_host_uuid: string;
anvil_node2_host_uuid: string;
query_time: number;
modified_date: string;
};
};
host_uuid: {

Loading…
Cancel
Save