Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Matias committed 2019-04-15 10:07:06 -03:00
commit 7a8757bbda
11 files changed
+585 -710

No files matched your search

+8 -1
View File
@@ -5,4 +5,11 @@ bin/*
node_modules/*
this.server.config.json
.env
.env
dependency/
\.nyc_output/
coverage/*
\.vscode/
+45 -78
View File
@@ -1,18 +1,8 @@
const {
Aborter,
BlobURL,
BlockBlobURL,
ContainerURL,
ServiceURL,
StorageURL,
SharedKeyCredential
} = require("@azure/storage-blob")
const beautify = require("json-beautify");
const beautify = require("json-beautify")
const { logger } = require('../logs/logger')
const util = require('util')
exports.newCopySimulator = function newCopySimulator() {
exports.newCopySimulator = function newCopySimulator(pStorage) {
let thisObject = {
getFileContent: getFileContent,
@@ -21,36 +11,15 @@ exports.newCopySimulator = function newCopySimulator() {
removeSimulator: removeSimulator
}
let serviceURL = getServiceURL();
let storage = pStorage
return thisObject;
function getServiceURL() {
// Enter your storage account name and shared key
const account = process.env.STORAGE_BASE_URL;
const accountKey = process.env.STORAGE_CONNECTION_STRING;
// Use SharedKeyCredential with storage account and account key
const sharedKeyCredential = new SharedKeyCredential(account, accountKey);
// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
// List containers
const serviceURL = new ServiceURL(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
pipeline
);
logger.info("Connected to te file Storage.")
return serviceURL
}
return thisObject
async function copySimulator(pTeamCodeName, pBotCodeName, pBotDisplayName) {
try {
logger.info('copySimulator started for bot %s', pBotCodeName)
let templatePath = "aaplatform/AATemplate/bots/AAJason-Indicator-Bot"
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")
@@ -101,11 +70,11 @@ exports.newCopySimulator = function newCopySimulator() {
// Write the new files
let newSimulatorName = "simulator-" + pBotCodeName + "-Indicator-Bot"
let newSimulatorPath = "aaplatform/" + pTeamCodeName + "/bots/" + newSimulatorName
await writeFileContent(newSimulatorPath, "Commons.js", commons)
await writeFileContent(newSimulatorPath, "this.bot.config.json", beautify(parsedConfig, null, 2, 80))
await writeFileContent(newSimulatorPath + "/Multi-Period-Daily", "User.Bot.js", codeDaily)
await writeFileContent(newSimulatorPath + "/Multi-Period-Market", "User.Bot.js", codeMarket)
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)
@@ -121,11 +90,11 @@ exports.newCopySimulator = function newCopySimulator() {
// Delete simulator code
let newSimulatorName = "simulator-" + pBotCodeName + "-Indicator-Bot"
let newSimulatorPath = "aaplatform/" + pTeamCodeName + "/bots/" + newSimulatorName
await deleteBlob(newSimulatorPath, "Commons.js")
await deleteBlob(newSimulatorPath, "this.bot.config.json")
await deleteBlob(newSimulatorPath + "/Multi-Period-Daily", "User.Bot.js")
await deleteBlob(newSimulatorPath + "/Multi-Period-Market", "User.Bot.js")
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)
@@ -136,44 +105,42 @@ exports.newCopySimulator = function newCopySimulator() {
}
async function getFileContent(containerName, blobName) {
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
let downloadResponse = await blockBlobURL.download(Aborter.none, 0)
return await streamToString(downloadResponse.readableStreamBody)
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(containerName, blobName, content) {
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
const blobURL = BlobURL.fromContainerURL(containerURL, blobName)
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL)
await blockBlobURL.upload(
Aborter.none,
content,
content.length
)
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(containerName, blobName) {
async function deleteBlob(teamName, containerName, blobName) {
try {
const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName)
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName)
await blockBlobURL.delete(Aborter.none)
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)
}
}
// A helper method used to read a Node.js readable stream into string
async function streamToString(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", data => {
chunks.push(data.toString());
});
readableStream.on("end", () => {
resolve(chunks.join(""));
});
readableStream.on("error", reject)
});
}
}
+20 -23
View File
@@ -6,16 +6,13 @@
initialize: initialize
}
let masterAppServerURL;
let storage;
let masterAppServerURL, storage
return thisObject;
function initialize(pServerConfig, pStorage) {
storage = pStorage;
masterAppServerURL = pServerConfig.masterAppServerURL
storage = pStorage
}
function newTeam(pTeamCodeName, pTeamDisplayName, pUserName, pBotCodeName, pBotDisplayName, pUserId, callBackFunction) {
@@ -308,7 +305,7 @@
}
const newCopySimulator = require("./CopySimulator")
let copySimulator = newCopySimulator.newCopySimulator()
let copySimulator = newCopySimulator.newCopySimulator(storage)
await copySimulator.copySimulator(pTeamCodeName, pBotCodeName, pBotDisplayName)
forkAACloud();
@@ -599,19 +596,19 @@
}
}
`, variables, function (req, res) {
if (res.status === 401) {
console.log('[ERROR] TeamSetup -> newTeam -> Error trying to save the session token at the Users Module');
console.log('[ERROR] TeamSetup -> newTeam -> res.status = 401');
}
}).then(res => {
if (res.errors) {
console.log('[ERROR] TeamSetup -> newTeam -> Error trying to save the session token at the Users Module');
console.log('[ERROR] TeamSetup -> newTeam -> res.errors = ' + res.errors);
}
}).catch(error => {
console.log('Error trying to save the session token at the Users Module');
console.log('[ERROR] TeamSetup -> newTeam -> errors = ' + errors);
});
if (res.status === 401) {
console.log('[ERROR] TeamSetup -> newTeam -> Error trying to save the session token at the Users Module');
console.log('[ERROR] TeamSetup -> newTeam -> res.status = 401');
}
}).then(res => {
if (res.errors) {
console.log('[ERROR] TeamSetup -> newTeam -> Error trying to save the session token at the Users Module');
console.log('[ERROR] TeamSetup -> newTeam -> res.errors = ' + res.errors);
}
}).catch(error => {
console.log('Error trying to save the session token at the Users Module');
console.log('[ERROR] TeamSetup -> newTeam -> errors = ' + errors);
});
} catch (err) {
@@ -656,7 +653,7 @@
"configFile": "this.bot.config.json"
},
{
"repo": "simulator-"+ pBotCodeName + "-Indicator-Bot",
"repo": "simulator-" + pBotCodeName + "-Indicator-Bot",
"configFile": "this.bot.config.json"
}
],
@@ -836,7 +833,7 @@
}
// TODO Fix-Me: this method is trying to remove from the container that was removed by the previous method.
// TODO Fix-Me: this method is trying to remove from the container that was removed by the previous method.
// It must remove the files from the aaplatform/team-name folder instead
function deleteBotConfig() {
@@ -885,7 +882,7 @@
}
const newCopySimulator = require("./CopySimulator")
let copySimulator = newCopySimulator.newCopySimulator()
let copySimulator = newCopySimulator.newCopySimulator(storage)
await copySimulator.removeSimulator(pTeamCodeName, pBotCodeName)
deleteAACloud();
Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 B

File renamed without changes.
+2 -1
View File
@@ -35,7 +35,6 @@ function newAppLoader() {
"MQService",
"BottomSpace/DeleteTradingHistory.js",
"BottomSpace/ChartAspectRatio.js",
"TopSpace/CurrentEvent.js",
"TopSpace/EndUser.js",
@@ -57,6 +56,7 @@ function newAppLoader() {
"Files/DailyFiles.js",
"Files/FileCursor.js",
"Files/FileSequence.js",
"Files/FileStorage.js",
"FloatingSpace/NoteSets.js",
"FloatingSpace/Note.js",
@@ -69,6 +69,7 @@ function newAppLoader() {
"Scales/ChartGrid.js",
"Scales/RightScale.js",
"Scales/TimeScale.js",
"BreakpointsBar.js",
"Plotter.js",
-42
View File
@@ -138,48 +138,6 @@ function callServer(pContentToSend, pPath, callBackFunction) {
}
function newFileStorage() {
thisObject = {
getBlobToText: getBlobToText
};
return thisObject;
function getBlobToText(pContainerName, pPath, callBackFunction) {
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
let response = JSON.parse(xhttp.responseText);
callBackFunction(response.err, response.text, "");
}
};
try {
let request = {
conatinerName: pContainerName,
path: pPath
};
request = JSON.stringify(request);
let path = "FileService";
let blob = new Blob([request], { type: 'text/plain' });
xhttp.open("POST", path, true);
xhttp.send(blob);
} catch (err) {
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] getBlobToText -> err.message = " & err.message); }
}
}
}
+18 -18
View File
@@ -3,8 +3,8 @@
let thisObject = {
readData: readData,
writeData: writeData,
createContainer: createContainer,
deleteContainer: deleteContainer,
createContainer: createContainer,
deleteContainer: deleteContainer,
deleteBlob: deleteBlob,
initialize: initialize
}
@@ -21,7 +21,7 @@
storageData = pStorageData;
serverConfig = pServerConfig;
minioClient = new Minio.Client({
endPoint: process.env.MINIO_END_POINT,
port: JSON.parse(process.env.MINIO_PORT),
@@ -29,7 +29,7 @@
accessKey: process.env.MINIO_ACCESS_KEY,
secretKey: process.env.MINIO_SECRET_KEY
})
}
function readData(pOrg, pPath, pFile, saveAtCache, callBackFunction) {
@@ -125,7 +125,7 @@
storageData.set(pOrg + '.' + pPath + '.' + pFile, text);
}
if (err !== null || text === null) {
if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> Error Received from Storage Library. "); }
@@ -139,19 +139,19 @@
/* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
try {
// 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);
}
// 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);
@@ -445,4 +445,4 @@
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
}
+3 -3
View File
@@ -80,7 +80,7 @@
if (err) {
onFileReceived(err, null, "Error retrieving file " + textFilename + " from bucket " + bucketName);
return
return
}
dataStream.on('data', function (chunk) {
data += chunk
@@ -319,7 +319,7 @@
/* ContainerAlreadyExists check */
if (JSON.stringify(err).indexOf("ContainerNotFound") > 0) {
if (err.code === "NoSuchBucket") {
let err = {
resutl: global.CUSTOM_FAIL_RESPONSE.result,
@@ -348,4 +348,4 @@
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
}
+489 -543
View File
File diff suppressed because it is too large. Load diff
-1
View File
@@ -7,7 +7,6 @@
"name": "Luis-Fernando-Molina"
},
"dependencies": {
"@azure/storage-blob": "^10.3.0",
"@octokit/rest": "^14.0.9",
"@superalgos/mqservice": "0.0.12",
"atob": "^2.1.2",