updated private cloud functions
This commit is contained in:
1
private-backend/.gitignore
vendored
1
private-backend/.gitignore
vendored
@@ -95,4 +95,5 @@ fabric.properties
|
||||
|
||||
# Customized ignore files
|
||||
target
|
||||
private-backend.iml
|
||||
private-server.iml
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# IRext private server
|
||||
# IRext Private Backend
|
||||
|
||||
Private server is a runtime that any user can deploy and access it with IRext restful web service call or SDK.
|
||||
|
||||
### Runtime environment
|
||||
- Java runtime 1.7 or above
|
||||
- Mysql server 5.6 or above
|
||||
- Redis service
|
||||
- Mysql server 8.0 or above
|
||||
- Redis server 4.0 or above
|
||||
- A Linux OS is preferred
|
||||
|
||||
### Deploy
|
||||
- Fetch or compile libirdecode_jni.so out of source code of irext/core.
|
||||
- Run following command when you fetched or compiled the private-server.jar out of the private server Spring-Boot project.
|
||||
- Run following command when you fetched or compiled the private-backend-<version>.jar out of the private server Spring-Boot project.
|
||||
|
||||
```shell script
|
||||
java -jar private-server.jar
|
||||
java -jar private-backend-<version>.jar
|
||||
```
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.irext.server</groupId>
|
||||
<artifactId>private-server</artifactId>
|
||||
<artifactId>private-backend</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ import net.irext.server.request.CreateRemoteReferenceRequest;
|
||||
import net.irext.server.utils.Constants;
|
||||
import net.irext.server.mapper.*;
|
||||
import net.irext.server.model.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -199,7 +201,7 @@ public class IndexingLogic {
|
||||
remoteRef.setBrandName(brandName);
|
||||
remoteRef.setCityCode(remoteIndex.getCityCode());
|
||||
remoteRef.setOperatorId(remoteIndex.getOperatorId());
|
||||
remoteRef.setRemoteCode(remoteIndex.getId().toString());
|
||||
remoteRef.setRemoteCode("");
|
||||
remoteRef.setRemote(remoteIndex.getRemote());
|
||||
remoteRef.setProtocol(remoteIndex.getProtocol());
|
||||
remoteRef.setRemoteMap(remoteIndex.getRemoteMap());
|
||||
@@ -220,8 +222,26 @@ public class IndexingLogic {
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
return response.body().string();
|
||||
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Request request, IOException e) {
|
||||
System.err.println("remoteRef request failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Response response) throws IOException {
|
||||
try {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("unexpected code from remoteRef response: " + response);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("error processing remoteRef response: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Constants {
|
||||
public static final int STATUS_INVALID = 0;
|
||||
public static final int STATUS_PARA_DATA = 15;
|
||||
|
||||
public static final String REMOTE_REF_URL = "http://192.168.75.128:8083/irext-server/remote_ref/create_remote_ref";
|
||||
public static final String REMOTE_REF_URL = "http://srv.irext.net/irext-server/remote_ref/create_remote_ref";
|
||||
|
||||
public enum CategoryID {
|
||||
AIR_CONDITIONER(1),
|
||||
|
||||
@@ -13,7 +13,6 @@ app.post('/irext/int/list_categories', intService.listCategories);
|
||||
app.post('/irext/int/list_brands', intService.listBrands);
|
||||
app.post('/irext/int/list_indexes', intService.listIndexes);
|
||||
app.post('/irext/int/list_ir_protocols', intService.listIRProtocols);
|
||||
app.post('/irext/int/download_bin', intService.downloadIndex);
|
||||
|
||||
app.post('/irext/int/list_unpublished_brands', intService.listUnpublishedBrands);
|
||||
app.post('/irext/int/list_unpublished_remote_indexes', intService.listUnpublishedRemoteIndexes);
|
||||
|
||||
@@ -233,26 +233,6 @@ exports.searchRemoteIndexes = function (req, res) {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* function : Download remote binary by post request
|
||||
* parameter : remote index ID
|
||||
* return : Redirect to binary download
|
||||
*/
|
||||
exports.downloadIndex = function (req, res) {
|
||||
let remoteIndexID = req.body.index_id;
|
||||
|
||||
internalLogic.downloadRemoteBinCachedWorkUnit(remoteIndexID, function (serveBinErr, filePath) {
|
||||
if (errorCode.SUCCESS.code === serveBinErr.code) {
|
||||
logger.info("download file located at " + filePath);
|
||||
res.download(filePath, "");
|
||||
} else {
|
||||
logger.info("download file failed");
|
||||
res.write('');
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* function : Download remote binary
|
||||
* parameter : remote index ID
|
||||
@@ -260,8 +240,10 @@ exports.downloadIndex = function (req, res) {
|
||||
*/
|
||||
exports.downloadRemoteIndex = function (req, res) {
|
||||
let remoteIndexID = req.query.remote_index_id;
|
||||
let adminId = req.query.admin_id;
|
||||
let token = req.query.token;
|
||||
|
||||
internalLogic.downloadRemoteBinCachedWorkUnit(remoteIndexID, function (serveBinErr, filePath) {
|
||||
internalLogic.downloadRemoteBinCachedWorkUnit(adminId, token, remoteIndexID, function (serveBinErr, filePath) {
|
||||
if (errorCode.SUCCESS.code === serveBinErr.code) {
|
||||
logger.info("download file located at " + filePath);
|
||||
res.download(filePath, "");
|
||||
|
||||
@@ -63,25 +63,25 @@
|
||||
<hr>
|
||||
<div>
|
||||
<div class="btn-group" role="group" aria-label="...">
|
||||
<button class="btn btn-normal btn-default" onclick="loadRemoteList();" style="font-size: 14px;">
|
||||
<button class="btn btn-normal" onclick="loadRemoteList();" style="font-size: 14px;">
|
||||
<span class="glyphicon glyphicon-refresh" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
<button class="btn btn-normal btn-default" onclick="onCreateRemote();" style="font-size: 14px;">
|
||||
<button class="btn btn-normal" onclick="onCreateRemote();" style="font-size: 14px;">
|
||||
<span class="glyphicon glyphicon-plus" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
<button class="btn btn-normal btn-danger" onclick="onDeleteRemote();" style="font-size: 14px;">
|
||||
<button class="btn btn-normal" onclick="onDeleteRemote();" style="font-size: 14px;">
|
||||
<span class="glyphicon glyphicon-trash" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
<button class="btn btn-normal btn-warning" onclick="onFallbackRemote();" style="font-size: 14px;">
|
||||
<button class="btn btn-normal" onclick="onFallbackRemote();" style="font-size: 14px;">
|
||||
<span class="glyphicon glyphicon-arrow-left" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
<button class="btn btn-normal btn-warning" onclick="onVerifyRemote(1);" style="font-size: 14px;">
|
||||
<button class="btn btn-normal" onclick="onVerifyRemote(1);" style="font-size: 14px;">
|
||||
<span class="glyphicon glyphicon-remove" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
<button class="btn btn-normal btn-warning" onclick="onVerifyRemote(0);" style="font-size: 14px;">
|
||||
<button class="btn btn-normal" onclick="onVerifyRemote(0);" style="font-size: 14px;">
|
||||
<span class="glyphicon glyphicon-ok" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
<button id="download_bin_button" class="btn btn-normal btn-info" onclick="downloadBin();" style="font-size: 14px;">
|
||||
<button class="btn btn-normal btn-info" onclick="downloadBin();" style="font-size: 14px;" id="download_bin_button" >
|
||||
<span class="glyphicon glyphicon-cloud-download" style="vertical-align:middle; margin-bottom: 3px;"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -40,9 +40,10 @@ let adminAuth = new AdminAuth(REDIS_HOST, REDIS_PORT, null, REDIS_PASSWORD);
|
||||
// relative XML file path
|
||||
let PROTOCOL_PATH = "protocol";
|
||||
|
||||
let contributeProtocolService = "/irext-server/contribute/contribute_protocol";
|
||||
let contributeProtocolService = "/irext-server/contribution/contribute_protocol";
|
||||
let contributeBrandsService = "/irext-server/contribution/contribute_brands";
|
||||
let contributeRemoteIndexesService = "/irext-server/contribution/contribute_remote_indexes";
|
||||
let createRemoteRefService = "/irext-server/remote_ref/create_remote_ref";
|
||||
|
||||
exports.listCategoriesWorkUnit = function (lang, from, count, callback) {
|
||||
let conditions = {
|
||||
@@ -331,7 +332,7 @@ exports.searchRemoteIndexesWorkUnit = function (lang, remoteMap, from, count, ca
|
||||
});
|
||||
};
|
||||
|
||||
exports.downloadRemoteBinCachedWorkUnit = function (remoteIndexID, callback) {
|
||||
exports.downloadRemoteBinCachedWorkUnit = function (adminId, token, remoteIndexID, callback) {
|
||||
RemoteIndex.getRemoteIndexByID(remoteIndexID, function (getRemoteIndexErr, remoteIndex) {
|
||||
if (errorCode.SUCCESS.code === getRemoteIndexErr.code && null != remoteIndex) {
|
||||
let fileName = "irda_" + remoteIndex.protocol + "_" + remoteIndex.remote + ".bin";
|
||||
@@ -342,6 +343,93 @@ exports.downloadRemoteBinCachedWorkUnit = function (remoteIndexID, callback) {
|
||||
fs.exists(localBinFileName, function (exists) {
|
||||
if (exists) {
|
||||
logger.info("file " + localBinFileName + " already exists, serve directly");
|
||||
// create remote reference of this remote index
|
||||
let categoryId = 0;
|
||||
let categoryName = '';
|
||||
let brandId = 0;
|
||||
let brandName = '';
|
||||
let name = '';
|
||||
let remoteRef = null;
|
||||
RemoteIndex.getRemoteIndexByID(remoteIndexID, function (getRemoteIndexErr, remoteIndex) {
|
||||
if (errorCode.SUCCESS.code === getRemoteIndexErr.code) {
|
||||
categoryId = remoteIndex.category_id;
|
||||
brandId = remoteIndex.brand_id;
|
||||
Category.getCategoryByID(categoryId, function (getCategoryErr, category) {
|
||||
if (errorCode.SUCCESS.code === getCategoryErr.code) {
|
||||
categoryName = category.name;
|
||||
if (enums.CATEGORY_STB !== categoryId) {
|
||||
Brand.getBrandByID(brandId, function (getBrandErr, brand) {
|
||||
if (errorCode.SUCCESS.code === getBrandErr.code) {
|
||||
brandName = brand.name;
|
||||
name = brandName + categoryName;
|
||||
remoteRef = {
|
||||
"name": name,
|
||||
"categoryId": categoryId,
|
||||
"categoryName": categoryName,
|
||||
"brandId": brandId,
|
||||
"brandName": brandName,
|
||||
"cityCode": "",
|
||||
"operatorId": 0,
|
||||
"remoteCode": "",
|
||||
"subCate": remoteIndex.sub_cate,
|
||||
"protocol": remoteIndex.protocol,
|
||||
"remote": remoteIndex.remote,
|
||||
"remoteMap": remoteIndex.remote_map,
|
||||
}
|
||||
let queryParams = new Map();
|
||||
let requestSender =
|
||||
new RequestSender(EXTERNAL_SERVER_ADDRESS,
|
||||
EXTERNAL_SERVER_PORT,
|
||||
createRemoteRefService,
|
||||
queryParams);
|
||||
let createRemoteRefRequest = {
|
||||
"id": adminId,
|
||||
"token": token,
|
||||
"remoteRef": remoteRef,
|
||||
};
|
||||
requestSender.sendPostRequest(createRemoteRefRequest,
|
||||
function (createRemoteRefErr, createRemoteRefResponse) {
|
||||
logger.info(createRemoteRefErr);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
name = categoryName + "-" + remoteIndex.city_code + "-" + remoteIndex.operator_id;
|
||||
remoteRef = {
|
||||
"name": name,
|
||||
"categoryId": categoryId,
|
||||
"categoryName": categoryName,
|
||||
"brandId": 0,
|
||||
"brandName": "",
|
||||
"cityCode": remoteIndex.city_code,
|
||||
"operatorId": remoteIndex.operator_id,
|
||||
"remoteCode": "",
|
||||
"subCate": remoteIndex.sub_cate,
|
||||
"protocol": remoteIndex.protocol,
|
||||
"remote": remoteIndex.remote,
|
||||
"remoteMap": remoteIndex.remote_map,
|
||||
}
|
||||
let queryParams = new Map();
|
||||
let requestSender =
|
||||
new RequestSender(EXTERNAL_SERVER_ADDRESS,
|
||||
EXTERNAL_SERVER_PORT,
|
||||
createRemoteRefService,
|
||||
queryParams);
|
||||
let createRemoteRefRequest = {
|
||||
"id": adminId,
|
||||
"token": token,
|
||||
"remoteRef": remoteRef,
|
||||
};
|
||||
requestSender.sendPostRequest(createRemoteRefRequest,
|
||||
function (createRemoteRefErr, createRemoteRefResponse) {
|
||||
logger.info(createRemoteRefErr);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
callback(error, localBinFileName);
|
||||
} else {
|
||||
logger.info("file " + localBinFileName + " does not exist");
|
||||
|
||||
Reference in New Issue
Block a user