fix(striker-ui-api): empty existing database hash before re-reading to remove deleted data

main
Tsu-ba-me 9 months ago
parent 56fb79e041
commit 69f4186739
  1. 22
      striker-ui-api/src/lib/accessModule.ts
  2. 9
      striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts

@ -331,6 +331,24 @@ const getData = async <T>(...keys: string[]) => {
return data; return data;
}; };
const mutateData = async <T>(args: {
keys: string[];
operator: string;
value: string;
}): Promise<T> => {
const { keys, operator, value } = args;
const chain = `data->${keys.join('->')}`;
const {
sub_results: [data],
} = await access.interact<{ sub_results: [T] }>('x', chain, operator, value);
shvar(data, `${chain} data: `);
return data;
};
const getAnvilData = async () => { const getAnvilData = async () => {
await subroutine('get_anvils'); await subroutine('get_anvils');
@ -338,6 +356,9 @@ const getAnvilData = async () => {
}; };
const getDatabaseConfigData = async () => { const getDatabaseConfigData = async () => {
// Empty the existing data->database hash before re-reading updated values.
await mutateData<string>({ keys: ['database'], operator: '=', value: '{}' });
const [ecode] = await subroutine<[ecode: string]>('read_config', { const [ecode] = await subroutine<[ecode: string]>('read_config', {
pre: ['Storage'], pre: ['Storage'],
}); });
@ -494,6 +515,7 @@ export {
getPeerData, getPeerData,
getUpsSpec, getUpsSpec,
getVncinfo, getVncinfo,
mutateData,
query, query,
subroutine as sub, subroutine as sub,
write, write,

@ -18,6 +18,15 @@ export const deleteHostConnection: RequestHandler<
const hostUuid = toHostUUID(key); const hostUuid = toHostUUID(key);
const peerHostUuids = body[key]; const peerHostUuids = body[key];
/**
* Removing one or more peer of a striker doesn't update the globals in
* access module's memory, meaning there will be broken references to the
* removed peer for, i.e., database connections.
*
* TODO: find a solution to update the necessary pieces after removing
* peer(s).
*/
for (const peerHostUuid of peerHostUuids) { for (const peerHostUuid of peerHostUuids) {
try { try {
await job({ await job({

Loading…
Cancel
Save