Removing unused files
This commit is contained in:
1 parent
569031b161
commit
6bae6c7d34
18 files changed
+133
-58148
No files matched your search
@@ -1,349 +0,0 @@
|
||||
exports.newAzureStorage = function newAzureStorage() {
|
||||
|
||||
let thisObject = {
|
||||
readData: readData,
|
||||
writeData: writeData,
|
||||
createContainer: createContainer,
|
||||
deleteContainer: deleteContainer,
|
||||
deleteBlob: deleteBlob,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storageData;
|
||||
let ecosystem;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pStorageData, pEcosystem) {
|
||||
|
||||
storageData = pStorageData;
|
||||
ecosystem = pEcosystem;
|
||||
}
|
||||
|
||||
function readData(pOrg, pPath, pFile, saveAtCache, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> pFile = " + pFile); }
|
||||
|
||||
let cacheVersion;
|
||||
|
||||
if (storageData !== undefined) {
|
||||
|
||||
cacheVersion = storageData.get(pOrg + '.' + pPath + '.' + pFile);
|
||||
}
|
||||
|
||||
if (cacheVersion !== undefined) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> " + pOrg + '.' + pPath + '.' + pFile + " found at cache."); }
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, cacheVersion);
|
||||
|
||||
} else {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> " + pOrg + '.' + pPath + '.' + pFile + " NOT found at cache."); }
|
||||
|
||||
let connectionDetails = getConnectionDetails(pOrg, pPath, pFile);
|
||||
connectionDetails.blobService.getBlobToText(connectionDetails.container, connectionDetails.filePath, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> onFileReceived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Azure Storage -> readData -> onFileReceived -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> onFileReceived -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> onFileReceived -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> readData -> onFileReceived -> pFile = " + pFile); }
|
||||
|
||||
if (saveAtCache === true) {
|
||||
|
||||
storageData.set(pOrg + '.' + pPath + '.' + pFile, text);
|
||||
|
||||
}
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> readData -> onFileReceived -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> readData -> onFileReceived -> Returning an empty JSON object string. "); }
|
||||
|
||||
let response = {
|
||||
result: global.DEFAULT_FAIL_RESPONSE.result,
|
||||
message: global.DEFAULT_FAIL_RESPONSE.message,
|
||||
code: 'FileNotFound'
|
||||
}
|
||||
|
||||
callBackFunction(response);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, text);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> readData -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> readData -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove this functions and resolve them inside the Teams module.
|
||||
function writeData(pOrg, pPath, pFile, pFileContent, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> pFile = " + pFile); }
|
||||
|
||||
let blobText = pFileContent.toString();
|
||||
let connectionDetails = getConnectionDetails(pOrg, pPath, pFile);
|
||||
connectionDetails.blobService.createBlockBlobFromText(connectionDetails.container, connectionDetails.filePath, blobText, onFileCreated);
|
||||
|
||||
function onFileCreated(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> onFileCreated -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Azure Storage -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> onFileCreated -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> onFileCreated -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> writeData -> onFileCreated -> pFile = " + pFile); }
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> writeData -> onFileCreated -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> writeData -> onFileCreated -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> writeData -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteBlob(pOrg, pPath, pFile, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> pFile = " + pFile); }
|
||||
|
||||
let connectionDetails = getConnectionDetails(pOrg, pPath, pFile);
|
||||
connectionDetails.blobService.deleteBlob(connectionDetails.container, connectionDetails.filePath, onBlobDeleted);
|
||||
|
||||
function onBlobDeleted(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> onBlobDeleted -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> onBlobDeleted -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Azure Storage -> deleteBlob -> onBlobDeleted -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> onBlobDeleted -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> onBlobDeleted -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteBlob -> onBlobDeleted -> pFile = " + pFile); }
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> deleteBlob -> onBlobDeleted -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> deleteBlob -> onBlobDeleted -> err = " + JSON.stringify(err)); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> deleteBlob -> onBlobDeleted -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> deleteBlob -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function createContainer(pContainerName, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> createContainer -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> createContainer -> pContainerName = " + pContainerName); }
|
||||
|
||||
let containerName = pContainerName.toLowerCase();
|
||||
|
||||
let storage = require('azure-storage');
|
||||
let connectionString = process.env.STORAGE_CONNECTION_STRING;
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
blobService.createContainer(containerName, onContainerCreated);
|
||||
|
||||
function onContainerCreated(err) {
|
||||
|
||||
if (err) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> createContainer -> onContainerCreated -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> createContainer -> onContainerCreated -> err = " + JSON.stringify(err)); }
|
||||
|
||||
|
||||
/* ContainerAlreadyExists check */
|
||||
|
||||
if (JSON.stringify(err).indexOf("ContainerAlreadyExists") > 0) {
|
||||
|
||||
let err = {
|
||||
resutl: global.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: "ContainerAlreadyExists"
|
||||
};
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> createContainer -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteContainer(pContainerName, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteContainer -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Azure Storage -> deleteContainer -> pContainerName = " + pContainerName); }
|
||||
|
||||
let containerName = pContainerName.toLowerCase();
|
||||
|
||||
let storage = require('azure-storage');
|
||||
let connectionString = process.env.STORAGE_CONNECTION_STRING;
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
blobService.deleteContainer(containerName, onContainerDeleted);
|
||||
|
||||
function onContainerDeleted(err) {
|
||||
|
||||
if (err) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> deleteContainer -> onContainerDeleted -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Azure Storage -> deleteContainer -> onContainerDeleted -> err = " + JSON.stringify(err)); }
|
||||
|
||||
|
||||
/* ContainerAlreadyExists check */
|
||||
|
||||
if (JSON.stringify(err).indexOf("ContainerNotFound") > 0) {
|
||||
|
||||
let err = {
|
||||
resutl: global.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: "ContainerNotFound"
|
||||
};
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Azure Storage -> deleteContainer -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function getConnectionDetails(pOrg, pPath, pFile){
|
||||
let filePath, container, host, accessKey, teamCodeName;
|
||||
|
||||
if (pOrg === undefined) {
|
||||
/* This is used when the requests come from the browser, for background compatibility. */
|
||||
filePath = pPath;
|
||||
teamCodeName = pFile;
|
||||
} else {
|
||||
/* This is used for internal requests within AAWeb, for background compatibility. */
|
||||
filePath = pOrg + "/" + pPath + "/" + pFile;
|
||||
teamCodeName = pOrg.split("/")[0];
|
||||
}
|
||||
|
||||
// TODO Temporary looking on on the server side for the team connection, so the client calls are not modified.
|
||||
for (let i = 0; i < ecosystem.devTeams.length; i++) {
|
||||
const devTeam = ecosystem.devTeams[i];
|
||||
if(devTeam.codeName.toLowerCase() === teamCodeName.toLowerCase()){
|
||||
host = devTeam.host.storage;
|
||||
accessKey = devTeam.host.accessKey;
|
||||
container = devTeam.host.container;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < ecosystem.hosts.length; i++) {
|
||||
const devTeam = ecosystem.hosts[i];
|
||||
if(devTeam.codeName.toLowerCase() === teamCodeName.toLowerCase()){
|
||||
host = devTeam.host.storage;
|
||||
accessKey = devTeam.host.accessKey;
|
||||
container = devTeam.host.container;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(host === undefined){
|
||||
console.log("[ERROR] Azure Storage -> readData -> Host has not been found for team: " + teamCodeName );
|
||||
}
|
||||
|
||||
if(accessKey === undefined){
|
||||
console.log("[ERROR] Azure Storage -> readData -> Access key has not been found for team: " + teamCodeName);
|
||||
}
|
||||
|
||||
let storage = require('azure-storage');
|
||||
let blobService = storage.createBlobServiceWithSas(host, accessKey);
|
||||
return {
|
||||
blobService,
|
||||
container,
|
||||
filePath
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
exports.newBotScripts = function newBotScripts() {
|
||||
|
||||
let thisObject = {
|
||||
getScript: getScript,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storage;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(ecosystem, pStorage, callBackFunction) {
|
||||
|
||||
storage = pStorage;
|
||||
|
||||
let storageData = new Map(); // For backwards compatibility only. Not used.
|
||||
|
||||
storage.initialize(storageData, ecosystem);
|
||||
|
||||
callBackFunction();
|
||||
}
|
||||
|
||||
function getScript(pDevTeam, pSource, pRepo, pPath, callBackFunction) {
|
||||
|
||||
storage.readData(pDevTeam + "/" + pSource, pRepo, pPath, false, onDataArrived);
|
||||
|
||||
function onDataArrived(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Entering function."); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("[ERROR] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Could not read a file. ");
|
||||
console.log("[ERROR] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> err.message = " + err.message);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
let data;
|
||||
|
||||
if (pData !== undefined) {
|
||||
|
||||
data = pData.toString();
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
data = browserify(data);
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, data);
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function browserify(pData) {
|
||||
|
||||
let result = pData.substring(pData.indexOf('=') + 2);
|
||||
|
||||
result = replaceAll(result, "require", "webRequire");
|
||||
result = replaceAll(result, "global", "window");
|
||||
|
||||
return result;
|
||||
|
||||
function replaceAll(text, search, replacement) {
|
||||
return text.replace(new RegExp(search, 'g'), replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,479 +0,0 @@
|
||||
exports.newConfigReader = function newConfigReader() {
|
||||
|
||||
let thisObject = {
|
||||
loadConfigs: loadConfigs,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storage;
|
||||
let storageData;
|
||||
let ecosystemObject;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pEcosystemObject, pStorageData, pStorage, callBackFunction) {
|
||||
storage = pStorage;
|
||||
storageData = pStorageData;
|
||||
ecosystemObject = pEcosystemObject;
|
||||
|
||||
try {
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> initialize -> Initializing storage."); }
|
||||
storage.initialize(storageData, ecosystemObject);
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
} catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> initialize -> Error initilizing the storage. Stack:", err.stack);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function loadConfigs(callBackFunction) {
|
||||
|
||||
readHostsConfigs();
|
||||
|
||||
function readHostsConfigs() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> Entering function."); }
|
||||
|
||||
let requestsSent = 0;
|
||||
let responsesReceived = 0;
|
||||
|
||||
for (let i = 0; i < ecosystemObject.hosts.length; i++) {
|
||||
|
||||
let host = ecosystemObject.hosts[i];
|
||||
|
||||
getCompetitions();
|
||||
getPlotters();
|
||||
|
||||
function getCompetitions() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getCompetitions -> Entering function."); }
|
||||
|
||||
/* In this first section we will load the competitions configurations. */
|
||||
|
||||
for (let j = 0; j < host.competitions.length; j++) {
|
||||
|
||||
let competition = host.competitions[j];
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.readData(host.codeName + "/" + "competitions", competition.repo, competition.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> host.codeName = " + host.codeName); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> competition.repo = " + competition.repo); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> pData = " + pData); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> Could not read a file. ");
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> err.message = " + err.message);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
responsesReceived++;
|
||||
|
||||
pData = pData.toString();
|
||||
pData = pData.trim(); // remove first byte with some encoding.
|
||||
|
||||
let configObj = JSON.parse(pData);
|
||||
|
||||
/* Since we are going to replace the full bot object and we dont want to lose these two properties, we do this: */
|
||||
|
||||
configObj.repo = competition.repo;
|
||||
configObj.configFile = competition.configFile;
|
||||
|
||||
host.competitions[j] = configObj;
|
||||
|
||||
if (requestsSent === responsesReceived) {
|
||||
|
||||
readDevTeamsConfigs();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getCompetitions -> Cloud -> onDataArrived -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getCompetitions -> getCompetitions -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function getPlotters() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getPlotters -> getPlotters -> Entering function."); }
|
||||
|
||||
/* In this second section we will load the competition plotters configurations. */
|
||||
|
||||
for (let j = 0; j < host.plotters.length; j++) {
|
||||
|
||||
let plotter = host.plotters[j];
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.readData(host.codeName + "/" + "plotters", plotter.repo, plotter.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> host.codeName = " + host.codeName); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> plotter.repo = " + plotter.repo); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> pData = " + pData); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> Could not read a file. ");
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> err.message = " + err.message);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
responsesReceived++;
|
||||
|
||||
pData = pData.toString();
|
||||
pData = pData.trim(); // remove first byte with some encoding.
|
||||
|
||||
let configObj = JSON.parse(pData);
|
||||
|
||||
/* Since we are going to replace the full bot object and we dont want to lose these two properties, we do this: */
|
||||
|
||||
configObj.repo = plotter.repo;
|
||||
configObj.configFile = plotter.configFile;
|
||||
|
||||
host.plotters[j] = configObj;
|
||||
|
||||
if (requestsSent === responsesReceived) {
|
||||
|
||||
readDevTeamsConfigs();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getPlotters -> Cloud -> onDataArrived -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> getPlotters -> getCompetitions -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readHostsConfigs -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function readDevTeamsConfigs() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> Entering function."); }
|
||||
|
||||
/*
|
||||
|
||||
Each bot has its configuration at its own repo since each team must be able to change it at will.
|
||||
So what we do here is to use the master config at the AAPlatform repo that we already have on
|
||||
memory and inject into it the config of each bot.
|
||||
|
||||
Inmediatelly after that, we also load the Plotters configs using the same technique.
|
||||
|
||||
*/
|
||||
|
||||
let requestsSent = 0;
|
||||
let responsesReceived = 0;
|
||||
|
||||
for (let i = 0; i < ecosystemObject.devTeams.length; i++) {
|
||||
|
||||
let devTeam = ecosystemObject.devTeams[i];
|
||||
|
||||
getBots();
|
||||
getPlotters();
|
||||
|
||||
function getBots() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getBots -> Entering function."); }
|
||||
|
||||
/* In the next section we are loading the bots configurations. */
|
||||
|
||||
for (let j = 0; j < devTeam.bots.length; j++) {
|
||||
|
||||
let bot = devTeam.bots[j];
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.readData(devTeam.codeName + "/" + "bots", bot.repo, bot.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> devTeam.codeName = " + devTeam.codeName); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> bot.repo = " + bot.repo); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> pData = " + pData); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> Could not read a file. ");
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> err.message = " + err.message);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
responsesReceived++;
|
||||
|
||||
if (pData !== "{}") { // If for any reason we could not tet this config, then we just exclude this bot to improve resiliency.
|
||||
|
||||
pData = pData.toString();
|
||||
pData = pData.trim(); // remove first byte with some encoding.
|
||||
|
||||
let configObj = JSON.parse(pData);
|
||||
|
||||
/* Since we are going to replace the full bot object and we dont want to lose these two properties, we do this: */
|
||||
|
||||
configObj.repo = bot.repo;
|
||||
configObj.configFile = bot.configFile;
|
||||
|
||||
/* Here we will add all the possible Clones of this bot */
|
||||
|
||||
if (configObj.genes !== undefined) {
|
||||
|
||||
/* Here, based on the genes we will create one instance for each combination of genes */
|
||||
|
||||
let valueMatrix = [];
|
||||
|
||||
for (let i = 0; i < configObj.genes.length; i++) {
|
||||
|
||||
let gene = configObj.genes[i];
|
||||
|
||||
let possibleValues = [];
|
||||
|
||||
for (let j = gene.lowerLimit; j <= gene.upperLimit; j++) {
|
||||
|
||||
possibleValues.push(j);
|
||||
|
||||
}
|
||||
|
||||
valueMatrix.push(possibleValues);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Now we have all the possible genes values in a multi-dimensional matrix.
|
||||
We will go thorugh each of the elements of each dimension and get each combination possible with the other dimmensions.
|
||||
*/
|
||||
|
||||
let combinations = [];
|
||||
let combination = [];
|
||||
let dimensionIndex = 0;
|
||||
|
||||
calculateCombinations(dimensionIndex, combination);
|
||||
|
||||
function calculateCombinations(pDimensionIndex, pCombination) {
|
||||
|
||||
let dimension = valueMatrix[pDimensionIndex];
|
||||
|
||||
for (let j = 0; j < dimension.length; j++) {
|
||||
|
||||
let copy = JSON.parse(JSON.stringify(pCombination));
|
||||
|
||||
let value = dimension[j];
|
||||
copy.push(value);
|
||||
|
||||
if (pDimensionIndex < valueMatrix.length - 1) {
|
||||
|
||||
calculateCombinations(pDimensionIndex + 1, copy);
|
||||
|
||||
} else {
|
||||
|
||||
combinations.push(copy);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We delete the bot definition since it is going to be replaced by one definition for each of its clones. */
|
||||
|
||||
devTeam.bots.splice(j);
|
||||
|
||||
/* At this point we have an array with all the possible combinations, we just need to create an instance for each one and set the genes according to that. */
|
||||
|
||||
for (let i = 0; i < combinations.length; i++) {
|
||||
|
||||
let botConfig = JSON.parse(JSON.stringify(configObj));
|
||||
let combination = combinations[i];
|
||||
let genes = {};
|
||||
let clonKey = "";
|
||||
|
||||
for (let j = 0; j < botConfig.genes.length; j++) {
|
||||
|
||||
genes[botConfig.genes[j].name] = combination[j];
|
||||
clonKey = clonKey + "." + combination[j];
|
||||
|
||||
}
|
||||
|
||||
let clonName = "Clon" + clonKey;
|
||||
let clonConfig = JSON.parse(JSON.stringify(botConfig));
|
||||
|
||||
/* Lets adapt the bot config so as to tune it for the new clon. */
|
||||
|
||||
clonConfig.displayName = clonConfig.displayName + " " + clonName;
|
||||
clonConfig.codeName = clonConfig.codeName + "-" + clonName;
|
||||
|
||||
/*
|
||||
for (let j = 0; j < clonConfig.products.length; j++) {
|
||||
|
||||
let product = clonConfig.products[j];
|
||||
|
||||
for (let k = 0; k < product.dataSets.length; k++) {
|
||||
|
||||
let dataSet = product.dataSets[k];
|
||||
|
||||
dataSet.filePath = dataSet.filePath.replace("@Clon", "-" + clonName);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
devTeam.bots.push(clonConfig);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
/* If the bot does not have any genes at all we do what we did before clones existed */
|
||||
|
||||
devTeam.bots[j] = configObj;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (requestsSent === responsesReceived) {
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, ecosystemObject);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getBots -> Cloud -> onDataArrived -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getBots -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function getPlotters() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Entering Function."); }
|
||||
|
||||
/* In the next section we are loading the plotters configurations. */
|
||||
|
||||
for (let j = 0; j < devTeam.plotters.length; j++) {
|
||||
|
||||
let plotter = devTeam.plotters[j];
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.readData(devTeam.codeName + "/" + "plotters", plotter.repo, plotter.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> devTeam.codeName = " + devTeam.codeName); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> plotter.repo = " + plotter.repo); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> pData = " + pData); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> Could not read a file. ");
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> err.message = " + err.message);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
responsesReceived++;
|
||||
|
||||
if (pData !== "{}") { // If for any reason we could not tet this config, then we just exclude this bot to improve resiliency.
|
||||
|
||||
pData = pData.toString();
|
||||
pData = pData.trim(); // remove first byte with some encoding.
|
||||
|
||||
let configObj = JSON.parse(pData);
|
||||
|
||||
/* Since we are going to replace the full plotter object and we dont want to lose these two properties, we do this: */
|
||||
|
||||
configObj.repo = plotter.repo;
|
||||
configObj.configFile = plotter.configFile;
|
||||
|
||||
devTeam.plotters[j] = configObj;
|
||||
|
||||
}
|
||||
|
||||
if (requestsSent === responsesReceived) {
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, ecosystemObject);
|
||||
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Cloud -> onDataArrived -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> getPlotters -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
exports.newFileCloud = function newFileCloud() {
|
||||
const MODULE_NAME = 'File Cloud'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const axios = require('axios')
|
||||
|
||||
let thisObject = {
|
||||
getBlobToText: getBlobToText
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function getBlobToText(container, filePath, host, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { console.log('[INFO] getBlobToText -> Entering function.'+filePath) }
|
||||
|
||||
let headers
|
||||
|
||||
axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
query web_FileContent($container: String!, $filePath: String!, $accessKey: String!, $storage: String!){
|
||||
web_FileContent(file: { container: $container, filePath: $filePath, accessKey: $accessKey, storage: $storage })
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
container: container,
|
||||
filePath: filePath,
|
||||
storage: '',
|
||||
accessKey: ''
|
||||
}
|
||||
},
|
||||
headers: headers
|
||||
}).then(res => {
|
||||
if (res.data.errors) {
|
||||
if (ERROR_LOG === true) { console.log(MODULE_NAME + ' : ' + '[ERROR] AppPreLoader -> getBlobToText -> response.text = ' + JSON.stringify(res.data.errors)) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE, '', '')
|
||||
}
|
||||
let response = res.data.data.web_FileContent
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, response, '')
|
||||
}).catch(error => {
|
||||
if (ERROR_LOG === true) { console.log(MODULE_NAME + ' : ' + '[ERROR] AppPreLoader -> getBlobToText -> Invalid JSON received. ') }
|
||||
if (ERROR_LOG === true) { console.log(MODULE_NAME + ' : ' + '[ERROR] AppPreLoader -> getBlobToText -> response.text = ' + error.message) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE, '', '')
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { console.log('[ERROR] getBlobToText -> err = ' + err.stack) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
exports.newGithub = function newGithub() {
|
||||
|
||||
let thisObject = {
|
||||
getGithubData: getGithubData,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let githubData;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pGithubData) {
|
||||
|
||||
githubData = pGithubData;
|
||||
|
||||
}
|
||||
|
||||
function getGithubData(pOrg, pRepo, pPath, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Github -> getGithubData -> Entering function."); }
|
||||
|
||||
let cacheVersion = githubData.get(pOrg + '.' + pRepo + '.' + pPath)
|
||||
|
||||
if (cacheVersion !== undefined) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Github -> getGithubData -> " + pOrg + '.' + pRepo + '.' + pPath + " found at cache."); }
|
||||
|
||||
callBackFunction(cacheVersion);
|
||||
|
||||
} else {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Github -> getGithubData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
|
||||
|
||||
const octokit = require('@octokit/rest')()
|
||||
global.atob = require("atob");
|
||||
|
||||
let owner = pOrg;
|
||||
let repo = pRepo;
|
||||
let branch = "master";
|
||||
let page = 1;
|
||||
let per_page = 100;
|
||||
let ref = "master";
|
||||
let path = pPath;
|
||||
|
||||
octokit.repos.getContent({ owner, repo, path, ref }, onContent);
|
||||
|
||||
function onContent(error, result) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Github -> getGithubData -> onContent -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Github -> getGithubData -> onContent -> error = " + error); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Github -> getGithubData -> onContent -> Github.com responded to request " + pOrg + '.' + pRepo + '.' + pPath + " with result = " + result.toString().substring(0, 100)); }
|
||||
|
||||
if (error !== null) { console.log("[ERROR] Github -> getGithubData -> onContent -> " + error); }
|
||||
|
||||
let decoded = atob(result.data.content);
|
||||
|
||||
/*
|
||||
|
||||
This method usually brings up to 3 characters of encoding info at the begining of the JSON string which destroys the JSON format.
|
||||
We will run the following code with the intention to eliminate this problem.
|
||||
|
||||
*/
|
||||
|
||||
let cleanString = decoded;
|
||||
let jsonTest;
|
||||
|
||||
try {
|
||||
jsonTest = JSON.parse(cleanString);
|
||||
} catch (err) {
|
||||
cleanString = decoded.substring(1);
|
||||
try {
|
||||
jsonTest = JSON.parse(cleanString);
|
||||
} catch (err) {
|
||||
cleanString = decoded.substring(2);
|
||||
try {
|
||||
jsonTest = JSON.parse(cleanString);
|
||||
} catch (err) {
|
||||
cleanString = decoded.substring(3);
|
||||
try {
|
||||
jsonTest = JSON.parse(cleanString);
|
||||
} catch (err) {
|
||||
console.log("[INFO] Github -> getGithubData -> onContent -> Could not clean the data received -> Data = " + decoded.substring(0, 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
githubData.set(pOrg + '.' + pRepo + '.' + pPath, cleanString);
|
||||
|
||||
callBackFunction(cleanString);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Github -> getGithubData -> onContent -> err.message = " + err.message);
|
||||
callBackFunction("{}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Github -> getGithubData -> err.message = " + err.message);
|
||||
callBackFunction("{}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,349 +0,0 @@
|
||||
exports.newMinioStorage = function newMinioStorage() {
|
||||
|
||||
let thisObject = {
|
||||
readData: readData,
|
||||
writeData: writeData,
|
||||
createContainer: createContainer,
|
||||
deleteContainer: deleteContainer,
|
||||
deleteBlob: deleteBlob,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storageData;
|
||||
|
||||
let Minio = require('minio');
|
||||
let minioClient;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pStorageData) {
|
||||
|
||||
storageData = pStorageData;
|
||||
|
||||
minioClient = new Minio.Client({
|
||||
endPoint: process.env.MINIO_END_POINT,
|
||||
port: JSON.parse(process.env.MINIO_PORT),
|
||||
useSSL: JSON.parse(process.env.MINIO_USE_SSL),
|
||||
accessKey: process.env.MINIO_ACCESS_KEY,
|
||||
secretKey: process.env.MINIO_SECRET_KEY
|
||||
})
|
||||
}
|
||||
|
||||
function readData(pParam1, pParam2, pParam3, saveAtCache, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> pParam1 = " + pParam1); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> pParam2 = " + pParam2); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> pParam3 = " + pParam3); }
|
||||
|
||||
let cacheVersion;
|
||||
|
||||
if (storageData !== undefined) {
|
||||
|
||||
cacheVersion = storageData.get(pParam1 + '.' + pParam2 + '.' + pParam3);
|
||||
}
|
||||
|
||||
if (cacheVersion !== undefined) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> " + pParam1 + '.' + pParam2 + '.' + pParam3 + " found at cache."); }
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, cacheVersion);
|
||||
|
||||
} else {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> " + pParam1 + '.' + pParam2 + '.' + pParam3 + " NOT found at cache."); }
|
||||
|
||||
let bucketName = 'aaplatform';
|
||||
let textFilename;
|
||||
|
||||
if (pParam1 === undefined) {
|
||||
|
||||
/* This is used when the requests come from the browser, for background compatibility. */
|
||||
|
||||
bucketName = pParam3;
|
||||
textFilename = pParam2.substring(pParam2.indexOf("/") + 1, pParam2.length);
|
||||
|
||||
} else {
|
||||
|
||||
/* This is used for internal requests within AAWeb, for background compatibility. */
|
||||
|
||||
bucketName = 'aaplatform';
|
||||
textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
|
||||
}
|
||||
|
||||
minioClient.getObject(bucketName, textFilename, function (err, dataStream) {
|
||||
let data = '';
|
||||
|
||||
if (err) {
|
||||
onFileReceived(err, null, "Error retrieving file " + textFilename + " from bucket " + bucketName);
|
||||
return
|
||||
}
|
||||
dataStream.on('data', function (chunk) {
|
||||
data += chunk
|
||||
})
|
||||
dataStream.on('end', function () {
|
||||
onFileReceived(null, data, "Data retrieved.");
|
||||
})
|
||||
dataStream.on('error', function (err) {
|
||||
onFileReceived(err, null, "Error on data stream while retrieving file " + textFilename + " from bucket " + bucketName);
|
||||
})
|
||||
})
|
||||
|
||||
function onFileReceived(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> onFileReceived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Minio Storage -> readData -> onFileReceived -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> onFileReceived -> pParam1 = " + pParam1); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> onFileReceived -> pParam2 = " + pParam2); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> readData -> onFileReceived -> pParam3 = " + pParam3); }
|
||||
|
||||
if (saveAtCache === true) {
|
||||
|
||||
storageData.set(pParam1 + '.' + pParam2 + '.' + pParam3, text);
|
||||
|
||||
}
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> readData -> onFileReceived -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> readData -> onFileReceived -> Returning an empty JSON object string. "); }
|
||||
|
||||
if (err.code === 'NoSuchKey') {
|
||||
|
||||
let customErr = {
|
||||
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: 'FileNotFound',
|
||||
code: 'FileNotFound'
|
||||
}
|
||||
|
||||
callBackFunction(customErr);
|
||||
return;
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, text);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> readData -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> readData -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function writeData(pParam1, pParam2, pParam3, pFileContent, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> pParam1 = " + pParam1); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> pParam2 = " + pParam2); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> pParam3 = " + pParam3); }
|
||||
|
||||
let bucketName = 'aaplatform';
|
||||
let text = pFileContent.toString();
|
||||
let textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
|
||||
|
||||
minioClient.putObject(bucketName, textFilename, text, 'text/plain', onFileCreated)
|
||||
|
||||
function onFileCreated(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> onFileCreated -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Minio Storage -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> onFileCreated -> pParam1 = " + pParam1); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> onFileCreated -> pParam2 = " + pParam2); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> writeData -> onFileCreated -> pParam3 = " + pParam3); }
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> writeData -> onFileCreated -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> writeData -> onFileCreated -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> writeData -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteBlob(pParam1, pParam2, pParam3, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> pParam1 = " + pParam1); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> pParam2 = " + pParam2); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> pParam3 = " + pParam3); }
|
||||
|
||||
let bucketName = 'aaplatform';
|
||||
let textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
|
||||
|
||||
minioClient.removeObject(bucketName, textFilename, onBlobDeleted)
|
||||
|
||||
function onBlobDeleted(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> onBlobDeleted -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> onBlobDeleted -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Minio Storage -> deleteBlob -> onBlobDeleted -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> onBlobDeleted -> pParam1 = " + pParam1); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> onBlobDeleted -> pParam2 = " + pParam2); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteBlob -> onBlobDeleted -> pParam3 = " + pParam3); }
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> deleteBlob -> onBlobDeleted -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> deleteBlob -> onBlobDeleted -> err = " + JSON.stringify(err)); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> deleteBlob -> onBlobDeleted -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> deleteBlob -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function createContainer(pContainerName, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> createContainer -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> createContainer -> pContainerName = " + pContainerName); }
|
||||
|
||||
let containerName = pContainerName.toLowerCase();
|
||||
|
||||
minioClient.makeBucket(containerName, "", onContainerCreated)
|
||||
|
||||
function onContainerCreated(err) {
|
||||
|
||||
if (err) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> createContainer -> onContainerCreated -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> createContainer -> onContainerCreated -> err = " + JSON.stringify(err)); }
|
||||
|
||||
|
||||
/* ContainerAlreadyExists check */
|
||||
|
||||
if (JSON.stringify(err).indexOf("ContainerAlreadyExists") > 0) {
|
||||
|
||||
let err = {
|
||||
resutl: global.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: "ContainerAlreadyExists"
|
||||
};
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> createContainer -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteContainer(pContainerName, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteContainer -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Minio Storage -> deleteContainer -> pContainerName = " + pContainerName); }
|
||||
|
||||
let containerName = pContainerName.toLowerCase();
|
||||
|
||||
minioClient.removeBucket(containerName, onContainerDeleted)
|
||||
|
||||
function onContainerDeleted(err) {
|
||||
|
||||
if (err) {
|
||||
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> deleteContainer -> onContainerDeleted -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Minio Storage -> deleteContainer -> onContainerDeleted -> err = " + JSON.stringify(err)); }
|
||||
|
||||
|
||||
/* ContainerAlreadyExists check */
|
||||
|
||||
if (err.code === "NoSuchBucket") {
|
||||
|
||||
let err = {
|
||||
resutl: global.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: "ContainerNotFound"
|
||||
};
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Minio Storage -> deleteContainer -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
exports.newSessionManager = function newSessionManager() {
|
||||
|
||||
let thisObject = {
|
||||
getSession: getSession,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let activeSessions = new Map();
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(ecosystem, storage, callBackFunction) {
|
||||
|
||||
try {
|
||||
// TODO Sessions need to be handled by the master app
|
||||
|
||||
const sessions = require('./config/sessions.json');
|
||||
|
||||
for (let i = 0; i < sessions.length; i++) {
|
||||
let session = sessions[i];
|
||||
activeSessions.set(session.sessionToken, session);
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
// storage.initialize(undefined, ecosystem);
|
||||
// storage.readData("AdvancedAlgos", "AAPlatform", "open.sessions.json", false, onData);
|
||||
|
||||
// function onData(err, pText) {
|
||||
|
||||
// if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
// console.log("[ERROR] SessionManager -> initialize -> readSessions -> onData -> Could not read a file. ");
|
||||
// console.log("[ERROR] SessionManager -> initialize -> readSessions -> onData -> err.message = " + err.message);
|
||||
|
||||
// callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// let sessions = JSON.parse(pText);
|
||||
|
||||
// for (let i = 0; i < sessions.length; i++) {
|
||||
|
||||
// let session = sessions[i];
|
||||
|
||||
// activeSessions.set(session.sessionToken, session);
|
||||
|
||||
// }
|
||||
|
||||
// callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
// }
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] readSessions -> err = " + err.message);
|
||||
console.log("[HINT] You need to have a file at this path -> " + filePath);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getSession(pSessionToken) {
|
||||
|
||||
return activeSessions.get(pSessionToken);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user