fix(striker-ui-api): reduce required variables when creating jobs

main
Tsu-ba-me 2 years ago
parent e28ad3b0b2
commit 107b119d52
  1. 26
      striker-ui-api/src/lib/accessModule.ts
  2. 5
      striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts
  3. 44
      striker-ui-api/src/lib/request_handlers/host/configStriker.ts
  4. 18
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  5. 19
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts
  6. 10
      striker-ui-api/src/types/DBInsertOrUpdateJobFunction.d.ts

@ -78,8 +78,14 @@ const execModuleSubroutine = (
};
};
const dbInsertOrUpdateJob = (options?: DBInsertOrUpdateJobOptions) =>
execModuleSubroutine('insert_or_update_jobs', options).stdout;
const dbInsertOrUpdateJob = (
{ job_progress = 0, line = 0, ...rest }: DBJobParams,
{ spawnSyncOptions }: DBInsertOrUpdateJobOptions = {},
) =>
execModuleSubroutine('insert_or_update_jobs', {
spawnSyncOptions,
subParams: { job_progress, line, ...rest },
}).stdout;
const dbJobAnvilSyncShared = (
jobName: string,
@ -88,32 +94,20 @@ const dbJobAnvilSyncShared = (
jobDescription: string,
{ jobHostUUID }: DBJobAnvilSyncSharedOptions = { jobHostUUID: undefined },
) => {
const subParams: {
file: string;
line: number;
job_command: string;
job_data: string;
job_name: string;
job_title: string;
job_description: string;
job_host_uuid?: string;
job_progress: number;
} = {
const subParams: DBJobParams = {
file: __filename,
line: 0,
job_command: SERVER_PATHS.usr.sbin['anvil-sync-shared'].self,
job_data: jobData,
job_name: `storage::${jobName}`,
job_title: `job_${jobTitle}`,
job_description: `job_${jobDescription}`,
job_progress: 0,
};
if (jobHostUUID) {
subParams.job_host_uuid = jobHostUUID;
}
return dbInsertOrUpdateJob({ subParams });
return dbInsertOrUpdateJob(subParams);
};
const dbQuery = (query: string, options?: SpawnSyncOptions) => {

@ -35,15 +35,12 @@ export const buildHostPowerHandler: (
(request, response) => {
const subParams: DBJobParams = {
file: __filename,
line: 0,
job_data: '',
job_progress: 100,
...MANAGE_HOST_POWER_JOB_PARAMS[task],
};
try {
job({ subParams });
job(subParams);
} catch (subError) {
stderr(`Failed to ${task} host; CAUSE: ${subError}`);

@ -116,11 +116,9 @@ export const configStriker: RequestHandler<
try {
job({
subParams: {
file: __filename,
line: 0,
job_command: SERVER_PATHS.usr.sbin['anvil-configure-host'].self,
job_data: `${fvar(1, 'domain')}=${domainName}
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-configure-host'].self,
job_data: `${fvar(1, 'domain')}=${domainName}
${fvar(1, 'organization')}=${organizationName}
${fvar(1, 'prefix')}=${organizationPrefix}
${fvar(1, 'sequence')}=${hostNumber}
@ -129,32 +127,30 @@ ${fvar(2, 'gateway')}=${networkGateway}
${fvar(2, 'host_name')}=${hostName}
${fvar(2, 'striker_password')}=${adminPassword}
${fvar(2, 'striker_user')}=admin${
networks.reduce<{
counters: Record<InitializeStrikerNetworkForm['type'], number>;
result: string;
}>(
(reduceContainer, { interfaces, ipAddress, subnetMask, type }) => {
const { counters } = reduceContainer;
networks.reduce<{
counters: Record<InitializeStrikerNetworkForm['type'], number>;
result: string;
}>(
(reduceContainer, { interfaces, ipAddress, subnetMask, type }) => {
const { counters } = reduceContainer;
counters[type] = counters[type] ? counters[type] + 1 : 1;
counters[type] = counters[type] ? counters[type] + 1 : 1;
const networkShortName = `${type}${counters[type]}`;
const networkShortName = `${type}${counters[type]}`;
reduceContainer.result += `
reduceContainer.result += `
${fvar(2, `${networkShortName}_ip`)}=${ipAddress}
${fvar(2, `${networkShortName}_subnet_mask`)}=${subnetMask}
${buildNetworkLinks(2, networkShortName, interfaces)}`;
return reduceContainer;
},
{ counters: {}, result: '' },
).result
}`,
job_name: 'configure::network',
job_title: 'job_0001',
job_description: 'job_0071',
job_progress: 0,
},
return reduceContainer;
},
{ counters: {}, result: '' },
).result
}`,
job_name: 'configure::network',
job_title: 'job_0001',
job_description: 'job_0071',
});
} catch (subError) {
console.log(`Failed to queue striker initialization; CAUSE: ${subError}`);

@ -137,17 +137,13 @@ driver_iso=${dataDriverISO}`;
console.log(`provisionServerJobHostUUID: [${provisionServerJobHostUUID}]`);
job({
subParams: {
file: __filename,
line: 0,
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_progress: 0,
job_host_uuid: provisionServerJobHostUUID,
},
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,
});
response.status(202).send();

@ -128,21 +128,16 @@ export const getServerDetail: RequestHandler = (request, response) => {
try {
job({
subParams: {
file: __filename,
line: 0,
job_command:
SERVER_PATHS.usr.sbin['anvil-get-server-screenshot'].self,
job_data: `server-uuid=${serverUUID}
file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-get-server-screenshot'].self,
job_data: `server-uuid=${serverUUID}
request-host-uuid=${requestHostUUID}
resize=${resizeArgs}
out-file-id=${epoch}`,
job_name: `get_server_screenshot::${serverUUID}::${epoch}`,
job_title: 'job_0356',
job_description: 'job_0357',
job_progress: 0,
job_host_uuid: serverHostUUID,
},
job_name: `get_server_screenshot::${serverUUID}::${epoch}`,
job_title: 'job_0356',
job_description: 'job_0357',
job_host_uuid: serverHostUUID,
});
} catch (subError) {
console.log(

@ -1,18 +1,16 @@
type DBJobParams = {
file: string;
line: number;
line?: number;
job_command: string;
job_data: string;
job_data?: string;
job_name: string;
job_title: string;
job_description: string;
job_host_uuid?: string;
job_progress: number;
job_progress?: number;
};
type DBInsertOrUpdateJobOptions = Omit<
ExecModuleSubroutineOptions,
'subParams' | 'subModuleName'
> & {
subParams?: DBJobParams;
};
>;

Loading…
Cancel
Save