fix(striker-ui-api): ignore deleted servers in all servers-related queries

main
Tsu-ba-me 1 year ago
parent b15df65c07
commit 6babc33006
  1. 7
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts
  2. 5
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts
  3. 5
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts
  4. 8
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  5. 8
      striker-ui-api/src/lib/request_handlers/server/deleteServer.ts

@ -1,6 +1,10 @@
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 { stdoutVar } from '../../shell';
@ -99,6 +103,7 @@ const buildQueryAnvilDetail = ({
FROM server_definitions AS ser_def
) AS pos_ser_def
ON server_uuid = server_definition_server_uuid
WHERE ser.server_state != '${DELETED}'
${groupByPhrase}`;
};

@ -1,5 +1,7 @@
import { RequestHandler } from 'express';
import { DELETED } from '../../consts';
import { query } from '../../accessModule';
import { getShortHostName } from '../../disassembleHostName';
import { stderr } from '../../shell';
@ -72,7 +74,8 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async (
FROM servers AS a
JOIN server_definitions AS b
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) {
stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`);

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
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 { stderr } from '../../shell';
@ -88,7 +88,8 @@ export const getAnvilMemory: RequestHandler<
FROM server_definitions AS a
JOIN servers AS b
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) {
stderr(`Failed to get anvil ${anvilUuid} server info; CAUSE: ${error}`);

@ -1,7 +1,7 @@
import assert from 'assert';
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 { job, query } from '../../accessModule';
@ -49,7 +49,11 @@ export const createServer: RequestHandler = async (request, response) => {
);
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(

@ -1,7 +1,7 @@
import assert from 'assert';
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 { sanitize } from '../../sanitize';
@ -39,7 +39,11 @@ export const deleteServer: RequestHandler<
);
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`);

Loading…
Cancel
Save