-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in EPOC-394-update-oh-orchestrator-to-compa (pull request #2)
EPOC-394 update oh orchestrator to compa Approved-by: Abdullah Abdulqader Approved-by: Roman Teyibov Approved-by: Metin Barut
- Loading branch information
Showing
21 changed files
with
555 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const rp = require('request-promise'); | ||
|
||
const fetchActiveAgreements = (containerPort, correlationId) => rp({ | ||
uri: `http://localhost:${containerPort}/agreement`, | ||
}) | ||
.then((response) => { | ||
let parsedResponse = {}; | ||
|
||
try { | ||
parsedResponse = JSON.parse(response); | ||
} | ||
catch (e) { | ||
throw new Error('Error occured while parsing response from Anax'); | ||
} | ||
if (!parsedResponse.agreements) return []; | ||
return parsedResponse.agreements.active; | ||
}) | ||
.catch((error) => { | ||
console.log('===> Error occured while fetching agreements', error); | ||
}); | ||
|
||
module.exports = { | ||
fetchActiveAgreements, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { getRequestData } = require('./requestDataHelper'); | ||
|
||
const { | ||
dataRequest, | ||
fileDownloadRequest, | ||
} = require('./socketHelper'); | ||
|
||
const ESS_REQUEST_BASE_PATH = 'https://localhost/api/v1'; | ||
|
||
const getObjectsByType = (nodeId, agreementId, objectType, correlationId) => getRequestData(nodeId, agreementId, correlationId) | ||
.then((requestData) => { | ||
const request = { | ||
method: 'GET', | ||
path: `${ESS_REQUEST_BASE_PATH}/objects/${objectType}`, | ||
}; | ||
|
||
const completeRequest = { ...request, ...requestData }; | ||
return dataRequest(nodeId, completeRequest, correlationId); | ||
}); | ||
|
||
const markObjectReceived = (nodeId, agreementId, objectType, objectId, correlationId) => getRequestData(nodeId, agreementId, correlationId) | ||
.then((requestData) => { | ||
const request = { | ||
method: 'PUT', | ||
path: `${ESS_REQUEST_BASE_PATH}/objects/${objectType}/${objectId}/received`, | ||
}; | ||
|
||
const completeRequest = { ...request, ...requestData }; | ||
return dataRequest(nodeId, completeRequest, correlationId); | ||
}); | ||
|
||
const downloadObjectFile = (nodeId, agreementId, objectType, objectId, outputFilePath, correlationId) => getRequestData(nodeId, agreementId, correlationId) | ||
.then((requestData) => { | ||
const request = { | ||
method: 'GET', | ||
path: `${ESS_REQUEST_BASE_PATH}/objects/${objectType}/${objectId}/data`, | ||
}; | ||
|
||
const completeRequest = { ...request, ...requestData }; | ||
|
||
return fileDownloadRequest(nodeId, outputFilePath, completeRequest, correlationId); | ||
}); | ||
|
||
const establishObectTypeWebhook = (nodeId, agreementId, objectType, receiverUrl, correlationId) => getRequestData(nodeId, agreementId, correlationId) | ||
.then((requestData) => { | ||
const request = { | ||
method: 'PUT', | ||
path: `${ESS_REQUEST_BASE_PATH}/objects/${objectType}`, | ||
body: JSON.stringify({ | ||
action: 'register', | ||
url: receiverUrl, | ||
}), | ||
}; | ||
|
||
const completeRequest = { ...request, ...requestData }; | ||
return dataRequest(nodeId, completeRequest, correlationId); | ||
}); | ||
|
||
module.exports = { | ||
getObjectsByType, | ||
downloadObjectFile, | ||
markObjectReceived, | ||
establishObectTypeWebhook, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const Promise = require('bluebird'); | ||
const fs = require('fs-extra'); | ||
|
||
const { anaxContainersStorageDir } = require('../../configuration/config'); | ||
const { shortenNodeId } = require('../../util/nodeUtil'); | ||
|
||
const getRequestData = (nodeId, agreementId, correlationId) => Promise.resolve() | ||
.then(() => { | ||
const authDataPromises = []; | ||
|
||
const shortenedNodeId = shortenNodeId(nodeId); | ||
const certFilePath = `${anaxContainersStorageDir}/${shortenedNodeId}/ess-auth/SSL/cert/cert.pem`; | ||
const essSocketFilePath = `${anaxContainersStorageDir}/${shortenedNodeId}/fss-domain-socket/essapi.sock`; | ||
const authKeyFilePath = `${anaxContainersStorageDir}/${shortenedNodeId}/ess-auth/${agreementId}/auth.json`; | ||
|
||
console.log('===> files', { | ||
certFilePath, | ||
essSocketFilePath, | ||
authKeyFilePath, | ||
}); | ||
|
||
authDataPromises.push(fs.access(essSocketFilePath) | ||
.then(() => essSocketFilePath) | ||
.catch((err) => { | ||
throw new Error(`Failed to find/access to socketPath for nodeId, error: ${err}`); | ||
})); | ||
|
||
authDataPromises.push(fs.readJSON(authKeyFilePath) | ||
.catch((err) => { | ||
throw new Error(`ESS Auth key file cannot be read, error: ${err}`); | ||
}) | ||
.then(({ id, token }) => Buffer.from(`${id}:${token}`).toString('base64'))); | ||
|
||
authDataPromises.push(fs.readFile(certFilePath) | ||
.then((content) => { | ||
if (!content) { | ||
throw new Error('ESS Cert file does not contain anything'); | ||
} | ||
|
||
let fetchedCert; | ||
try { | ||
fetchedCert = Buffer.from(content).toString(); | ||
return fetchedCert; | ||
} | ||
catch (err) { | ||
throw new Error(`ESS Cert file content cannot be converted to string, error: ${err}`); | ||
} | ||
})); | ||
|
||
return Promise.all(authDataPromises) | ||
.then(([socketPath, authToken, cert]) => { | ||
const requestData = { | ||
cert, | ||
headers: { | ||
Authorization: `Basic ${authToken}`, | ||
}, | ||
socketPath, | ||
}; | ||
|
||
return requestData; | ||
}); | ||
}); | ||
|
||
module.exports = { | ||
getRequestData, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const Promise = require('bluebird'); | ||
const https = require('https'); | ||
const fs = require('fs-extra'); | ||
|
||
const dataRequest = (nodeId, request, correlationId) => new Promise((resolve, reject) => { | ||
console.log('===> in dataRequest'); | ||
console.log('===> nodeId', nodeId); | ||
|
||
const callback = (res) => { | ||
let allData = ''; | ||
res.setEncoding('utf8'); | ||
|
||
res.on('data', (data) => { | ||
allData += data; | ||
}); | ||
|
||
res.on('error', (error) => { | ||
reject(new Error(`Received error from ESS socket, error: ${error}`)); | ||
}); | ||
|
||
res.on('close', () => { | ||
let result; | ||
try { | ||
result = JSON.parse(allData); | ||
} | ||
catch (e) { | ||
result = allData; | ||
} | ||
|
||
const response = {}; | ||
response.headers = res.headers; | ||
response.status = { | ||
code: res.statusCode, | ||
message: res.statusMessage, | ||
}; | ||
|
||
resolve(result); | ||
}); | ||
}; | ||
|
||
const clientRequest = https.request(request, callback); | ||
if (request.body) clientRequest.write(request.body); | ||
clientRequest.end(); | ||
}); | ||
|
||
const fileDownloadRequest = (nodeId, outputFilePath, request, correlationId) => new Promise((resolve, reject) => { | ||
const dest = fs.createWriteStream(outputFilePath); | ||
|
||
const callback = (res) => { | ||
res.on('data', (data) => { | ||
dest.write(data); | ||
}); | ||
|
||
res.on('error', (error) => { | ||
reject(new Error(`Received error from ESS socket, error: ${error}`)); | ||
}); | ||
|
||
res.on('close', () => { | ||
resolve(); | ||
}); | ||
}; | ||
const clientRequest = https.request(request, callback); | ||
if (request.body) clientRequest.write(request.body); | ||
clientRequest.end(); | ||
}); | ||
|
||
module.exports = { | ||
dataRequest, | ||
fileDownloadRequest, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const rp = require('request-promise'); | ||
const fs = require('fs-extra'); | ||
|
||
const { | ||
mcdnAuthToken, | ||
edgeEngine: { | ||
projectId, | ||
}, | ||
} = require('../configuration/config'); | ||
|
||
const mCDNURL = `http://${gatewayNodeIpAddress}:8083/${projectId}/mcdn/v1`; | ||
const MCDN_FILES_ENDPOINT = `${mCDNURL}/files`; | ||
|
||
const postFile = (nodeId, pathName, fileName, localFilePath, correlationId) => { | ||
const mCDNFilePath = `${MCDN_FILES_ENDPOINT}/${pathName}/${fileName}`; | ||
|
||
return rp({ | ||
uri: mCDNFilePath, | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${mcdnAuthToken}`, | ||
'Content-Type': 'multipart/form-data', | ||
}, | ||
formData: { | ||
file: { | ||
value: fs.createReadStream(localFilePath), | ||
options: { | ||
filename: fileName, | ||
contentType: 'application/zip', | ||
}, | ||
}, | ||
metadata: JSON.stringify({ | ||
mimeType: 'application/zip', | ||
}), | ||
}, | ||
}) | ||
.then(() => ({ mCDNURL, pathName, fileName })); | ||
}; | ||
|
||
module.exports = { | ||
postFile, | ||
}; |
Oops, something went wrong.