Skip to content

Commit

Permalink
EPOC-540 Added lint or custom DNS feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintoormimik committed Mar 21, 2022
1 parent 21e2285 commit e960b54
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 97 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mimik_ohorchestrator",
"version": "1.1.2",
"version": "1.1.3",
"swaggerFile": {
"version": "1.1.0",
"account": "mimik",
Expand Down
2 changes: 2 additions & 0 deletions src/configuration/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const pack = require('../../package.json');
* | EDGE_DEPLOYMENT_CONTAINER_ENV | edgeEngine container env representing edge deployment | HZN_DEPLOYMENT_LOCATION=edgeNode |
* | ANAX_DOCKER_TAG | Anax container version | 2.30.0-794 |
* | MAXIMUM_FILE_SIZE | Maximum file size that can be shared using content delivery (ESS/mess) | 100 | in MB
* | ANAX_CONTAINERS_CUSTOM_DNS_IP | Ip address of the DNS server for anax docker containers | 'empty string' | Not required
*
* These values are on top of what is needed in the [configuration](https://bitbucket.org/mimiktech/configuration) library.
*
Expand Down Expand Up @@ -109,6 +110,7 @@ module.exports = (() => {
gatewayNodeSyncJobInterval: parseInt(process.env.GATEWAY_NODE_SYNC_JOB_INTERVAL, 10) || 120,
anaxContainersPortNumStart: parseInt(process.env.ANAX_CONTAINERS_PORT_NUM_START, 10) || 8200,
anaxContainersPortNumEnd: parseInt(process.env.ANAX_CONTAINERS_PORT_NUM_END, 10) || 8999,
anaxContainersCustomDNSIP: process.env.ANAX_CONTAINERS_CUSTOM_DNS_IP || '',
edgeDeploymentContainerEnv: process.env.EDGE_DEPLOYMENT_CONTAINER_ENV || 'HZN_DEPLOYMENT_LOCATION=edgeNode',
},
});
Expand Down
8 changes: 5 additions & 3 deletions src/external/essRequests/socketHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const dataRequest = (nodeId, request, correlationId) => new Promise((resolve, re
const clientRequest = https.request(request, callback);
if (request.body) clientRequest.write(request.body);
clientRequest.end();
} catch (error) {
}
catch (error) {
reject(error);
}
});
Expand All @@ -66,8 +67,9 @@ const fileDownloadRequest = (nodeId, outputFilePath, request, correlationId) =>
try {
const clientRequest = https.request(request, callback);
if (request.body) clientRequest.write(request.body);
clientRequest.end();
} catch (error) {
clientRequest.end();
}
catch (error) {
reject(error);
}
});
Expand Down
7 changes: 3 additions & 4 deletions src/external/mdeployRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ const getContainersForExternalNode = (externalNodeId, correlationId) => rp({
}
const { data } = response.data[0].responseBody;
return data;
})
});

const deleteContainersForExternalNode = (externalNodeId, containerIds, correlationId) => Promise.map(containerIds, (containerId) => rp({
const deleteContainersForExternalNode = (externalNodeId, containerIds, correlationId) => Promise.map(containerIds, () => rp({
method: 'POST',
headers: {
'x-correlation-id': correlationId,
Expand All @@ -103,8 +103,7 @@ const deleteContainersForExternalNode = (externalNodeId, containerIds, correlati
method: 'DELETE',
},
},
})
.catch(() => {}));
}).catch(() => {}));

const clientStatusValues = {
ACTIVE: 'active',
Expand Down
3 changes: 1 addition & 2 deletions src/external/messRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const postFile = (nodeId, pathName, fileName, localFilePath, correlationId) => r
const form = new FormData();
form.append('file', fs.createReadStream(localFilePath));


return rpRetry({
method: 'PUT',
headers: {
Expand All @@ -47,7 +46,7 @@ const postFile = (nodeId, pathName, fileName, localFilePath, correlationId) => r
data: form,
maxBodyLength: maxFileSize,
maxContentLength: maxFileSize,
})
});
});

module.exports = {
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { startJobs } = require('./lib/jobs');
const { startupTasks } = require('./lib/startHelper');
const { cleanupAllNodes } = require('./lib/mdeployCleanup');

let correlationId = getCorrelationId('service-startup-preOps');
const correlationId = getCorrelationId('service-startup-preOps');

init(app, __dirname, config, [], cluster(config), {
preOps: [
Expand All @@ -23,6 +23,4 @@ init(app, __dirname, config, [], cluster(config), {
({ config } = result);
});



module.exports = app;
13 changes: 6 additions & 7 deletions src/lib/anaxHelper/essHelper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable consistent-return */
const fs = require('fs-extra');

const logger = require('@mimik/sumologic-winston-logger');
Expand Down Expand Up @@ -31,8 +32,7 @@ const {
} = require('../../configuration/config');

const processingObjects = {};
const ESS_OBJECT_DOWNLOADED_STATUS = 'completelyReceived';
// const ESS_OBJECT_RECEIVED_STATUS = 'objreceived'; TODO remove if not used
const ESS_OBJECT_DOWNLOADED_STATUS = 'completelyReceived'; // 'objreceived' is the final received status ie when received by oh-orchestrator and marked by API

const getObjectsBeingDownloadedFlag = (nodeId, agreementId, objectType, objectId) => `${nodeId}_${agreementId}_${objectType}_${objectId}`;

Expand All @@ -59,8 +59,8 @@ const pollForObjectByType = (nodeId, agreementId, objectType, correlationId) =>

const contentDeploymentInstructionProperty = objectProperties.find(
(property) => property.type === gatewayDeploymentPropertyType
&& property.name === gatewayDeploymentPropertyName
)
&& property.name === gatewayDeploymentPropertyName,
);

if (!contentDeploymentInstructionProperty) return;

Expand All @@ -72,6 +72,7 @@ const pollForObjectByType = (nodeId, agreementId, objectType, correlationId) =>

processingObjects[objectsBeingDownloadedFlag] = true;

// eslint-disable-next-line consistent-return
return getCurrentNode(correlationId)
.then((gatewayNode) => {
const outputFileDir = getESSStorageDir(nodeId, agreementId, objectType);
Expand All @@ -89,15 +90,13 @@ const pollForObjectByType = (nodeId, agreementId, objectType, correlationId) =>
})
.finally(() => {
delete processingObjects[objectsBeingDownloadedFlag];
})
});
});
});
})
.catch(() => { });
});



const initializePolling = (node, correlationId) => {
const { id: nodeId } = node;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/anaxHelper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Promise = require('bluebird');
const getPort = require('get-port');

const { updateAnaxState } = require('../../models/nodeModel');
const { initializePolling } =require('./essHelper');
const { initializePolling } = require('./essHelper');
const {
findNode,
createNode,
Expand Down
48 changes: 24 additions & 24 deletions src/lib/anaxHelper/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const Promise = require('bluebird');
const fs = require('fs-extra');

const logger = require('@mimik/sumologic-winston-logger');
const { rpRetry } = require('@mimik/request-retry');
const { getRichError } = require('@mimik/response-helper');

const { scriptFileValues } = require('../../util/scriptUtil');
const { anaxContainersCustomDNSIP } = require('../../configuration/config');
const { getArch, scriptCommandValues } = require('../../util/anaxUtil');
const { checkIfNodeConfigured } = require('../../external/anaxRequests');
const { runScriptFile, runScriptCommand } = require('../scriptHelper');
Expand All @@ -28,10 +28,11 @@ const {
getNodeConfigFilePath,
} = require('../../util/anaxUtil');

const timeout = () => new Promise((resolve, reject) => { setTimeout(resolve, 5000); });
const timeout = () => new Promise((resolve) => { setTimeout(resolve, 5000); });

const updateHznCliConfig = (nodeId, correlationId) => {
const configFilePath = getNodeConfigFilePath(nodeId);
// eslint-disable-next-line max-len
const configFileData = `HZN_EXCHANGE_URL=${exchangeUrl}\nHZN_FSS_CSSURL=${cssUrl}\nHZN_NODE_ID=${nodeId}\nHZN_ORG_ID=${orgId}\nHZN_EXCHANGE_USER_AUTH=${exchangeUserAuth}\nHZN_AGBOT_URL=${agbotUrl}\n`;

return fs.ensureFile(configFilePath)
Expand Down Expand Up @@ -77,6 +78,7 @@ const deployAnaxNode = (nodeId, nodePort, dockerSocketFilePath, correlationId) =
HORIZON_AGENT_PORT: nodePort,
ANAX_TAG: anaxDockerTag,
ARCH: getArch(),
CUSTOM_DNS_IP: anaxContainersCustomDNSIP === '' ? undefined : anaxContainersCustomDNSIP,
},
correlationId,
];
Expand Down Expand Up @@ -120,29 +122,27 @@ const registerAnaxNode = (nodeId, nodePort, policyFilePath, correlationId) => {
});
};

const unregisterAnaxNode = (nodeId, nodePort, correlationId) => {
return runScriptCommand(
scriptCommandValues.UNREGISTER_ANAX,
undefined,
{
HZN_ORG_ID: orgId,
HORIZON_URL: `http://localhost:${nodePort}`,
HZN_EXCHANGE_URL: exchangeUrl,
HZN_EXCHANGE_USER_AUTH: exchangeUserAuth,
HZN_EXCHANGE_NODE_AUTH: `${nodeId}:${defaultNodeToken}`,
},
correlationId,
)
.then(timeout)
.then(() => checkIfNodeConfigured(nodePort, correlationId))
.then(() => {
if (isNodeConfigured) throw getRichError('System', 'Node did not get unregistered', { nodeId, nodePort, policyFilePath }, null, 'error', correlationId);

logger.debug('Unregistered Anax Node', {
nodeId, nodePort, correlationId,
});
const unregisterAnaxNode = (nodeId, nodePort, correlationId) => runScriptCommand(
scriptCommandValues.UNREGISTER_ANAX,
undefined,
{
HZN_ORG_ID: orgId,
HORIZON_URL: `http://localhost:${nodePort}`,
HZN_EXCHANGE_URL: exchangeUrl,
HZN_EXCHANGE_USER_AUTH: exchangeUserAuth,
HZN_EXCHANGE_NODE_AUTH: `${nodeId}:${defaultNodeToken}`,
},
correlationId,
)
.then(timeout)
.then(() => checkIfNodeConfigured(nodePort, correlationId))
.then((isNodeConfigured) => {
if (isNodeConfigured) throw getRichError('System', 'Node did not get unregistered', { nodeId, nodePort }, null, 'error', correlationId);

logger.debug('Unregistered Anax Node', {
nodeId, nodePort, correlationId,
});
};
});

const purgeDocker = () => runScriptCommand(scriptCommandValues.NUKE_DOCKER)
.catch(() => { }); // To catch if no containers found
Expand Down
3 changes: 0 additions & 3 deletions src/lib/jobs/gatewayNodeSyncJob.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const uuid = require('uuid');

const logger = require('@mimik/sumologic-winston-logger');
const { getRichError } = require('@mimik/response-helper');
const { getCorrelationId } = require('@mimik/request-helper');
Expand Down Expand Up @@ -55,7 +53,6 @@ const start = (correlationId) => getClient(correlationId)
interval = setInterval(syncNodes, gatewayNodeSyncJobInterval * 1000);
});


const stop = () => Promise.resolve()
.then(() => {
clearInterval(interval);
Expand Down
6 changes: 2 additions & 4 deletions src/lib/mdeployCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const cleanupNode = (id, correlationId) => getContainersForExternalNode(id, corr
// TODO Handle error
.catch(() => { });

const cleanupAllNodes = (correlationId) => {
return nodeModel.getAllNodes(correlationId)
.then((nodes) => Promise.map(nodes, ({ id }) => cleanupNode(id, correlationId)));
};
const cleanupAllNodes = (correlationId) => nodeModel.getAllNodes(correlationId)
.then((nodes) => Promise.map(nodes, ({ id }) => cleanupNode(id, correlationId)));

module.exports = {
cleanupNode,
Expand Down
1 change: 0 additions & 1 deletion src/lib/scriptHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const Promise = require('bluebird');
const childProcess = require('child_process');

const logger = require('@mimik/sumologic-winston-logger');
const { getRichError } = require('@mimik/response-helper');

const runScriptFile = (scriptFileName, args = '', env = {}, correlationId) => {
let scriptEnvs = '';
Expand Down
6 changes: 2 additions & 4 deletions src/lib/startHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ const startupTasks = (newCorrelationId) => {
correlationId = newCorrelationId;

return makeScriptExecutable();
}


};

module.exports = {
startupTasks,
}
};
Loading

0 comments on commit e960b54

Please sign in to comment.