createContainer function implemented

This commit is contained in:
Luis Fernando Molina committed 2018-07-02 13:09:41 +02:00
1 parent 86487a8346
commit 6ca5036540
3 files changed
+208 -25

No files matched your search

+140 -7
View File
@@ -30,10 +30,11 @@
/*
Procedure to create a new Team, User and Bot:
1. Add it to the Ecosystem.
2. Agregarlo al archivo de sessiones. --> copiar la session local a Develop
3. Crear el container del nuevo devTeam.
1. Create Continer. This will also tell us if the Team name is not already in use. FALTA ERROR HANDLING Y EN STORAGE EL LOG DE ERRORS
2. Add it to the Ecosystem.
3. Add it to Sessions.
4. Crear el folder del nuevo devTeam en el container aaplatform.
5. Copiar el bot a devTeam/bots --> Cambiarle el nombre al folder
6. Modificar la configuracion del bot reemplazando el devTeam y el Nombre.
@@ -45,7 +46,28 @@
*/
addToEcosystem();
createContainer();
function createContainer() {
if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> createContainer -> Entering function."); }
storage.createContainer(pTeamCodeName, onContainerCreated);
function onContainerCreated(err) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log("[ERROR] TeamSetup -> newTeam -> createContainer -> onContainerCreated -> Could not create the container. ");
console.log("[ERROR] TeamSetup -> newTeam -> createContainer -> onContainerCreated -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
callBackFunction(global.DEFAULT_OK_RESPONSE);
}
}
function addToEcosystem() {
@@ -70,6 +92,7 @@
return;
}
pFileContent = pFileContent.trim();
let ecosystem = JSON.parse(pFileContent);
let newTeam = {
@@ -133,11 +156,121 @@
function addToSessions() {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> addToSessions -> Entering function."); }
storage.readData("AdvancedAlgos", "AAPlatform", "open.sessions.json", false, onDataRead);
function onDataRead(err, pFileContent) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> addToSessions -> onDataRead -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> onDataRead -> Could not read a file. ");
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> onDataRead -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
pFileContent = pFileContent.trim();
let sessions = JSON.parse(pFileContent);
let token = createRandomToken();
function createRandomToken() {
let text = "";
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 128; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
let newSession = {
sessionToken: token,
userName: pUserName,
devTeams: [
{
codeName: pTeamCodeName,
displayName: pTeamDisplayName,
userBots: [
{
displayName: pBotName,
codeName: pBotName,
type: "Trading",
repo: pBotName + "-Trading-Bot",
processes: [
{
name: "Trading-Process"
}
]
}
],
devTeamDependencies: ["AAMasters", "AAVikings"]
}
],
exchangeKeys: [
{
exchange: "Poloniex",
key: "",
secret: ""
}
]
};
sessions.push(newSession);
let fileContent = JSON.stringify(sessions);
storage.writeData("AdvancedAlgos", "AAPlatform", "open.sessions.json", fileContent, onDataWritten);
function onDataWritten(err) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] TeamSetup -> newTeam -> addToSessions -> onDataRead -> onDataWritten -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> onDataRead -> onDataWritten -> Could not write a file. ");
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> onDataRead -> onDataWritten -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
createContainer();
} catch (err) {
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> onDataRead -> onDataWritten -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
} catch (err) {
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> onDataRead -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
} catch (err) {
console.log("[ERROR] TeamSetup -> newTeam -> addToSessions -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
callBackFunction(global.DEFAULT_OK_RESPONSE);
} catch (err) {
console.log("[ERROR] TeamSetup -> newTeam -> err.message = " + err.message);
+1 -1
View File
@@ -21,7 +21,7 @@
let storage = STORAGE.newStorage();
storage.initialize(undefined, pServerConfig);
storage.readData("AdvancedAlgos", "AAPlatform", "Open.Sessions.json", false, onData);
storage.readData("AdvancedAlgos", "AAPlatform", "open.sessions.json", false, onData);
function onData(err, pText) {
+67 -17
View File
@@ -3,6 +3,7 @@
let thisObject = {
readData: readData,
writeData: writeData,
createContainer: createContainer,
initialize: initialize
}
@@ -114,12 +115,10 @@
try {
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pOrg = " + pOrg); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pPath = " + pPath); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pFile = " + pFile); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> " + pOrg + '.' + pPath + '.' + pFile + " NOT found at cache."); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pOrg = " + pOrg); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pPath = " + pPath); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pFile = " + pFile); }
let storage = require('azure-storage');
let connectionString;
@@ -149,18 +148,17 @@
try {
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
if (LOG_FILE_CONTENT === true) { console.log("[INFO] API -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pOrg = " + pOrg); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pPath = " + pPath); }
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pFile = " + pFile); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pOrg = " + pOrg); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pPath = " + pPath); }
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pFile = " + pFile); }
if (err !== null || text === null) {
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> Error Received from API Library. "); }
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> Returning an empty JSON object string. "); }
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> writeData -> onFileCreated -> Error Received from Storage Library. "); }
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
@@ -170,13 +168,65 @@
callBackFunction(global.DEFAULT_OK_RESPONSE);
} catch (err) {
console.log("[ERROR] API -> writeData -> onFileCreated -> err.message = " + err.message);
console.log("[ERROR] Storage -> writeData -> onFileCreated -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
} catch (err) {
console.log("[ERROR] API -> writeData -> err.message = " + err.message);
console.log("[ERROR] Storage -> writeData -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function createContainer(pContainerName, pPath, pFile, pFileContent, callBackFunction) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> createContainer -> Entering function."); }
if (CONSOLE_LOG === true) { console.log("[INFO] 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);
pContainerName.toLowerCase();
blobService.createContainer(pContainerName, onContainerCreated);
function onContainerCreated(err) {
if (err) {
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> createContainer -> onContainerCreated -> Error Received from Storage Library. "); }
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> createContainer -> onContainerCreated -> err = " + JSON.stringify(err)); }
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
callBackFunction(global.DEFAULT_OK_RESPONSE);
}
} catch (err) {
console.log("[ERROR] Storage -> createContainer -> err.message = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}