AACloud Config is 100% read from the cloud

This commit is contained in:
Luis Fernando Molina committed 2018-05-22 12:37:18 +02:00
1 parent af73e40a34
commit 6f83547b16
6 files changed
+145 -98

No files matched your search

+9 -9
View File
@@ -12,9 +12,7 @@ exports.newBlobStorage = function newBlobStorage(BOT) {
let storage = require('azure-storage');
const DEBUG_MODULE = require('./DebugLog');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
let logger;
let thisObject = {
@@ -27,7 +25,7 @@ exports.newBlobStorage = function newBlobStorage(BOT) {
let readOnlyBlobService;
let writeOnlyBlobService;
let containerName;
let environment = global.STORAGE_CONN_STRING_FOLDER;
let environment = global.CURRENT_ENVIRONMENT;
return thisObject;
@@ -35,24 +33,26 @@ exports.newBlobStorage = function newBlobStorage(BOT) {
try {
containerName = pDataOwner.toLowerCase();
if (disableLogging === true) {
FULL_LOG = false;
LOG_FILE_CONTENT = false;
} else {
logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
logger.fileName = MODULE_NAME + '.' + pDataOwner;
}
containerName = pDataOwner.toLowerCase();
logger.fileName = MODULE_NAME + '.' + pDataOwner.devTeam + '.' + pDataOwner.bot + '.' + containerName;
if (pDataOwner.environment !== undefined) { // This is use for data migration from one environment to the other.
environment = pDataOwner.environment;
logger.fileName = MODULE_NAME + '.' + pDataOwner.devTeam + '.' + pDataOwner.bot + '.' + containerName;
}
if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
+1 -1
View File
@@ -78,7 +78,7 @@ exports.newFileStorage = function newFileStorage(BOT) {
try {
let fs = require('fs');
filePath = '../' + 'Connection-Strings' + '/' + global.STORAGE_CONN_STRING_FOLDER + '/' + dataOwner + '.azure.storage.connstring';
filePath = '../' + 'Connection-Strings' + '/' + global.CURRENT_ENVIRONMENT + '/' + dataOwner + '.azure.storage.connstring';
let connObj = JSON.parse(fs.readFileSync(filePath, 'utf8'));
callBack(global.DEFAULT_OK_RESPONSE, connObj);
+125 -84
View File
@@ -2,6 +2,84 @@
exports.newRoot = function newRoot() {
/* Global constants definitions. */
/* Callbacks default responses. */
global.DEFAULT_OK_RESPONSE = {
result: "Ok",
message: "Operation Succeeded"
};
global.DEFAULT_FAIL_RESPONSE = {
result: "Fail",
message: "Operation Failed"
};
global.DEFAULT_RETRY_RESPONSE = {
result: "Retry",
message: "Retry Later"
};
global.CUSTOM_OK_RESPONSE = {
result: "Ok, but check Message",
message: "Custom Message"
};
global.CUSTOM_FAIL_RESPONSE = {
result: "Fail Because",
message: "Custom Message"
};
/* Current state of the art fixed parameters */
global.MARKET = {
assetA: "USDT",
assetB: "BTC",
};
/* Currently only one exchange is supported. */
global.EXCHANGE_NAME = "Poloniex";
/* This is the Execution Datetime */
global.EXECUTION_DATETIME = new Date();
/* Time Periods Definitions. */
global.marketFilesPeriods =
'[' +
'[' + 24 * 60 * 60 * 1000 + ',' + '"24-hs"' + ']' + ',' +
'[' + 12 * 60 * 60 * 1000 + ',' + '"12-hs"' + ']' + ',' +
'[' + 8 * 60 * 60 * 1000 + ',' + '"08-hs"' + ']' + ',' +
'[' + 6 * 60 * 60 * 1000 + ',' + '"06-hs"' + ']' + ',' +
'[' + 4 * 60 * 60 * 1000 + ',' + '"04-hs"' + ']' + ',' +
'[' + 3 * 60 * 60 * 1000 + ',' + '"03-hs"' + ']' + ',' +
'[' + 2 * 60 * 60 * 1000 + ',' + '"02-hs"' + ']' + ',' +
'[' + 1 * 60 * 60 * 1000 + ',' + '"01-hs"' + ']' + ']';
global.marketFilesPeriods = JSON.parse(global.marketFilesPeriods);
global.dailyFilePeriods =
'[' +
'[' + 45 * 60 * 1000 + ',' + '"45-min"' + ']' + ',' +
'[' + 40 * 60 * 1000 + ',' + '"40-min"' + ']' + ',' +
'[' + 30 * 60 * 1000 + ',' + '"30-min"' + ']' + ',' +
'[' + 20 * 60 * 1000 + ',' + '"20-min"' + ']' + ',' +
'[' + 15 * 60 * 1000 + ',' + '"15-min"' + ']' + ',' +
'[' + 10 * 60 * 1000 + ',' + '"10-min"' + ']' + ',' +
'[' + 05 * 60 * 1000 + ',' + '"05-min"' + ']' + ',' +
'[' + 04 * 60 * 1000 + ',' + '"04-min"' + ']' + ',' +
'[' + 03 * 60 * 1000 + ',' + '"03-min"' + ']' + ',' +
'[' + 02 * 60 * 1000 + ',' + '"02-min"' + ']' + ',' +
'[' + 01 * 60 * 1000 + ',' + '"01-min"' + ']' + ']';
global.dailyFilePeriods = JSON.parse(global.dailyFilePeriods);
const ROOT_DIR = './';
const MODULE_NAME = "Root";
let thisObject = {
initialize: initialize,
start: start
@@ -9,14 +87,56 @@ exports.newRoot = function newRoot() {
const FULL_LOG = true;
let cloudStorage;
return thisObject;
function initialize() {
function initialize(callBackFunction) {
try {
console.log("[INFO] Root -> initialize -> Entering function. ");
}
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
cloudStorage = BLOB_STORAGE.newBlobStorage();
cloudStorage.initialize("AAPlatform", onInizialized, true);
function onInizialized(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
let filePath = "AdvancedAlgos" + "/" + "AACloud";
let fileName = "this.config.json";
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
function onFileReceived(err, text) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log("[ERROR] Root -> initialize -> onInizialized -> onFileReceived -> err = " + err.message);
return;
}
try {
global.PLATFORM_CONFIG = JSON.parse(text);
callBackFunction();
} catch (err) {
console.log("[ERROR] Root -> initialize -> onInizialized -> onFileReceived -> err = " + err.message);
return;
}
}
} else {
console.log("[ERROR] Root -> initialize -> onInizialized -> err = " + err.message);
return;
}
}
}
catch (err) {
console.log("[ERROR] Root -> initialize -> err.message = " + err.message);
return;
}
function start() {
/* First thing to do is to read the config and guess which bot we will be running. */
@@ -35,93 +155,14 @@ exports.newRoot = function newRoot() {
return;
}
}
/* The following global variable tells the system if it is running on test mode or production. */
global.STORAGE_CONN_STRING_FOLDER = global.PLATFORM_CONFIG.storageConnStringFolder; // 'Testnet', 'Mixed' or 'Production', or whatever folder name the conn strings files are into.
function start() {
/* Now we will run according to what we see at the config file. */
const ROOT_DIR = './';
const MODULE_NAME = "Root";
const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog');
/* Global constants definitions. */
/* Callbacks default responses. */
global.DEFAULT_OK_RESPONSE = {
result: "Ok",
message: "Operation Succeeded"
};
global.DEFAULT_FAIL_RESPONSE = {
result: "Fail",
message: "Operation Failed"
};
global.DEFAULT_RETRY_RESPONSE = {
result: "Retry",
message: "Retry Later"
};
global.CUSTOM_OK_RESPONSE = {
result: "Ok, but check Message",
message: "Custom Message"
};
global.CUSTOM_FAIL_RESPONSE = {
result: "Fail Because",
message: "Custom Message"
};
/* Current state of the art fixed parameters */
global.MARKET = {
assetA: "USDT",
assetB: "BTC",
};
/* Currently only one exchange is supported. */
global.EXCHANGE_NAME = "Poloniex";
/* This is the Execution Datetime */
global.EXECUTION_DATETIME = new Date();
/* Time Periods Definitions. */
global.marketFilesPeriods =
'[' +
'[' + 24 * 60 * 60 * 1000 + ',' + '"24-hs"' + ']' + ',' +
'[' + 12 * 60 * 60 * 1000 + ',' + '"12-hs"' + ']' + ',' +
'[' + 8 * 60 * 60 * 1000 + ',' + '"08-hs"' + ']' + ',' +
'[' + 6 * 60 * 60 * 1000 + ',' + '"06-hs"' + ']' + ',' +
'[' + 4 * 60 * 60 * 1000 + ',' + '"04-hs"' + ']' + ',' +
'[' + 3 * 60 * 60 * 1000 + ',' + '"03-hs"' + ']' + ',' +
'[' + 2 * 60 * 60 * 1000 + ',' + '"02-hs"' + ']' + ',' +
'[' + 1 * 60 * 60 * 1000 + ',' + '"01-hs"' + ']' + ']';
global.marketFilesPeriods = JSON.parse(global.marketFilesPeriods);
global.dailyFilePeriods =
'[' +
'[' + 45 * 60 * 1000 + ',' + '"45-min"' + ']' + ',' +
'[' + 40 * 60 * 1000 + ',' + '"40-min"' + ']' + ',' +
'[' + 30 * 60 * 1000 + ',' + '"30-min"' + ']' + ',' +
'[' + 20 * 60 * 1000 + ',' + '"20-min"' + ']' + ',' +
'[' + 15 * 60 * 1000 + ',' + '"15-min"' + ']' + ',' +
'[' + 10 * 60 * 1000 + ',' + '"10-min"' + ']' + ',' +
'[' + 05 * 60 * 1000 + ',' + '"05-min"' + ']' + ',' +
'[' + 04 * 60 * 1000 + ',' + '"04-min"' + ']' + ',' +
'[' + 03 * 60 * 1000 + ',' + '"03-min"' + ']' + ',' +
'[' + 02 * 60 * 1000 + ',' + '"02-min"' + ']' + ',' +
'[' + 01 * 60 * 1000 + ',' + '"01-min"' + ']' + ']';
global.dailyFilePeriods = JSON.parse(global.dailyFilePeriods);
/* Small Function to fix numbers into strings in a cool way. */
function pad(str, max) {
+9 -2
View File
@@ -1,4 +1,8 @@
global.CURRENT_ENVIRONMENT = "Develop";
process.on('uncaughtException', function (err) {
console.log('[INFO] Run -> uncaughtException -> err.message = ' + err.message);
return;
@@ -53,8 +57,11 @@ function startRoot() {
const ROOT_MODULE = require(ROOT_DIR + 'Root');
let root = ROOT_MODULE.newRoot();
root.initialize();
root.start();
root.initialize(onInitialized);
function onInitialized() {
root.start();
}
}
+1 -1
View File
@@ -39,7 +39,7 @@
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
cloudStorage = BLOB_STORAGE.newBlobStorage(bot);
cloudStorage.initialize("AAPlatform", onInizialized, true);
cloudStorage.initialize("AAPlatform", onInizialized);
function onInizialized(err) {
-1
View File
@@ -15,6 +15,5 @@
}
],
"stopGracefully": false,
"storageConnStringFolder": "Develop",
"maxLogLoops": 5
}