fix(striker-ui-api): migrate job to access interact

main
Tsu-ba-me 2 years ago
parent 7d73fc931e
commit d8cc7d9979
  1. 110
      striker-ui-api/src/lib/accessModule.ts
  2. 8
      striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts
  3. 23
      striker-ui-api/src/lib/request_handlers/command/runManifest.ts
  4. 8
      striker-ui-api/src/lib/request_handlers/command/updateSystem.ts
  5. 8
      striker-ui-api/src/lib/request_handlers/file/buildQueryFileDetail.ts
  6. 16
      striker-ui-api/src/lib/request_handlers/file/createFile.ts
  7. 29
      striker-ui-api/src/lib/request_handlers/file/deleteFile.ts
  8. 10
      striker-ui-api/src/lib/request_handlers/file/getFile.ts
  9. 6
      striker-ui-api/src/lib/request_handlers/file/getFileDetail.ts
  10. 5
      striker-ui-api/src/lib/request_handlers/file/index.ts
  11. 134
      striker-ui-api/src/lib/request_handlers/file/updateFile.ts
  12. 4
      striker-ui-api/src/lib/request_handlers/host/configStriker.ts
  13. 2
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts
  14. 28
      striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts
  15. 2
      striker-ui-api/src/lib/request_handlers/host/prepareHost.ts
  16. 38
      striker-ui-api/src/lib/request_handlers/host/setHostInstallTarget.ts
  17. 2
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  18. 2
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts
  19. 22
      striker-ui-api/src/lib/request_handlers/ssh-key/deleteSSHKeyConflict.ts
  20. 191
      striker-ui-api/src/routes/file.ts
  21. 5
      striker-ui-api/src/types/DBInsertOrUpdateFunctionCommon.d.ts
  22. 2
      striker-ui-api/src/types/DBInsertOrUpdateJobFunction.d.ts

@ -1,10 +1,4 @@
import {
ChildProcess,
spawn,
SpawnOptions,
spawnSync,
SpawnSyncOptions,
} from 'child_process';
import { ChildProcess, spawn, SpawnOptions } from 'child_process';
import EventEmitter from 'events';
import { readFileSync } from 'fs';
@ -186,90 +180,18 @@ const write = async (script: string) => {
return wcode;
};
const execAnvilAccessModule = (
args: string[],
options: SpawnSyncOptions = {},
) => {
const {
encoding = 'utf-8',
timeout = 10000,
...restSpawnSyncOptions
} = options;
const { error, stderr, stdout } = spawnSync(
SERVER_PATHS.usr.sbin['anvil-access-module'].self,
args,
{ encoding, timeout, ...restSpawnSyncOptions },
);
if (error) {
throw error;
}
if (stderr.length > 0) {
throw new Error(stderr.toString());
}
let output;
try {
output = JSON.parse(stdout.toString());
} catch (stdoutParseError) {
output = stdout;
sherr(
`Failed to parse anvil-access-module stdout; CAUSE: ${stdoutParseError}`,
);
}
return {
stdout: output,
};
};
const execModuleSubroutine = (
subName: string,
{
spawnSyncOptions,
subModuleName,
subParams,
}: ExecModuleSubroutineOptions = {},
) => {
const args = ['--sub', subName];
// Defaults to "Database" in anvil-access-module.
if (subModuleName) {
args.push('--sub-module', subModuleName);
}
if (subParams) {
args.push('--sub-params', JSON.stringify(subParams));
}
shout(
`...${subModuleName}->${subName} with params: ${JSON.stringify(
subParams,
null,
2,
)}`,
);
const { stdout } = execAnvilAccessModule(args, spawnSyncOptions);
const insertOrUpdateJob = async ({
job_progress = 0,
line = 0,
...rest
}: DBJobParams) => {
const [uuid]: [string] = await subroutine('insert_or_update_jobs', {
params: [{ job_progress, line, ...rest }],
});
return {
stdout: stdout['sub_results'],
};
return uuid;
};
const dbInsertOrUpdateJob = (
{ job_progress = 0, line = 0, ...rest }: DBJobParams,
{ spawnSyncOptions }: DBInsertOrUpdateJobOptions = {},
) =>
execModuleSubroutine('insert_or_update_jobs', {
spawnSyncOptions,
subParams: { job_progress, line, ...rest },
}).stdout;
const insertOrUpdateVariable: DBInsertOrUpdateVariableFunction = async (
params,
) => {
@ -280,7 +202,7 @@ const insertOrUpdateVariable: DBInsertOrUpdateVariableFunction = async (
return uuid;
};
const dbJobAnvilSyncShared = (
const anvilSyncShared = (
jobName: string,
jobData: string,
jobTitle: string,
@ -300,10 +222,10 @@ const dbJobAnvilSyncShared = (
subParams.job_host_uuid = jobHostUUID;
}
return dbInsertOrUpdateJob(subParams);
return insertOrUpdateJob(subParams);
};
const dbSubRefreshTimestamp = () => {
const refreshTimestamp = () => {
let result: string;
try {
@ -420,10 +342,10 @@ const getUpsSpec = async () => {
};
export {
dbInsertOrUpdateJob as job,
insertOrUpdateJob as job,
insertOrUpdateVariable as variable,
dbJobAnvilSyncShared,
dbSubRefreshTimestamp as timestamp,
anvilSyncShared,
refreshTimestamp as timestamp,
getData,
getFenceSpec,
getHostData,

@ -32,7 +32,7 @@ export const buildHostPowerHandler: (
task?: 'poweroff' | 'reboot',
) => RequestHandler =
(task = 'reboot') =>
(request, response) => {
async (request, response) => {
const subParams: DBJobParams = {
file: __filename,
@ -40,13 +40,11 @@ export const buildHostPowerHandler: (
};
try {
job(subParams);
await job(subParams);
} catch (subError) {
stderr(`Failed to ${task} host; CAUSE: ${subError}`);
response.status(500).send();
return;
return response.status(500).send();
}
response.status(204).send();

@ -81,9 +81,7 @@ export const runManifest: RequestHandler<
assert(isHostListUnique, `Each entry in hosts must be unique`);
} catch (assertError) {
handleAssertError(assertError);
return;
return handleAssertError(assertError);
}
let rawHostListData: AnvilDataHostListHash | undefined;
@ -99,15 +97,11 @@ export const runManifest: RequestHandler<
`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`,
);
response.status(500).send();
return;
return response.status(500).send();
}
if (!rawHostListData || !rawManifestListData || !rawSysData) {
response.status(404).send();
return;
return response.status(404).send();
}
const { host_uuid: hostUuidMapToData } = rawHostListData;
@ -167,16 +161,15 @@ export const runManifest: RequestHandler<
params: [anParams],
});
joinAnJobs.forEach((jobParams) => {
for (const jobParams of joinAnJobs) {
jobParams.job_data += `,anvil_uuid=${newAnUuid}`;
job(jobParams);
});
await job(jobParams);
}
} catch (subError) {
stderr(`Failed to record new anvil node entry; CAUSE: ${subError}`);
response.status(500).send();
return;
return response.status(500).send();
}
response.status(204).send();

@ -5,9 +5,9 @@ import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { stderr } from '../../shell';
export const updateSystem: RequestHandler = (request, response) => {
export const updateSystem: RequestHandler = async (request, response) => {
try {
job({
await job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-update-system'].self,
job_description: 'job_0004',
@ -17,9 +17,7 @@ export const updateSystem: RequestHandler = (request, response) => {
} catch (subError) {
stderr(`Failed to initiate system update; CAUSE: ${subError}`);
response.status(500).send();
return;
return response.status(500).send();
}
response.status(204).send();

@ -1,7 +1,9 @@
import { DELETED } from '../../consts';
import join from '../../join';
import { stdoutVar } from '../../shell';
const buildQueryFileDetail = ({
export const buildQueryFileDetail = ({
fileUUIDs = ['*'],
}: {
fileUUIDs?: string[] | '*';
@ -34,8 +36,6 @@ const buildQueryFileDetail = ({
ON fil.file_uuid = fil_loc.file_location_file_uuid
JOIN anvils AS anv
ON fil_loc.file_location_anvil_uuid = anv.anvil_uuid
WHERE fil.file_type != 'DELETED'
WHERE fil.file_type != '${DELETED}'
${condFileUUIDs};`;
};
export default buildQueryFileDetail;

@ -0,0 +1,16 @@
import { RequestHandler } from 'express';
import { anvilSyncShared } from '../../accessModule';
import { stdout, stdoutVar } from '../../shell';
export const createFile: RequestHandler = async ({ file, body }, response) => {
stdout('Receiving shared file.');
if (!file) return response.status(400).send();
stdoutVar({ body, file });
await anvilSyncShared('move_incoming', `file=${file.path}`, '0132', '0133');
response.status(201).send();
};

@ -0,0 +1,29 @@
import { RequestHandler } from 'express';
import { DELETED } from '../../consts';
import { anvilSyncShared, query, timestamp, write } from '../../accessModule';
export const deleteFile: RequestHandler = async (request, response) => {
const { fileUUID } = request.params;
const [[oldFileType]] = await query(
`SELECT file_type FROM files WHERE file_uuid = '${fileUUID}';`,
);
if (oldFileType !== DELETED) {
await write(
`UPDATE files
SET
file_type = '${DELETED}',
modified_date = '${timestamp()}'
WHERE file_uuid = '${fileUUID}';`,
);
await anvilSyncShared('purge', `file_uuid=${fileUUID}`, '0136', '0137', {
jobHostUUID: 'all',
});
}
response.status(204).send();
};

@ -1,10 +1,12 @@
import { RequestHandler } from 'express';
import { DELETED } from '../../consts';
import buildGetRequestHandler from '../buildGetRequestHandler';
import buildQueryFileDetail from './buildQueryFileDetail';
import { buildQueryFileDetail } from './buildQueryFileDetail';
import { sanitize } from '../../sanitize';
const getFile: RequestHandler = buildGetRequestHandler((request) => {
export const getFile: RequestHandler = buildGetRequestHandler((request) => {
const { fileUUIDs } = request.query;
let query = `
@ -15,7 +17,7 @@ const getFile: RequestHandler = buildGetRequestHandler((request) => {
file_type,
file_md5sum
FROM files
WHERE file_type != 'DELETED';`;
WHERE file_type != '${DELETED}';`;
if (fileUUIDs) {
query = buildQueryFileDetail({
@ -27,5 +29,3 @@ const getFile: RequestHandler = buildGetRequestHandler((request) => {
return query;
});
export default getFile;

@ -1,12 +1,10 @@
import { RequestHandler } from 'express';
import buildGetRequestHandler from '../buildGetRequestHandler';
import buildQueryFileDetail from './buildQueryFileDetail';
import { buildQueryFileDetail } from './buildQueryFileDetail';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
const getFileDetail: RequestHandler = buildGetRequestHandler(
export const getFileDetail: RequestHandler = buildGetRequestHandler(
({ params: { fileUUID } }) =>
buildQueryFileDetail({ fileUUIDs: [sanitizeSQLParam(fileUUID)] }),
);
export default getFileDetail;

@ -0,0 +1,5 @@
export * from './createFile';
export * from './deleteFile';
export * from './getFile';
export * from './getFileDetail';
export * from './updateFile';

@ -0,0 +1,134 @@
import { RequestHandler } from 'express';
import { anvilSyncShared, query, timestamp, write } from '../../accessModule';
import { stderr, stdoutVar } from '../../shell';
export const updateFile: RequestHandler = async (request, response) => {
const { body = {}, params } = request;
stdoutVar(body, 'Begin edit single file. body=');
const { fileUUID } = params;
const { fileName, fileLocations, fileType } = body;
const anvilSyncSharedFunctions = [];
let sqlscript = '';
if (fileName) {
const [[oldFileName]] = await query(
`SELECT file_name FROM files WHERE file_uuid = '${fileUUID}';`,
);
stdoutVar({ oldFileName, fileName });
if (fileName !== oldFileName) {
sqlscript += `
UPDATE files
SET
file_name = '${fileName}',
modified_date = '${timestamp()}'
WHERE file_uuid = '${fileUUID}';`;
anvilSyncSharedFunctions.push(() =>
anvilSyncShared(
'rename',
`file_uuid=${fileUUID}\nold_name=${oldFileName}\nnew_name=${fileName}`,
'0138',
'0139',
{ jobHostUUID: 'all' },
),
);
}
}
if (fileType) {
sqlscript += `
UPDATE files
SET
file_type = '${fileType}',
modified_date = '${timestamp()}'
WHERE file_uuid = '${fileUUID}';`;
anvilSyncSharedFunctions.push(() =>
anvilSyncShared('check_mode', `file_uuid=${fileUUID}`, '0143', '0144', {
jobHostUUID: 'all',
}),
);
}
if (fileLocations) {
fileLocations.forEach(
async ({
fileLocationUUID,
isFileLocationActive,
}: {
fileLocationUUID: string;
isFileLocationActive: boolean;
}) => {
let fileLocationActive = 0;
let jobName = 'purge';
let jobTitle = '0136';
let jobDescription = '0137';
if (isFileLocationActive) {
fileLocationActive = 1;
jobName = 'pull_file';
jobTitle = '0132';
jobDescription = '0133';
}
sqlscript += `
UPDATE file_locations
SET
file_location_active = '${fileLocationActive}',
modified_date = '${timestamp()}'
WHERE file_location_uuid = '${fileLocationUUID}';`;
const targetHosts: [
n1uuid: string,
n2uuid: string,
dr1uuid: null | string,
][] = await query(
`SELECT
anv.anvil_node1_host_uuid,
anv.anvil_node2_host_uuid,
anv.anvil_dr1_host_uuid
FROM anvils AS anv
JOIN file_locations AS fil_loc
ON anv.anvil_uuid = fil_loc.file_location_anvil_uuid
WHERE fil_loc.file_location_uuid = '${fileLocationUUID}';`,
);
targetHosts.flat().forEach((hostUUID: null | string) => {
if (hostUUID) {
anvilSyncSharedFunctions.push(() =>
anvilSyncShared(
jobName,
`file_uuid=${fileUUID}`,
jobTitle,
jobDescription,
{ jobHostUUID: hostUUID },
),
);
}
});
},
);
}
let wcode: number;
try {
wcode = await write(sqlscript);
} catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`);
return response.status(500).send();
}
anvilSyncSharedFunctions.forEach(async (fn, index) =>
stdoutVar(await fn(), `Anvil sync shared [${index}] output: `),
);
response.status(200).send(wcode);
};

@ -41,7 +41,7 @@ export const configStriker: RequestHandler<
unknown,
undefined,
Partial<InitializeStrikerForm>
> = (request, response) => {
> = async (request, response) => {
const { body = {} } = request;
stdoutVar(body, 'Begin initialize Striker; body=');
@ -116,7 +116,7 @@ export const configStriker: RequestHandler<
}
try {
job({
await job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-configure-host'].self,
job_data: `${fvar(1, 'domain')}=${domainName}

@ -159,7 +159,7 @@ export const createHostConnection: RequestHandler<
const peerJobCommand = `${SERVER_PATHS.usr.sbin['striker-manage-peers'].self} --add --host-uuid ${localHostUUID} --host ${localIPAddress} --port ${localDBPort} --ping ${commonPing}`;
try {
job({
await job({
file: __filename,
job_command: jobCommand,
job_data: `password=${commonPassword}

@ -10,33 +10,31 @@ export const deleteHostConnection: RequestHandler<
unknown,
undefined,
DeleteHostConnectionRequestBody
> = (request, response) => {
> = async (request, response) => {
const { body } = request;
const hostUUIDs = Object.keys(body);
const hostUuids = Object.keys(body);
hostUUIDs.forEach((key) => {
const hostUUID = toHostUUID(key);
const peerHostUUIDs = body[key];
for (const key of hostUuids) {
const hostUuid = toHostUUID(key);
const peerHostUuids = body[key];
peerHostUUIDs.forEach((peerHostUUID) => {
for (const peerHostUuid of peerHostUuids) {
try {
job({
await job({
file: __filename,
job_command: `${SERVER_PATHS.usr.sbin['striker-manage-peers'].self} --remove --host-uuid ${peerHostUUID}`,
job_command: `${SERVER_PATHS.usr.sbin['striker-manage-peers'].self} --remove --host-uuid ${peerHostUuid}`,
job_description: 'job_0014',
job_host_uuid: hostUUID,
job_host_uuid: hostUuid,
job_name: 'striker-peer::delete',
job_title: 'job_0013',
});
} catch (subError) {
stderr(`Failed to delete peer ${peerHostUUID}; CAUSE: ${subError}`);
stderr(`Failed to delete peer ${peerHostUuid}; CAUSE: ${subError}`);
response.status(500).send();
return;
return response.status(500).send();
}
}
}
});
});
response.status(204).send();
};

@ -121,7 +121,7 @@ export const prepareHost: RequestHandler<
});
}
job({
await job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['striker-initialize-host'].self,
job_data: `enterprise_uuid=${dataEnterpriseUUID}

@ -4,36 +4,38 @@ import { LOCAL } from '../../consts/LOCAL';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { stderr, stdout } from '../../shell';
export const setHostInstallTarget: RequestHandler = (request, response) => {
stdout(
`Begin set host install target.\n${JSON.stringify(request.body, null, 2)}`,
);
const { isEnableInstallTarget } =
request.body as SetHostInstallTargetRequestBody;
const { hostUUID: rawHostUUID } = request.params as UpdateHostParams;
const hostUUID: string | undefined =
rawHostUUID === LOCAL ? undefined : rawHostUUID;
import { stderr, stdoutVar } from '../../shell';
export const setHostInstallTarget: RequestHandler<
UpdateHostParams,
undefined,
SetHostInstallTargetRequestBody
> = async (request, response) => {
const { body, params } = request;
stdoutVar(body, `Begin set host install target; body=`);
const { isEnableInstallTarget } = body;
const { hostUUID: rHostUuid } = params;
const hostUuid: string | undefined =
rHostUuid === LOCAL ? undefined : rHostUuid;
const task = isEnableInstallTarget ? 'enable' : 'disable';
try {
job({
await job({
file: __filename,
job_command: `${SERVER_PATHS.usr.sbin['striker-manage-install-target'].self} --${task}`,
job_description: 'job_0016',
job_host_uuid: hostUUID,
job_host_uuid: hostUuid,
job_name: `install-target::${task}`,
job_title: 'job_0015',
});
} catch (subError) {
stderr(`Failed to ${task} install target; CAUSE: ${subError}`);
response.status(500).send();
return;
return response.status(500).send();
}
response.status(200).send();
response.status(204).send();
};

@ -150,7 +150,7 @@ driver_iso=${driverIsoUuid}`;
stdout(`provisionServerJobHostUUID=[${provisionServerJobHostUUID}]`);
try {
job({
await job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-provision-server'].self,
job_data: provisionServerJobData,

@ -128,7 +128,7 @@ export const getServerDetail: RequestHandler = async (request, response) => {
}
try {
job({
await job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-get-server-screenshot'].self,
job_data: `server-uuid=${serverUUID}

@ -10,32 +10,30 @@ export const deleteSSHKeyConflict: RequestHandler<
unknown,
undefined,
DeleteSshKeyConflictRequestBody
> = (request, response) => {
> = async (request, response) => {
const { body } = request;
const hostUUIDs = Object.keys(body);
const hostUuids = Object.keys(body);
hostUUIDs.forEach((key) => {
const hostUUID = toHostUUID(key);
const stateUUIDs = body[key];
for (const uuid of hostUuids) {
const hostUuid = toHostUUID(uuid);
const stateUuids = body[uuid];
try {
job({
await job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-manage-keys'].self,
job_data: stateUUIDs.join(','),
job_data: stateUuids.join(','),
job_description: 'job_0057',
job_host_uuid: hostUUID,
job_host_uuid: hostUuid,
job_name: 'manage::broken_keys',
job_title: 'job_0056',
});
} catch (subError) {
stderr(`Failed to delete bad SSH keys; CAUSE: ${subError}`);
response.status(500).send();
return;
return response.status(500).send();
}
}
});
response.status(204).send();
};

@ -1,194 +1,21 @@
import express from 'express';
import { DELETED } from '../lib/consts';
import {
dbJobAnvilSyncShared,
timestamp,
query,
write,
} from '../lib/accessModule';
import getFile from '../lib/request_handlers/file/getFile';
import getFileDetail from '../lib/request_handlers/file/getFileDetail';
createFile,
deleteFile,
getFile,
getFileDetail,
updateFile,
} from '../lib/request_handlers/file';
import uploadSharedFiles from '../middlewares/uploadSharedFiles';
import { stderr, stdout, stdoutVar } from '../lib/shell';
const router = express.Router();
router
.delete('/:fileUUID', async (request, response) => {
const { fileUUID } = request.params;
const [[oldFileType]] = await query(
`SELECT file_type FROM files WHERE file_uuid = '${fileUUID}';`,
);
if (oldFileType !== DELETED) {
await write(
`UPDATE files
SET
file_type = '${DELETED}',
modified_date = '${timestamp()}'
WHERE file_uuid = '${fileUUID}';`,
);
dbJobAnvilSyncShared('purge', `file_uuid=${fileUUID}`, '0136', '0137', {
jobHostUUID: 'all',
});
}
response.status(204).send();
})
.delete('/:fileUUID', deleteFile)
.get('/', getFile)
.get('/:fileUUID', getFileDetail)
.post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => {
stdout('Receiving shared file.');
if (file) {
stdoutVar({ body, file });
dbJobAnvilSyncShared(
'move_incoming',
`file=${file.path}`,
'0132',
'0133',
);
response.status(200).send();
}
})
.put('/:fileUUID', async (request, response) => {
const { body = {}, params } = request;
stdoutVar(body, 'Begin edit single file. body=');
const { fileUUID } = params;
const { fileName, fileLocations, fileType } = body;
const anvilSyncSharedFunctions = [];
let sqlscript = '';
if (fileName) {
const [[oldFileName]] = await query(
`SELECT file_name FROM files WHERE file_uuid = '${fileUUID}';`,
);
stdoutVar({ oldFileName, fileName });
if (fileName !== oldFileName) {
sqlscript += `
UPDATE files
SET
file_name = '${fileName}',
modified_date = '${timestamp()}'
WHERE file_uuid = '${fileUUID}';`;
anvilSyncSharedFunctions.push(() =>
dbJobAnvilSyncShared(
'rename',
`file_uuid=${fileUUID}\nold_name=${oldFileName}\nnew_name=${fileName}`,
'0138',
'0139',
{ jobHostUUID: 'all' },
),
);
}
}
if (fileType) {
sqlscript += `
UPDATE files
SET
file_type = '${fileType}',
modified_date = '${timestamp()}'
WHERE file_uuid = '${fileUUID}';`;
anvilSyncSharedFunctions.push(() =>
dbJobAnvilSyncShared(
'check_mode',
`file_uuid=${fileUUID}`,
'0143',
'0144',
{ jobHostUUID: 'all' },
),
);
}
if (fileLocations) {
fileLocations.forEach(
async ({
fileLocationUUID,
isFileLocationActive,
}: {
fileLocationUUID: string;
isFileLocationActive: boolean;
}) => {
let fileLocationActive = 0;
let jobName = 'purge';
let jobTitle = '0136';
let jobDescription = '0137';
if (isFileLocationActive) {
fileLocationActive = 1;
jobName = 'pull_file';
jobTitle = '0132';
jobDescription = '0133';
}
sqlscript += `
UPDATE file_locations
SET
file_location_active = '${fileLocationActive}',
modified_date = '${timestamp()}'
WHERE file_location_uuid = '${fileLocationUUID}';`;
const targetHosts: [
n1uuid: string,
n2uuid: string,
dr1uuid: null | string,
][] = await query(
`SELECT
anv.anvil_node1_host_uuid,
anv.anvil_node2_host_uuid,
anv.anvil_dr1_host_uuid
FROM anvils AS anv
JOIN file_locations AS fil_loc
ON anv.anvil_uuid = fil_loc.file_location_anvil_uuid
WHERE fil_loc.file_location_uuid = '${fileLocationUUID}';`,
);
targetHosts.flat().forEach((hostUUID: null | string) => {
if (hostUUID) {
anvilSyncSharedFunctions.push(() =>
dbJobAnvilSyncShared(
jobName,
`file_uuid=${fileUUID}`,
jobTitle,
jobDescription,
{ jobHostUUID: hostUUID },
),
);
}
});
},
);
}
let wcode: number;
try {
wcode = await write(sqlscript);
} catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`);
return response.status(500).send();
}
anvilSyncSharedFunctions.forEach((fn, index) =>
stdoutVar(fn(), `Anvil sync shared [${index}] output: `),
);
response.status(200).send(wcode);
});
.post('/', uploadSharedFiles.single('file'), createFile)
.put('/:fileUUID', updateFile);
export default router;

@ -2,8 +2,3 @@ type DBInsertOrUpdateFunctionCommonParams = ModuleSubroutineCommonParams & {
file: string;
line?: number;
};
type DBInsertOrUpdateFunctionCommonOptions = Omit<
ExecModuleSubroutineOptions,
'subParams' | 'subModuleName'
>;

@ -7,5 +7,3 @@ type DBJobParams = DBInsertOrUpdateFunctionCommonParams & {
job_host_uuid?: string;
job_progress?: number;
};
type DBInsertOrUpdateJobOptions = DBInsertOrUpdateFunctionCommonOptions;

Loading…
Cancel
Save