diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index b8394c22..828c218a 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.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) => { diff --git a/striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts b/striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts index e809085a..b69c6377 100644 --- a/striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts +++ b/striker-ui-api/src/lib/request_handlers/command/buildHostPowerHandler.ts @@ -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}`); diff --git a/striker-ui-api/src/lib/request_handlers/host/configStriker.ts b/striker-ui-api/src/lib/request_handlers/host/configStriker.ts index 8e757668..0ae24596 100644 --- a/striker-ui-api/src/lib/request_handlers/host/configStriker.ts +++ b/striker-ui-api/src/lib/request_handlers/host/configStriker.ts @@ -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; - result: string; - }>( - (reduceContainer, { interfaces, ipAddress, subnetMask, type }) => { - const { counters } = reduceContainer; + networks.reduce<{ + counters: Record; + 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}`); diff --git a/striker-ui-api/src/lib/request_handlers/server/createServer.ts b/striker-ui-api/src/lib/request_handlers/server/createServer.ts index 9a6dd37e..d3b8a8d3 100644 --- a/striker-ui-api/src/lib/request_handlers/server/createServer.ts +++ b/striker-ui-api/src/lib/request_handlers/server/createServer.ts @@ -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(); diff --git a/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts b/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts index 1da95227..449dd9f8 100644 --- a/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts @@ -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( diff --git a/striker-ui-api/src/types/DBInsertOrUpdateJobFunction.d.ts b/striker-ui-api/src/types/DBInsertOrUpdateJobFunction.d.ts index 26424ca5..4c8a7052 100644 --- a/striker-ui-api/src/types/DBInsertOrUpdateJobFunction.d.ts +++ b/striker-ui-api/src/types/DBInsertOrUpdateJobFunction.d.ts @@ -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; -}; +>;