Merge pull request #44 from AAVikings/develop
Storage and session management change
This commit is contained in:
26 files changed
+414
-59211
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
|
||||
|
||||
+224
-25
@@ -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,31 +13,28 @@ 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',
|
||||
'MQService',
|
||||
|
||||
'ChartsSpace/ChartUtilities.js',
|
||||
'ChartsSpace/PlottersManager.js',
|
||||
'ChartsSpace/TimelineChart.js',
|
||||
'ChartsSpace/TimeMachine.js',
|
||||
'ChartsSpace/ViewPort.js',
|
||||
'ChartsSpace/TimeLineCoordinateSystem.js',
|
||||
'ChartsSpace/ChartUtilities.js',
|
||||
'ChartsSpace/PlottersManager.js',
|
||||
'ChartsSpace/TimelineChart.js',
|
||||
'ChartsSpace/TimeMachine.js',
|
||||
'ChartsSpace/ViewPort.js',
|
||||
'ChartsSpace/TimeLineCoordinateSystem.js',
|
||||
|
||||
'TopSpace/CurrentEvent.js',
|
||||
'TopSpace/EndUser.js',
|
||||
'TopSpace/Login.js',
|
||||
|
||||
'StrategySpace/StrategizerGateway.js',
|
||||
@@ -88,14 +84,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',
|
||||
@@ -113,12 +109,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 {
|
||||
@@ -134,7 +130,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.') }
|
||||
@@ -160,4 +156,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"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user