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