[undone] removed Ali-OSS related logic from irext console

This commit is contained in:
strawmanbobi
2016-12-04 12:14:03 +08:00
parent 067f428f6f
commit 2ffa59e204

View File

@@ -165,19 +165,9 @@ exports.downloadRemoteBinCachedWorkUnit = function(remoteIndexID, callback) {
logger.info("file " + localBinFileName + " already exists, serve directly"); logger.info("file " + localBinFileName + " already exists, serve directly");
callback(error, localBinFileName); callback(error, localBinFileName);
} else { } else {
logger.info("file " + localBinFileName + " does not exist, download it from OSS"); logger.info("file " + localBinFileName + " does not exist");
var aliOss = new OSS(OSS_HOST, DEBUG_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET); error = errorCode.FAILED;
aliOss.serveObjectByID(fileName, localBinFileName, callback(error, NULL);
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);
}
});
} }
}); });
} else { } else {
@@ -290,7 +280,8 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
// step 3, if successfully created tag binary file, upload binary to OSS // step 3, if successfully created tag binary file, upload binary to OSS
logger.info("remote " + remoteIndex.remote_name + " has successfully been generated"); logger.info("remote " + remoteIndex.remote_name + " has successfully been generated");
outputPath = fileDir; 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"; outputFilePath = outputPath + "/irda_" + tagType + "_" + newACRemoteNumber + ".bin";
logger.info("final tag binary output file = " + outputFilePath); 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); 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); var fileHash = checksum(fileData);
logger.info("hash of binary file = " + fileHash); logger.info("hash of binary file = " + fileHash);
var conditions = { var conditions = {
@@ -318,67 +310,48 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
logger.info("this remote is duplicated by binary value"); logger.info("this remote is duplicated by binary value");
callback(errorCode.DUPLICATED_REMOTE_CODE, null); callback(errorCode.DUPLICATED_REMOTE_CODE, null);
} else { } else {
var aliOss = new OSS(OSS_HOST, DEBUG_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET); // step 4, create remote index record in db
// do not specify objectID for newly created media remoteIndex.remote_name = newACRemoteNumber + "";
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 + "";
newRemoteIndex = { newRemoteIndex = {
category_id: remoteIndex.category_id, category_id: remoteIndex.category_id,
category_name: remoteIndex.category_name, category_name: remoteIndex.category_name,
brand_id: remoteIndex.brand_id, brand_id: remoteIndex.brand_id,
brand_name: remoteIndex.brand_name, brand_name: remoteIndex.brand_name,
protocol: tagType, protocol: tagType,
remote: remoteIndex.remote_name, remote: remoteIndex.remote_name,
remote_map: tagType + "_" + newACRemoteNumber, remote_map: tagType + "_" + newACRemoteNumber,
priority: remoteIndex.priority, priority: remoteIndex.priority,
sub_cate: subCate, sub_cate: subCate,
remote_number: remoteIndex.remote_number, remote_number: remoteIndex.remote_number,
category_name_tw: remoteIndex.category_name_tw, category_name_tw: remoteIndex.category_name_tw,
brand_name_tw: remoteIndex.brand_name_tw, brand_name_tw: remoteIndex.brand_name_tw,
binary_md5: fileHash, binary_md5: fileHash,
input_source: inputSource input_source: inputSource
}; };
// see if this remote index is already in database // see if this remote index is already in database
var conditions = { var conditions = {
//category_id: remoteIndex.category_id, //category_id: remoteIndex.category_id,
//brand_id: remoteIndex.brand_id, //brand_id: remoteIndex.brand_id,
protocol: tagType, protocol: tagType,
remote: remoteIndex.remote_name, remote: remoteIndex.remote_name,
status: orm.gt(enums.ITEM_INVALID) 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); 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 + "/"; protocolPath = fileDir + "/" + PROTOCOL_PATH + "/";
protocolFileName = remoteIndex.protocol_name + ".bin"; protocolFileName = remoteIndex.protocol_name + ".bin";
localProtocolFileName = protocolPath + 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); logger.info("protocol binary fetched from OSS, continue processing with remote file");
aliOss.serveObjectByID(protocolFileName, localProtocolFileName, remoteXMLFilePath = fileDir + "/" + remoteIndex.remote_name + ".xml";
function (serveObjectErr, response) { logger.info("remote XML file path = " + remoteXMLFilePath);
if (errorCode.SUCCESS.code == serveObjectErr) { //////////////////////////////////////
logger.info("protocol binary fetched from OSS, continue processing with remote file"); // step 2, parse python run-time path, python file name and user arguments
remoteXMLFilePath = fileDir + "/" + remoteIndex.remote_name + ".xml"; pythonRuntimeDir = fileDir + "/" + remoteDir;
logger.info("remote XML file path = " + remoteXMLFilePath); 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 // step 4, try executing merge script
pythonRuntimeDir = fileDir + "/" + remoteDir; 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; userArgs.length = 0;
// python s_$category.py [remote_xml_file_abs_file] [remote_xml_file_name] [remote_xml_dir_abs_path] // python irda_tv_merge.py [protocol_dir_abs_path]
userArgs.push(remoteXMLFilePath); // [remote_bin_file_abs_path] [output_$category_dir_abs_path]
userArgs.push(remoteIndex.remote_name + ".xml"); logger.info("protocol path = " + protocolPath + ", remote bin path = " + remoteBinFilePath +
userArgs.push(fileDir + "/"); ", output = " + outputPath);
userArgs.push(categoryID); 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);
////////////////////////////////////// fs.readFile(outputFilePath, function(readFileErr, fileData) {
// step 3, try executing remote encoding script if (readFileErr) {
var pythonCaller = new PythonCaller(); logger.error("read remote code binary file error : " + readFileErr);
try { callback(errorCode.FAILED, null);
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs, function(remoteGenErr, genResult) { } else {
if(errorCode.SUCCESS.code == remoteGenErr) { 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;
////////////////////////////////////// if (enums.CATEGORY_STB == remoteIndex.category_id) {
// step 4, try executing merge script conditions = {
logger.info("remote " + remoteIndex.remote_name + " has successfully been generated." + category_id: remoteIndex.category_id,
" continue merging with protocol"); city_code: remoteIndex.city_code,
pythonFile = "irda_tv_merge.py"; binary_md5: fileHash
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);
}
});
}
});
}
});
} else { } else {
callback(errorCode.FAILED, null); conditions = {
category_id: remoteIndex.category_id,
brand_id: remoteIndex.brand_id,
binary_md5: fileHash
};
} }
});
} else { RemoteIndex.findRemoteIndexByCondition(conditions,
callback(errorCode.FAILED, null); function(findRemoteIndexesErr, remoteIndexes) {
} if (errorCode.SUCCESS.code == findRemoteIndexesErr.code &&
}); null != remoteIndexes && remoteIndexes.length > 0) {
} catch (exception) { logger.info("this remote is duplicated by binary value");
logger.error('failed to execute python script from application'); callback(errorCode.DUPLICATED_REMOTE_CODE, null);
callback(errorCode.FAILED, 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 { } else {
logger.info("failed to fetch protocol binary file, return with failure");
callback(errorCode.FAILED, null); callback(errorCode.FAILED, null);
} }
}); });
} catch (exception) {
logger.error('failed to execute python script from application');
callback(errorCode.FAILED, null);
}
} }
} else { } else {
logger.info("invalid admin ID, return directly"); logger.info("invalid admin ID, return directly");
@@ -614,9 +558,13 @@ exports.deleteRemoteIndexWorkUnit = function (remoteIndex, adminID, callback) {
} }
} }
var requestSender = 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 && if(errorCode.SUCCESS.code == deleteRemoteIndexesRequestErr &&
JSON.parse(deleteRemoteIndexesResponse).status.code == errorCode.SUCCESS.code) { JSON.parse(deleteRemoteIndexesResponse).status.code == errorCode.SUCCESS.code) {
@@ -689,8 +637,8 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
var fileDir = unixFilePath.substring(0, lios); var fileDir = unixFilePath.substring(0, lios);
var outputFileName = ''; var outputFileName = '';
var uploadedRIIds = []; var uploadedRIIds = [];
var downloadOssFilePath = ''; var sourceFileName = '';
var localFilePath = ''; var targetFileName = '';
var conditions = null; var conditions = null;
conditions = { conditions = {
@@ -705,60 +653,30 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
if(errorCode.SUCCESS.code == findRemoteIndexErr.code) { if(errorCode.SUCCESS.code == findRemoteIndexErr.code) {
logger.info("find remote indexes successfully, size of remote index list : " + remoteIndexes.length); 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) { async.eachSeries(remoteIndexes, function (remoteIndex, innerCallback) {
var remoteName = remoteIndex.remote; var remoteName = remoteIndex.remote;
var protocolName = remoteIndex.protocol; var protocolName = remoteIndex.protocol;
var binFileName = fileDir + "/irda_" + protocolName + "_" + remoteName + ".bin"; var binFileName = fileDir + "/irda_" + protocolName + "_" + remoteName + ".bin";
logger.info("binary file name = " + binFileName); logger.info("binary file name = " + binFileName);
// step 2, copy file to transfer path
downloadOssFilePath = "irda_" + protocolName + "_" + sourceFileName = FILE_TEMP_PATH + "/irda_" + protocolName + "_" +
remoteName + ".bin"; remoteName + ".bin";
localFilePath = FILE_TEMP_PATH + "/binary_transfer/" + downloadOssFilePath; targetFileName = FILE_TEMP_PATH + "/binary_transfer" + "/irda_" + protocolName + "_" +
logger.info("local file path = " + localFilePath); remoteName + ".bin";
aliOss.serveObjectByID(downloadOssFilePath, localFilePath, var readStream = fs.createReadStream(sourceFileName);
function (serveObjectErr, response) { var writeStream = fs.createWriteStream(targetFileName);
if (errorCode.SUCCESS.code == serveObjectErr) { readStream.pipe(writeStream);
logger.info("serve remote binary object successfully : " + downloadOssFilePath); 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) { }, function(err) {
if (err) { if (err) {
logger.warn("failed to upload some item of remote indexes"); 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); queryParams.put("app_token", REQUEST_APP_TOKEN);
var requestSender = 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, requestSender.sendPostRequest(remoteIndexes,
function(publishRemoteIndexesRequestErr, publishRemoteIndexesResponse) { function(publishRemoteIndexesRequestErr, publishRemoteIndexesResponse) {