Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
0215dbcd00
26 files changed
+407
-59205
No files matched your search
@@ -19,5 +19,3 @@ obj/*
|
||||
bin/*
|
||||
/.vscode
|
||||
Project.njsproj
|
||||
|
||||
this.server.config.dev.json
|
||||
@@ -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
|
||||
@@ -6,8 +6,6 @@ bin/*
|
||||
|
||||
.env
|
||||
.env.dev
|
||||
this.server.config.json
|
||||
this.server.config.dev.json
|
||||
|
||||
/node_modules
|
||||
/dependency
|
||||
|
||||
@@ -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
@@ -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
+1
-2
@@ -17,13 +17,12 @@ function newEcosystem() {
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let ECOSYSTEM = "@ecosystem.json@";
|
||||
let ECOSYSTEM = JSON.parse(window.localStorage.getItem('ecosystem'));
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function setEvent(input) {
|
||||
|
||||
+5
-22
@@ -1,23 +1,6 @@
|
||||
|
||||
|
||||
function getNewPlotter(pDevTeamOrHost, pPlotter, pModule) {
|
||||
|
||||
let plotter;
|
||||
let fullCode = pDevTeamOrHost + pPlotter + pModule;
|
||||
fullCode = fullCode.replace(/-/g, "");
|
||||
|
||||
switch (fullCode) {
|
||||
|
||||
// Cases
|
||||
|
||||
default:
|
||||
{
|
||||
throw("getNewPlotter: " + fullCode + " not found.")
|
||||
}
|
||||
}
|
||||
|
||||
return plotter;
|
||||
function getNewPlotter(pDevTeamOrHost, pPlotter, pModule) {
|
||||
let functionName = pDevTeamOrHost + pPlotter + pModule;
|
||||
functionName = functionName.replace(/-/g, "");
|
||||
functionName = 'new' + functionName
|
||||
return window[functionName]();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-18
@@ -1,19 +1,6 @@
|
||||
|
||||
function getNewPlotterPanel(pDevTeamOrHost, pPlotter, pModule, pPanel) {
|
||||
|
||||
let plotterPanel;
|
||||
let fullCode = pDevTeamOrHost + pPlotter + pModule + pPanel;
|
||||
fullCode = fullCode.replace(/-/g, "");
|
||||
|
||||
switch (fullCode) {
|
||||
|
||||
// Cases
|
||||
|
||||
default:
|
||||
{
|
||||
throw ("getNewPlotterPanel: " + fullCode + " not found.")
|
||||
}
|
||||
}
|
||||
|
||||
return plotterPanel;
|
||||
function getNewPlotterPanel(pDevTeamOrHost, pPlotter, pModule, pPanel) {
|
||||
let functionName = pDevTeamOrHost + pPlotter + pModule + pPanel;
|
||||
functionName = functionName.replace(/-/g, "");
|
||||
functionName = 'new' + functionName
|
||||
return window[functionName]();
|
||||
}
|
||||
@@ -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" />
|
||||
@@ -77,12 +69,10 @@
|
||||
<Content Include="index.html" />
|
||||
<Content Include="Server\Exchange\Wrappers\binanceProperties.json" />
|
||||
<Content Include="Server\Exchange\Wrappers\poloniexProperties.json" />
|
||||
<Content Include="this.server.config.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Azure\" />
|
||||
<Folder Include="Server\Exchange\" />
|
||||
<Folder Include="AABrowserAPI\" />
|
||||
<Folder Include="Server\Exchange\Wrappers\" />
|
||||
<Folder Include="Scripts\" />
|
||||
<Folder Include="Server\" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# AAWeb
|
||||
|
||||
The main function of AAWeb is to serve the js files needed at the browser to run the Canvas App.
|
||||
The main function of AAWeb is to serve the js files needed at the browser to run the Canvas App.
|
||||
|
||||
## Current Status
|
||||
|
||||
@@ -22,8 +22,7 @@ You will need to clone these repos which contains the actual scripts of the Canv
|
||||
At the configuration file, you must verify that this is pointing to the place where you clonned the 2 previous repositories:
|
||||
|
||||
```
|
||||
"pathToFilesComponent": "../Files-Component/src",
|
||||
"pathToCloudAppWrapperComponent": "../CloudApp-Wrapper-Component/src",
|
||||
"pathToFilesComponent": "../Files-Component/src"
|
||||
```
|
||||
|
||||
## Execution
|
||||
|
||||
+217
-18
@@ -1,10 +1,9 @@
|
||||
let dashboard
|
||||
|
||||
function newAppLoader () {
|
||||
function newAppLoader() {
|
||||
const MODULE_NAME = 'App Loader'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const INTENSIVE_LOG = false
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
@@ -14,18 +13,16 @@ function newAppLoader () {
|
||||
|
||||
return thisObject
|
||||
|
||||
function loadModules () {
|
||||
async function loadModules() {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Entering function.') }
|
||||
|
||||
let ecosystem = await loadEcosystem()
|
||||
window.localStorage.setItem('ecosystem', JSON.stringify(ecosystem))
|
||||
let plotters = getPlotters(ecosystem)
|
||||
|
||||
let modulesArray = [
|
||||
|
||||
/* CloudWebScripts */
|
||||
|
||||
/* Plotters */
|
||||
|
||||
/* PlotterPanels */
|
||||
|
||||
'Globals.js',
|
||||
'Ecosystem.js',
|
||||
'MQService',
|
||||
@@ -38,7 +35,6 @@ function newAppLoader () {
|
||||
'ChartsSpace/TimeLineCoordinateSystem.js',
|
||||
|
||||
'TopSpace/CurrentEvent.js',
|
||||
'TopSpace/EndUser.js',
|
||||
'TopSpace/Login.js',
|
||||
|
||||
'StrategySpace/StrategizerGateway.js',
|
||||
@@ -96,14 +92,14 @@ function newAppLoader () {
|
||||
|
||||
'Scales/RateScale.js',
|
||||
'Scales/TimeScale.js',
|
||||
'Scales/TimePeriodScale.js',
|
||||
'Scales/Commons.js',
|
||||
'Scales/TimePeriodScale.js',
|
||||
'Scales/Commons.js',
|
||||
|
||||
'CockpitSpace/AssetBalances.js',
|
||||
'CockpitSpace/Speedometer.js',
|
||||
'CockpitSpace/RestartSimulation.js',
|
||||
'CockpitSpace/GraphQLRestartSimulation.js',
|
||||
'CockpitSpace/FullScreen.js',
|
||||
'CockpitSpace/RestartSimulation.js',
|
||||
'CockpitSpace/GraphQLRestartSimulation.js',
|
||||
'CockpitSpace/FullScreen.js',
|
||||
|
||||
'Plotter.js',
|
||||
'PlotterPanel.js',
|
||||
@@ -121,12 +117,12 @@ function newAppLoader () {
|
||||
'Container.js',
|
||||
'Displace.js',
|
||||
|
||||
'Azure/azure-storage.blob.js',
|
||||
|
||||
'Utilities.js',
|
||||
'Dashboard.js'
|
||||
]
|
||||
|
||||
modulesArray = modulesArray.concat(plotters)
|
||||
|
||||
let downloadedCounter = 0
|
||||
let versionParam = window.canvasApp.version
|
||||
if (versionParam === undefined) { versionParam = '' } else {
|
||||
@@ -142,7 +138,7 @@ function newAppLoader () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> path = ' + path) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> total requested = ' + (i + 1)) }
|
||||
|
||||
function onRequired (pModule) {
|
||||
function onRequired(pModule) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Module Downloaded.') }
|
||||
@@ -168,4 +164,207 @@ function newAppLoader () {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
async function loadEcosystem() {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadEcosystem -> Entering function.') }
|
||||
|
||||
let headers
|
||||
let accessToken = window.localStorage.getItem('access_token')
|
||||
if (accessToken !== null) {
|
||||
headers = {
|
||||
authorization: 'Bearer ' + accessToken
|
||||
}
|
||||
}
|
||||
|
||||
let response = await axios({
|
||||
url: window.canvasApp.graphQL.masterAppApiUrl,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
query {
|
||||
web_GetEcosystem {
|
||||
id
|
||||
devTeams {
|
||||
codeName
|
||||
displayName
|
||||
host {
|
||||
url
|
||||
storage
|
||||
container
|
||||
accessKey
|
||||
}
|
||||
bots {
|
||||
codeName
|
||||
displayName
|
||||
type
|
||||
profilePicture
|
||||
repo
|
||||
configFile
|
||||
products{
|
||||
codeName
|
||||
displayName
|
||||
description
|
||||
dataSets{
|
||||
codeName
|
||||
type
|
||||
validPeriods
|
||||
filePath
|
||||
fileName
|
||||
dataRange{
|
||||
filePath
|
||||
fileName
|
||||
}
|
||||
}
|
||||
exchangeList{
|
||||
name
|
||||
}
|
||||
plotter{
|
||||
devTeam
|
||||
codeName
|
||||
moduleName
|
||||
repo
|
||||
}
|
||||
}
|
||||
}
|
||||
plotters {
|
||||
codeName
|
||||
displayName
|
||||
modules{
|
||||
codeName
|
||||
moduleName
|
||||
description
|
||||
profilePicture
|
||||
panels{
|
||||
codeName
|
||||
moduleName
|
||||
event
|
||||
}
|
||||
}
|
||||
repo
|
||||
configFile
|
||||
}
|
||||
}
|
||||
hosts {
|
||||
codeName
|
||||
displayName
|
||||
host {
|
||||
url
|
||||
storage
|
||||
container
|
||||
accessKey
|
||||
}
|
||||
competitions {
|
||||
codeName
|
||||
displayName
|
||||
description
|
||||
startDatetime
|
||||
finishDatetime
|
||||
formula
|
||||
plotter{
|
||||
devTeam
|
||||
codeName
|
||||
host{
|
||||
url
|
||||
storage
|
||||
container
|
||||
accessKey
|
||||
}
|
||||
moduleName
|
||||
repo
|
||||
}
|
||||
rules
|
||||
prizes
|
||||
participants
|
||||
repo
|
||||
configFile
|
||||
}
|
||||
plotters {
|
||||
codeName
|
||||
displayName
|
||||
modules{
|
||||
codeName
|
||||
moduleName
|
||||
description
|
||||
profilePicture
|
||||
panels{
|
||||
codeName
|
||||
moduleName
|
||||
event
|
||||
}
|
||||
}
|
||||
repo
|
||||
configFile
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
headers: headers
|
||||
})
|
||||
|
||||
if (response.data.errors) {
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + ' : ' + '[ERROR] AppPreLoader -> loadEcosystem -> response.text = ' + JSON.stringify(res.data.errors)) }
|
||||
throw error
|
||||
}
|
||||
|
||||
return response.data.data.web_GetEcosystem
|
||||
}
|
||||
|
||||
function getPlotters(ecosystem) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> Entering function.') }
|
||||
|
||||
|
||||
let plotters = []
|
||||
let devTeams = ecosystem.devTeams
|
||||
let hosts = ecosystem.hosts
|
||||
|
||||
plotters = plotters.concat(addScript(devTeams))
|
||||
plotters = plotters.concat(addScript(hosts))
|
||||
|
||||
return plotters
|
||||
}
|
||||
|
||||
function addScript(pDevTeamsOrHosts) {
|
||||
if (INFO_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> addScript -> Entering function.') }
|
||||
const htmlLinePlotter = 'Plotters/@devTeam@/@repo@/@module@.js'
|
||||
const htmlLinePlotterPanel = 'PlotterPanels/@devTeam@/@repo@/@module@.js'
|
||||
let plotters = []
|
||||
|
||||
for (let i = 0; i < pDevTeamsOrHosts.length; i++) {
|
||||
let devTeam = pDevTeamsOrHosts[i]
|
||||
for (let j = 0; j < devTeam.plotters.length; j++) {
|
||||
let plotter = devTeam.plotters[j]
|
||||
if (plotter.modules !== undefined) {
|
||||
for (let k = 0; k < plotter.modules.length; k++) {
|
||||
let module = plotter.modules[k]
|
||||
let htmlLineCopy = htmlLinePlotter
|
||||
|
||||
let stringToInsert
|
||||
stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName)
|
||||
stringToInsert = stringToInsert.replace('@repo@', plotter.repo)
|
||||
stringToInsert = stringToInsert.replace('@module@', module.moduleName)
|
||||
|
||||
plotters.push(stringToInsert)
|
||||
|
||||
if (module.panels !== undefined) {
|
||||
for (let l = 0; l < module.panels.length; l++) {
|
||||
let panel = module.panels[l]
|
||||
let htmlLineCopy = htmlLinePlotterPanel
|
||||
|
||||
let stringToInsert
|
||||
stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName)
|
||||
stringToInsert = stringToInsert.replace('@repo@', plotter.repo)
|
||||
stringToInsert = stringToInsert.replace('@module@', panel.moduleName)
|
||||
|
||||
plotters.push(stringToInsert)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return plotters
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,454 +0,0 @@
|
||||
exports.newAzureStorage = function newAzureStorage() {
|
||||
|
||||
let thisObject = {
|
||||
readData: readData,
|
||||
writeData: writeData,
|
||||
createContainer: createContainer,
|
||||
deleteContainer: deleteContainer,
|
||||
deleteBlob: deleteBlob,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storageData;
|
||||
let serverConfig;
|
||||
|
||||
let Minio = require('minio');
|
||||
let minioClient;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pStorageData, pServerConfig) {
|
||||
|
||||
storageData = pStorageData;
|
||||
serverConfig = pServerConfig;
|
||||
|
||||
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(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 storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
|
||||
let pParam1 = pOrg;
|
||||
let pParam2 = pPath;
|
||||
let pParam3 = pFile;
|
||||
let container = 'aaplatform';
|
||||
let azurePath = pOrg + "/" + pPath + "/" + pFile;
|
||||
|
||||
let bucketName = 'aaplatform';
|
||||
let textFilename;
|
||||
|
||||
if (pParam1 === undefined) {
|
||||
|
||||
/* This is used when the requests come from the browser, for background compatibility. */
|
||||
|
||||
container = pParam3;
|
||||
azurePath = pParam2;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
blobService.getBlobToText(container, azurePath, 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;
|
||||
|
||||
}
|
||||
|
||||
/* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
|
||||
|
||||
// try {
|
||||
|
||||
// minioClient.putObject(bucketName, textFilename, text, 'text/plain', function (err) {
|
||||
// if (err) {
|
||||
// console.log("ERROR AT MINIO SERVER PUTTING OBJECT : " + err);
|
||||
// return;
|
||||
// }
|
||||
// console.log(textFilename + ' Successfully uploaded ' + textFilename + ' the MINIO SERVER');
|
||||
// })
|
||||
|
||||
// } catch (err) {
|
||||
// console.log("ERROR UPDATING MINIO SERVER : " + err);
|
||||
// }
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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 storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
let blobPath = pOrg + "/" + pPath + "/" + pFile;
|
||||
let blobText = pFileContent.toString();
|
||||
|
||||
blobService.createBlockBlobFromText('aaplatform', blobPath, 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 storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
let blobPath = pOrg + "/" + pPath + "/" + pFile;
|
||||
|
||||
blobService.deleteBlob('aaplatform', blobPath, 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 storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
|
||||
let containerName = pContainerName.toLowerCase();
|
||||
|
||||
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_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 storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
|
||||
let containerName = pContainerName.toLowerCase();
|
||||
|
||||
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_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
exports.newAzureStorageAccessManager = function newAzureStorageAccessManager() {
|
||||
|
||||
let thisObject = {
|
||||
getPermission: getPermission,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let connectionString;
|
||||
let blobEndpoint;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(serverConfig, callBackFunction) {
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
blobEndpoint = serverConfig.productsStorage.Develop.fileUri;
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
blobEndpoint = serverConfig.productsStorage.Production.fileUri;
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
callBackFunction();
|
||||
}
|
||||
|
||||
function getPermission(pContainer, pType, pDays) {
|
||||
|
||||
let azure = require('azure-storage');
|
||||
let blobService = azure.createBlobService(connectionString);
|
||||
|
||||
let startDate = new Date();
|
||||
startDate.setDate(startDate.getDate() - 1);
|
||||
|
||||
let expiryDate = new Date(startDate);
|
||||
expiryDate.setDate(startDate.getDate() + pDays);
|
||||
|
||||
let azurePermissions;
|
||||
|
||||
switch (pType) {
|
||||
case "READ": {
|
||||
azurePermissions = azure.BlobUtilities.SharedAccessPermissions.READ;
|
||||
break;
|
||||
}
|
||||
case "WRITE": {
|
||||
azurePermissions = azure.BlobUtilities.SharedAccessPermissions.WRITE;
|
||||
break;
|
||||
}
|
||||
case "DELETE": {
|
||||
azurePermissions = azure.BlobUtilities.SharedAccessPermissions.DELETE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobName = undefined;
|
||||
|
||||
let sharedAccessPolicy = {
|
||||
AccessPolicy: {
|
||||
Permissions: azurePermissions,
|
||||
Start: startDate,
|
||||
Expiry: expiryDate
|
||||
}
|
||||
};
|
||||
|
||||
let sasToken = blobService.generateSharedAccessSignature(pContainer, blobName, sharedAccessPolicy);
|
||||
|
||||
return "BlobEndpoint=" + blobEndpoint + ";SharedAccessSignature=" + sasToken + "";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
exports.newBotScripts = function newBotScripts() {
|
||||
|
||||
let thisObject = {
|
||||
getScript: getScript,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storage;
|
||||
|
||||
let serverConfig;
|
||||
let storageData;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pServerConfig, pStorage, callBackFunction) {
|
||||
|
||||
storage = pStorage;
|
||||
|
||||
let storageData = new Map(); // For backwards compatibility only. Not used.
|
||||
|
||||
storage.initialize(storageData, pServerConfig);
|
||||
|
||||
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,621 +0,0 @@
|
||||
exports.newConfigReader = function newConfigReader() {
|
||||
|
||||
let thisObject = {
|
||||
loadConfigs: loadConfigs,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
const GITHUB = require('../Server/Github');
|
||||
let github = GITHUB.newGithub();
|
||||
|
||||
let storage;
|
||||
|
||||
let serverConfig;
|
||||
let storageData;
|
||||
let ecosystem;
|
||||
let ecosystemObject;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pEcosystem, pEcosystemObject, pStorageData, pStorage, callBackFunction) {
|
||||
|
||||
storage = pStorage;
|
||||
storageData = pStorageData;
|
||||
ecosystem = pEcosystem;
|
||||
ecosystemObject = pEcosystemObject;
|
||||
|
||||
readAAWebConfig();
|
||||
|
||||
function readAAWebConfig() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readAAWebConfig -> Entering function."); }
|
||||
|
||||
let fs = require('fs');
|
||||
|
||||
let fileName = './this.server.config.json';
|
||||
fs.readFile(fileName, onFileRead);
|
||||
|
||||
function onFileRead(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readAAWebConfig -> onFileRead -> Entering function."); }
|
||||
|
||||
let fileText;
|
||||
|
||||
fileText = file.toString();
|
||||
fileText = fileText.trim(); // remove first byte with some encoding.
|
||||
|
||||
serverConfig = JSON.parse(fileText);
|
||||
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] ConfigReader -> readAAWebConfig -> onFileRead -> fileText = " + fileText); }
|
||||
|
||||
CONSOLE_LOG = serverConfig.webServerLog.console;
|
||||
LOG_FILE_CONTENT = serverConfig.webServerLog.fileContent;
|
||||
|
||||
/* Finalize initializations. */
|
||||
|
||||
storage.initialize(storageData, serverConfig);
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, serverConfig);
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readAAWebConfig -> onFileRead -> File = " + fileName + " Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readAAWebConfig -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadConfigs(callBackFunction) {
|
||||
|
||||
readEcosystemConfig();
|
||||
|
||||
function readEcosystemConfig() {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readEcosystemConfig -> Entering function."); }
|
||||
|
||||
/*
|
||||
|
||||
This configuration file is the backbone of the system. The first file we are going to get is a template where other configurations are
|
||||
injected and the files ends up inflated with all these configs in one single JSON object that in turn is later injected into a
|
||||
javascript module with an object that is going to instantiate it at run-time.
|
||||
|
||||
*/
|
||||
|
||||
storage.readData('AdvancedAlgos', 'AAPlatform', 'ecosystem.json', true, onDataArrived);
|
||||
|
||||
function onDataArrived(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readEcosystemConfig -> Cloud -> onDataArrived -> Entering function."); }
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("[ERROR] ConfigReader -> readEcosystemConfig -> Cloud -> onDataArrived -> Could not read a file. ");
|
||||
console.log("[ERROR] ConfigReader -> readEcosystemConfig -> Cloud -> onDataArrived -> err.message = " + err.message);
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
ecosystem = pData.toString();
|
||||
ecosystem = ecosystem.trim(); // remove first byte with some encoding.
|
||||
|
||||
ecosystemObject = JSON.parse(ecosystem);
|
||||
readHostsConfigs();
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> loadConfigs -> readEcosystemConfig -> onDataArrived -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> loadConfigs -> readEcosystemConfig -> Error = " + err);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
addStoragePermissions(configObj);
|
||||
|
||||
/* 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, ecosystem, 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, ecosystem, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addStoragePermissions(pConfigObj) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] ConfigReader -> readDevTeamsConfigs -> addStoragePermissions -> Entering function."); }
|
||||
|
||||
if (pConfigObj.storage !== undefined) { return; } // If this information is at the config file, then we take it, otherwise, we define it here.
|
||||
|
||||
let fileUri;
|
||||
let sas;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
fileUri = serverConfig.productsStorage.Develop.fileUri;
|
||||
sas = serverConfig.productsStorage.Develop.sas;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
fileUri = serverConfig.productsStorage.Production.fileUri;
|
||||
sas = serverConfig.productsStorage.Production.sas;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pConfigObj.storage = {
|
||||
sas: sas,
|
||||
fileUri: fileUri
|
||||
};
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] ConfigReader -> readDevTeamsConfigs -> addStoragePermissions -> 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,351 +0,0 @@
|
||||
exports.newMinioStorage = function newMinioStorage() {
|
||||
|
||||
let thisObject = {
|
||||
readData: readData,
|
||||
writeData: writeData,
|
||||
createContainer: createContainer,
|
||||
deleteContainer: deleteContainer,
|
||||
deleteBlob: deleteBlob,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storageData;
|
||||
let serverConfig;
|
||||
|
||||
let Minio = require('minio');
|
||||
let minioClient;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pStorageData, pServerConfig) {
|
||||
|
||||
storageData = pStorageData;
|
||||
serverConfig = pServerConfig;
|
||||
|
||||
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,62 +0,0 @@
|
||||
exports.newSessionManager = function newSessionManager() {
|
||||
|
||||
let thisObject = {
|
||||
getSession: getSession,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let activeSessions = new Map();
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pServerConfig, storage, callBackFunction) {
|
||||
|
||||
readSessions();
|
||||
|
||||
function readSessions() {
|
||||
|
||||
try {
|
||||
|
||||
storage.initialize(undefined, pServerConfig);
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -17,7 +17,6 @@
|
||||
<body id="body" style="margin: 0px; padding: 0px; border: 0px; " onresize="window.canvasApp.eventHandler.raiseEvent('Browser Resized');" onload="
|
||||
window.canvasApp={
|
||||
version: '1.0.0' , // This is used to avoid catching problems at the browser level.
|
||||
sessionToken: '',
|
||||
executingAt: 'Master App',
|
||||
visible: true,
|
||||
topMargin: 85,
|
||||
@@ -39,4 +38,4 @@
|
||||
<div id="inputDiv"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@@ -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
|
||||
})
|
||||
Generated
+32
-952
File diff suppressed because it is too large.
Load diff
+1
-9
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,9 @@
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
/* These 2 are global variables, that is why they do not have a let or var */
|
||||
|
||||
CONSOLE_LOG = true
|
||||
CONSOLE_ERROR_LOG = true
|
||||
LOG_FILE_CONTENT = false
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> Node Server Starting.') }
|
||||
|
||||
let serverConfig
|
||||
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'
|
||||
|
||||
global.DEFAULT_OK_RESPONSE = {
|
||||
result: 'Ok',
|
||||
@@ -36,105 +30,15 @@ global.CUSTOM_FAIL_RESPONSE = {
|
||||
message: 'Custom Message'
|
||||
}
|
||||
|
||||
let storageData = new Map()
|
||||
|
||||
let botScripts // This module is the one which grabs user bots scrips from the storage, and browserifys them.
|
||||
|
||||
let ecosystem
|
||||
let ecosystemObject
|
||||
|
||||
// 'use strict';
|
||||
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')
|
||||
const FILE_CLOUD = require('./Server/FileCloud')
|
||||
let fileCloud = FILE_CLOUD.newFileCloud()
|
||||
let storageData = new Map()
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
let sessionManager // This module have all authenticated active sessions.
|
||||
let storageAccessManager // This module manages the SAS for user to access the cloud storage from the browser.
|
||||
|
||||
initialize()
|
||||
|
||||
function initialize () {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> initialize -> Entering function.') }
|
||||
|
||||
/* Clear all cached information. */
|
||||
|
||||
storageData = new Map()
|
||||
|
||||
const CONFIG_READER = require('./Server/ConfigReader')
|
||||
let configReader = CONFIG_READER.newConfigReader()
|
||||
|
||||
configReader.initialize(ecosystem, ecosystemObject, storageData, storage, onInitialized)
|
||||
|
||||
function onInitialized (err, pServerConfig) {
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log('[ERROR] server -> initialize -> onInitialized -> err.message = ' + err.message)
|
||||
console.log('[ERROR] server -> initialize -> onInitialized -> Terminating Execution. ')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
serverConfig = pServerConfig
|
||||
|
||||
configReader.loadConfigs(onConfigsLoaded)
|
||||
|
||||
function onConfigsLoaded (err, pEcosystem, pEcosystemObject) {
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log('[ERROR] server -> initialize -> onInitialized -> onConfigsLoaded -> err.message = ' + err.message)
|
||||
console.log('[ERROR] server -> initialize -> onInitialized -> onConfigsLoaded -> Terminating Execution. ')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ecosystem = pEcosystem
|
||||
ecosystemObject = pEcosystemObject
|
||||
|
||||
storage.initialize(storageData, serverConfig)
|
||||
|
||||
const SESSION_MANAGER = require('./Server/SessionManager')
|
||||
sessionManager = SESSION_MANAGER.newSessionManager()
|
||||
|
||||
sessionManager.initialize(serverConfig, storage, onInitialized)
|
||||
|
||||
function onInitialized () {
|
||||
const STORAGE_ACCESS_MANAGER = require('./Server/AzureStorageAccessManager')
|
||||
storageAccessManager = STORAGE_ACCESS_MANAGER.newAzureStorageAccessManager()
|
||||
|
||||
storageAccessManager.initialize(serverConfig, onInitialized)
|
||||
|
||||
function onInitialized () {
|
||||
const BOT_SCRIPTS = require('./Server/BotsScripts')
|
||||
botScripts = BOT_SCRIPTS.newBotScripts()
|
||||
|
||||
botScripts.initialize(serverConfig, storage, onInitialized)
|
||||
|
||||
function onInitialized () {
|
||||
startHtttpServer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
startHtttpServer()
|
||||
|
||||
function startHtttpServer () {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> startHtttpServer -> Entering function.') }
|
||||
@@ -150,18 +54,16 @@ function startHtttpServer () {
|
||||
}
|
||||
|
||||
function onBrowserRequest (request, response) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> Entering function.') }
|
||||
if (CONSOLE_LOG === true && request.url.indexOf('NO-LOG') === -1) { console.log('[INFO] server -> onBrowserRequest -> request.url = ' + request.url) }
|
||||
|
||||
let htmlResponse
|
||||
let requestParameters = request.url.split('/')
|
||||
|
||||
if (requestParameters[1].indexOf('index.html') >= 0) {
|
||||
/*
|
||||
We use this to solve the problem when someone is arriving to the site with a sessionToken in the queryString. We extract here that
|
||||
token, that will be sent later embedded into the HTML code, so that it can enter into the stardard circuit where any site can put
|
||||
the sessionToken into their HTML code and from there the Browser app will log the user in.
|
||||
*/
|
||||
/*
|
||||
We use this to solve the problem when someone is arriving to the site with a sessionToken in the queryString. We extract here that
|
||||
token, that will be sent later embedded into the HTML code, so that it can enter into the stardard circuit where any site can put
|
||||
the sessionToken into their HTML code and from there the Browser app will log the user in.
|
||||
*/
|
||||
|
||||
let queryString = requestParameters[1].split('?')
|
||||
|
||||
@@ -177,7 +79,7 @@ function onBrowserRequest (request, response) {
|
||||
|
||||
switch (requestParameters[1]) {
|
||||
|
||||
case serverConfig.reinitializeCommand: {
|
||||
case process.env.REINITIALIZE_COMMAND: {
|
||||
initialize()
|
||||
|
||||
respondWithContent('Node JS Server Reinitilized.', response)
|
||||
@@ -185,245 +87,28 @@ function onBrowserRequest (request, response) {
|
||||
break
|
||||
|
||||
case 'MQService':
|
||||
{
|
||||
let filePath = "./node_modules/@superalgos/mqservice/orderLifeCicle/webDependency.js"
|
||||
{
|
||||
let filePath = './node_modules/@superalgos/mqservice/orderLifeCicle/webDependency.js'
|
||||
|
||||
respondWithFile(filePath, response)
|
||||
break;
|
||||
}
|
||||
respondWithFile(filePath, response)
|
||||
break
|
||||
}
|
||||
|
||||
case 'FileService':
|
||||
{
|
||||
|
||||
processPost(request, response, onPostReceived)
|
||||
|
||||
function onPostReceived(pData) {
|
||||
|
||||
let request = JSON.parse(pData);
|
||||
|
||||
storage.readData(undefined, request.path, request.conatinerName, false, onReady)
|
||||
|
||||
function onReady(err, pFileContent) {
|
||||
|
||||
let responseToClient = {
|
||||
err: err,
|
||||
text: pFileContent
|
||||
};
|
||||
|
||||
respondWithContent(JSON.stringify(responseToClient), response);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 'Plotter.js':
|
||||
{
|
||||
/*
|
||||
|
||||
This file is build dinamically because it has the code to instantiate the different configured Plotters. The instantiation code
|
||||
will be generated using a pre-defined string with replacement points. We will go through the configuration file to learn
|
||||
about all the possible plotters the system can load.
|
||||
|
||||
*/
|
||||
|
||||
let fs = require('fs')
|
||||
try {
|
||||
let fileName = 'Plotter.js'
|
||||
fs.readFile(fileName, onFileRead)
|
||||
|
||||
function onFileRead (err, file) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> Entering function.') }
|
||||
|
||||
try {
|
||||
let fileContent = file.toString()
|
||||
|
||||
/* This is the string we will use to insert into the Plotters.js script. */
|
||||
|
||||
let caseString = '' +
|
||||
' case "@newFunctionName@":' + '\n' +
|
||||
' {' + '\n' +
|
||||
' plotter = newPlotterName();' + '\n' +
|
||||
' }' + '\n' +
|
||||
' break;' + '\n' + '\n'
|
||||
|
||||
let devTeams = ecosystemObject.devTeams
|
||||
let hosts = ecosystemObject.hosts
|
||||
|
||||
addToFileContent(devTeams)
|
||||
addToFileContent(hosts)
|
||||
|
||||
function addToFileContent (pDevTeamsOrHosts) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addToFileContent -> Entering function.') }
|
||||
|
||||
for (let i = 0; i < pDevTeamsOrHosts.length; i++) {
|
||||
let devTeam = pDevTeamsOrHosts[i]
|
||||
|
||||
for (let j = 0; j < devTeam.plotters.length; j++) {
|
||||
let plotter = devTeam.plotters[j]
|
||||
|
||||
for (let k = 0; k < plotter.modules.length; k++) {
|
||||
|
||||
let module = plotter.modules[k]
|
||||
|
||||
let caseStringCopy = caseString
|
||||
|
||||
let newFunctionName = devTeam.codeName + plotter.codeName + module.codeName
|
||||
newFunctionName = newFunctionName.replace(/-/g, '')
|
||||
|
||||
let stringToInsert
|
||||
stringToInsert = caseStringCopy.replace('@newFunctionName@', newFunctionName)
|
||||
stringToInsert = stringToInsert.replace('newPlotterName', 'new' + newFunctionName)
|
||||
|
||||
let firstPart = fileContent.substring(0, fileContent.indexOf('// Cases'))
|
||||
let secondPart = fileContent.substring(fileContent.indexOf('// Cases'))
|
||||
|
||||
fileContent = firstPart + stringToInsert + secondPart
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
respondWithContent(fileContent, response)
|
||||
} catch (err) {
|
||||
console.log('[ERROR] server -> onBrowserRequest -> File Not Found: ' + fileName + ' or Error = ' + err)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
respondWithFile('./Plotter.js', response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'PlotterPanel.js':
|
||||
{
|
||||
/*
|
||||
|
||||
This file is build dinamically because it has the code to instantiate the different configured Plotter Panels. The instantiation code
|
||||
will be generated using a pre-defined string with replacement points. We will go through the configuration file to learn
|
||||
about all the possible plotters panels the system can load.
|
||||
|
||||
*/
|
||||
|
||||
let fs = require('fs')
|
||||
try {
|
||||
let fileName = 'PlotterPanel.js'
|
||||
fs.readFile(fileName, onFileRead)
|
||||
|
||||
function onFileRead (err, file) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> Entering function.') }
|
||||
|
||||
try {
|
||||
let fileContent = file.toString()
|
||||
|
||||
/* This is the string we will use to insert into the Plotters.js script. */
|
||||
|
||||
let caseString = '' +
|
||||
' case "@newFunctionName@":' + '\n' +
|
||||
' {' + '\n' +
|
||||
' plotterPanel = newPlotterPanelName();' + '\n' +
|
||||
' }' + '\n' +
|
||||
' break;' + '\n' + '\n'
|
||||
|
||||
let devTeams = ecosystemObject.devTeams
|
||||
let hosts = ecosystemObject.hosts
|
||||
|
||||
addToFileContent(devTeams)
|
||||
addToFileContent(hosts)
|
||||
|
||||
function addToFileContent (pDevTeamsOrHosts) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addToFileContent -> Entering function.') }
|
||||
|
||||
for (let i = 0; i < pDevTeamsOrHosts.length; i++) {
|
||||
let devTeam = pDevTeamsOrHosts[i]
|
||||
|
||||
for (let j = 0; j < devTeam.plotters.length; j++) {
|
||||
let plotter = devTeam.plotters[j]
|
||||
|
||||
for (let k = 0; k < plotter.modules.length; k++) {
|
||||
|
||||
let module = plotter.modules[k]
|
||||
|
||||
for (let l = 0; l < module.panels.length; l++) {
|
||||
|
||||
let panel = module.panels[l]
|
||||
|
||||
let caseStringCopy = caseString
|
||||
|
||||
let newFunctionName = devTeam.codeName + plotter.codeName + module.codeName + panel.codeName
|
||||
newFunctionName = newFunctionName.replace(/-/g, '')
|
||||
|
||||
let stringToInsert
|
||||
stringToInsert = caseStringCopy.replace('@newFunctionName@', newFunctionName)
|
||||
stringToInsert = stringToInsert.replace('newPlotterPanelName', 'new' + newFunctionName)
|
||||
|
||||
let firstPart = fileContent.substring(0, fileContent.indexOf('// Cases'))
|
||||
let secondPart = fileContent.substring(fileContent.indexOf('// Cases'))
|
||||
|
||||
fileContent = firstPart + stringToInsert + secondPart
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
respondWithContent(fileContent, response)
|
||||
} catch (err) {
|
||||
console.log('[ERROR] server -> onBrowserRequest -> File Not Found: ' + fileName + ' or Error = ' + err)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
respondWithFile('./PlotterPanel.js', response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Ecosystem.js':
|
||||
{
|
||||
/*
|
||||
|
||||
At this page we need to insert the configuration file for the whole system that we assamble before at the begining of this module
|
||||
execution. So what we do is to load a template file with an insertion point where the configuration json is injected in.
|
||||
|
||||
*/
|
||||
|
||||
let fs = require('fs')
|
||||
try {
|
||||
let fileName = 'Ecosystem.js'
|
||||
fs.readFile(fileName, onFileRead)
|
||||
|
||||
function onFileRead (err, file) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> Entering function.') }
|
||||
|
||||
try {
|
||||
let fileContent = file.toString()
|
||||
let insertContent = JSON.stringify(ecosystemObject)
|
||||
|
||||
fileContent = fileContent.replace('"@ecosystem.json@"', insertContent)
|
||||
|
||||
respondWithContent(fileContent, response)
|
||||
} catch (err) {
|
||||
console.log('[ERROR] server -> onBrowserRequest -> File Not Found: ' + fileName + ' or Error = ' + err)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'CloudAppWrapper': // This means the BrowserRun folder.
|
||||
{
|
||||
let filePath = requestParameters[2]
|
||||
|
||||
if (requestParameters[3] !== undefined) {
|
||||
filePath = filePath + '/' + requestParameters[3]
|
||||
}
|
||||
|
||||
if (requestParameters[4] !== undefined) {
|
||||
filePath = filePath + '/' + requestParameters[4]
|
||||
}
|
||||
|
||||
respondWithFile(serverConfig.pathToCloudAppWrapperComponent + '/' + filePath, response)
|
||||
respondWithFile('./Ecosystem.js', response)
|
||||
}
|
||||
break
|
||||
|
||||
@@ -457,421 +142,104 @@ function onBrowserRequest (request, response) {
|
||||
|
||||
case 'CockpitSpace': // This means the CockpitSpace folder.
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/CockpitSpace/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/CockpitSpace/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'TopSpace': // This means the TopSpace folder.
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/TopSpace/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/TopSpace/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'StrategySpace': // This means the StrategySpace folder.
|
||||
{
|
||||
if (requestParameters[3] === undefined) {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/StrategySpace/' + requestParameters[2], response)
|
||||
return
|
||||
}
|
||||
if (requestParameters[4] === undefined) {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/StrategySpace/' + requestParameters[2] + '/' + requestParameters[3] , response)
|
||||
return
|
||||
}
|
||||
if (requestParameters[5] === undefined) {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/StrategySpace/' + requestParameters[2] + '/' + requestParameters[3] + '/' + requestParameters[4], response)
|
||||
return
|
||||
}
|
||||
|
||||
{
|
||||
if (requestParameters[3] === undefined) {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/StrategySpace/' + requestParameters[2], response)
|
||||
return
|
||||
}
|
||||
break
|
||||
if (requestParameters[4] === undefined) {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/StrategySpace/' + requestParameters[2] + '/' + requestParameters[3], response)
|
||||
return
|
||||
}
|
||||
if (requestParameters[5] === undefined) {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/StrategySpace/' + requestParameters[2] + '/' + requestParameters[3] + '/' + requestParameters[4], response)
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'ControlsToolBox': // This means the StrategySpace folder.
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/ControlsToolBox/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
{
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/ControlsToolBox/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Utilities': // This means the StrategySpace folder.
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/Utilities/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'AABrowserAPI': // This means the Scripts folder.
|
||||
{
|
||||
switch (requestParameters[2]) {
|
||||
|
||||
case "authenticateUser": {
|
||||
|
||||
const AABROWSER_API_USER_AUTHENTICATION = require('./AABrowserAPI/' + 'UserAuthentication');
|
||||
let userAuthentication = AABROWSER_API_USER_AUTHENTICATION.newUserAuthentication();
|
||||
|
||||
userAuthentication.initialize(sessionManager, storageAccessManager);
|
||||
userAuthentication.authenticateUser(requestParameters[3], onFinish);
|
||||
|
||||
function onFinish(err, pUserProfile) {
|
||||
|
||||
let responseToBrowser = {
|
||||
err: err,
|
||||
userProfile: pUserProfile
|
||||
};
|
||||
|
||||
respondWithContent(JSON.stringify(responseToBrowser), response);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "newTeam": {
|
||||
|
||||
const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup');
|
||||
let teamSetup = AABROWSER_API_TEAM_SETUP.newTeamSetup();
|
||||
|
||||
teamSetup.initialize(serverConfig, storage);
|
||||
|
||||
let devTeamCodeName = decodeURI(requestParameters[3]);
|
||||
let devTeamDisplayName = decodeURI(requestParameters[4]);
|
||||
let userName = decodeURI(requestParameters[5]);
|
||||
let botCodeName = decodeURI(requestParameters[6]);
|
||||
let botDisplayName = decodeURI(requestParameters[7]);
|
||||
let userId = decodeURI(requestParameters[8]);
|
||||
let sharedSecret = decodeURI(requestParameters[9]);
|
||||
|
||||
if (sharedSecret !== serverConfig.newTeamSharedSecret) {
|
||||
|
||||
let customFailResponse = {
|
||||
result: global.DEFAULT_FAIL_RESPONSE.result,
|
||||
message: "The shared secret provided is incorrect"
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(customFailResponse), response);
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[WARN] server -> AABrowserAPI -> newTeam -> Shared Secret Received Incorrect."); }
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
teamSetup.newTeam(devTeamCodeName, devTeamDisplayName, userName, botCodeName, botDisplayName, userId, onSetupFinished);
|
||||
|
||||
function onSetupFinished(err) {
|
||||
|
||||
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
/* We must re-load all the webserver caches.*/
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(err), response)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'deleteTeam': {
|
||||
const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup')
|
||||
let teamSetup = AABROWSER_API_TEAM_SETUP.newTeamSetup()
|
||||
|
||||
teamSetup.initialize(serverConfig, storage)
|
||||
|
||||
let devTeamCodeName = decodeURI(requestParameters[3])
|
||||
let userName = decodeURI(requestParameters[4])
|
||||
let botCodeName = decodeURI(requestParameters[5])
|
||||
let userId = decodeURI(requestParameters[6])
|
||||
let sharedSecret = decodeURI(requestParameters[7])
|
||||
|
||||
if (sharedSecret !== serverConfig.deleteTeamSharedSecret) {
|
||||
let customFailResponse = {
|
||||
result: global.DEFAULT_FAIL_RESPONSE.result,
|
||||
message: 'The shared secret provided is incorrect'
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(customFailResponse), response)
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log('[WARN] server -> AABrowserAPI -> deleteTeam -> Shared Secret Received Incorrect.') }
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
teamSetup.deleteTeam(devTeamCodeName, userName, botCodeName, userId, onSetupFinished)
|
||||
|
||||
function onSetupFinished (err) {
|
||||
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
|
||||
/* We must re-load all the webserver caches. */
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(err), response)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/Utilities/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Scripts': // This means the Scripts folder.
|
||||
{
|
||||
if (requestParameters[2] === 'AppLoader.js') {
|
||||
let fs = require('fs')
|
||||
try {
|
||||
let fileName = './Scripts/' + 'AppLoader.js'
|
||||
fs.readFile(fileName, onFileRead)
|
||||
|
||||
function onFileRead (err, file) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> Entering function.') }
|
||||
|
||||
try {
|
||||
let fileContent = file.toString()
|
||||
|
||||
addPlotters()
|
||||
|
||||
function addPlotters () {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> Entering function.') }
|
||||
|
||||
let htmlLinePlotter = '' + '\n' +
|
||||
' "Plotters/@devTeam@/@repo@/@module@.js",'
|
||||
|
||||
let htmlLinePlotterPanel = '' + '\n' +
|
||||
' "PlotterPanels/@devTeam@/@repo@/@module@.js",'
|
||||
|
||||
let devTeams = ecosystemObject.devTeams
|
||||
let hosts = ecosystemObject.hosts
|
||||
|
||||
addScript(devTeams)
|
||||
addScript(hosts)
|
||||
|
||||
function addScript (pDevTeamsOrHosts) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> addScript -> Entering function.') }
|
||||
|
||||
for (let i = 0; i < pDevTeamsOrHosts.length; i++) {
|
||||
|
||||
let devTeam = pDevTeamsOrHosts[i]
|
||||
|
||||
for (let j = 0; j < devTeam.plotters.length; j++) {
|
||||
|
||||
let plotter = devTeam.plotters[j]
|
||||
|
||||
if (plotter.modules !== undefined) {
|
||||
|
||||
for (let k = 0; k < plotter.modules.length; k++) {
|
||||
|
||||
let module = plotter.modules[k]
|
||||
|
||||
let htmlLineCopy = htmlLinePlotter
|
||||
|
||||
let stringToInsert
|
||||
stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName)
|
||||
stringToInsert = stringToInsert.replace('@repo@', plotter.repo)
|
||||
stringToInsert = stringToInsert.replace('@module@', module.moduleName)
|
||||
|
||||
let firstPart = fileContent.substring(0, fileContent.indexOf('/* Plotters */') + 14)
|
||||
let secondPart = fileContent.substring(fileContent.indexOf('/* Plotters */') + 14)
|
||||
|
||||
fileContent = firstPart + stringToInsert + secondPart
|
||||
|
||||
if (module.panels !== undefined) {
|
||||
|
||||
for (let l = 0; l < module.panels.length; l++) {
|
||||
|
||||
let panel = module.panels[l]
|
||||
|
||||
let htmlLineCopy = htmlLinePlotterPanel
|
||||
|
||||
let stringToInsert
|
||||
stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName)
|
||||
stringToInsert = stringToInsert.replace('@repo@', plotter.repo)
|
||||
stringToInsert = stringToInsert.replace('@module@', panel.moduleName)
|
||||
|
||||
let firstPart = fileContent.substring(0, fileContent.indexOf('/* PlotterPanels */') + 19)
|
||||
let secondPart = fileContent.substring(fileContent.indexOf('/* PlotterPanels */') + 19)
|
||||
|
||||
fileContent = firstPart + stringToInsert + secondPart
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
respondWithContent(fileContent, response)
|
||||
} catch (err) {
|
||||
console.log('[ERROR] server -> onBrowserRequest -> File Not Found: ' + fileName + ' or Error = ' + err)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
} else {
|
||||
respondWithFile('./Scripts/' + requestParameters[2], response)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'AACloud': // This means the cloud folder.
|
||||
{
|
||||
let filePath = requestParameters[2]
|
||||
|
||||
if (requestParameters[3] !== undefined) {
|
||||
filePath = filePath + '/' + requestParameters[3]
|
||||
}
|
||||
|
||||
if (requestParameters[4] !== undefined) {
|
||||
filePath = filePath + '/' + requestParameters[4]
|
||||
}
|
||||
|
||||
let map = storageData
|
||||
|
||||
let script = map.get(filePath)
|
||||
|
||||
if (script !== undefined) {
|
||||
respondWithContent(script, response)
|
||||
} else {
|
||||
if (CONSOLE_LOG === true) { console.log('[WARN] server -> onBrowserRequest -> readEcosystemConfig -> Script Not Found.') }
|
||||
if (CONSOLE_LOG === true) { console.log('[WARN] server -> onBrowserRequest -> readEcosystemConfig -> requestParameters[2] = ' + requestParameters[2]) }
|
||||
|
||||
respondWithContent('', response)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case 'Bots': // This means the cloud folder.
|
||||
{
|
||||
switch (requestParameters[3]) {
|
||||
|
||||
case 'bots': {
|
||||
let devTeam = requestParameters[2]
|
||||
let source = requestParameters[3]
|
||||
let repo = requestParameters[4]
|
||||
let path
|
||||
|
||||
if (requestParameters[6] !== undefined) {
|
||||
path = requestParameters[5] + '/' + requestParameters[6]
|
||||
} else {
|
||||
path = requestParameters[5]
|
||||
}
|
||||
|
||||
botScripts.getScript(devTeam, source, repo, path, onScriptReady)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case 'members': {
|
||||
let devTeam = requestParameters[2]
|
||||
let source = requestParameters[3] + '/' + requestParameters[4]
|
||||
let repo = requestParameters[5]
|
||||
let path
|
||||
|
||||
if (requestParameters[7] !== undefined) {
|
||||
path = requestParameters[6] + '/' + requestParameters[7]
|
||||
} else {
|
||||
path = requestParameters[6]
|
||||
}
|
||||
|
||||
botScripts.getScript(devTeam, source, repo, path, onScriptReady)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
default : {
|
||||
if (CONSOLE_LOG === true) { console.log('[ERROR] server -> onBrowserRequest -> Bots -> Invalid Request. ') }
|
||||
}
|
||||
}
|
||||
|
||||
function onScriptReady (err, pScript) {
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log('[ERROR] server -> onBrowserRequest -> Bots -> onScriptReady -> Could not read a file. ')
|
||||
console.log('[ERROR] server -> onBrowserRequest -> Bots -> onScriptReady -> err.message = ' + err.message)
|
||||
|
||||
pScript = '/* Your bot source code could not be retrieved. */'
|
||||
}
|
||||
|
||||
respondWithContent(pScript, response)
|
||||
}
|
||||
respondWithFile('./Scripts/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
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':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'ChartLayers':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Azure':
|
||||
{
|
||||
respondWithFile('./' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Spaces':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Scales':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Files':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToFilesComponent + '/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_FILES_COMPONENT + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'FloatingSpace':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
case 'ChartsSpace':
|
||||
{
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
{
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1] + '/' + requestParameters[2], response)
|
||||
}
|
||||
break
|
||||
|
||||
default:
|
||||
{
|
||||
@@ -892,7 +260,7 @@ function onBrowserRequest (request, response) {
|
||||
try {
|
||||
let fileContent = file.toString()
|
||||
|
||||
/* The second request parameters is the sessionToken, if it exists. */
|
||||
/* The second request parameters is the sessionToken, if it exists. */
|
||||
|
||||
if (requestParameters[2] !== '' && requestParameters[2] !== undefined) {
|
||||
fileContent = fileContent.replace("window.canvasApp.sessionToken = ''", "window.canvasApp.sessionToken = '" + requestParameters[2] + "'")
|
||||
@@ -907,18 +275,9 @@ function onBrowserRequest (request, response) {
|
||||
console.log(err)
|
||||
}
|
||||
} else {
|
||||
respondWithFile(serverConfig.pathToCanvasApp + '/' + requestParameters[1], response)
|
||||
respondWithFile(process.env.PATH_TO_CANVAS_APP + '/' + requestParameters[1], response)
|
||||
}
|
||||
}
|
||||
|
||||
function sendResponseToBrowser (htmlResponse) {
|
||||
if (CONSOLE_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> sendResponseToBrowser -> Entering function.') }
|
||||
|
||||
response.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
response.write(htmlResponse)
|
||||
|
||||
response.end('\n')
|
||||
}
|
||||
}
|
||||
|
||||
function respondWithContent (content, response) {
|
||||
@@ -933,7 +292,7 @@ function respondWithContent (content, response) {
|
||||
response.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
response.write(content)
|
||||
response.end('\n')
|
||||
// console.log("Content Sent: " + content);
|
||||
// console.log("Content Sent: " + content);
|
||||
} catch (err) {
|
||||
returnEmptyArray(response)
|
||||
}
|
||||
@@ -962,11 +321,11 @@ function respondWithFile (fileName, response) {
|
||||
response.setHeader('Expires', '0') // Proxies.
|
||||
response.setHeader('Access-Control-Allow-Origin', '*') // Allows to access data from other domains.
|
||||
|
||||
// response.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
// response.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
response.write(htmlResponse)
|
||||
response.end('\n')
|
||||
// console.log("File Sent: " + fileName);
|
||||
//
|
||||
// console.log("File Sent: " + fileName);
|
||||
//
|
||||
} catch (err) {
|
||||
console.log('[ERROR] server -> respondWithFile -> onFileRead -> File Not Found: ' + fileName + ' or Error = ' + err)
|
||||
returnEmptyArray()
|
||||
@@ -1020,25 +379,28 @@ function returnEmptyArray (response) {
|
||||
}
|
||||
}
|
||||
|
||||
function processPost (request, response, callback) {
|
||||
let data = ''
|
||||
if (typeof callback !== 'function') return null
|
||||
function respondWithSourceCode (requestParameters, response) {
|
||||
let devTeam = requestParameters[2]
|
||||
let codeName = requestParameters[3]
|
||||
let moduleName = requestParameters[4]
|
||||
|
||||
if (request.method == 'POST') {
|
||||
request.on('data', function (pData) {
|
||||
data += pData
|
||||
if (data.length > 1e6) {
|
||||
data = ''
|
||||
response.writeHead(413, { 'Content-Type': 'text/plain' }).end()
|
||||
request.connection.destroy()
|
||||
}
|
||||
})
|
||||
let filePath = devTeam + '/plotters/' + codeName + '/' + moduleName
|
||||
|
||||
request.on('end', function () {
|
||||
callback(data)
|
||||
})
|
||||
} else {
|
||||
response.writeHead(405, { 'Content-Type': 'text/plain' })
|
||||
response.end()
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user