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

This commit is contained in:
Luis Fernando Molina committed 2019-07-30 10:20:36 +02:00
commit cdc438957f
5 files changed
+179 -105

No files matched your search

+37 -21
View File
@@ -1,13 +1,23 @@
const axios = require('axios')
let fs = require('fs')
const { promisify } = require('util')
const readFileAsync = promisify(fs.readFile);
exports.getEcosystem = async function () {
try {
if (!global.ECOSYSTEM) {
const ecosystemResponse = await axios({
url: process.env.GATEWAY_ENDPOINT_K8S,
method: 'post',
data: {
query: `
try {
if (!global.ECOSYSTEM) {
let executionOnCloud = false
if (process.env.ON_CLOUD !== undefined) {
executionOnCloud = JSON.parse(process.env.ON_CLOUD)
}
if (executionOnCloud) {
const ecosystemResponse = await axios({
url: process.env.GATEWAY_ENDPOINT_K8S,
method: 'post',
data: {
query: `
query {
web_GetEcosystem {
id
@@ -52,21 +62,27 @@ exports.getEcosystem = async function () {
}
}
`
},
headers: {
authorization: process.env.AUTHORIZATION
}
})
//TODO Competition hosts not retrieved currently
},
headers: {
authorization: process.env.AUTHORIZATION
}
})
//TODO Competition hosts not retrieved currently
if (ecosystemResponse.data.errors)
throw new Error(ecosystemResponse.data.errors[0].message)
if (ecosystemResponse.data.errors)
throw new Error(ecosystemResponse.data.errors[0].message)
global.ECOSYSTEM = ecosystemResponse.data.data.web_GetEcosystem;
}
return global.ECOSYSTEM
} catch (error) {
throw new Error('There has been an error getting the Ecosystem: ', error)
global.ECOSYSTEM = ecosystemResponse.data.data.web_GetEcosystem
} else {
let fileLocation = process.env.CONFIG_PATH + 'ecosystem.json'
let ecosystem = await readFileAsync(fileLocation, { encoding: 'utf8' })
global.ECOSYSTEM = JSON.parse(ecosystem)
}
}
return global.ECOSYSTEM
} catch (error) {
throw new Error('There has been an error getting the Ecosystem: ', error)
}
}
+100 -51
View File
@@ -1,5 +1,10 @@
const axios = require('axios')
const Ecosystem = require('./Ecosystem')
let fs = require('fs')
const { promisify } = require('util')
const readFileAsync = promisify(fs.readFile)
const writeFileAsync = promisify(fs.writeFile)
const path = require('path')
exports.newFileStorage = function newFileStorage() {
const MODULE_NAME = 'FileStorage'
@@ -40,47 +45,54 @@ exports.newFileStorage = function newFileStorage() {
}
async function getTextFile(container, filePath, callBackFunction) {
try {
logInfo('getTextFile: ' + container.toLowerCase() + '/...' + filePath.substring(filePath.length - 110, filePath.length))
logInfo('getTextFile: ' + container.toLowerCase() + '/...' + filePath.substring(filePath.length - 110, filePath.length))
try {
let host = await getDevTeamHost(container)
let response = await axios({
url: host.url + 'graphql',
method: 'post',
data: {
query: `
query web_FileContent($file: web_FileInput){
web_FileContent(file: $file)
}
`,
variables: {
file: {
container: container.toLowerCase(),
filePath,
storage: host.storage,
accessKey: host.accessKey
if (host.url.indexOf('localhost') !== -1) {
let fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath
let fileContent = await readFileAsync(fileLocation)
callBackFunction(global.DEFAULT_OK_RESPONSE, fileContent.toString())
} else {
let response = await axios({
url: host.url + 'graphql',
method: 'post',
data: {
query: `
query web_FileContent($file: web_FileInput){
web_FileContent(file: $file)
}
`,
variables: {
file: {
container: container.toLowerCase(),
filePath,
storage: host.storage,
accessKey: host.accessKey
}
}
}
})
if (response.data.errors) {
callBackFunction({ code: response.data.errors[0] })
return
}
})
if (response.data.errors) {
callBackFunction({ code: response.data.errors[0] })
return
if (response.data.data.web_FileContent) {
callBackFunction(global.DEFAULT_OK_RESPONSE, response.data.data.web_FileContent)
} else {
callBackFunction({ code: 'The specified key does not exist.' })
}
}
if (response.data.data.web_FileContent) {
callBackFunction(global.DEFAULT_OK_RESPONSE, response.data.data.web_FileContent)
} else {
callBackFunction({ code: 'The specified key does not exist.' })
}
} catch (err) {
if (verifyRetry(err.code) && currentRetryGetTextFile < MAX_RETRY) {
currentRetryGetTextFile++
logInfo('getTextFile -> Retrying connection to the server because received error: ' + err.code + '. Retry #: ' + currentRetryGetTextFile)
getTextFile(container, filePath, callBackFunction)
} else if (err.code === 'ENOENT') {
callBackFunction({ code: 'The specified key does not exist.' })
} else {
currentRetryGetTextFile = 0
logError('getTextFile -> error = ' + err.message)
@@ -90,40 +102,48 @@ exports.newFileStorage = function newFileStorage() {
}
async function createTextFile(container, filePath, fileContent, callBackFunction) {
try {
logInfo('createTextFile -> Entering function: ' + container.toLowerCase() + '/...' + filePath.substring(filePath.length - 110, filePath.length))
logInfo('createTextFile -> Entering function: ' + container.toLowerCase() + '/...' + filePath.substring(filePath.length - 110, filePath.length))
try {
let host = await getDevTeamHost(container)
let response = await axios({
url: process.env.GATEWAY_ENDPOINT_K8S,
method: 'post',
data: {
query: `
if (host.url.indexOf('localhost') !== -1) {
let fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath
let directoryPath = fileLocation.substring(0, fileLocation.lastIndexOf('/') + 1);
mkDirByPathSync(directoryPath)
await writeFileAsync(fileLocation, fileContent)
callBackFunction(global.DEFAULT_OK_RESPONSE)
} else {
let response = await axios({
url: process.env.GATEWAY_ENDPOINT_K8S,
method: 'post',
data: {
query: `
mutation web_CreateFile($file: web_FileInput){
web_CreateFile(file: $file)
}
`,
variables: {
file: {
container: container.toLowerCase(),
filePath,
storage: 'localStorage',
accessKey: host.ownerKey,
fileContent
variables: {
file: {
container: container.toLowerCase(),
filePath,
storage: 'localStorage',
accessKey: host.ownerKey,
fileContent
}
}
}
}
})
})
if (!response || response.data.errors) {
let customErr = {
result: global.CUSTOM_FAIL_RESPONSE.result,
message: response.data.errors[0]
if (!response || response.data.errors) {
let customErr = {
result: global.CUSTOM_FAIL_RESPONSE.result,
message: response.data.errors[0]
}
callBackFunction(customErr)
} else {
callBackFunction(global.DEFAULT_OK_RESPONSE)
}
callBackFunction(customErr)
} else {
callBackFunction(global.DEFAULT_OK_RESPONSE)
}
} catch (err) {
@@ -158,4 +178,33 @@ exports.newFileStorage = function newFileStorage() {
}
return false
}
function mkDirByPathSync(targetDir, { isRelativeToScript = false } = {}) {
const sep = path.sep;
const initDir = path.isAbsolute(targetDir) ? sep : '';
const baseDir = isRelativeToScript ? __dirname : '.';
return targetDir.split(sep).reduce((parentDir, childDir) => {
const curDir = path.resolve(baseDir, parentDir, childDir);
try {
fs.mkdirSync(curDir);
} catch (err) {
if (err.code === 'EEXIST') { // curDir already exists!
return curDir;
}
// To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
if (err.code === 'ENOENT') { // Throw the original parentDir error on curDir `ENOENT` failure.
throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
}
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
if (!caughtErr || caughtErr && curDir === path.resolve(targetDir)) {
throw err; // Throw if it's just the last created dir.
}
}
return curDir;
}, initDir);
}
}
+28 -18
View File
@@ -1,38 +1,48 @@
const axios = require('axios')
let fs = require('fs')
const { promisify } = require('util')
const readFileAsync = promisify(fs.readFile);
exports.getStrategy = async function () {
try {
if (!global.STRATEGY) {
let fbSlug = process.env.BOT
if (process.env.TEST_FB !== undefined) {
fbSlug = process.env.TEST_FB
let executionOnCloud = false
if (process.env.ON_CLOUD !== undefined) {
executionOnCloud = JSON.parse(process.env.ON_CLOUD)
}
const strategizerResponse = await axios({
url: process.env.GATEWAY_ENDPOINT_K8S,
method: 'post',
data: {
query: `
if (executionOnCloud) {
const strategizerResponse = await axios({
url: process.env.GATEWAY_ENDPOINT_K8S,
method: 'post',
data: {
query: `
query($fbSlug: String!){
strategizer_TradingSystemByFb(fbSlug: $fbSlug){
data
}
}
`,
variables: {
fbSlug: fbSlug
variables: {
fbSlug: process.env.BOT
},
},
},
headers: {
authorization: process.env.AUTHORIZATION
}
})
headers: {
authorization: process.env.AUTHORIZATION
}
})
if (strategizerResponse.data.errors)
throw new Error(strategizerResponse.data.errors[0].message)
if (strategizerResponse.data.errors)
throw new Error(strategizerResponse.data.errors[0].message)
global.STRATEGY = strategizerResponse.data.data.strategizer_TradingSystemByFb.data;
global.STRATEGY = strategizerResponse.data.data.strategizer_TradingSystemByFb.data;
} else {
let fileLocation = process.env.CONFIG_PATH + 'userConfig.json'
let strategy = await readFileAsync(fileLocation, { encoding: 'utf8' })
global.STRATEGY = JSON.parse(strategy)
}
}
return global.STRATEGY
} catch (error) {
+13 -14
View File
@@ -1,23 +1,22 @@
{
"name": "@superalgos/clone-executor",
"version": "1.0.48",
"version": "1.0.51",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@superalgos/exchange-gateway": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/@superalgos/exchange-gateway/-/exchange-gateway-0.0.9.tgz",
"integrity": "sha512-wuCPM9xWeDUBoZRkrDOB+abobyW3ZTNEzGvuaFH1wLpUxeNUCKjYMH1v/CJfAJunP78OfVQJ/VrHOLgYKFaBeA==",
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/@superalgos/exchange-gateway/-/exchange-gateway-0.0.10.tgz",
"integrity": "sha512-VsiGeEyqD7NXvn2tFoqqz036WRBtzy6HvpbXqhl/+xG4SMbo2w9hb6AdAeH4KxuU2S7l/oO8zI9d15f30Q191Q==",
"requires": {
"axios": "0.19.0",
"dotenv": "8.0.0",
"lodash": "4.17.11",
"nonce": "1.0.4",
"querystring": "0.2.0",
"request": "2.88.0",
"retry": "0.12.0",
"superagent": "5.1.0",
"underscore": "1.9.1"
"nonce": "^1.0.4",
"querystring": "^0.2.0",
"request": "^2.88.0",
"retry": "^0.12.0",
"superagent": "^5.0.2",
"underscore": "^1.9.1"
}
},
"@superalgos/mqservice": {
@@ -541,9 +540,9 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"semver": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.2.0.tgz",
"integrity": "sha512-jdFC1VdUGT/2Scgbimf7FSx9iJLXoqfglSF+gJeuNWVpiE37OIbc1jywR/GJyFdz3mnkz2/id0L0J/cr0izR5A=="
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
},
"simple-swizzle": {
"version": "0.2.2",
+1 -1
View File
@@ -13,7 +13,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@superalgos/exchange-gateway": "0.0.9",
"@superalgos/exchange-gateway": "0.0.10",
"@superalgos/mqservice": "^0.0.17",
"axios": "^0.19.0",
"dotenv": "^8.0.0",