From 6babc33006a720cc1d955c004921f0327d436719 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 16 Oct 2023 04:08:37 -0400 Subject: [PATCH] fix(striker-ui-api): ignore deleted servers in all servers-related queries --- .../lib/request_handlers/anvil/buildQueryAnvilDetail.ts | 7 ++++++- .../src/lib/request_handlers/anvil/getAnvilCpu.ts | 5 ++++- .../src/lib/request_handlers/anvil/getAnvilMemory.ts | 5 +++-- .../src/lib/request_handlers/server/createServer.ts | 8 ++++++-- .../src/lib/request_handlers/server/deleteServer.ts | 8 ++++++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts b/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts index c07d2da9..8b504353 100644 --- a/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.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}`; }; diff --git a/striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts b/striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts index 9a0d9133..1c28d9e0 100644 --- a/striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts +++ b/striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts @@ -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 = 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}`); diff --git a/striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts b/striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts index 5adb3b4a..cb4105af 100644 --- a/striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts +++ b/striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts @@ -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}`); diff --git a/striker-ui-api/src/lib/request_handlers/server/createServer.ts b/striker-ui-api/src/lib/request_handlers/server/createServer.ts index b2746a1a..66e05446 100644 --- a/striker-ui-api/src/lib/request_handlers/server/createServer.ts +++ b/striker-ui-api/src/lib/request_handlers/server/createServer.ts @@ -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( diff --git a/striker-ui-api/src/lib/request_handlers/server/deleteServer.ts b/striker-ui-api/src/lib/request_handlers/server/deleteServer.ts index 99918213..2eb68496 100644 --- a/striker-ui-api/src/lib/request_handlers/server/deleteServer.ts +++ b/striker-ui-api/src/lib/request_handlers/server/deleteServer.ts @@ -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`);