|
|
|
@ -16,7 +16,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
unknown, |
|
|
|
|
undefined, |
|
|
|
|
CreateHostConnectionRequestBody |
|
|
|
|
> = (request, response) => { |
|
|
|
|
> = async (request, response) => { |
|
|
|
|
const { |
|
|
|
|
body: { |
|
|
|
|
dbName = 'anvil', |
|
|
|
@ -46,16 +46,15 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
let peerHostUUID: string; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
({ hostUUID: peerHostUUID, isConnected: isPeerReachable } = getPeerData( |
|
|
|
|
peerIPAddress, |
|
|
|
|
{ password: commonPassword, port: peerSSHPort }, |
|
|
|
|
)); |
|
|
|
|
({ hostUUID: peerHostUUID, isConnected: isPeerReachable } = |
|
|
|
|
await getPeerData(peerIPAddress, { |
|
|
|
|
password: commonPassword, |
|
|
|
|
port: peerSSHPort, |
|
|
|
|
})); |
|
|
|
|
} catch (subError) { |
|
|
|
|
stderr(`Failed to get peer data; CAUSE: ${subError}`); |
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stdoutVar({ peerHostUUID, isPeerReachable }); |
|
|
|
@ -65,9 +64,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
`Cannot connect to peer; please verify credentials and SSH keys validity.`, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
response.status(400).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(400).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
@ -78,9 +75,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
} catch (subError) { |
|
|
|
|
stderr(`Failed to get matching IP address; CAUSE: ${subError}`); |
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stdoutVar({ localIPAddress }); |
|
|
|
@ -107,9 +102,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
} catch (subError) { |
|
|
|
|
stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`); |
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
@ -130,9 +123,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
} catch (fsError) { |
|
|
|
|
stderr(`Failed to remove ${pgpassFilePath}; CAUSE: ${fsError}`); |
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stdoutVar({ isPeerDBReachable }); |
|
|
|
@ -142,9 +133,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
`Cannot connect to peer database; please verify database credentials.`, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
response.status(400).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(400).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const localHostUUID = getLocalHostUUID(); |
|
|
|
@ -160,9 +149,7 @@ export const createHostConnection: RequestHandler< |
|
|
|
|
} catch (subError) { |
|
|
|
|
stderr(`Failed to get local database data from hash; CAUSE: ${subError}`); |
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const jobCommand = `${SERVER_PATHS.usr.sbin['striker-manage-peers'].self} --add --host-uuid ${peerHostUUID} --host ${peerIPAddress} --port ${commonDBPort} --ping ${commonPing}`; |
|
|
|
@ -181,9 +168,7 @@ peer_job_command=${peerJobCommand}`, |
|
|
|
|
} catch (subError) { |
|
|
|
|
stderr(`Failed to add peer ${peerHostUUID}; CAUSE: ${subError}`); |
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
return response.status(500).send(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
response.status(201).send(); |
|
|
|
|