fix(striker-ui-api): add get anvil memory summary WIP

main
Tsu-ba-me 2 years ago
parent d4eeb2eb89
commit fc075d778a
  1. 4
      striker-ui-api/src/lib/consts/NODE_AND_DR_RESERVED_MEMORY_SIZE.ts
  2. 3
      striker-ui-api/src/lib/consts/index.ts
  3. 3
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts
  4. 81
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts
  5. 1
      striker-ui-api/src/lib/request_handlers/anvil/index.ts
  6. 2
      striker-ui-api/src/routes/anvil.ts
  7. 8
      striker-ui-api/src/types/ApiAn.d.ts

@ -1,4 +1,2 @@
// Unit: bytes
const NODE_AND_DR_RESERVED_MEMORY_SIZE = 8589934592;
export default NODE_AND_DR_RESERVED_MEMORY_SIZE;
export const NODE_AND_DR_RESERVED_MEMORY_SIZE = 8589934592;

@ -5,6 +5,9 @@ export { SERVER_PATHS };
export * from './AN_VARIABLE_NAME_LIST';
export * from './DELETED';
export * from './EXIT_CODE_LIST';
export * from './LOCAL';
export * from './NODE_AND_DR_RESERVED_MEMORY_SIZE';
export * from './OS_LIST';
export * from './PROCESS_OWNER';
export * from './REG_EXP_PATTERNS';
export * from './SERVER_PORT';

@ -1,5 +1,4 @@
import NODE_AND_DR_RESERVED_MEMORY_SIZE from '../../consts/NODE_AND_DR_RESERVED_MEMORY_SIZE';
import { OS_LIST } from '../../consts/OS_LIST';
import { NODE_AND_DR_RESERVED_MEMORY_SIZE, OS_LIST } from '../../consts';
import join from '../../join';
import { stdoutVar } from '../../shell';

@ -0,0 +1,81 @@
import { RequestHandler } from 'express';
import { NODE_AND_DR_RESERVED_MEMORY_SIZE } from '../../consts';
import { query } from '../../accessModule';
import { stderr } from '../../shell';
export const getAnvilMemory: RequestHandler<
AnvilDetailParamsDictionary
> = async (request, response) => {
const {
params: { anvilUuid },
} = request;
let hostMemoryRows: [
hostUuid: string,
minMemoryTotal: null | string,
hostMemoryTotal: string,
hostMemoryFree: string,
hostSwapTotal: string,
hostSwapFree: string,
][];
try {
hostMemoryRows = await query(
`SELECT
b.host_uuid,
MIN(c.scan_hardware_ram_total) AS min_memory_total,
c.scan_hardware_ram_total,
c.scan_hardware_memory_free,
c.scan_hardware_swap_total,
c.scan_hardware_swap_free
FROM anvils AS a
JOIN hosts AS b
ON b.host_uuid IN (
a.anvil_node1_host_uuid,
a.anvil_node2_host_uuid,
a.anvil_dr1_host_uuid
)
JOIN scan_hardware AS c
ON b.host_uuid = c.scan_hardware_host_uuid
WHERE a.anvil_uuid = '${anvilUuid}'
GROUP BY
b.host_uuid,
c.scan_hardware_ram_total,
c.scan_hardware_memory_free,
c.scan_hardware_swap_total,
c.scan_hardware_swap_free
ORDER BY b.host_name;`,
);
} catch (error) {
stderr(`Failed to get anvil ${anvilUuid} memory info; CAUSE: ${error}`);
return response.status(500).send();
}
const {
0: { 1: rTotal },
} = hostMemoryRows;
if (rTotal === null) return response.status(404).send();
const total = Number.parseInt(rTotal);
const hosts: AnvilDetailHostMemory[] =
hostMemoryRows.map<AnvilDetailHostMemory>(
([host_uuid, , mtotal, mfree, stotal, sfree]) => ({
free: Number.parseInt(mfree),
host_uuid,
swap_free: Number.parseInt(sfree),
swap_total: Number.parseInt(stotal),
total: Number.parseInt(mtotal),
}),
);
return response.status(200).send({
hosts,
reserved: NODE_AND_DR_RESERVED_MEMORY_SIZE,
total,
});
};

@ -1,3 +1,4 @@
export * from './getAnvil';
export * from './getAnvilCpu';
export * from './getAnvilDetail';
export * from './getAnvilMemory';

@ -4,6 +4,7 @@ import {
getAnvil,
getAnvilCpu,
getAnvilDetail,
getAnvilMemory,
} from '../lib/request_handlers/anvil';
const router = express.Router();
@ -11,6 +12,7 @@ const router = express.Router();
router
.get('/', getAnvil)
.get('/:anvilUuid/cpu', getAnvilCpu)
.get('/:anvilUuid/memory', getAnvilMemory)
.get('/:anvilUuid', getAnvilDetail);
export default router;

@ -1,3 +1,11 @@
type AnvilDetailHostMemory = {
free: number;
host_uuid: string;
swap_free: number;
swap_total: number;
total: number;
};
type AnvilDetailHostSummary = {
host_name: string;
host_uuid: string;

Loading…
Cancel
Save