fix(striker-ui-api): wrap missed job calls in try-catch

main
Tsu-ba-me 2 years ago
parent 3a01052e03
commit 00aa2c02df
  1. 26
      striker-ui-api/src/lib/request_handlers/host/updateHost.ts
  2. 38
      striker-ui-api/src/lib/request_handlers/server/createServer.ts

@ -4,7 +4,7 @@ import { LOCAL } from '../../consts/LOCAL';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { stdout } from '../../shell';
import { stderr, stdout } from '../../shell';
export const updateHost: RequestHandler<
{ hostUUID: string },
@ -25,14 +25,22 @@ export const updateHost: RequestHandler<
if (isEnableInstallTarget !== undefined) {
const task = isEnableInstallTarget ? 'enable' : 'disable';
job({
file: __filename,
job_command: `${SERVER_PATHS.usr.sbin['striker-manage-install-target'].self} --${task}`,
job_description: 'job_0016',
job_host_uuid: hostUUID,
job_name: `install-target::${task}`,
job_title: 'job_0015',
});
try {
job({
file: __filename,
job_command: `${SERVER_PATHS.usr.sbin['striker-manage-install-target'].self} --${task}`,
job_description: 'job_0016',
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;
}
}
response.status(200).send();

@ -6,10 +6,10 @@ import { REP_INTEGER, REP_UUID } from '../../consts/REG_EXP_PATTERNS';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { dbQuery, job } from '../../accessModule';
import { stderr, stdout } from '../../shell';
export const createServer: RequestHandler = ({ body }, response) => {
console.log('Creating server.');
console.dir(body, { depth: null });
stdout(`Creating server.\n${JSON.stringify(body, null, 2)}`);
const {
serverName,
@ -81,7 +81,7 @@ export const createServer: RequestHandler = ({ body }, response) => {
`Data anvil UUID must be a valid UUID; got [${dataAnvilUUID}].`,
);
} catch (assertError) {
console.log(
stdout(
`Failed to assert value when trying to provision a server; CAUSE: ${assertError}.`,
);
@ -99,7 +99,7 @@ storage_size=${dataStorageSize}
install_iso=${dataInstallISO}
driver_iso=${dataDriverISO}`;
console.log(`provisionServerJobData: [${provisionServerJobData}]`);
stdout(`provisionServerJobData=[${provisionServerJobData}]`);
const [[provisionServerJobHostUUID]] = dbQuery(
`SELECT
@ -134,17 +134,25 @@ driver_iso=${dataDriverISO}`;
ON pri_hos.phl = nod_1.phr;`,
).stdout;
console.log(`provisionServerJobHostUUID: [${provisionServerJobHostUUID}]`);
job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-provision-server'].self,
job_data: provisionServerJobData,
job_name: 'server:provision',
job_title: 'job_0147',
job_description: 'job_0148',
job_host_uuid: provisionServerJobHostUUID,
});
stdout(`provisionServerJobHostUUID=[${provisionServerJobHostUUID}]`);
try {
job({
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-provision-server'].self,
job_data: provisionServerJobData,
job_name: 'server:provision',
job_title: 'job_0147',
job_description: 'job_0148',
job_host_uuid: provisionServerJobHostUUID,
});
} catch (subError) {
stderr(`Failed to provision server; CAUSE: ${subError}`);
response.status(500).send();
return;
}
response.status(202).send();
};

Loading…
Cancel
Save