Removing unused files

This commit is contained in:
Matias committed 2019-05-27 21:07:44 -03:00
1 parent 569031b161
commit 6bae6c7d34
18 files changed
+133 -58148

No files matched your search

+7
View File
@@ -1,4 +1,11 @@
NODE_ENV=production
PORT=4101
# Server commands
REINITIALIZE_COMMAND=REINITIALIZE_COMMAND
NEW_TEAM_SHARED_SECRET=NEW_TEAM_SHARED_SECRET
DELETE_TEAM_SHARED_SECRET=DELETE_TEAM_SHARED_SECRET
PATH_TO_CANVAS_APP=../CanvasApp
PATH_TO_FILES_COMPONENT=../Files-Component/src
GATEWAY_ENDPOINT=http://localhost:4100/graphql
-137
View File
@@ -1,137 +0,0 @@
const beautify = require("json-beautify")
const { logger } = require('../logs/logger')
const util = require('util')
exports.newCopySimulator = function newCopySimulator(pStorage) {
let thisObject = {
getFileContent: getFileContent,
writeFileContent: writeFileContent,
copySimulator: copySimulator,
removeSimulator: removeSimulator
}
let storage = pStorage
return thisObject
async function copySimulator(pTeamCodeName, pBotCodeName, pBotDisplayName) {
try {
logger.info('copySimulator started for bot %s', pBotCodeName)
let templatePath = "bots/AAJason-Indicator-Bot"
let commons = await getFileContent(templatePath, "Commons.js")
let config = await getFileContent(templatePath, "this.bot.config.json")
let codeDaily = await getFileContent(templatePath + "/Multi-Period-Daily", "User.Bot.js")
let codeMarket = await getFileContent(templatePath + "/Multi-Period-Market", "User.Bot.js")
// Change config to adapt the new indicator
let botCodeName = "simulator-" + pBotCodeName
let parsedConfig = JSON.parse(config)
parsedConfig.displayName = "Simulator " + pBotDisplayName
parsedConfig.codeName = botCodeName
parsedConfig.devTeam = pTeamCodeName
parsedConfig.profilePicture = pBotCodeName + ".png"
parsedConfig.processes[0].statusDependencies[0].devTeam = pTeamCodeName
parsedConfig.processes[0].statusDependencies[0].bot = botCodeName
parsedConfig.processes[1].statusDependencies[2].devTeam = pTeamCodeName
parsedConfig.processes[1].statusDependencies[2].bot = botCodeName
//Changing Indicator Output
parsedConfig.products[0].storageAccount = pTeamCodeName
parsedConfig.products[0].dataSets[0].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Market/@Period"
parsedConfig.products[0].dataSets[1].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily/@Period/@Year/@Month/@Day"
parsedConfig.products[0].dataSets[1].dataRange.filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Trading-Simulation/Multi-Period-Daily"
parsedConfig.products[1].storageAccount = pTeamCodeName
parsedConfig.products[1].dataSets[0].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Market/@Period"
parsedConfig.products[1].dataSets[1].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily/@Period/@Year/@Month/@Day"
parsedConfig.products[1].dataSets[1].dataRange.filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Conditions/Multi-Period-Daily"
parsedConfig.products[2].storageAccount = pTeamCodeName
parsedConfig.products[2].dataSets[0].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Market/@Period"
parsedConfig.products[2].dataSets[1].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily/@Period/@Year/@Month/@Day"
parsedConfig.products[2].dataSets[1].dataRange.filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Strategies/Multi-Period-Daily"
parsedConfig.products[3].storageAccount = pTeamCodeName
parsedConfig.products[3].dataSets[0].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Market/@Period"
parsedConfig.products[3].dataSets[1].filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily/@Period/@Year/@Month/@Day"
parsedConfig.products[3].dataSets[1].dataRange.filePath = pTeamCodeName + "/" + parsedConfig.codeName + ".1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Simulation-Trades/Multi-Period-Daily"
// Write the new files
let newSimulatorName = "simulator-" + pBotCodeName + "-Indicator-Bot"
let newSimulatorPath = "bots/" + newSimulatorName
await writeFileContent(pTeamCodeName, newSimulatorPath, "Commons.js", commons)
await writeFileContent(pTeamCodeName, newSimulatorPath, "this.bot.config.json", beautify(parsedConfig, null, 2, 80))
await writeFileContent(pTeamCodeName, newSimulatorPath + "/Multi-Period-Daily", "User.Bot.js", codeDaily)
await writeFileContent(pTeamCodeName, newSimulatorPath + "/Multi-Period-Market", "User.Bot.js", codeMarket)
logger.info('copySimulator completed for bot %s', pBotCodeName)
} catch (err) {
logger.error('copySimulator error for bot: %s, file: %s: %s', pBotCodeName, blobName, err)
throw err
}
}
async function removeSimulator(pTeamCodeName, pBotCodeName) {
try {
logger.info('removeSimulator started for bot %s', pBotCodeName)
// Delete simulator code
let newSimulatorName = "simulator-" + pBotCodeName + "-Indicator-Bot"
let newSimulatorPath = "bots/" + newSimulatorName
await deleteBlob(pTeamCodeName, newSimulatorPath, "Commons.js")
await deleteBlob(pTeamCodeName, newSimulatorPath, "this.bot.config.json")
await deleteBlob(pTeamCodeName, newSimulatorPath + "/Multi-Period-Daily", "User.Bot.js")
await deleteBlob(pTeamCodeName, newSimulatorPath + "/Multi-Period-Market", "User.Bot.js")
logger.info('removeSimulator completed for bot %s', pBotCodeName)
} catch (err) {
logger.error('copySimulator error for bot %s: %s', pBotCodeName, err)
throw err
}
}
async function getFileContent(containerName, blobName) {
storage.readData[util.promisify.custom] = n => new Promise((resolve, reject) => {
storage.readData("AATemplate", containerName, blobName, false, (err, pFileContent) => {
resolve(pFileContent)
})
})
let readData = util.promisify(storage.readData)
let fileContent = await readData()
return fileContent
}
async function writeFileContent(teamName, containerName, blobName, content) {
storage.writeData[util.promisify.custom] = n => new Promise((resolve, reject) => {
storage.writeData(teamName, containerName, blobName, content, (err, value) => {
resolve()
})
})
let writeData = util.promisify(storage.writeData)
let response = await writeData()
return response
}
async function deleteBlob(teamName, containerName, blobName) {
try {
storage.deleteBlob[util.promisify.custom] = n => new Promise((resolve, reject) => {
storage.deleteBlob(teamName, containerName, blobName, (err, value) => {
resolve()
})
})
let deleteBlob = util.promisify(storage.deleteBlob)
let response = await deleteBlob()
return response
} catch (err) {
logger.warn('Error deleting the file: %s%s', containerName, blobName)
}
}
}
File diff suppressed because it is too large. Load diff
-102
View File
@@ -1,102 +0,0 @@
exports.newUserAuthentication = function newUserAuthentication() {
MAX_STORAGE_PERMISSION_DAYS = 3;
let thisObject = {
authenticateUser: authenticateUser,
initialize: initialize
};
let sessionManager;
let storageAccessManager;
return thisObject;
function initialize(pSessionManager, pStorageAccessManager) {
sessionManager = pSessionManager;
storageAccessManager = pStorageAccessManager;
}
function authenticateUser(pSessionToken, callBackFunction) {
let userProfile = {
userName: "",
devTeams: [],
storagePermissions: []
};
/* The first possibility is that the sessionToken is not there. */
if (pSessionToken === "") {
callBackFunction(global.DEFAULT_OK_RESPONSE, userProfile);
return;
}
/* The second posiibility is that the session is not found. */
let session = sessionManager.getSession(pSessionToken);
if (session === undefined) {
let customResponse = {
result: global.CUSTOM_FAIL_RESPONSE.result,
message: "Invalid session token received. Please login again."
};
callBackFunction(customResponse, userProfile);
return;
}
/* The last one is that the session is found, meaning valid. */
userProfile.userName = session.userName;
userProfile.devTeams = session.devTeams;
for (let i = 0; i < session.devTeams.length; i++) {
let devTeam = session.devTeams[i];
let container = devTeam.codeName.toLowerCase();
let readPermission = storageAccessManager.getPermission(container, "READ", MAX_STORAGE_PERMISSION_DAYS);
let writePermission = storageAccessManager.getPermission(container, "WRITE", MAX_STORAGE_PERMISSION_DAYS);
let deletePermission = storageAccessManager.getPermission(container, "DELETE", MAX_STORAGE_PERMISSION_DAYS);
userProfile.storagePermissions.push([devTeam.codeName + "." + "READ", readPermission]);
userProfile.storagePermissions.push([devTeam.codeName + "." + "WRITE", writePermission]);
userProfile.storagePermissions.push([devTeam.codeName + "." + "DELETE", deletePermission]);
console.log(devTeam.codeName + "." + "READ" + ":" + readPermission);
console.log(devTeam.codeName + "." + "WRITE" + ":" + writePermission);
console.log(devTeam.codeName + "." + "DELETE" + ":" + writePermission);
/* Each devTeam potentially depends on data from other devTeams. The user will need the storage permissions to read that data. */
for (j = 0; j < devTeam.devTeamDependencies.length; j++) {
let dependecy = devTeam.devTeamDependencies[j];
let container = dependecy.toLowerCase();
let readPermission = storageAccessManager.getPermission(container, "READ", MAX_STORAGE_PERMISSION_DAYS);
userProfile.storagePermissions.push([dependecy + "." + "READ", readPermission]);
console.log(dependecy + "." + "READ" + ":" + readPermission);
}
}
/* In order to be able to download a bot source code, the user will need READ permissions over the Platform container. */
let container = "aaplatform";
let readPermission = storageAccessManager.getPermission(container, "READ", MAX_STORAGE_PERMISSION_DAYS);
userProfile.storagePermissions.push(["AAPlatform" + "." + "READ", readPermission]);
callBackFunction(global.DEFAULT_OK_RESPONSE, userProfile);
}
};
File diff suppressed because it is too large. Load diff
-9
View File
@@ -30,14 +30,6 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Include="AABrowserAPI\CopySimulator.js" />
<Compile Include="AABrowserAPI\TeamSetup.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="AABrowserAPI\UserAuthentication.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="Azure\azure-storage.blob.js" />
<Compile Include="Ecosystem.js" />
<Compile Include="Plotter.js" />
<Compile Include="PlotterPanel.js" />
@@ -81,7 +73,6 @@
<ItemGroup>
<Folder Include="Azure\" />
<Folder Include="Server\Exchange\" />
<Folder Include="AABrowserAPI\" />
<Folder Include="Server\Exchange\Wrappers\" />
<Folder Include="Scripts\" />
<Folder Include="Server\" />
+8 -2
View File
@@ -211,8 +211,8 @@ function newAppLoader() {
name
}
plotter{
codeName
devTeam
codeName
moduleName
repo
}
@@ -253,8 +253,14 @@ function newAppLoader() {
finishDatetime
formula
plotter{
devTeam
codeName
host
host{
url
storage
container
accessKey
}
moduleName
repo
}
-349
View File
@@ -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
}
}
}
-76
View File
@@ -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);
}
}
}
-479
View File
@@ -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);
}
}
}
}
+53
View File
@@ -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) }
}
}
}
-108
View File
@@ -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("{}");
}
}
}
-349
View File
@@ -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);
}
}
}
-68
View File
@@ -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);
}
}
-39
View File
@@ -1,39 +0,0 @@
const winston = require('winston')
const util = require('util')
const options = {
file: {
level: 'info',
filename: './logs/app.log',
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false,
timestamp: true
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
timestamp: true
}
}
exports.logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.colorize(),
winston.format.splat(),
winston.format.timestamp({ format: 'YY/MM/DD HH:mm' }),
winston.format.printf(
info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(util.inspect(info.message)))}`
)
),
transports: [
// new winston.transports.File(options.file),
new winston.transports.Console(options.console)
],
exitOnError: false // do not exit on handled exceptions
})
+32 -952
View File
File diff suppressed because it is too large. Load diff
+1 -9
View File
@@ -10,16 +10,8 @@
"url": "https://github.com/Superalgos/AAWeb.git"
},
"dependencies": {
"@octokit/rest": "^14.0.9",
"@superalgos/mqservice": "0.0.12",
"atob": "^2.1.2",
"azure-storage": "^2.10.2",
"dotenv": "^6.2.0",
"graphql": "^14.2.0",
"graphql-client": "^2.0.1",
"json-beautify": "^1.0.1",
"minio": "^7.0.5",
"request": "^2.88.0",
"winston": "^3.2.1"
"axios": "0.18.0"
}
}
+32 -58
View File
@@ -5,8 +5,6 @@ CONSOLE_LOG = process.env.CONSOLE_LOG === "true"
CONSOLE_ERROR_LOG = process.env.CONSOLE_ERROR_LOG === "true"
LOG_FILE_CONTENT = process.env.LOG_FILE_CONTENT === "true"
if (CONSOLE_LOG === true) { console.log('[INFO] server -> Node Server Starting.') }
global.DEFAULT_OK_RESPONSE = {
result: 'Ok',
message: 'Operation Succeeded'
@@ -32,37 +30,15 @@ global.CUSTOM_FAIL_RESPONSE = {
message: 'Custom Message'
}
let storageData
let http = require('http')
let port = process.env.PORT || 1337
let isHttpServerStarted = false
const AZURE_STORAGE = require('./Server/AzureStorage')
const MINIO_STORAGE = require('./Server/MinioStorage')
let ecosystemObject = require("./Server/config/ecosystem.json");
switch (process.env.STORAGE_PROVIDER) {
case 'Azure': {
storage = AZURE_STORAGE.newAzureStorage();
break;
}
case 'Minio': {
storage = MINIO_STORAGE.newMinioStorage();
break;
}
default: {
console.log('[ERROR] server -> Storage Provider not supported -> process.env.STORAGE_PROVIDER = ' + process.env.STORAGE_PROVIDER)
return;
}
}
const FILE_CLOUD = require('./Server/FileCloud')
let fileCloud = FILE_CLOUD.newFileCloud()
let storageData= new Map()
initialize()
function initialize() {
if (CONSOLE_LOG === true) { console.log('[INFO] server -> initialize -> Entering function.') }
storageData = new Map()
storage.initialize(storageData, ecosystemObject)
startHtttpServer()
}
startHtttpServer()
function startHtttpServer() {
if (CONSOLE_LOG === true) { console.log('[INFO] server -> startHtttpServer -> Entering function.') }
@@ -204,35 +180,13 @@ function onBrowserRequest(request, response) {
case 'Plotters': // This means the plotter folder, not to be confused with the Plotters script!
{
storage.readData(requestParameters[2] + '/' + 'plotters', requestParameters[3], requestParameters[4], true, onDataArrived)
function onDataArrived(err, pData) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log('[ERROR] server -> onBrowserRequest -> Plotters -> onDataArrived -> Could not read a file. ')
console.log('[ERROR] server -> onBrowserRequest -> Plotters -> onDataArrived -> err.message = ' + err.message)
pData = ''
}
respondWithContent(pData, response)
}
respondWithSourceCode (requestParameters, response)
}
break
case 'PlotterPanels': // This means the PlotterPanels folder, not to be confused with the Plotter Panels scripts!
{
storage.readData(requestParameters[2] + '/' + 'plotters', requestParameters[3], requestParameters[4], true, onDataArrived)
function onDataArrived(err, pData) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log('[ERROR] server -> onBrowserRequest -> Plotters -> PlotterPanels -> Could not read a file. ')
console.log('[ERROR] server -> onBrowserRequest -> Plotters -> PlotterPanels -> err.message = ' + err.message)
pData = ''
}
respondWithContent(pData, response)
}
respondWithSourceCode (requestParameters, response)
}
break
case 'Panels':
@@ -247,12 +201,6 @@ function onBrowserRequest(request, response) {
}
break
case 'Azure':
{
respondWithFile('./' + requestParameters[1] + '/' + requestParameters[2], response)
}
break
case 'Spaces':
{
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
@@ -420,3 +368,29 @@ function returnEmptyArray(response) {
console.log('[ERROR] server -> returnEmptyArray -> err.message ' + err.message)
}
}
function respondWithSourceCode(requestParameters, response){
let devTeam = requestParameters[2]
let codeName = requestParameters[3]
let moduleName = requestParameters[4]
let filePath = devTeam + '/plotters/' + codeName + '/' + moduleName
let cachedSourceCode = storageData.get(filePath)
if(cachedSourceCode){
respondWithContent(cachedSourceCode, response)
return
}
fileCloud.getBlobToText(devTeam.toLowerCase(), filePath, null, onDataArrived )
function onDataArrived(err, pData) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log('[ERROR] server -> onBrowserRequest -> respondWithSourceCode -> Could not read a file. ')
console.log('[ERROR] server -> onBrowserRequest -> respondWithSourceCode -> err.message = ' + err.message)
pData = ''
}
storageData.set(filePath, pData)
respondWithContent(pData, response)
}
}