feat: support requestID auto append in agent websocket

This commit is contained in:
CaiHQ 2021-11-01 18:52:02 +08:00
parent 66b18fd63a
commit f0cc46c7af
5 changed files with 158 additions and 279 deletions

View File

@ -34,12 +34,11 @@ import java.util.*;
public class CMActions implements OnHashCallback { public class CMActions implements OnHashCallback {
private static final String PARAM_ACTION = "action"; private static final String PARAM_ACTION = "action";
private static final String MISSING_ARGUMENT = private static final JsonObject MISSING_ARGUMENT = JsonUtil.parseString("{\"action\":\"onExecuteResult\",\"executeTime\":-1,"
+ "\"status\":\"Error\",\"result\":\"missing arguments\"}");
private static final JsonObject INVALID_DOI = JsonUtil.parseString(
"{\"action\":\"onExecuteResult\",\"executeTime\":-1," "{\"action\":\"onExecuteResult\",\"executeTime\":-1,"
+ "\"status\":\"Error\",\"result\":\"missing arguments\"}"; + "\"status\":\"Error\",\"result\":\"invalid contract doi\"}");
private static final String INVALID_DOI =
"{\"action\":\"onExecuteResult\",\"executeTime\":-1,"
+ "\"status\":\"Error\",\"result\":\"invalid contract doi\"}";
private static final Logger LOGGER = LogManager.getLogger(CMActions.class); private static final Logger LOGGER = LogManager.getLogger(CMActions.class);
public static ContractManager manager = initManager(); public static ContractManager manager = initManager();
public static FuncInvokeInfo FUNCINVOKEINFO = new FuncInvokeInfo(); // 合约调用时参数和结果 public static FuncInvokeInfo FUNCINVOKEINFO = new FuncInvokeInfo(); // 合约调用时参数和结果
@ -95,11 +94,8 @@ public class CMActions implements OnHashCallback {
public static void listContractProcessWithFirstWithOwner( public static void listContractProcessWithFirstWithOwner(
String owner, String id, ResultCallback resultCallback) { String owner, String id, ResultCallback resultCallback) {
LOGGER.debug("[CMActions listContractProcessWithFirstWithOwner] id=" + id); LOGGER.debug("[CMActions listContractProcessWithFirstWithOwner] id=" + id);
String data = manager.listContractsWithOwner(owner, id, 1 << 1);
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onListContractProcess", data);
ret.action = "onListContractProcess";
ret.data = manager.listContractsWithOwner(owner, id, 1 << 1);
resultCallback.onResult(JsonUtil.toJson(ret));
} }
public static String file2Str(File file) { public static String file2Str(File file) {
@ -202,8 +198,7 @@ public class CMActions implements OnHashCallback {
c, c,
new ResultCallback() { new ResultCallback() {
@Override @Override
public void onResult(String str) { public void onResult(JsonObject ret) {
JsonObject ret = JsonParser.parseString(str).getAsJsonObject();
ret.addProperty("responseID", c.getRequestID()); ret.addProperty("responseID", c.getRequestID());
ret.addProperty("action", "onExecuteResult"); ret.addProperty("action", "onExecuteResult");
String costTime = (System.currentTimeMillis() - start) + ""; String costTime = (System.currentTimeMillis() - start) + "";
@ -218,9 +213,14 @@ public class CMActions implements OnHashCallback {
c.getArg(), c.getArg(),
ret.has("result") ? ret.get("result").toString() : ""); ret.has("result") ? ret.get("result").toString() : "");
} }
System.out.println(str); System.out.println(ret.toString());
resultCallback.onResult(ret.toString()); resultCallback.onResult(ret.toString());
} }
@Override
public void onResult(String str) {
throw new IllegalStateException("Can't reach here");
}
}, },
hashcb); hashcb);
} }
@ -385,16 +385,14 @@ public class CMActions implements OnHashCallback {
@Action(async = true) @Action(async = true)
public void ping(JsonObject args, ResultCallback resultCallback) { public void ping(JsonObject args, ResultCallback resultCallback) {
resultCallback.onResult("{\"action\":\"pong\"}"); ReplyUtil.simpleReply(resultCallback, "pong", null);
} }
@Action(async = true) @Action(async = true)
public void getMock(JsonObject args, final ResultCallback resultCallback) { public void getMock(JsonObject args, final ResultCallback resultCallback) {
Result ret = new Result();
String contractID = ""; String contractID = "";
String operation = ""; String operation = "";
ret.action = "onGetMock"; Object data = null;
ret.responseID = args.get("requestID").getAsString();
if (args.has("contractID")) { if (args.has("contractID")) {
contractID = args.get("contractID").getAsString(); contractID = args.get("contractID").getAsString();
ProjectConfig config = manager.projectRecoder.getProjectConfig(contractID); ProjectConfig config = manager.projectRecoder.getProjectConfig(contractID);
@ -405,21 +403,18 @@ public class CMActions implements OnHashCallback {
System.out.println(operation); System.out.println(operation);
System.out.println("config" + config.getMockConfig().config.get(operation)); System.out.println("config" + config.getMockConfig().config.get(operation));
ret.data = config.getMockConfig().config.get(operation); data = config.getMockConfig().config.get(operation);
} else { } else {
System.out.println("config" + config.getMockConfig()); System.out.println("config" + config.getMockConfig());
ret.data = config.getMockConfig(); data = config.getMockConfig();
} }
} }
ReplyUtil.simpleReply(resultCallback, "onGetMock", data);
resultCallback.onResult(JsonUtil.toJson(ret));
} }
@Action(async = true) @Action(async = true)
public void setMock(JsonObject args, final ResultCallback resultCallback) { public void setMock(JsonObject args, final ResultCallback resultCallback) {
Result ret = new Result(); String data = "failed";
ret.action = "onSetMock";
if (args.has("requestID")) ret.responseID = args.get("requestID").getAsString();
String contractID = ""; String contractID = "";
String operation = ""; String operation = "";
//String mock = ""; //String mock = "";
@ -434,26 +429,22 @@ public class CMActions implements OnHashCallback {
config.setMock(operation, mock); config.setMock(operation, mock);
manager.projectRecoder.updateValue(config); manager.projectRecoder.updateValue(config);
if (client == null) { if (client == null) {
ret.data = "failed"; data = "failed";
} else { } else {
manager.loadProjectConfig(client); manager.loadProjectConfig(client);
ret.data = "success"; data = "success";
} }
} else { } else {
ret.data = "failed"; data = "failed";
} }
ReplyUtil.simpleReply(resultCallback, "onSetMock", data);
resultCallback.onResult(JsonUtil.toJson(ret));
} }
@Action(async = true) @Action(async = true)
public void getMask(JsonObject args, final ResultCallback resultCallback) { public void getMask(JsonObject args, final ResultCallback resultCallback) {
Result ret = new Result();
String contractID = ""; String contractID = "";
String operation = ""; String operation = "";
ret.action = "onGetMask"; Object data = null;
ret.responseID = args.get("requestID").getAsString();
if (args.has("contractID")) { if (args.has("contractID")) {
contractID = args.get("contractID").getAsString(); contractID = args.get("contractID").getAsString();
ProjectConfig config = manager.projectRecoder.getProjectConfig(contractID); ProjectConfig config = manager.projectRecoder.getProjectConfig(contractID);
@ -464,22 +455,18 @@ public class CMActions implements OnHashCallback {
System.out.println(operation); System.out.println(operation);
System.out.println("config" + config.getMaskConfig().config.get(operation)); System.out.println("config" + config.getMaskConfig().config.get(operation));
ret.data = config.getMaskConfig().config.get(operation); data = config.getMaskConfig().config.get(operation);
} else { } else {
System.out.println("config" + config.getMaskConfig()); System.out.println("config" + config.getMaskConfig());
ret.data = config.getMaskConfig(); data = config.getMaskConfig();
} }
} }
ReplyUtil.simpleReply(resultCallback, "onGetMask", data);
resultCallback.onResult(JsonUtil.toJson(ret));
} }
@Action(async = true) @Action(async = true)
public void setMask(JsonObject args, final ResultCallback resultCallback) { public void setMask(JsonObject args, final ResultCallback resultCallback) {
String data = "failed";
Result ret = new Result();
ret.action = "onSetMask";
if (args.has("requestID")) ret.responseID = args.get("requestID").getAsString();
String contractID = ""; String contractID = "";
String operation = ""; String operation = "";
//JsonElement mask = JsonParser.parseString(""); //JsonElement mask = JsonParser.parseString("");
@ -498,17 +485,14 @@ public class CMActions implements OnHashCallback {
// client.contractMeta.contract.setMask(operation,mask); // client.contractMeta.contract.setMask(operation,mask);
// client.setMask(operation,mask); // client.setMask(operation,mask);
// client.get.syncGet("","setMask",""); // client.get.syncGet("","setMask","");
if (client == null) { if (client != null) {
ret.data = "failed";
} else {
manager.loadProjectConfig(client); manager.loadProjectConfig(client);
ret.data = "success"; data = "success";
} }
// System.out.println("clientmask"+client.contractMeta.contract.Mask); // System.out.println("clientmask"+client.contractMeta.contract.Mask);
} }
System.out.println("setMask"); ReplyUtil.simpleReply(resultCallback, "onSetMask", data);
resultCallback.onResult(JsonUtil.toJson(ret));
} }
// TODO we should support Anonymous contract execution? userPermission = 1 << 13 // TODO we should support Anonymous contract execution? userPermission = 1 << 13
@ -529,41 +513,28 @@ public class CMActions implements OnHashCallback {
// 节点管理者 // 节点管理者
@Action(userPermission = 1L << 19) @Action(userPermission = 1L << 19)
public void listAllContractProcess(JsonObject args, ResultCallback resultCallback) { public void listAllContractProcess(JsonObject args, ResultCallback resultCallback) {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onListContractProcess", manager.listContracts(""));
ret.action = "onListContractProcess";
ret.data = manager.listContracts("");
resultCallback.onResult(JsonUtil.toJson(ret));
} }
// 合约使用者,合约管理者 // 合约使用者,合约管理者
@Action(userPermission = 1L << 19) @Action(userPermission = 1L << 19)
public void listContractProcess(JsonObject args, ResultCallback resultCallback) { public void listContractProcess(JsonObject args, ResultCallback resultCallback) {
String data;
if (args.has("verifiedPubKey")) { if (args.has("verifiedPubKey")) {
Result ret = new Result(); data = manager.listContractsWithOwner(
ret.action = "onListContractProcess";
ret.data =
manager.listContractsWithOwner(
args.get("verifiedPubKey").getAsString(), args.get("verifiedPubKey").getAsString(),
null, null,
args.has("filters") ? args.get("filters").getAsInt() : 0); args.has("filters") ? args.get("filters").getAsInt() : 0);
resultCallback.onResult(JsonUtil.toJson(ret)); ReplyUtil.simpleReply(resultCallback, "onListContractProcess", data);
} else { } else {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onListContractProcess", "Failed: Illegal user");
ret.action = "onListContractProcess";
ret.data = "Failed: Illegal user";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
} }
@Action @Action
public void listTheContractProcess(JsonObject args, ResultCallback resultCallback) { public void listTheContractProcess(JsonObject args, ResultCallback resultCallback) {
Result ret = new Result(); String data = manager.listTheContracts(args.get("contractID").getAsString());
ret.action = "onListTheContractProcess"; ReplyUtil.simpleReply(resultCallback, "onListTheContractProcess", data);
ret.data = manager.listTheContracts(args.get("contractID").getAsString());
if (args.has("requestID")) ret.responseID = args.get("requestID").getAsString();
if (args.has("requestID")) ret.responseID = args.get("requestID").getAsString();
resultCallback.onResult(JsonUtil.toJson(ret));
} }
private void setMemInfo(Map<String, Object> lineInfo, Sigar sigar, int pid) { private void setMemInfo(Map<String, Object> lineInfo, Sigar sigar, int pid) {
@ -585,18 +556,12 @@ public class CMActions implements OnHashCallback {
@Action(userPermission = 1L << 16) @Action(userPermission = 1L << 16)
public void queryContractResourceInfo(JsonObject args, ResultCallback resultCallback) { public void queryContractResourceInfo(JsonObject args, ResultCallback resultCallback) {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onQueryContractResourceInfo", manager.getContractResourceInfo());
ret.action = "onQueryContractResourceInfo";
ret.data = manager.getContractResourceInfo();
resultCallback.onResult(JsonUtil.toJson(ret));
} }
@Action(userPermission = 1L << 16) @Action(userPermission = 1L << 16)
public void queryFreeResourceInfo(JsonObject args, ResultCallback resultCallback) { public void queryFreeResourceInfo(JsonObject args, ResultCallback resultCallback) {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onQueryFreeResourceInfo", manager.getFreeResourceInfo());
ret.action = "onQueryFreeResourceInfo";
ret.data = manager.getFreeResourceInfo();
resultCallback.onResult(JsonUtil.toJson(ret));
} }
// 查看本地合约日志详情 // 查看本地合约日志详情
@ -612,10 +577,9 @@ public class CMActions implements OnHashCallback {
String sDate = df.format(date); String sDate = df.format(date);
data2.remove("date"); data2.remove("date");
data2.addProperty("date", sDate); data2.addProperty("date", sDate);
resultCallback.onResult(data2.toString()); resultCallback.onResult(data2);
} else { } else {
resultCallback.onResult( ReplyUtil.simpleReply(resultCallback, "onQueryContractLogDetail", "Can't get detail by this key!");
"\"action\":\"onQueryContractLogDetail\",\"data\":\"Can't get detail by this key!\"}");
} }
} }
@ -637,13 +601,10 @@ public class CMActions implements OnHashCallback {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onWriteDyjs", "success");
ret.action = "onWriteDyjs";
ret.data = "success";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
@Action(userPermission = 1L << 17) // TODO:shujy @Action(userPermission = 1L << 17) // TODO:shujunyi
public void evaluates(JsonObject json, final ResultCallback resultCallback) { public void evaluates(JsonObject json, final ResultCallback resultCallback) {
String contractName = json.get("contractName").getAsString(); String contractName = json.get("contractName").getAsString();
String functionName = json.get("functionName").getAsString(); String functionName = json.get("functionName").getAsString();
@ -667,7 +628,6 @@ public class CMActions implements OnHashCallback {
public void startContractBatched(JsonObject args, ResultCallback resultCallback) { public void startContractBatched(JsonObject args, ResultCallback resultCallback) {
Map<String, Object> ret = new HashMap<>(); Map<String, Object> ret = new HashMap<>();
ret.put("action", "onStartContract"); ret.put("action", "onStartContract");
JsonArray array = JsonArray array =
JsonParser.parseString(args.get("fileList").getAsString()).getAsJsonArray(); JsonParser.parseString(args.get("fileList").getAsString()).getAsJsonArray();
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
@ -701,7 +661,7 @@ public class CMActions implements OnHashCallback {
} }
} }
LOGGER.debug("startContractBatched ret = " + ret); LOGGER.debug("startContractBatched ret = " + ret);
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
} }
@ -798,10 +758,7 @@ public class CMActions implements OnHashCallback {
ret.put("data", manager.startContractAndRedirect(c, System.out)); // createPS() ret.put("data", manager.startContractAndRedirect(c, System.out)); // createPS()
ret.put("cid", c.getID()); ret.put("cid", c.getID());
ret.put("executeTime", System.currentTimeMillis() - start); ret.put("executeTime", System.currentTimeMillis() - start);
if (args.has("requestID")) { resultCallback.onResult(ret);
ret.put("responseID", args.get("requestID").getAsString());
}
resultCallback.onResult(JsonUtil.toJson(ret));
LOGGER.info("handler is null " + (handler == null)); LOGGER.info("handler is null " + (handler == null));
LOGGER.info(args.get("verifiedPubKey").getAsString()); LOGGER.info(args.get("verifiedPubKey").getAsString());
if (handler != null) { if (handler != null) {
@ -923,11 +880,7 @@ public class CMActions implements OnHashCallback {
ret.put("data", manager.startContractAndRedirect(c, System.out)); // createPS() ret.put("data", manager.startContractAndRedirect(c, System.out)); // createPS()
ret.put("cid", c.getID()); ret.put("cid", c.getID());
ret.put("executeTime", System.currentTimeMillis() - start); ret.put("executeTime", System.currentTimeMillis() - start);
resultCallback.onResult(ret);
if (args.has("requestID")) {
ret.put("responseID", args.get("requestID").getAsString());
}
resultCallback.onResult(JsonUtil.toJson(ret));
if (handler != null) { if (handler != null) {
listContractProcessWithFirstWithOwner( listContractProcessWithFirstWithOwner(
args.get("verifiedPubKey").getAsString(), args.get("verifiedPubKey").getAsString(),
@ -945,10 +898,7 @@ public class CMActions implements OnHashCallback {
manager.changeDumpPeriod(c.getID(), args.get("dumpPeriod").getAsString()); manager.changeDumpPeriod(c.getID(), args.get("dumpPeriod").getAsString());
} }
} else { } else {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onStartContract", "Failed: Illegal user");
ret.action = "onStartContract";
ret.data = "Failed: Illegal user";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
} }
@ -1056,7 +1006,7 @@ public class CMActions implements OnHashCallback {
if (args.has("requestID")) { if (args.has("requestID")) {
ret.put("responseID", args.get("requestID").getAsString()); ret.put("responseID", args.get("requestID").getAsString());
} }
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
if (handler != null) { if (handler != null) {
listContractProcessWithFirstWithOwner( listContractProcessWithFirstWithOwner(
@ -1075,10 +1025,7 @@ public class CMActions implements OnHashCallback {
manager.changeDumpPeriod(c.getID(), args.get("dumpPeriod").getAsString()); manager.changeDumpPeriod(c.getID(), args.get("dumpPeriod").getAsString());
} }
} else { } else {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback, "onStartContractAsDebug", "Failed: Illegal user");
ret.action = "onStartContractAsDebug";
ret.data = "Failed: Illegal user";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
} }
@ -1089,7 +1036,7 @@ public class CMActions implements OnHashCallback {
ret.put("action", "onGetDumpPeriod"); ret.put("action", "onGetDumpPeriod");
ret.put("data", manager.getDumpPeriod(contractName)); ret.put("data", manager.getDumpPeriod(contractName));
ret.put("contractName", contractName); ret.put("contractName", contractName);
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(userPermission = 1L << 25, async = true) @Action(userPermission = 1L << 25, async = true)
@ -1102,17 +1049,13 @@ public class CMActions implements OnHashCallback {
ret.put("action", "onChangeDumpPeriod"); ret.put("action", "onChangeDumpPeriod");
ret.put("data", manager.changeDumpPeriod(contractName, dumpPeriod)); ret.put("data", manager.changeDumpPeriod(contractName, dumpPeriod));
ret.put("executeTime", System.currentTimeMillis() - start); ret.put("executeTime", System.currentTimeMillis() - start);
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(userPermission = 1L << 17) @Action(userPermission = 1L << 17)
public void getCodeByID(JsonObject args, ResultCallback resultCallback) { public void getCodeByID(JsonObject args, ResultCallback resultCallback) {
String code = manager.getScriptStrByID(args.get("contractID").getAsString()); String code = manager.getScriptStrByID(args.get("contractID").getAsString());
Result r = new Result(); ReplyUtil.simpleReply(resultCallback, "onCodeResult", code);
r.data = code;
r.action = "onCodeResult";
r.status = true;
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1L << 23) @Action(userPermission = 1L << 23)
@ -1124,7 +1067,7 @@ public class CMActions implements OnHashCallback {
if (contractName == null) { if (contractName == null) {
ret.put("action", "onListMemoryFiles"); ret.put("action", "onListMemoryFiles");
ret.put("data", "failed"); ret.put("data", "failed");
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
return; return;
} }
File f = new File(String.format("%s/%s", GlobalConf.instance.memoryDir, contractName)); File f = new File(String.format("%s/%s", GlobalConf.instance.memoryDir, contractName));
@ -1139,7 +1082,7 @@ public class CMActions implements OnHashCallback {
ret.put("data", dirs); ret.put("data", dirs);
} }
ret.put("action", "onListMemoryFiles"); ret.put("action", "onListMemoryFiles");
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(async = true, userPermission = 1L << 25) @Action(async = true, userPermission = 1L << 25)
@ -1151,7 +1094,7 @@ public class CMActions implements OnHashCallback {
String contractName = manager.getContractNameByID(contractID); String contractName = manager.getContractNameByID(contractID);
if (contractName == null) { if (contractName == null) {
res.put("data", "failed"); res.put("data", "failed");
resultCallback.onResult(JsonUtil.toJson(res)); resultCallback.onResult(res);
return; return;
} }
@ -1171,7 +1114,7 @@ public class CMActions implements OnHashCallback {
res.put("time", cost + "s"); res.put("time", cost + "s");
res.put("data", "success"); res.put("data", "success");
res.put("size", ByteUtil.byteTo(f.length())); res.put("size", ByteUtil.byteTo(f.length()));
resultCallback.onResult(JsonUtil.toJson(res)); resultCallback.onResult(res);
} }
@Action(async = true, userPermission = 1L << 23) @Action(async = true, userPermission = 1L << 23)
@ -1197,7 +1140,7 @@ public class CMActions implements OnHashCallback {
// ret.data = bo.toString(); // ret.data = bo.toString();
res.put("data", bo.toString()); res.put("data", bo.toString());
} }
resultCallback.onResult(JsonUtil.toJson(res)); resultCallback.onResult(res);
} }
@Action(async = true, userPermission = 1L << 26) @Action(async = true, userPermission = 1L << 26)
@ -1209,25 +1152,24 @@ public class CMActions implements OnHashCallback {
LOGGER.debug("forContract :"); LOGGER.debug("forContract :");
// strs2.append("[CMActions] forContract :\n"); // strs2.append("[CMActions] forContract :\n");
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
} }
@Action(userPermission = 1L << 19) @Action(userPermission = 1L << 19)
public void connectTo(JsonObject args, ResultCallback resultCallback) { public void connectTo(JsonObject args, ResultCallback resultCallback) {
String data;
if (!args.has("id")) { if (!args.has("id")) {
resultCallback.onResult( ReplyUtil.simpleReply(resultCallback,"onConnectTo","missing contract id");
"{\"action\":\"onConnectTo\",\"data\":\"missing contract id\"}");
return; return;
} }
String contractID = args.get("id").getAsString(); String contractID = args.get("id").getAsString();
LOGGER.info("connectTo:" + contractID); LOGGER.info("connectTo:" + contractID);
if (contractID == null) { if (contractID == null) {
resultCallback.onResult( ReplyUtil.simpleReply(resultCallback,"onConnectTo","can't find contract id");
"{\"action\":\"onConnectTo\",\"data\":\"can't find contract id\"}");
return; return;
} }
manager.redirect(contractID, createPS(), ""); manager.redirect(contractID, createPS(), "");
resultCallback.onResult("{\"action\":\"onConnectTo\",\"data\":\"success\"}"); ReplyUtil.simpleReply(resultCallback,"onConnectTo","success");
} }
private PrintStream createPS() { private PrintStream createPS() {
@ -1274,7 +1216,7 @@ public class CMActions implements OnHashCallback {
r.put("action", "onKillContractProcess"); r.put("action", "onKillContractProcess");
r.put("data", ret); r.put("data", ret);
r.put("executeTime", System.currentTimeMillis() - s); r.put("executeTime", System.currentTimeMillis() - s);
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
return; return;
} }
@ -1302,10 +1244,7 @@ public class CMActions implements OnHashCallback {
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
} }
} else { } else {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback,"onKillContractProcess","Failed: Illegal parameters");
ret.action = "onKillContractProcess";
ret.data = "Failed: Illegal parameters";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
} }
@ -1325,7 +1264,7 @@ public class CMActions implements OnHashCallback {
r.put("action", "onQueryContractInstanceDOI"); r.put("action", "onQueryContractInstanceDOI");
r.put("data", ret); r.put("data", ret);
r.put("executeTime", System.currentTimeMillis() - s); r.put("executeTime", System.currentTimeMillis() - s);
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
} }
@ -1465,7 +1404,7 @@ public class CMActions implements OnHashCallback {
r.put("executeTime", System.currentTimeMillis() - start); r.put("executeTime", System.currentTimeMillis() - start);
// GRPCPool.writeToChain(c.getOwner(), privKey, gson.toJson(r), // GRPCPool.writeToChain(c.getOwner(), privKey, gson.toJson(r),
// json.getString("requestID")); // json.getString("requestID"));
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
} }
public String staticVerify(Contract c) { public String staticVerify(Contract c) {
@ -1487,7 +1426,7 @@ public class CMActions implements OnHashCallback {
Map<String, String> r = new HashMap<>(); Map<String, String> r = new HashMap<>();
r.put("action", "onGetControlFlow"); r.put("action", "onGetControlFlow");
r.put("result", manager.getControlFlow(c)); r.put("result", manager.getControlFlow(c));
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
} }
@Action(async = true, userPermission = 1L << 26) @Action(async = true, userPermission = 1L << 26)
@ -1509,13 +1448,13 @@ public class CMActions implements OnHashCallback {
c.setOwner(pubkey); c.setOwner(pubkey);
if (!c.verifySignature()) { if (!c.verifySignature()) {
r.put("data", "verify failed"); r.put("data", "verify failed");
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
return; return;
} }
r.put("data", manager.startContractAndRedirect(c, System.out)); r.put("data", manager.startContractAndRedirect(c, System.out));
r.put("cid", c.getID()); r.put("cid", c.getID());
r.put("executeTime", System.currentTimeMillis() - start); r.put("executeTime", System.currentTimeMillis() - start);
resultCallback.onResult(JsonUtil.toJson(r)); resultCallback.onResult(r);
if (args.has("dumpPeriod")) { if (args.has("dumpPeriod")) {
LOGGER.debug("[CMActions]启动后设置dump周期" + args.get("dumpPeriod").getAsString()); LOGGER.debug("[CMActions]启动后设置dump周期" + args.get("dumpPeriod").getAsString());
@ -1527,8 +1466,6 @@ public class CMActions implements OnHashCallback {
public void killAllContract(JsonObject args, ResultCallback resultCallback) { public void killAllContract(JsonObject args, ResultCallback resultCallback) {
if (args.has("verifiedPubKey")) { if (args.has("verifiedPubKey")) {
if (ContractManager.checkNodeManager(args.get(("verifiedPubKey")).getAsString())) { if (ContractManager.checkNodeManager(args.get(("verifiedPubKey")).getAsString())) {
Result r = new Result();
r.action = "onKillAllContract";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Kill:"); sb.append("Kill:");
try { try {
@ -1566,22 +1503,15 @@ public class CMActions implements OnHashCallback {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
r.data = sb.toString();
ExecutionManager.instance.updateLocalContractToNodeCenter(); ExecutionManager.instance.updateLocalContractToNodeCenter();
resultCallback.onResult(JsonUtil.toJson(r)); ReplyUtil.simpleReply(resultCallback,"onKillAllContract",sb.toString());
manager.stopAllContracts(); manager.stopAllContracts();
} else { } else {
manager.stopAllContractsWithOwner(args.get(("verifiedPubKey")).getAsString()); manager.stopAllContractsWithOwner(args.get(("verifiedPubKey")).getAsString());
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback,"onKillAllContract","Success");
ret.action = "onKillAllContract";
ret.data = "Success";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
} else { } else {
Result ret = new Result(); ReplyUtil.simpleReply(resultCallback,"onKillAllContract","Failed: Illegal user");
ret.action = "onKillAllContract";
ret.data = "Failed: Illegal user";
resultCallback.onResult(JsonUtil.toJson(ret));
} }
} }
@ -1623,14 +1553,14 @@ public class CMActions implements OnHashCallback {
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("status", "Error"); ret.addProperty("status", "Error");
ret.addProperty("result", "missing arguments, contractID"); ret.addProperty("result", "missing arguments, contractID");
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
return; return;
} }
ContractResult cr = manager.getLogSize(json.get("contractID").getAsString()); ContractResult cr = manager.getLogSize(json.get("contractID").getAsString());
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("status", cr.status.toString()); ret.addProperty("status", cr.status.toString());
ret.add("result", cr.result); ret.add("result", cr.result);
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(async = true, userPermission = 1L << 22) @Action(async = true, userPermission = 1L << 22)
@ -1640,7 +1570,7 @@ public class CMActions implements OnHashCallback {
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("status", "Error"); ret.addProperty("status", "Error");
ret.addProperty("result", "missing arguments, contractID / offset / count"); ret.addProperty("result", "missing arguments, contractID / offset / count");
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
return; return;
} }
String contractID = json.get("contractID").getAsString(); String contractID = json.get("contractID").getAsString();
@ -1654,7 +1584,7 @@ public class CMActions implements OnHashCallback {
JsonUtil.fromJson( JsonUtil.fromJson(
cr.result, new TypeToken<List<Map<String, String>>>() { cr.result, new TypeToken<List<Map<String, String>>>() {
}.getType())); }.getType()));
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(async = true, userPermission = 1L << 22) @Action(async = true, userPermission = 1L << 22)
@ -1664,7 +1594,7 @@ public class CMActions implements OnHashCallback {
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("status", "Error"); ret.addProperty("status", "Error");
ret.addProperty("result", "missing arguments, contractID / count"); ret.addProperty("result", "missing arguments, contractID / count");
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
return; return;
} }
String contractID = json.get("contractID").getAsString(); String contractID = json.get("contractID").getAsString();
@ -1684,7 +1614,7 @@ public class CMActions implements OnHashCallback {
} }
ret.put("contractID", contractID); ret.put("contractID", contractID);
resultCallback.onResult(JsonUtil.toJson(ret)); resultCallback.onResult(ret);
} }
@Action(async = true, userPermission = 0L) @Action(async = true, userPermission = 0L)
@ -1724,7 +1654,7 @@ public class CMActions implements OnHashCallback {
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("status", "Error"); ret.addProperty("status", "Error");
ret.addProperty("result", "Cannot form TCP connection to " + nodeName); ret.addProperty("result", "Cannot form TCP connection to " + nodeName);
rc.onResult(JsonUtil.toJson(ret)); rc.onResult(ret);
} }
} }
} }
@ -1862,7 +1792,7 @@ public class CMActions implements OnHashCallback {
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("action", "onAskTimeRecorder"); ret.addProperty("action", "onAskTimeRecorder");
ret.addProperty("data", data); ret.addProperty("data", data);
resultCallback.onResult(ret.toString()); resultCallback.onResult(ret);
} }
@Action(async = true) @Action(async = true)
@ -1908,7 +1838,7 @@ public class CMActions implements OnHashCallback {
JsonObject ret = new JsonObject(); JsonObject ret = new JsonObject();
ret.addProperty("action", "onAskMasterElectTimeRecorder"); ret.addProperty("action", "onAskMasterElectTimeRecorder");
ret.addProperty("data", data); ret.addProperty("data", data);
resultCallback.onResult(ret.toString()); resultCallback.onResult(ret);
} }
@Action(async = true, userPermission = 1L << 12) @Action(async = true, userPermission = 1L << 12)

View File

@ -115,19 +115,11 @@ public class LedgerActions {
() -> { () -> {
try { try {
ByteString hash = future.get().getHash(); ByteString hash = future.get().getHash();
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onSendTransaction", true, HashUtil.byteArray2Str(hash.toByteArray()));
r.action = "onSendTransaction";
r.status = true;
r.data = HashUtil.byteArray2Str(hash.toByteArray());
resultCallback.onResult(JsonUtil.toJson(r));
} catch (Exception e) { } catch (Exception e) {
Result r = new Result();
ByteArrayOutputStream bo = new ByteArrayOutputStream(); ByteArrayOutputStream bo = new ByteArrayOutputStream();
r.action = "onSendTransaction"; String dataStr = bo.toString();
r.status = false; ReplyUtil.replyWithStatus(resultCallback, "onSendTransaction", false, dataStr);
e.printStackTrace(new PrintStream(bo));
r.data = bo.toString();
resultCallback.onResult(JsonUtil.toJson(r));
e.printStackTrace(); e.printStackTrace();
} }
}, },

View File

@ -39,9 +39,9 @@ public class ManagerActions {
@Action(userPermission = 1L << 11) @Action(userPermission = 1L << 11)
public void getEncodedUUID(JsonObject args, ResultCallback resultCallback) { public void getEncodedUUID(JsonObject args, ResultCallback resultCallback) {
Result r = new Result(); String data = null;
try { try {
r.data = data =
ByteUtils.toHexString( ByteUtils.toHexString(
SM2Util.encrypt( SM2Util.encrypt(
GlobalConf.instance.keyPair.getPublicKey(), GlobalConf.instance.keyPair.getPublicKey(),
@ -49,10 +49,7 @@ public class ManagerActions {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
r.status = true; ReplyUtil.replyWithStatus(resultCallback, "onGetEncodedUUID", true, data);
r.msg = null;
r.action = "onGetEncodedUUID";
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
@ -67,40 +64,39 @@ public class ManagerActions {
try { try {
String key = args.get("key").getAsString(); String key = args.get("key").getAsString();
String val = args.get("val").getAsString(); String val = args.get("val").getAsString();
Result r = new Result(); boolean
r.msg = null; status = true;
r.action = "onUpdateConfig"; Object data;
r.status = true;
switch (key) { switch (key) {
case "licence": case "licence":
r.data = GlobalConf.resetLicence(val); data = GlobalConf.resetLicence(val);
break; break;
case "projectDir": case "projectDir":
r.data = r.status = GlobalConf.resetProjectDir(val); data = status = GlobalConf.resetProjectDir(val);
break; break;
case "yjsPath": case "yjsPath":
r.data = r.status = GlobalConf.resetYjsPath(val); data = status = GlobalConf.resetYjsPath(val);
break; break;
case "dataChain": case "dataChain":
r.data = r.status = GlobalConf.resetDataChain(val); data = status = GlobalConf.resetDataChain(val);
break; break;
case "doipConfig": case "doipConfig":
r.data = r.status = GlobalConf.resetDOIPConfig(val); data = status = GlobalConf.resetDOIPConfig(val);
break; break;
case "nodeCenter": case "nodeCenter":
r.data = r.status = GlobalConf.resetNodeCenter(val); data = status = GlobalConf.resetNodeCenter(val);
break; break;
case "nodeName": case "nodeName":
r.data = r.status = GlobalConf.resetNodeName(val); data = status = GlobalConf.resetNodeName(val);
break; break;
case "masterAddress": case "masterAddress":
r.data = r.status = GlobalConf.resetMasterAddress(val); data = status = GlobalConf.resetMasterAddress(val);
break; break;
default: default:
r.status = false; status = false;
r.data = "unsupported key:" + key; data = "unsupported key:" + key;
} }
resultCallback.onResult(JsonUtil.toJson(r)); ReplyUtil.replyWithStatus(resultCallback, "onUpdateConfig", status, data);
return; return;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -111,9 +107,7 @@ public class ManagerActions {
@Action(userPermission = 1L << 11) @Action(userPermission = 1L << 11)
// 弃用 新节点管理界面使用loadNodeConfig // 弃用 新节点管理界面使用loadNodeConfig
public void loadConfig(JsonObject args, ResultCallback resultCallback) { public void loadConfig(JsonObject args, ResultCallback resultCallback) {
Result r = new Result();
r.action = "onLoadConfig";
r.responseID=args.get("requestID").toString();
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("projectDir", GlobalConf.instance.projectDir); data.put("projectDir", GlobalConf.instance.projectDir);
data.put("yjsPath", GlobalConf.instance.yjsPath); data.put("yjsPath", GlobalConf.instance.yjsPath);
@ -124,10 +118,7 @@ public class ManagerActions {
data.put("expireTime", new Date(GlobalConf.instance.expireTime) + ""); data.put("expireTime", new Date(GlobalConf.instance.expireTime) + "");
data.put("nodeName", GlobalConf.instance.name); data.put("nodeName", GlobalConf.instance.name);
data.put("doipConfig", GlobalConf.instance.doipConfig); data.put("doipConfig", GlobalConf.instance.doipConfig);
r.data = data; ReplyUtil.replyWithStatus(resultCallback, "onLoadConfig", true, data);
r.status = true;
r.msg = null;
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1L << 11) @Action(userPermission = 1L << 11)
@ -136,11 +127,7 @@ public class ManagerActions {
new ResultCallback() { new ResultCallback() {
@Override @Override
public void onResult(String str) { public void onResult(String str) {
Result ret = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onListNodeInfos", true, str);
ret.status = true;
ret.action = "onListNodeInfos";
ret.data = str;
resultCallback.onResult(JsonUtil.toJson(ret));
} }
}); });
} }
@ -154,10 +141,6 @@ public class ManagerActions {
// Action in NodeNodePortal 节点配置 // Action in NodeNodePortal 节点配置
@Action(userPermission = 1L << 11) @Action(userPermission = 1L << 11)
public void loadNodeConfig(JsonObject args, ResultCallback resultCallback) { public void loadNodeConfig(JsonObject args, ResultCallback resultCallback) {
Result r = new Result();
r.action = "onLoadNodeConfig";
if (args.has("requestID"))
r.responseID=args.get("requestID").getAsString();
Map<String, String> data = new HashMap<>(); Map<String, String> data = new HashMap<>();
data.put("yjsPath", GlobalConf.instance.yjsPath); data.put("yjsPath", GlobalConf.instance.yjsPath);
data.put("nodeCenter", GlobalConf.getNodeCenterUrl()); data.put("nodeCenter", GlobalConf.getNodeCenterUrl());
@ -171,24 +154,14 @@ public class ManagerActions {
data.put("clusterConnected", String.valueOf(NetworkManager.instance.getNCClientHandler().isConnected())); data.put("clusterConnected", String.valueOf(NetworkManager.instance.getNCClientHandler().isConnected()));
data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr()); data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr());
data.put("masterAddress", GlobalConf.instance.masterAddress); data.put("masterAddress", GlobalConf.instance.masterAddress);
r.data = data; ReplyUtil.replyWithStatus(resultCallback, "onLoadNodeConfig", true, data);
r.status = true;
r.msg = null;
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void changeNodeCenter(JsonObject args, ResultCallback resultCallback) { public void changeNodeCenter(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
Result r = new Result(); LOGGER.debug(JsonUtil.toJson(args));
r.msg = null; ReplyUtil.replyWithStatus(resultCallback, "onChangeNodeCenter", true, GlobalConf.resetNodeCenter(val));
r.action = "onChangeNodeCenter";
r.status = true;
r.data = GlobalConf.resetNodeCenter(val);
LOGGER.debug(JsonUtil.toJson(r));
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
@ -196,80 +169,42 @@ public class ManagerActions {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
String lines = val.replace(" ", "\n"); String lines = val.replace(" ", "\n");
LOGGER.debug("changeBDledger " + lines); LOGGER.debug("changeBDledger " + lines);
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onChangeBDledger", true, GlobalConf.resetDataChain(lines));
r.msg = null;
r.action = "onChangeBDledger";
r.status = true;
r.data = GlobalConf.resetDataChain(lines);
LOGGER.debug(JsonUtil.toJson(r));
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void changeNodeName(JsonObject args, ResultCallback resultCallback) { public void changeNodeName(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onChangeNodeName", true, GlobalConf.resetNodeName(val));
r.msg = null;
r.action = "onChangeNodeName";
r.status = true;
r.data = GlobalConf.resetNodeName(val);
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void changeIpPort(JsonObject args, ResultCallback resultCallback) { public void changeIpPort(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onChangeIpPort", true, GlobalConf.resetIpPort(val));
r.msg = null;
r.action = "onChangeIpPort";
r.status = true;
r.data = GlobalConf.resetIpPort(val);
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void changeDOIPConfig(JsonObject args, ResultCallback resultCallback) { public void changeDOIPConfig(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onChangeDOIPConfig", true, GlobalConf.resetDOIPConfig(val));
r.msg = null;
r.action = "onChangeDOIPConfig";
r.status = true;
r.data = GlobalConf.resetDOIPConfig(val);
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void changeYJSPath(JsonObject args, ResultCallback resultCallback) { public void changeYJSPath(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onChangeYJSPath", true, GlobalConf.resetYjsPath(val));
r.msg = null;
r.action = "onChangeYJSPath";
r.status = true;
r.data = GlobalConf.resetYjsPath(val);
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 10) @Action(userPermission = 1 << 10)
public void uploadLicence(JsonObject args, ResultCallback resultCallback) { public void uploadLicence(JsonObject args, ResultCallback resultCallback) {
String val = args.get("data").getAsString(); String val = args.get("data").getAsString();
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onUploadLicence", true, GlobalConf.resetLicence(val));
r.msg = null;
r.action = "onUploadLicence";
r.status = true;
r.data = GlobalConf.resetLicence(val);
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action(userPermission = 1 << 11) @Action(userPermission = 1 << 11)
public void getPeerID(JsonObject args, ResultCallback resultCallback) { public void getPeerID(JsonObject args, ResultCallback resultCallback) {
Result r = new Result(); ReplyUtil.replyWithStatus(resultCallback, "onGetPeerID", true, GlobalConf.instance.peerID);
r.msg = null;
r.action = "onGetPeerID";
r.status = true;
r.data = GlobalConf.instance.peerID;
resultCallback.onResult(JsonUtil.toJson(r));
} }
@Action @Action
@ -292,8 +227,7 @@ public class ManagerActions {
String already = String already =
KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey); KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), pubKey);
if (already != null && already.contains(role.toString())) { if (already != null && already.contains(role.toString())) {
resultCallback.onResult( ReplyUtil.simpleReply(resultCallback, "onApplyNodeRole", "already has!");
"{\"action\":\"onApplyNodeRole\",\"data\":\"already has!\"}");
return; return;
} }
@ -310,15 +244,17 @@ public class ManagerActions {
CMTables.ApplyTime.toString(), CMTables.ApplyTime.toString(),
pubKey, pubKey,
Long.toString(new Date().getTime())); Long.toString(new Date().getTime()));
resultCallback.onResult( ReplyUtil.simpleReply(resultCallback, "onApplyNodeRole", "success");
"{\"action\":\"onApplyNodeRole\",\"data\":\"success\"}");
return; return;
} }
} }
JsonObject ret = new JsonObject();
ret.addProperty("action", "onApplyNodeRole");
ret.addProperty("data", "success");
ret.addProperty("role", ro);
resultCallback.onResult( resultCallback.onResult(
"{\"action\":\"onApplyNodeRole\",\"data\":\"success\",\"role\":\"" ret);
+ ro
+ "\"}");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -1,5 +1,6 @@
package org.bdware.server.trustedmodel; package org.bdware.server.trustedmodel;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -80,17 +81,17 @@ public class MasterProxy implements MasterStub {
request.getRequestID(), request.getRequestID(),
new ResultCallback() { new ResultCallback() {
@Override @Override
public void onResult(String str) { public void onResult(String ret) {
String ret = JsonObject result =JsonUtil.parseString(ret);
ContractManager.instance.extractEventsFromContractResult( ContractManager.instance.extractEventsFromContractResult(
null, str, client, request, start); null, result, client, request, start);
LOGGER.debug( LOGGER.debug(
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date(System.currentTimeMillis())) .format(new Date(System.currentTimeMillis()))
+ " [MasterProxy] executeByMaster 结果是 " + " [MasterProxy] executeByMaster 结果是 "
+ ret + ret
+ "\n"); + "\n");
rcb.onResult(ret); rcb.onResult(result);
} }
}, },
request); request);
@ -108,7 +109,7 @@ public class MasterProxy implements MasterStub {
new ContractResult( new ContractResult(
ContractResult.Status.Error, ContractResult.Status.Error,
new JsonPrimitive("canceled because of queue too long")); new JsonPrimitive("canceled because of queue too long"));
cb.onResult(JsonUtil.toJson(cr)); cb.onResult(JsonUtil.parseObject(cr));
CongestionControl.masterProxyLoad.decrementAndGet(); CongestionControl.masterProxyLoad.decrementAndGet();
return; return;
} }
@ -117,7 +118,7 @@ public class MasterProxy implements MasterStub {
new ResultCallback() { new ResultCallback() {
@Override @Override
public void onResult(String str) { public void onResult(String str) {
cb.onResult(str); cb.onResult(JsonUtil.parseString(str));
CongestionControl.masterProxyLoad.decrementAndGet(); CongestionControl.masterProxyLoad.decrementAndGet();
} }
}); });

View File

@ -17,6 +17,7 @@ import org.bdware.server.action.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -111,6 +112,7 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
} }
@Override @Override
@SuppressWarnings("unchecked")
protected void channelRead0(final ChannelHandlerContext ctx, WebSocketFrame frame) { protected void channelRead0(final ChannelHandlerContext ctx, WebSocketFrame frame) {
// ping and pong frames already handled // ping and pong frames already handled
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextWebSocketFrame) {
@ -159,11 +161,29 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
&& userManagerAction.getPubKey().length() > 0) { && userManagerAction.getPubKey().length() > 0) {
map.addProperty("verifiedPubKey", userManagerAction.getPubKey()); map.addProperty("verifiedPubKey", userManagerAction.getPubKey());
} }
final JsonObject jmap = map;
ae.handle( ae.handle(
action, action,
map, map,
new ResultCallback(ctx.channel()) { new ResultCallback(ctx.channel()) {
@Override
public void onResult(Map jo) {
if (jmap.has("requestID")) {
jo.put("responseID", jmap.get("requestID").getAsString());
}
onResult(JsonUtil.toJson(jo));
}
@Override
public void onResult(JsonObject jo) {
if (jmap.has("requestID")) {
jo.add("responseID", jmap.get("requestID"));
}
onResult(jo.toString());
}
@Override @Override
public void onResult(String ret) { public void onResult(String ret) {
if (ret != null) { if (ret != null) {