Simultaneous Support of Azure and Minio
This commit is contained in:
1 parent
2360a541e8
commit
817b2ec38c
4 files changed
+865
-651
No files matched your search
@@ -26,12 +26,23 @@ exports.newAzureBlobBlobStorage = function newAzureBlobBlobStorage(BOT, logger)
|
||||
let containerName;
|
||||
let environment = global.CURRENT_ENVIRONMENT;
|
||||
|
||||
let Minio = require('minio'); // Temporary during migration
|
||||
let minioClient; // Temporary during migration
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pDataOwner, callBackFunction, disableLogging) {
|
||||
|
||||
try {
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
containerName = pDataOwner.toLowerCase();
|
||||
|
||||
if (pDataOwner.environment !== undefined) { // This is use for data migration from one environment to the other.
|
||||
@@ -118,6 +129,16 @@ exports.newAzureBlobBlobStorage = function newAzureBlobBlobStorage(BOT, logger)
|
||||
|
||||
writeOnlyBlobService.createBlockBlobFromText(containerName, pFolderPath + "/" + pFileName, pFileContent, onFileCreated);
|
||||
|
||||
/* REPLICATION TO MINIO */
|
||||
minioClient.putObject(containerName, pFolderPath + "/" + pFileName, pFileContent, 'text/plain', function (err) {
|
||||
console.log(MODULE_NAME, "[INFO] 'createTextFile' -> Replicating to MINIO -> File = " + pFolderPath + "/" + pFileName);
|
||||
|
||||
if (err) {
|
||||
console.log(MODULE_NAME, "[WARN] 'createTextFile' -> Replicating to MINIO -> err = " + err.message);
|
||||
}
|
||||
|
||||
}); // Temporary during migration
|
||||
|
||||
function onFileCreated(err, result, response) {
|
||||
|
||||
try {
|
||||
@@ -372,6 +393,16 @@ exports.newAzureBlobBlobStorage = function newAzureBlobBlobStorage(BOT, logger)
|
||||
} else {
|
||||
if (FULL_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[INFO] getTextFile -> onFileReceived -> File retrieved."); }
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, text);
|
||||
|
||||
/* REPLICATION TO MINIO */
|
||||
minioClient.putObject(containerName, pFolderPath + "/" + pFileName, text, 'text/plain', function (err, dataStream) {
|
||||
console.log(MODULE_NAME, "[INFO] 'getTextFile' -> onFileReceived -> Replicating to MINIO -> File = " + pFolderPath + "/" + pFileName);
|
||||
|
||||
if (err) {
|
||||
console.log(MODULE_NAME, "[WARN] 'getTextFile' -> onFileReceived -> Replicating to MINIO -> err = " + err.message);
|
||||
}
|
||||
|
||||
}); // Temporary during migration
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
|
||||
+44
-20
@@ -18,8 +18,6 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
getTextFile: getTextFile
|
||||
};
|
||||
|
||||
let readOnlyBlobService;
|
||||
let writeOnlyBlobService;
|
||||
let containerName;
|
||||
let environment = global.CURRENT_ENVIRONMENT;
|
||||
|
||||
@@ -82,12 +80,9 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
|
||||
function createTextFile(pFolderPath, pFileName, pFileContent, callBackFunction) {
|
||||
|
||||
if (writeOnlyBlobService === undefined) {
|
||||
|
||||
if (ERROR_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[ERROR] createTextFile -> initialize function not executed or failed. Can not process this request. Sorry."); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
if (ERROR_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[ERROR] createTextFile -> initialize function not executed or failed. Can not process this request. Sorry."); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
try {
|
||||
|
||||
@@ -98,7 +93,7 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
logger.write(MODULE_NAME, "[INFO] createTextFile -> pFileName = " + pFileName);
|
||||
}
|
||||
|
||||
writeOnlyBlobService.createBlockBlobFromText(containerName, pFolderPath + "/" + pFileName, pFileContent, onFileCreated);
|
||||
minioClient.putObject(containerName, pFolderPath + "/" + pFileName, pFileContent, 'text/plain', onFileCreated)
|
||||
|
||||
function onFileCreated(err, result, response) {
|
||||
|
||||
@@ -151,7 +146,7 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
|
||||
logger.write(MODULE_NAME, "[INFO] createTextFile -> onFileCreated -> secondTry -> Retrying to create the file.");
|
||||
|
||||
writeOnlyBlobService.createBlockBlobFromText(containerName, pFolderPath + "/" + pFileName, pFileContent, onSecondTry);
|
||||
minioClient.putObject(containerName, pFolderPath + "/" + pFileName, pFileContent, 'text/plain', onSecondTry)
|
||||
|
||||
function onSecondTry(err, result, response) {
|
||||
|
||||
@@ -208,13 +203,10 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
|
||||
function getTextFile(pFolderPath, pFileName, callBackFunction) {
|
||||
|
||||
if (readOnlyBlobService === undefined) {
|
||||
|
||||
if (ERROR_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[ERROR] getTextFile -> initialize function not executed or failed. Can not process this request. Sorry."); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ERROR_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[ERROR] getTextFile -> initialize function not executed or failed. Can not process this request. Sorry."); }
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true && logger !== undefined) {
|
||||
@@ -224,7 +216,23 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
logger.write(MODULE_NAME, "[INFO] getTextFile -> pFileName = " + pFileName);
|
||||
}
|
||||
|
||||
readOnlyBlobService.getBlobToText(containerName, pFolderPath + "/" + pFileName, onFileReceived);
|
||||
minioClient.getObject(containerName, pFolderPath + "/" + pFileName, 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) {
|
||||
|
||||
@@ -272,7 +280,23 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
|
||||
logger.write(MODULE_NAME, "[INFO] getTextFile -> onFileReceived -> secondTry -> Retrying to get the file.");
|
||||
|
||||
readOnlyBlobService.getBlobToText(containerName, pFolderPath + "/" + pFileName, onSecondTry);
|
||||
minioClient.getObject(containerName, pFolderPath + "/" + pFileName, function (err, dataStream) {
|
||||
let data = '';
|
||||
|
||||
if (err) {
|
||||
onSecondTry(err, null, "Error retrieving file " + textFilename + " from bucket " + bucketName);
|
||||
return
|
||||
}
|
||||
dataStream.on('data', function (chunk) {
|
||||
data += chunk
|
||||
})
|
||||
dataStream.on('end', function () {
|
||||
onSecondTry(null, data, "Data retrieved.");
|
||||
})
|
||||
dataStream.on('error', function (err) {
|
||||
onSecondTry(err, null, "Error on data stream while retrieving file " + textFilename + " from bucket " + bucketName);
|
||||
})
|
||||
})
|
||||
|
||||
function onSecondTry(err, text, response) {
|
||||
|
||||
@@ -307,7 +331,7 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger)
|
||||
}
|
||||
}
|
||||
|
||||
if (err.code === "BlobNotFound") {
|
||||
if (err.code === "NoSuchKey") {
|
||||
|
||||
/* This is how Minio tell us the file does not exist. */
|
||||
|
||||
|
||||
Generated
+789
-631
File diff suppressed because it is too large.
Load diff
@@ -19,6 +19,7 @@
|
||||
"graphql": "^14.0.2",
|
||||
"jsonwebtoken": "^8.4.0",
|
||||
"lodash": "^4.17.11",
|
||||
"minio": "^7.0.5",
|
||||
"nodemailer": "^4.6.8",
|
||||
"nonce": "^1.0.4",
|
||||
"querystring": "^0.2.0",
|
||||
|
||||
Reference in new issue
Block a user