Merge pull request #501 from ylei-tsubame/rebuild-webui

Web UI: patch issues 456, 458, 487, 494, 496
main
Digimer 1 year ago committed by GitHub
commit 1d59ef632a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      striker-ui-api/out/index.js
  2. 7
      striker-ui-api/src/lib/buildCondition.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/anvil/buildAnvilSummary.ts
  4. 7
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts
  5. 8
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts
  6. 4
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilDetail.ts
  7. 5
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts
  8. 14
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilSummary.ts
  9. 3
      striker-ui-api/src/lib/request_handlers/file/buildQueryFileDetail.ts
  10. 3
      striker-ui-api/src/lib/request_handlers/file/getFile.ts
  11. 7
      striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts
  12. 6
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  13. 8
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  14. 8
      striker-ui-api/src/lib/request_handlers/server/deleteServer.ts

File diff suppressed because one or more lines are too long

@ -33,6 +33,9 @@ export const buildUnknownIDCondition = (
}; };
export const buildKnownIDCondition = ( export const buildKnownIDCondition = (
keys: string[] | '*' = '*', keys: string[] | 'all' | '*' = 'all',
conditionPrefix: string, conditionPrefix: string,
) => (keys[0] === '*' ? '' : buildIDCondition(keys, conditionPrefix)); ) =>
!(keys instanceof Array) || keys.some((v) => ['all', '*'].includes(v))
? ''
: buildIDCondition(keys, conditionPrefix);

@ -60,8 +60,6 @@ export const buildAnvilSummary = async ({
throw error; throw error;
} }
if (!scounts.length) throw new Error(`No host server records found`);
for (const huuid of [n1uuid, n2uuid]) { for (const huuid of [n1uuid, n2uuid]) {
const { const {
host_uuid: { host_uuid: {

@ -1,6 +1,10 @@
import { dSize } from 'format-data-size'; import { dSize } from 'format-data-size';
import { NODE_AND_DR_RESERVED_MEMORY_SIZE, OS_LIST_MAP } from '../../consts'; import {
DELETED,
NODE_AND_DR_RESERVED_MEMORY_SIZE,
OS_LIST_MAP,
} from '../../consts';
import join from '../../join'; import join from '../../join';
import { stdoutVar } from '../../shell'; import { stdoutVar } from '../../shell';
@ -99,6 +103,7 @@ const buildQueryAnvilDetail = ({
FROM server_definitions AS ser_def FROM server_definitions AS ser_def
) AS pos_ser_def ) AS pos_ser_def
ON server_uuid = server_definition_server_uuid ON server_uuid = server_definition_server_uuid
WHERE ser.server_state != '${DELETED}'
${groupByPhrase}`; ${groupByPhrase}`;
}; };

@ -1,5 +1,7 @@
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { DELETED } from '../../consts';
import { query } from '../../accessModule'; import { query } from '../../accessModule';
import { getShortHostName } from '../../disassembleHostName'; import { getShortHostName } from '../../disassembleHostName';
import { stderr } from '../../shell'; import { stderr } from '../../shell';
@ -72,7 +74,8 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async (
FROM servers AS a FROM servers AS a
JOIN server_definitions AS b JOIN server_definitions AS b
ON a.server_uuid = b.server_definition_server_uuid ON a.server_uuid = b.server_definition_server_uuid
WHERE a.server_anvil_uuid = '${anvilUuid}';`, WHERE a.server_state != '${DELETED}'
AND a.server_anvil_uuid = '${anvilUuid}';`,
); );
} catch (error) { } catch (error) {
stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`); stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`);
@ -99,7 +102,8 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async (
const cores = Number(rCores); const cores = Number(rCores);
const threads = Number(rThreads); const threads = Number(rThreads);
const vendor = model.replace(/^(\w+).*$/, '$1'); const matched = model.match(/amd|arm|intel|powerpc/i);
const vendor = matched ? matched[0] : model.replace(/^(\w+).*$/, '$1');
previous.hosts[uuid] = { previous.hosts[uuid] = {
cores, cores,

@ -34,9 +34,7 @@ export const getAnvilDetail: RequestHandler<
hosts, hosts,
}); });
} catch (error) { } catch (error) {
stderr( stderr(`Failed to get summary of anvil node ${anvilUuid}; CAUSE: ${error}`);
`Failed to get summary of anvil node pair ${anvilUuid}; CAUSE: ${error}`,
);
return response.status(500).send(); return response.status(500).send();
} }

@ -1,7 +1,7 @@
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { DataSizeUnit, dSize } from 'format-data-size'; import { DataSizeUnit, dSize } from 'format-data-size';
import { NODE_AND_DR_RESERVED_MEMORY_SIZE } from '../../consts'; import { DELETED, NODE_AND_DR_RESERVED_MEMORY_SIZE } from '../../consts';
import { query } from '../../accessModule'; import { query } from '../../accessModule';
import { stderr } from '../../shell'; import { stderr } from '../../shell';
@ -88,7 +88,8 @@ export const getAnvilMemory: RequestHandler<
FROM server_definitions AS a FROM server_definitions AS a
JOIN servers AS b JOIN servers AS b
ON b.server_uuid = a.server_definition_server_uuid ON b.server_uuid = a.server_definition_server_uuid
WHERE server_anvil_uuid = '${anvilUuid}';`, WHERE b.server_state != '${DELETED}'
AND b.server_anvil_uuid = '${anvilUuid}';`,
); );
} catch (error) { } catch (error) {
stderr(`Failed to get anvil ${anvilUuid} server info; CAUSE: ${error}`); stderr(`Failed to get anvil ${anvilUuid} server info; CAUSE: ${error}`);

@ -23,10 +23,16 @@ export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
const { anvil_uuid: alist } = anvils; const { anvil_uuid: alist } = anvils;
const result: AnvilSummary = { anvils: [] }; const result: AnvilSummary = { anvils: [] };
for (const auuid of Object.keys(alist)) { try {
result.anvils.push( for (const auuid of Object.keys(alist)) {
await buildAnvilSummary({ anvils, anvilUuid: auuid, hosts }), result.anvils.push(
); await buildAnvilSummary({ anvils, anvilUuid: auuid, hosts }),
);
}
} catch (error) {
stderr(`Failed to get summary of anvil nodes; CAUSE: ${error}`);
return response.status(500).send();
} }
response.json(result); response.json(result);

@ -46,5 +46,6 @@ export const buildQueryFileDetail = ({
JOIN hosts AS hos JOIN hosts AS hos
ON fil_loc.file_location_host_uuid = hos.host_uuid ON fil_loc.file_location_host_uuid = hos.host_uuid
WHERE fil.file_type != '${DELETED}' WHERE fil.file_type != '${DELETED}'
${condFileUUIDs};`; ${condFileUUIDs}
ORDER BY fil.file_name ASC;`;
}; };

@ -17,7 +17,8 @@ export const getFile: RequestHandler = buildGetRequestHandler((request) => {
file_type, file_type,
file_md5sum file_md5sum
FROM files FROM files
WHERE file_type != '${DELETED}';`; WHERE file_type != '${DELETED}'
ORDER BY file_name ASC;`;
if (fileUUIDs) { if (fileUUIDs) {
query = buildQueryFileDetail({ query = buildQueryFileDetail({

@ -42,7 +42,7 @@ const setCvar = (
export const buildQueryHostDetail: BuildQueryDetailFunction = ({ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
keys: hostUUIDs = '*', keys: hostUUIDs = '*',
} = {}) => { } = {}) => {
const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'a.host_uuid'); const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'WHERE a.host_uuid');
stdout(`condHostUUIDs=[${condHostUUIDs}]`); stdout(`condHostUUIDs=[${condHostUUIDs}]`);
@ -74,8 +74,9 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
ON b.variable_name LIKE '%link%_mac%' ON b.variable_name LIKE '%link%_mac%'
AND b.variable_value = c.network_interface_mac_address AND b.variable_value = c.network_interface_mac_address
AND a.host_uuid = c.network_interface_host_uuid AND a.host_uuid = c.network_interface_host_uuid
WHERE ${condHostUUIDs} ${condHostUUIDs}
ORDER BY cvar_name ASC, ORDER BY a.host_name ASC,
cvar_name ASC,
b.variable_name ASC;`; b.variable_name ASC;`;
const afterQueryReturn: QueryResultModifierFunction = const afterQueryReturn: QueryResultModifierFunction =

@ -29,7 +29,8 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
hos.host_type, hos.host_type,
hos.host_uuid hos.host_uuid
FROM hosts AS hos FROM hosts AS hos
${condition};`; ${condition}
ORDER BY hos.host_name ASC;`;
let afterQueryReturn: QueryResultModifierFunction | undefined = let afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>( buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>(
(previous, [hostName, hostType, hostUUID]) => { (previous, [hostName, hostType, hostUUID]) => {
@ -48,6 +49,9 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
); );
if (hostUUIDs) { if (hostUUIDs) {
// TODO: the output of host detail is designed to only contain one
// host, correct it to support multiple hosts to allow selecting
// multiple hosts' detail.
({ query, afterQueryReturn } = buildQueryHostDetail({ ({ query, afterQueryReturn } = buildQueryHostDetail({
keys: sanitize(hostUUIDs, 'string[]', { keys: sanitize(hostUUIDs, 'string[]', {
modifierType: 'sql', modifierType: 'sql',

@ -1,7 +1,7 @@
import assert from 'assert'; import assert from 'assert';
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { REP_UUID, SERVER_PATHS } from '../../consts'; import { DELETED, REP_UUID, SERVER_PATHS } from '../../consts';
import { OS_LIST_MAP } from '../../consts/OS_LIST'; import { OS_LIST_MAP } from '../../consts/OS_LIST';
import { job, query } from '../../accessModule'; import { job, query } from '../../accessModule';
@ -49,7 +49,11 @@ export const createServer: RequestHandler = async (request, response) => {
); );
const [[serverNameCount]] = await query( const [[serverNameCount]] = await query(
`SELECT COUNT(server_uuid) FROM servers WHERE server_name = '${serverName}'`, `SELECT
COUNT(server_uuid)
FROM servers
WHERE server_state != '${DELETED}'
AND server_name = '${serverName}'`,
); );
assert( assert(

@ -1,7 +1,7 @@
import assert from 'assert'; import assert from 'assert';
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { REP_UUID, SERVER_PATHS } from '../../consts'; import { DELETED, REP_UUID, SERVER_PATHS } from '../../consts';
import { job, query } from '../../accessModule'; import { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
@ -39,7 +39,11 @@ export const deleteServer: RequestHandler<
); );
const rows: [[string]] = await query( const rows: [[string]] = await query(
`SELECT server_host_uuid FROM servers WHERE server_uuid = '${serverUuid}';`, `SELECT
server_host_uuid
FROM servers
WHERE server_state != '${DELETED}'
AND server_uuid = '${serverUuid}';`,
); );
assert.ok(rows.length, `Server ${serverUuid} not found`); assert.ok(rows.length, `Server ${serverUuid} not found`);

Loading…
Cancel
Save