fix(striker-ui-api): migrate get anvil data to access interact

main
Tsu-ba-me 2 years ago
parent 66b02d4a77
commit f9d7449b7d
  1. 67
      striker-ui-api/src/lib/accessModule.ts
  2. 36
      striker-ui-api/src/lib/request_handlers/command/runManifest.ts
  3. 10
      striker-ui-api/src/lib/request_handlers/fence/getFenceTemplate.ts
  4. 8
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts
  5. 8
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts
  6. 19
      striker-ui-api/src/lib/request_handlers/manifest/getManifestDetail.ts
  7. 9
      striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts
  8. 2
      striker-ui-api/src/types/GetAnvilDataFunction.d.ts

@ -139,9 +139,6 @@ class Access extends EventEmitter {
const access = new Access();
const data = async <T>(...keys: string[]) =>
access.interact<T>('x', `data->${keys.join('->')}`);
const subroutine = async <T extends unknown[]>(
subroutine: string,
{
@ -150,7 +147,7 @@ const subroutine = async <T extends unknown[]>(
}: {
params?: unknown[];
pre?: string[];
},
} = {},
) => {
const chain = `${pre.join('->')}->${subroutine}`;
@ -319,19 +316,29 @@ const dbSubRefreshTimestamp = () => {
return result;
};
const getAnvilData = <HashType>(
dataStruct: AnvilDataStruct,
{ predata, ...spawnSyncOptions }: GetAnvilDataOptions = {},
): HashType =>
execAnvilAccessModule(
[
'--predata',
JSON.stringify(predata),
'--data',
JSON.stringify(dataStruct),
],
spawnSyncOptions,
).stdout;
const getData = async <T>(...keys: string[]) => {
const chain = `data->${keys.join('->')}`;
const {
sub_results: [data],
} = await access.interact<{ sub_results: [T] }>('x', chain);
shvar(data, `${chain} data: `);
return data;
};
const getFenceSpec = async () => {
await subroutine('get_fence_data', { pre: ['Striker'] });
return getData<unknown>('fence_data');
};
const getHostData = async () => {
await subroutine('get_hosts');
return getData<AnvilDataHostListHash>('hosts');
};
const getLocalHostName = () => {
let result: string;
@ -349,7 +356,7 @@ const getLocalHostName = () => {
return result;
};
const getLocalHostUUID = () => {
const getLocalHostUuid = () => {
let result: string;
try {
@ -365,6 +372,15 @@ const getLocalHostUUID = () => {
return result;
};
const getManifestData = async (manifestUuid?: string) => {
await subroutine('load_manifest', {
params: [{ manifest_uuid: manifestUuid }],
pre: ['Striker'],
});
return getData<AnvilDataManifestListHash>('manifests');
};
const getPeerData: GetPeerDataFunction = async (
target,
{ password, port } = {},
@ -396,17 +412,26 @@ const getPeerData: GetPeerDataFunction = async (
};
};
const getUpsSpec = async () => {
await subroutine('get_ups_data', { pre: ['Striker'] });
return getData<AnvilDataUPSHash>('ups_data');
};
export {
dbInsertOrUpdateJob as job,
dbInsertOrUpdateVariable as variable,
dbJobAnvilSyncShared,
dbSubRefreshTimestamp as timestamp,
execModuleSubroutine as sub,
getAnvilData,
getData,
getFenceSpec,
getHostData,
getLocalHostName,
getLocalHostUUID,
getLocalHostUuid as getLocalHostUUID,
getManifestData,
getPeerData,
data,
getUpsSpec,
query,
subroutine,
write,

@ -4,7 +4,13 @@ import { RequestHandler } from 'express';
import { REP_PEACEFUL_STRING, REP_UUID } from '../../consts/REG_EXP_PATTERNS';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { getAnvilData, job, sub } from '../../accessModule';
import {
getData,
getHostData,
getManifestData,
job,
sub,
} from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
@ -12,7 +18,7 @@ export const runManifest: RequestHandler<
{ manifestUuid: string },
undefined,
RunManifestRequestBody
> = (request, response) => {
> = async (request, response) => {
const {
params: { manifestUuid },
body: {
@ -85,29 +91,9 @@ export const runManifest: RequestHandler<
let rawSysData: AnvilDataSysHash | undefined;
try {
({
hosts: rawHostListData,
manifests: rawManifestListData,
sys: rawSysData,
} = getAnvilData<{
hosts?: AnvilDataHostListHash;
manifests?: AnvilDataManifestListHash;
sys?: AnvilDataSysHash;
}>(
{ hosts: true, manifests: true, sys: true },
{
predata: [
['Database->get_hosts'],
[
'Striker->load_manifest',
{
debug,
manifest_uuid: manifestUuid,
},
],
],
},
));
rawHostListData = await getHostData();
rawManifestListData = await getManifestData(manifestUuid);
rawSysData = await getData('sys');
} catch (subError) {
stderr(
`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`,

@ -1,15 +1,13 @@
import { RequestHandler } from 'express';
import { getAnvilData } from '../../accessModule';
import { getFenceSpec } from '../../accessModule';
import { stderr } from '../../shell';
export const getFenceTemplate: RequestHandler = (request, response) => {
export const getFenceTemplate: RequestHandler = async (request, response) => {
let rawFenceData;
try {
({ fence_data: rawFenceData } = getAnvilData<{ fence_data: unknown }>(
{ fence_data: true },
{ predata: [['Striker->get_fence_data']] },
));
rawFenceData = await getFenceSpec();
} catch (subError) {
stderr(`Failed to get fence device template; CAUSE: ${subError}`);

@ -3,7 +3,7 @@ import { RequestHandler } from 'express';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import {
getAnvilData,
getData,
getLocalHostUUID,
getPeerData,
job,
@ -140,10 +140,8 @@ export const createHostConnection: RequestHandler<
try {
const {
database: {
[localHostUUID]: { port: rawLocalDBPort },
},
} = getAnvilData<{ database: AnvilDataDatabaseHash }>({ database: true });
[localHostUUID]: { port: rawLocalDBPort },
} = await getData<AnvilDataDatabaseHash>('database');
localDBPort = sanitize(rawLocalDBPort, 'number');
} catch (subError) {

@ -1,4 +1,4 @@
import { getAnvilData, getLocalHostUUID } from '../../accessModule';
import { getData, getLocalHostUUID } from '../../accessModule';
import { buildUnknownIDCondition } from '../../buildCondition';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { toLocal } from '../../convertHostUUID';
@ -39,7 +39,7 @@ const buildHostConnections = (
);
export const getHostConnection = buildGetRequestHandler(
(request, buildQueryOptions) => {
async (request, buildQueryOptions) => {
const { hostUUIDs: rawHostUUIDs } = request.query;
let rawDatabaseData: AnvilDataDatabaseHash;
@ -59,9 +59,7 @@ export const getHostConnection = buildGetRequestHandler(
stdout(`condHostUUIDs=[${condHostUUIDs}]`);
try {
({ database: rawDatabaseData } = getAnvilData<{
database: AnvilDataDatabaseHash;
}>({ database: true }));
rawDatabaseData = await getData<AnvilDataDatabaseHash>('database');
} catch (subError) {
throw new Error(`Failed to get anvil data; CAUSE: ${subError}`);
}

@ -1,6 +1,6 @@
import { RequestHandler } from 'express';
import { getAnvilData } from '../../accessModule';
import { getManifestData } from '../../accessModule';
import { getEntityParts } from '../../disassembleEntityId';
import { stderr, stdout } from '../../shell';
@ -67,25 +67,18 @@ const handleSortNetworks = <T extends [string, unknown]>(
return result;
};
export const getManifestDetail: RequestHandler = (request, response) => {
export const getManifestDetail: RequestHandler = async (request, response) => {
const {
params: { manifestUUID },
params: { manifestUUID: manifestUuid },
} = request;
let rawManifestListData: AnvilDataManifestListHash | undefined;
try {
({ manifests: rawManifestListData } = getAnvilData<{
manifests?: AnvilDataManifestListHash;
}>(
{ manifests: true },
{
predata: [['Striker->load_manifest', { manifest_uuid: manifestUUID }]],
},
));
rawManifestListData = await getManifestData(manifestUuid);
} catch (subError) {
stderr(
`Failed to get install manifest ${manifestUUID}; CAUSE: ${subError}`,
`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`,
);
response.status(500).send();
@ -109,7 +102,7 @@ export const getManifestDetail: RequestHandler = (request, response) => {
const {
manifest_uuid: {
[manifestUUID]: {
[manifestUuid]: {
parsed: {
domain,
fences: fenceUuidList = {},

@ -1,16 +1,13 @@
import { RequestHandler } from 'express';
import { getAnvilData } from '../../accessModule';
import { getUpsSpec } from '../../accessModule';
import { stderr } from '../../shell';
export const getUPSTemplate: RequestHandler = (request, response) => {
export const getUPSTemplate: RequestHandler = async (request, response) => {
let rawUPSData: AnvilDataUPSHash;
try {
({ ups_data: rawUPSData } = getAnvilData<{ ups_data: AnvilDataUPSHash }>(
{ ups_data: true },
{ predata: [['Striker->get_ups_data']] },
));
rawUPSData = await getUpsSpec();
} catch (subError) {
stderr(`Failed to get ups template; CAUSE: ${subError}`);

@ -111,6 +111,6 @@ type AnvilDataUPSHash = {
};
};
type GetAnvilDataOptions = import('child_process').SpawnSyncOptions & {
type GetAnvilDataOptions = {
predata?: Array<[string, ...unknown[]]>;
};

Loading…
Cancel
Save