fix(striker-ui-api): replace get anvil shared storage summary

main
Tsu-ba-me 2 years ago
parent 0360b39598
commit d9e6061b6e
  1. 4
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilDetail.ts
  2. 67
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilStore.ts
  3. 1
      striker-ui-api/src/lib/request_handlers/anvil/index.ts
  4. 2
      striker-ui-api/src/routes/anvil.ts
  5. 87
      striker-ui-api/src/types/ApiAn.d.ts

@ -8,7 +8,7 @@ const buildHostStateMessage = (postfix = 2) => `message_022${postfix}`;
export const getAnvilDetail: RequestHandler< export const getAnvilDetail: RequestHandler<
AnvilDetailParamsDictionary, AnvilDetailParamsDictionary,
AnvilDetailResponseBody, AnvilDetail,
undefined undefined
> = async (request, response) => { > = async (request, response) => {
const { const {
@ -36,7 +36,7 @@ export const getAnvilDetail: RequestHandler<
}, },
} = anvils; } = anvils;
const result: AnvilDetailResponseBody = { anvil_state: 'optimal', hosts: [] }; const result: AnvilDetail = { anvil_state: 'optimal', hosts: [] };
for (const huuid of [n1uuid, n2uuid]) { for (const huuid of [n1uuid, n2uuid]) {
const { const {

@ -0,0 +1,67 @@
import assert from 'assert';
import { RequestHandler } from 'express';
import { REP_UUID } from '../../consts';
import { query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
export const getAnvilStore: RequestHandler<
AnvilDetailParamsDictionary
> = async (request, response) => {
const {
params: { anvilUuid: rAnUuid },
} = request;
const anUuid = sanitize(rAnUuid, 'string', { modifierType: 'sql' });
try {
assert(
REP_UUID.test(anUuid),
`Param UUID must be a valid UUIDv4; got [${anUuid}]`,
);
} catch (error) {
stderr(`Failed to assert value during get anvil storage; CAUSE: ${error}`);
return response.status(400).send();
}
let rows: [uuid: string, name: string, size: string, free: string][];
try {
rows = await query(
`SELECT
DISTINCT ON (b.storage_group_uuid) storage_group_uuid,
b.storage_group_name,
d.scan_lvm_vg_size,
d.scan_lvm_vg_free
FROM anvils AS a
JOIN storage_groups AS b
ON a.anvil_uuid = b.storage_group_anvil_uuid
JOIN storage_group_members AS c
ON b.storage_group_uuid = c.storage_group_member_storage_group_uuid
JOIN scan_lvm_vgs AS d
ON c.storage_group_member_vg_uuid = d.scan_lvm_vg_internal_uuid
WHERE a.anvil_uuid = '${anUuid}'
ORDER BY b.storage_group_uuid, d.scan_lvm_vg_free;`,
);
} catch (error) {
stderr(`Failed to get anvil storage summary; CAUSE: ${error}`);
return response.status(500).send();
}
const rsbody: AnvilDetailStoreSummary = {
storage_groups: rows.map<AnvilDetailStore>(
([sgUuid, sgName, sgSize, sgFree]) => ({
storage_group_free: sgFree,
storage_group_name: sgName,
storage_group_total: sgSize,
storage_group_uuid: sgUuid,
}),
),
};
return response.json(rsbody);
};

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

@ -6,6 +6,7 @@ import {
getAnvilDetail, getAnvilDetail,
getAnvilMemory, getAnvilMemory,
getAnvilNetwork, getAnvilNetwork,
getAnvilStore,
} from '../lib/request_handlers/anvil'; } from '../lib/request_handlers/anvil';
const router = express.Router(); const router = express.Router();
@ -15,6 +16,7 @@ router
.get('/:anvilUuid/cpu', getAnvilCpu) .get('/:anvilUuid/cpu', getAnvilCpu)
.get('/:anvilUuid/memory', getAnvilMemory) .get('/:anvilUuid/memory', getAnvilMemory)
.get('/:anvilUuid/network', getAnvilNetwork) .get('/:anvilUuid/network', getAnvilNetwork)
.get('/:anvilUuid/store', getAnvilStore)
.get('/:anvilUuid', getAnvilDetail); .get('/:anvilUuid', getAnvilDetail);
export default router; export default router;

@ -1,3 +1,15 @@
type AnvilDetailFileForProvisionServer = {
fileUUID: string;
fileName: string;
};
type AnvilDetailHostForProvisionServer = {
hostUUID: string;
hostName: string;
hostCPUCores: number;
hostMemory: string;
};
type AnvilDetailHostMemory = { type AnvilDetailHostMemory = {
free: string; free: string;
host_uuid: string; host_uuid: string;
@ -6,34 +18,25 @@ type AnvilDetailHostMemory = {
total: string; total: string;
}; };
type AnvilDetailHostSummary = { type AnvilDetailServerForProvisionServer = {
host_name: string; serverUUID: string;
host_uuid: string; serverName: string;
maintenance_mode: boolean; serverCPUCores: number;
state: string; serverMemory: string;
state_message: string;
state_percent: number;
};
type AnvilDetailParamsDictionary = {
anvilUuid: string;
};
type AnvilDetailResponseBody = {
anvil_state: string;
hosts: AnvilDetailHostSummary[];
}; };
type AnvilDetailFileForProvisionServer = { type AnvilDetailStore = {
fileUUID: string; storage_group_free: string;
fileName: string; storage_group_name: string;
storage_group_total: string;
storage_group_uuid: string;
}; };
type AnvilDetailHostForProvisionServer = { type AnvilDetailStoreForProvisionServer = {
hostUUID: string; storageGroupUUID: string;
hostName: string; storageGroupName: string;
hostCPUCores: number; storageGroupSize: string;
hostMemory: string; storageGroupFree: string;
}; };
type AnvilDetailSubnodeLink = { type AnvilDetailSubnodeLink = {
@ -57,22 +60,20 @@ type AnvilDetailSubnodeNetwork = {
host_uuid: string; host_uuid: string;
}; };
type AnvilDetailNetworkSummary = { // Types below are for typing request handlers:
hosts: AnvilDetailSubnodeNetwork[];
};
type AnvilDetailServerForProvisionServer = { type AnvilDetailHostSummary = {
serverUUID: string; host_name: string;
serverName: string; host_uuid: string;
serverCPUCores: number; maintenance_mode: boolean;
serverMemory: string; state: string;
state_message: string;
state_percent: number;
}; };
type AnvilDetailStoreForProvisionServer = { type AnvilDetail = {
storageGroupUUID: string; anvil_state: string;
storageGroupName: string; hosts: AnvilDetailHostSummary[];
storageGroupSize: string;
storageGroupFree: string;
}; };
type AnvilDetailForProvisionServer = { type AnvilDetailForProvisionServer = {
@ -91,6 +92,18 @@ type AnvilDetailForProvisionServer = {
storageGroups: AnvilDetailStoreForProvisionServer[]; storageGroups: AnvilDetailStoreForProvisionServer[];
}; };
type AnvilDetailNetworkSummary = {
hosts: AnvilDetailSubnodeNetwork[];
};
type AnvilDetailParamsDictionary = {
anvilUuid: string;
};
type AnvilDetailStoreSummary = {
storage_groups: AnvilDetailStore[];
};
type AnvilOverview = { type AnvilOverview = {
anvilName: string; anvilName: string;
anvilUUID: string; anvilUUID: string;

Loading…
Cancel
Save