[undone] removed Ali-OSS related logic from irext console
This commit is contained in:
@@ -165,19 +165,9 @@ exports.downloadRemoteBinCachedWorkUnit = function(remoteIndexID, callback) {
|
||||
logger.info("file " + localBinFileName + " already exists, serve directly");
|
||||
callback(error, localBinFileName);
|
||||
} else {
|
||||
logger.info("file " + localBinFileName + " does not exist, download it from OSS");
|
||||
var aliOss = new OSS(OSS_HOST, DEBUG_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
||||
aliOss.serveObjectByID(fileName, localBinFileName,
|
||||
function (serveObjectErr, response) {
|
||||
if (errorCode.SUCCESS.code == serveObjectErr) {
|
||||
logger.info("serve remote binary object and cached successfully");
|
||||
callback(error, localBinFileName);
|
||||
} else {
|
||||
logger.info("serve remote binary object and cached failed");
|
||||
error = errorCode.FAILED;
|
||||
callback(error, null);
|
||||
}
|
||||
});
|
||||
logger.info("file " + localBinFileName + " does not exist");
|
||||
error = errorCode.FAILED;
|
||||
callback(error, NULL);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -290,7 +280,8 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
||||
// step 3, if successfully created tag binary file, upload binary to OSS
|
||||
logger.info("remote " + remoteIndex.remote_name + " has successfully been generated");
|
||||
outputPath = fileDir;
|
||||
newACRemoteNumber = remoteIndex.remote_name.substring(remoteIndex.remote_name.lastIndexOf('_') + 1);
|
||||
newACRemoteNumber = remoteIndex.remote_name
|
||||
.substring(remoteIndex.remote_name.lastIndexOf('_') + 1);
|
||||
outputFilePath = outputPath + "/irda_" + tagType + "_" + newACRemoteNumber + ".bin";
|
||||
logger.info("final tag binary output file = " + outputFilePath);
|
||||
|
||||
@@ -302,7 +293,8 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
||||
logger.info("read remote binary file successfully, file size = " + fileData.length);
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 3.5, check if this remote index is already contained in remote index list by binary
|
||||
// step 3.5, check if this remote index is already
|
||||
// contained in remote index list by binary
|
||||
var fileHash = checksum(fileData);
|
||||
logger.info("hash of binary file = " + fileHash);
|
||||
var conditions = {
|
||||
@@ -318,67 +310,48 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
||||
logger.info("this remote is duplicated by binary value");
|
||||
callback(errorCode.DUPLICATED_REMOTE_CODE, null);
|
||||
} else {
|
||||
var aliOss = new OSS(OSS_HOST, DEBUG_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
||||
// do not specify objectID for newly created media
|
||||
outputFileName = "irda_" + tagType + "_" + newACRemoteNumber + ".bin";
|
||||
aliOss.saveObjectFromBinary(outputFileName, fileData, contentType,
|
||||
function (createObjectErr, objectID) {
|
||||
if (errorCode.SUCCESS.code == createObjectErr) {
|
||||
// deprecated: do not delete the output binary file for future use
|
||||
//////////////////////////////////////
|
||||
// step 4, create remote index record in db
|
||||
remoteIndex.remote_name = newACRemoteNumber + "";
|
||||
// step 4, create remote index record in db
|
||||
remoteIndex.remote_name = newACRemoteNumber + "";
|
||||
|
||||
newRemoteIndex = {
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
brand_name: remoteIndex.brand_name,
|
||||
protocol: tagType,
|
||||
remote: remoteIndex.remote_name,
|
||||
remote_map: tagType + "_" + newACRemoteNumber,
|
||||
priority: remoteIndex.priority,
|
||||
sub_cate: subCate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
category_name_tw: remoteIndex.category_name_tw,
|
||||
brand_name_tw: remoteIndex.brand_name_tw,
|
||||
binary_md5: fileHash,
|
||||
input_source: inputSource
|
||||
};
|
||||
newRemoteIndex = {
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
brand_name: remoteIndex.brand_name,
|
||||
protocol: tagType,
|
||||
remote: remoteIndex.remote_name,
|
||||
remote_map: tagType + "_" + newACRemoteNumber,
|
||||
priority: remoteIndex.priority,
|
||||
sub_cate: subCate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
category_name_tw: remoteIndex.category_name_tw,
|
||||
brand_name_tw: remoteIndex.brand_name_tw,
|
||||
binary_md5: fileHash,
|
||||
input_source: inputSource
|
||||
};
|
||||
|
||||
// see if this remote index is already in database
|
||||
var conditions = {
|
||||
//category_id: remoteIndex.category_id,
|
||||
//brand_id: remoteIndex.brand_id,
|
||||
protocol: tagType,
|
||||
remote: remoteIndex.remote_name,
|
||||
status: orm.gt(enums.ITEM_INVALID)
|
||||
};
|
||||
// see if this remote index is already in database
|
||||
var conditions = {
|
||||
//category_id: remoteIndex.category_id,
|
||||
//brand_id: remoteIndex.brand_id,
|
||||
protocol: tagType,
|
||||
remote: remoteIndex.remote_name,
|
||||
status: orm.gt(enums.ITEM_INVALID)
|
||||
};
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition(conditions,
|
||||
function(findRemoteIndexErr, remoteIndexes) {
|
||||
if(errorCode.SUCCESS.code == findRemoteIndexErr.code &&
|
||||
remoteIndexes &&
|
||||
remoteIndexes.length > 0) {
|
||||
logger.info("remote index already exists");
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition(conditions,
|
||||
function(findRemoteIndexErr, remoteIndexes) {
|
||||
if(errorCode.SUCCESS.code == findRemoteIndexErr.code &&
|
||||
remoteIndexes &&
|
||||
remoteIndexes.length > 0) {
|
||||
logger.info("remote index already exists, failed this time");
|
||||
/*
|
||||
RemoteIndex.updateRemoteIndex(remoteIndexes[0].id,
|
||||
newRemoteIndex,
|
||||
function(updateRemoteIndexErr, updatedRemoteIndex) {
|
||||
callback(updateRemoteIndexErr, updatedRemoteIndex);
|
||||
});
|
||||
*/
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
RemoteIndex.createRemoteIndex(newRemoteIndex,
|
||||
function(createRemoteIndexErr, createdRemoteIndex) {
|
||||
callback(createRemoteIndexErr, createdRemoteIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.error("save file object to OSS failed : " + createObjectErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
RemoteIndex.createRemoteIndex(newRemoteIndex,
|
||||
function(createRemoteIndexErr, createdRemoteIndex) {
|
||||
callback(createRemoteIndexErr, createdRemoteIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -401,195 +374,166 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
||||
protocolPath = fileDir + "/" + PROTOCOL_PATH + "/";
|
||||
protocolFileName = remoteIndex.protocol_name + ".bin";
|
||||
localProtocolFileName = protocolPath + remoteIndex.protocol_name + ".bin";
|
||||
var aliOss = new OSS(OSS_HOST, PROTOCOL_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
||||
aliOss.serveObjectByID(protocolFileName, localProtocolFileName,
|
||||
function (serveObjectErr, response) {
|
||||
if (errorCode.SUCCESS.code == serveObjectErr) {
|
||||
logger.info("protocol binary fetched from OSS, continue processing with remote file");
|
||||
remoteXMLFilePath = fileDir + "/" + remoteIndex.remote_name + ".xml";
|
||||
logger.info("remote XML file path = " + remoteXMLFilePath);
|
||||
logger.info("protocol binary fetched from OSS, continue processing with remote file");
|
||||
remoteXMLFilePath = fileDir + "/" + remoteIndex.remote_name + ".xml";
|
||||
logger.info("remote XML file path = " + remoteXMLFilePath);
|
||||
//////////////////////////////////////
|
||||
// step 2, parse python run-time path, python file name and user arguments
|
||||
pythonRuntimeDir = fileDir + "/" + remoteDir;
|
||||
userArgs.length = 0;
|
||||
// python s_$category.py [remote_xml_file_abs_file] [remote_xml_file_name] [remote_xml_dir_abs_path]
|
||||
userArgs.push(remoteXMLFilePath);
|
||||
userArgs.push(remoteIndex.remote_name + ".xml");
|
||||
userArgs.push(fileDir + "/");
|
||||
userArgs.push(categoryID);
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 3, try executing remote encoding script
|
||||
var pythonCaller = new PythonCaller();
|
||||
try {
|
||||
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs, function(remoteGenErr, genResult) {
|
||||
if(errorCode.SUCCESS.code == remoteGenErr) {
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 2, parse python run-time path, python file name and user arguments
|
||||
pythonRuntimeDir = fileDir + "/" + remoteDir;
|
||||
// step 4, try executing merge script
|
||||
logger.info("remote " + remoteIndex.remote_name + " has successfully been generated." +
|
||||
" continue merging with protocol");
|
||||
pythonFile = "irda_tv_merge.py";
|
||||
outputPath = fileDir;
|
||||
remoteBinFilePath = fileDir + "/" + remoteDir + remoteIndex.protocol_name + "#" +
|
||||
remoteIndex.remote_name + ".bin";
|
||||
userArgs.length = 0;
|
||||
// python s_$category.py [remote_xml_file_abs_file] [remote_xml_file_name] [remote_xml_dir_abs_path]
|
||||
userArgs.push(remoteXMLFilePath);
|
||||
userArgs.push(remoteIndex.remote_name + ".xml");
|
||||
userArgs.push(fileDir + "/");
|
||||
userArgs.push(categoryID);
|
||||
// python irda_tv_merge.py [protocol_dir_abs_path]
|
||||
// [remote_bin_file_abs_path] [output_$category_dir_abs_path]
|
||||
logger.info("protocol path = " + protocolPath + ", remote bin path = " + remoteBinFilePath +
|
||||
", output = " + outputPath);
|
||||
userArgs.push(protocolPath);
|
||||
userArgs.push(remoteBinFilePath);
|
||||
userArgs.push(outputPath);
|
||||
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs,
|
||||
function(remoteMergeErr, mergeResult) {
|
||||
logger.info("merge protocol error = " + remoteMergeErr);
|
||||
if(errorCode.SUCCESS.code == remoteMergeErr) {
|
||||
outputFilePath = outputPath + "/irda_" + remoteIndex.protocol_name + "_" +
|
||||
remoteIndex.remote_name + ".bin";
|
||||
logger.info("final output file = " + outputFilePath);
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 3, try executing remote encoding script
|
||||
var pythonCaller = new PythonCaller();
|
||||
try {
|
||||
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs, function(remoteGenErr, genResult) {
|
||||
if(errorCode.SUCCESS.code == remoteGenErr) {
|
||||
fs.readFile(outputFilePath, function(readFileErr, fileData) {
|
||||
if (readFileErr) {
|
||||
logger.error("read remote code binary file error : " + readFileErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("read remote binary file successfully, " +
|
||||
"file size = " + fileData.length);
|
||||
//////////////////////////////////////
|
||||
// step 5, check if this remote index is already contained in remote index
|
||||
// list by binary
|
||||
var fileHash = checksum(fileData);
|
||||
logger.info("hash of binary file = " + fileHash);
|
||||
var conditions = null;
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 4, try executing merge script
|
||||
logger.info("remote " + remoteIndex.remote_name + " has successfully been generated." +
|
||||
" continue merging with protocol");
|
||||
pythonFile = "irda_tv_merge.py";
|
||||
outputPath = fileDir;
|
||||
remoteBinFilePath = fileDir + "/" + remoteDir + remoteIndex.protocol_name + "#" +
|
||||
remoteIndex.remote_name + ".bin";
|
||||
userArgs.length = 0;
|
||||
// python irda_tv_merge.py [protocol_dir_abs_path] [remote_bin_file_abs_path] [output_$category_dir_abs_path]
|
||||
logger.info("protocol path = " + protocolPath + ", remote bin path = " + remoteBinFilePath +
|
||||
", output = " + outputPath);
|
||||
userArgs.push(protocolPath);
|
||||
userArgs.push(remoteBinFilePath);
|
||||
userArgs.push(outputPath);
|
||||
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs, function(remoteMergeErr, mergeResult) {
|
||||
logger.info("merge protocol error = " + remoteMergeErr);
|
||||
if(errorCode.SUCCESS.code == remoteMergeErr) {
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 5, upload file to aliyun OSS
|
||||
outputFilePath = outputPath + "/irda_" + remoteIndex.protocol_name + "_" +
|
||||
remoteIndex.remote_name + ".bin";
|
||||
logger.info("final output file = " + outputFilePath);
|
||||
|
||||
fs.readFile(outputFilePath, function(readFileErr, fileData) {
|
||||
if (readFileErr) {
|
||||
logger.error("read remote code binary file error : " + readFileErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("read remote binary file successfully, file size = " + fileData.length);
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 5.5, check if this remote index is already contained in remote index list by binary
|
||||
var fileHash = checksum(fileData);
|
||||
logger.info("hash of binary file = " + fileHash);
|
||||
var conditions = null;
|
||||
|
||||
if (enums.CATEGORY_STB == remoteIndex.category_id) {
|
||||
conditions = {
|
||||
category_id: remoteIndex.category_id,
|
||||
city_code: remoteIndex.city_code,
|
||||
binary_md5: fileHash
|
||||
};
|
||||
} else {
|
||||
conditions = {
|
||||
category_id: remoteIndex.category_id,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
binary_md5: fileHash
|
||||
};
|
||||
}
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition(conditions,
|
||||
function(findRemoteIndexesErr, remoteIndexes) {
|
||||
if (errorCode.SUCCESS.code == findRemoteIndexesErr.code &&
|
||||
null != remoteIndexes && remoteIndexes.length > 0) {
|
||||
logger.info("this remote is duplicated by binary value");
|
||||
callback(errorCode.DUPLICATED_REMOTE_CODE, null);
|
||||
} else {
|
||||
// do not specify objectID for newly created media
|
||||
outputFileName = "irda_" + remoteIndex.protocol_name + "_" +
|
||||
remoteIndex.remote_name + ".bin";
|
||||
aliOss = new OSS(OSS_HOST, DEBUG_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
||||
aliOss.saveObjectFromBinary(outputFileName, fileData, contentType,
|
||||
function (createObjectErr, objectID) {
|
||||
if (errorCode.SUCCESS.code == createObjectErr) {
|
||||
// deprecated: do not delete the output binary file for future use
|
||||
|
||||
//////////////////////////////////////
|
||||
// step 6, create remote index record in db
|
||||
if (remoteIndex.category_id == enums.CATEGORY_STB) {
|
||||
newRemoteIndex = {
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
city_code: remoteIndex.city_code,
|
||||
city_name: remoteIndex.city_name,
|
||||
operator_id: remoteIndex.operator_id,
|
||||
operator_name: remoteIndex.operator_name,
|
||||
protocol: remoteIndex.protocol_name,
|
||||
remote: remoteIndex.remote_name,
|
||||
remote_map: remoteIndex.protocol_name +
|
||||
'_' + remoteIndex.remote_name,
|
||||
priority: remoteIndex.priority,
|
||||
sub_cate: subCate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
city_name_tw: remoteIndex.city_name_tw,
|
||||
operator_name_tw: remoteIndex.operator_name_tw,
|
||||
binary_md5: fileHash,
|
||||
input_source: inputSource
|
||||
}
|
||||
} else {
|
||||
newRemoteIndex = {
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
brand_name: remoteIndex.brand_name,
|
||||
protocol: remoteIndex.protocol_name,
|
||||
remote: remoteIndex.remote_name,
|
||||
remote_map: remoteIndex.protocol_name +
|
||||
'_' + remoteIndex.remote_name,
|
||||
priority: remoteIndex.priority,
|
||||
sub_cate: subCate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
category_name_tw: remoteIndex.category_name_tw,
|
||||
brand_name_tw: remoteIndex.brand_name_tw,
|
||||
binary_md5: fileHash,
|
||||
input_source: inputSource
|
||||
}
|
||||
}
|
||||
|
||||
// see if this remote index is already in database
|
||||
var conditions = {
|
||||
// category_id: remoteIndex.category_id,
|
||||
// brand_id: remoteIndex.brand_id,
|
||||
protocol: remoteIndex.protocol_name,
|
||||
remote: remoteIndex.remote_name,
|
||||
status: orm.gt(enums.ITEM_INVALID)
|
||||
};
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition(conditions,
|
||||
function(findRemoteIndexErr, remoteIndexes) {
|
||||
if(errorCode.SUCCESS.code == findRemoteIndexErr.code &&
|
||||
remoteIndexes &&
|
||||
remoteIndexes.length > 0) {
|
||||
logger.info("remote index already exists, failed this time");
|
||||
/*
|
||||
RemoteIndex.updateRemoteIndex(remoteIndexes[0].id, newRemoteIndex,
|
||||
function(updateRemoteIndexErr, updatedRemoteIndex) {
|
||||
callback(updateRemoteIndexErr, updatedRemoteIndex);
|
||||
});
|
||||
*/
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
RemoteIndex.createRemoteIndex(newRemoteIndex,
|
||||
function(createRemoteIndexErr, createdRemoteIndex) {
|
||||
callback(createRemoteIndexErr, createdRemoteIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.error("save file object to OSS failed : " + createObjectErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (enums.CATEGORY_STB == remoteIndex.category_id) {
|
||||
conditions = {
|
||||
category_id: remoteIndex.category_id,
|
||||
city_code: remoteIndex.city_code,
|
||||
binary_md5: fileHash
|
||||
};
|
||||
} else {
|
||||
callback(errorCode.FAILED, null);
|
||||
conditions = {
|
||||
category_id: remoteIndex.category_id,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
binary_md5: fileHash
|
||||
};
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
} catch (exception) {
|
||||
logger.error('failed to execute python script from application');
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition(conditions,
|
||||
function(findRemoteIndexesErr, remoteIndexes) {
|
||||
if (errorCode.SUCCESS.code == findRemoteIndexesErr.code &&
|
||||
null != remoteIndexes && remoteIndexes.length > 0) {
|
||||
logger.info("this remote is duplicated by binary value");
|
||||
callback(errorCode.DUPLICATED_REMOTE_CODE, null);
|
||||
} else {
|
||||
//////////////////////////////////////
|
||||
// step 6, create remote index record in db
|
||||
if (remoteIndex.category_id == enums.CATEGORY_STB) {
|
||||
newRemoteIndex = {
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
city_code: remoteIndex.city_code,
|
||||
city_name: remoteIndex.city_name,
|
||||
operator_id: remoteIndex.operator_id,
|
||||
operator_name: remoteIndex.operator_name,
|
||||
protocol: remoteIndex.protocol_name,
|
||||
remote: remoteIndex.remote_name,
|
||||
remote_map: remoteIndex.protocol_name +
|
||||
'_' + remoteIndex.remote_name,
|
||||
priority: remoteIndex.priority,
|
||||
sub_cate: subCate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
city_name_tw: remoteIndex.city_name_tw,
|
||||
operator_name_tw: remoteIndex.operator_name_tw,
|
||||
binary_md5: fileHash,
|
||||
input_source: inputSource
|
||||
}
|
||||
} else {
|
||||
newRemoteIndex = {
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
brand_name: remoteIndex.brand_name,
|
||||
protocol: remoteIndex.protocol_name,
|
||||
remote: remoteIndex.remote_name,
|
||||
remote_map: remoteIndex.protocol_name +
|
||||
'_' + remoteIndex.remote_name,
|
||||
priority: remoteIndex.priority,
|
||||
sub_cate: subCate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
category_name_tw: remoteIndex.category_name_tw,
|
||||
brand_name_tw: remoteIndex.brand_name_tw,
|
||||
binary_md5: fileHash,
|
||||
input_source: inputSource
|
||||
}
|
||||
}
|
||||
|
||||
// see if this remote index is already in database
|
||||
var conditions = {
|
||||
// category_id: remoteIndex.category_id,
|
||||
// brand_id: remoteIndex.brand_id,
|
||||
protocol: remoteIndex.protocol_name,
|
||||
remote: remoteIndex.remote_name,
|
||||
status: orm.gt(enums.ITEM_INVALID)
|
||||
};
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition(conditions,
|
||||
function(findRemoteIndexErr, remoteIndexes) {
|
||||
if(errorCode.SUCCESS.code == findRemoteIndexErr.code &&
|
||||
remoteIndexes &&
|
||||
remoteIndexes.length > 0) {
|
||||
logger.info("remote index already exists");
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
RemoteIndex.createRemoteIndex(newRemoteIndex,
|
||||
function(createRemoteIndexErr, createdRemoteIndex) {
|
||||
callback(createRemoteIndexErr, createdRemoteIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.info("failed to fetch protocol binary file, return with failure");
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
} catch (exception) {
|
||||
logger.error('failed to execute python script from application');
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.info("invalid admin ID, return directly");
|
||||
@@ -614,9 +558,13 @@ exports.deleteRemoteIndexWorkUnit = function (remoteIndex, adminID, callback) {
|
||||
}
|
||||
}
|
||||
var requestSender =
|
||||
new RequestSender(PRIMARY_SERVER_ADDRESS, PRIMARY_SERVER_PORT, DELETE_REMOTE_INDEX_SERVICE, queryParams);
|
||||
new RequestSender(PRIMARY_SERVER_ADDRESS,
|
||||
PRIMARY_SERVER_PORT,
|
||||
DELETE_REMOTE_INDEX_SERVICE,
|
||||
queryParams);
|
||||
|
||||
requestSender.sendPostRequest(remoteIndex, function(deleteRemoteIndexesRequestErr, deleteRemoteIndexesResponse) {
|
||||
requestSender.sendPostRequest(remoteIndex,
|
||||
function(deleteRemoteIndexesRequestErr, deleteRemoteIndexesResponse) {
|
||||
/*
|
||||
if(errorCode.SUCCESS.code == deleteRemoteIndexesRequestErr &&
|
||||
JSON.parse(deleteRemoteIndexesResponse).status.code == errorCode.SUCCESS.code) {
|
||||
@@ -689,8 +637,8 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
|
||||
var fileDir = unixFilePath.substring(0, lios);
|
||||
var outputFileName = '';
|
||||
var uploadedRIIds = [];
|
||||
var downloadOssFilePath = '';
|
||||
var localFilePath = '';
|
||||
var sourceFileName = '';
|
||||
var targetFileName = '';
|
||||
|
||||
var conditions = null;
|
||||
conditions = {
|
||||
@@ -705,60 +653,30 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
|
||||
if(errorCode.SUCCESS.code == findRemoteIndexErr.code) {
|
||||
logger.info("find remote indexes successfully, size of remote index list : " + remoteIndexes.length);
|
||||
//////////////////////////////////////
|
||||
// step 2, download binaries from debug bucket and upload them to release bucket
|
||||
var aliOss = new OSS(OSS_HOST, DEBUG_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
||||
|
||||
async.eachSeries(remoteIndexes, function (remoteIndex, innerCallback) {
|
||||
var remoteName = remoteIndex.remote;
|
||||
var protocolName = remoteIndex.protocol;
|
||||
var binFileName = fileDir + "/irda_" + protocolName + "_" + remoteName + ".bin";
|
||||
logger.info("binary file name = " + binFileName);
|
||||
|
||||
downloadOssFilePath = "irda_" + protocolName + "_" +
|
||||
// step 2, copy file to transfer path
|
||||
sourceFileName = FILE_TEMP_PATH + "/irda_" + protocolName + "_" +
|
||||
remoteName + ".bin";
|
||||
localFilePath = FILE_TEMP_PATH + "/binary_transfer/" + downloadOssFilePath;
|
||||
logger.info("local file path = " + localFilePath);
|
||||
aliOss.serveObjectByID(downloadOssFilePath, localFilePath,
|
||||
function (serveObjectErr, response) {
|
||||
if (errorCode.SUCCESS.code == serveObjectErr) {
|
||||
logger.info("serve remote binary object successfully : " + downloadOssFilePath);
|
||||
targetFileName = FILE_TEMP_PATH + "/binary_transfer" + "/irda_" + protocolName + "_" +
|
||||
remoteName + ".bin";
|
||||
var readStream = fs.createReadStream(sourceFileName);
|
||||
var writeStream = fs.createWriteStream(targetFileName);
|
||||
readStream.pipe(writeStream);
|
||||
logger.info("copy remote binary object successfully : " + targetFileName);
|
||||
fs.readFile(targetFileName, function(readFileErr, fileData) {
|
||||
if (readFileErr) {
|
||||
logger.error("read remote code binary file error : " + readFileErr);
|
||||
innerCallback();
|
||||
} else {
|
||||
logger.info("read remote binary file successfully, file size = " + fileData.length);
|
||||
// TODO: send HTTP post request to release server
|
||||
|
||||
fs.readFile(localFilePath, function(readFileErr, fileData) {
|
||||
if (readFileErr) {
|
||||
logger.error("read remote code binary file error : " + readFileErr);
|
||||
innerCallback();
|
||||
} else {
|
||||
logger.info("read remote binary file successfully, file size = " + fileData.length);
|
||||
|
||||
// do not specify objectID for newly created media
|
||||
outputFileName = "irda_" + protocolName + "_" +
|
||||
remoteName + ".bin";
|
||||
aliOss = new OSS(OSS_HOST, RELEASE_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
||||
aliOss.saveObjectFromBinary(outputFileName, fileData, "application/octet-stream",
|
||||
function (createObjectErr, objectID) {
|
||||
if (errorCode.SUCCESS.code == createObjectErr) {
|
||||
logger.info("successfully uploaded file " + binFileName);
|
||||
// do not update status for unpublished remote indexes here since we need do more things
|
||||
/*
|
||||
RemoteIndex.publishRemoteIndex(remoteIndex.id, enums.ITEM_VALID, function(publishRemoteIndexErr) {
|
||||
// process next anyway
|
||||
innerCallback();
|
||||
});
|
||||
*/
|
||||
uploadedRIIds.push(remoteIndex.id);
|
||||
innerCallback();
|
||||
} else {
|
||||
logger.error("upload file " + binFileName + " failed");
|
||||
innerCallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.error("failed to download remote binary from bucket");
|
||||
innerCallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
logger.warn("failed to upload some item of remote indexes");
|
||||
@@ -784,7 +702,10 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
|
||||
queryParams.put("app_token", REQUEST_APP_TOKEN);
|
||||
|
||||
var requestSender =
|
||||
new RequestSender(PRIMARY_SERVER_ADDRESS, PRIMARY_SERVER_PORT, PUBLISH_REMOTE_INDEX_SERVICE, queryParams);
|
||||
new RequestSender(PRIMARY_SERVER_ADDRESS,
|
||||
PRIMARY_SERVER_PORT,
|
||||
PUBLISH_REMOTE_INDEX_SERVICE,
|
||||
queryParams);
|
||||
|
||||
requestSender.sendPostRequest(remoteIndexes,
|
||||
function(publishRemoteIndexesRequestErr, publishRemoteIndexesResponse) {
|
||||
|
||||
Reference in New Issue
Block a user