From 7c91416350b87ebdd764986e31e85e3d86c21a94 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Tue, 29 Nov 2022 15:14:58 +0800 Subject: [PATCH] add update node manager --- cmconfig.readme.md | 53 ++++++++++++------- .../java/org/bdware/server/CMHttpServer.java | 5 +- .../server/action/MultiRequestInfo.java | 31 +++++------ .../server/action/UserManagerAction.java | 25 +++++++++ .../client/NodeCenterClientController.java | 20 +++---- 5 files changed, 90 insertions(+), 44 deletions(-) diff --git a/cmconfig.readme.md b/cmconfig.readme.md index 76a98b5..0659823 100644 --- a/cmconfig.readme.md +++ b/cmconfig.readme.md @@ -1,62 +1,77 @@ # 配置项 + ## 示例格式 + ```json { - "cmi":"", - "debug":"", - "disableDoRepo":false, - "disableLocalLhs":false, - "doipCertPath":"", - "doipLhsAddress":"", - "doipPort":-1, - "doipUserHandle":"", - "enableEventPersistence":false, - "enableSsl":"./ssl/chained.pem:./ssl/domain.pem", - "ip":"127.0.0.1", - "isLAN":true, - "overwrite":false, - "servicePort":21030, - "textFileSuffixes":".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv", - "withBdledgerClient":"./runnable/bdledger_mac", - "withBdledgerServer":false, + "cmi": "", + "debug": "", + "disableDoRepo": false, + "disableLocalLhs": false, + "doipCertPath": "", + "doipLhsAddress": "", + "doipPort": -1, + "doipUserHandle": "", + "enableEventPersistence": false, + "enableSsl": "./ssl/chained.pem:./ssl/domain.pem", + "ip": "127.0.0.1", + "isLAN": true, + "overwrite": false, + "servicePort": 21030, + "textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv", + "withBdledgerClient": "./runnable/bdledger_mac", + "withBdledgerServer": false, "consistencyPlugins": "./libs/custom-plugin.jar", "startContract": [], "datachainConf": "021.node.internetapi.cn:21121" } ``` + ## consistencyPlugins 配置 + 下述四项插件使用字符串分割,如需添加多项,以逗号分隔,在cmconfig.json里修改如: + `````` "consistencyPlugins": "xxx/xxx.jar,xxx/xxx.jar" `````` + ## 通讯插件配置 + 下述四项插件使用字符串分割,如需添加多项,在cmconfig.json里修改如: + `````` "wsPluginActions": "org.bdware.metering.MeteringAction" `````` + 1. wsPluginActions: WS端,包括contractManagerFrameHandler和CMHttpHandler 2. clientToAgentPlugins: client -> cluster 包括MasterClientFrameHandler 3. clientToClusterPlugins:[], client -> NodeCenterClientHandler 4. tcpPlugins:tcp 包括TcpserverFrameHandler ## startContract配置说明 + 其中startConfig.json为json数组结构,格式如下: + ```json [ { "path": "./BDWareProjectDir/publicCompiled/xxx.ypk", "owner": "", + "killBeforeStart": "", "createParam": {} }, { - ... + } ] +``` path为必填配置项。表示启动的ypk的路径。 owner为可选配置,不填时,使用NodeManger的key作为Owner。 +killBeforeStart为可选配置,填写kill的合约名称。 createParam为可选配置。表示合约的启动参数。 -``` + ## datachainConf 配置说明 + 1.针对Window Docker/Mac Docker 可使用`"datachainConf":"host.docker.internal:2401"`进行配置。 2.针对Linux Docker,可通过查看`docker 0`的网卡IP进行设置。 diff --git a/src/main/java/org/bdware/server/CMHttpServer.java b/src/main/java/org/bdware/server/CMHttpServer.java index 739c6a0..4258777 100644 --- a/src/main/java/org/bdware/server/CMHttpServer.java +++ b/src/main/java/org/bdware/server/CMHttpServer.java @@ -168,6 +168,9 @@ public class CMHttpServer { Contract c = new Contract(); c.setScript(f.getAbsolutePath()); c.setType(ContractExecType.Sole); + if (jo.has("killBeforeStart")) { + ContractManager.instance.stopContract(jo.get("killBeforeStart").getAsString()); + } if (jo.has("owner")) c.setOwner(jo.get("owner").getAsString()); else @@ -182,7 +185,7 @@ public class CMHttpServer { }, 10, TimeUnit.SECONDS); } - if (cmdConf.datachainConf!=null){ + if (cmdConf.datachainConf != null) { GlobalConf.resetDataChain(cmdConf.datachainConf); } if (cmdConf.overwrite) { diff --git a/src/main/java/org/bdware/server/action/MultiRequestInfo.java b/src/main/java/org/bdware/server/action/MultiRequestInfo.java index c45a621..e48481f 100644 --- a/src/main/java/org/bdware/server/action/MultiRequestInfo.java +++ b/src/main/java/org/bdware/server/action/MultiRequestInfo.java @@ -76,22 +76,23 @@ public class MultiRequestInfo { if (-1 == cei.curExeSeq) cei.curExeSeq = mri.seq; //logger.info("调试位置 3 cei.curExeSeq=" + cei.curExeSeq + " MultiRequestInfo 执行请求 " + request.seq + " uniID=" + uniID + " Thread-id=" + Thread.currentThread().getId()); - String data2 = CMActions.manager.executeLocally(request, null); - // logger.info("本地执行的结果为\n" + data2); - Map ret = new HashMap<>(); - ret.put("action", "receiveTrustfullyResult"); - SM2KeyPair keyPair = GlobalConf.instance.keyPair; - ret.put("nodeID", keyPair.getPublicKeyStr()); - int seq = request.seq; + CMActions.manager.executeLocallyAsync(request, new ResultCallback() { + @Override + public void onResult(String str) { + Map ret = new HashMap<>(); + ret.put("action", "receiveTrustfullyResult"); + SM2KeyPair keyPair = GlobalConf.instance.keyPair; + ret.put("nodeID", keyPair.getPublicKeyStr()); + int seq = request.seq; - ret.put("responseID", uniID); - ret.put("executeTime", (System.currentTimeMillis() - start) + ""); - ret.put("data", data2); - mri.countIncrease(); - - //logger.info("返回 uniID=" + uniID + " 的结果"); - - mri.callbackMap.get(uniID).onResult(JsonUtil.toJson(ret)); + ret.put("responseID", uniID); + ret.put("executeTime", (System.currentTimeMillis() - start) + ""); + ret.put("data", str); + mri.countIncrease(); + //logger.info("返回 uniID=" + uniID + " 的结果"); + mri.callbackMap.get(uniID).onResult(JsonUtil.toJson(ret)); + } + }, null); } public synchronized void countIncrease() { diff --git a/src/main/java/org/bdware/server/action/UserManagerAction.java b/src/main/java/org/bdware/server/action/UserManagerAction.java index c527379..6fc06dc 100644 --- a/src/main/java/org/bdware/server/action/UserManagerAction.java +++ b/src/main/java/org/bdware/server/action/UserManagerAction.java @@ -42,6 +42,31 @@ public class UserManagerAction { handler = contractManagerFrameHandler; } + @Action(userPermission = 0) + public void resetNodeManager(JsonObject json, ResultCallback resultCallback) { + getNodeRole(json, new ResultCallback() { + @Override + public void onResult(String str) { + if (str.contains("NodeManager")) { + if (json.has("newPubKey")) { + String newPubKey = json.get("newPubKey").getAsString(); + KeyValueDBUtil.instance.setValue(CMTables.ConfigDB.toString(), NodeManager, newPubKey); + KeyValueDBUtil.instance.setValue( + CMTables.NodeRole.toString(), newPubKey, "NodeManager"); + resultCallback.onResult("{\"action\":\"onResetNodeManager\",\"data\":\"success\",\"pubKey\":\"" + + newPubKey + "\"}"); + } else { + //just keep the same + resultCallback.onResult("{\"action\":\"onResetNodeManager\",\"data\":\"success\",\"pubKey\":\"" + + getPubKey(json) + "\"}"); + } + } else { + resultCallback.onResult("{\"action\":\"onResetNodeManager\",\"data\":\"failed, no permission\"}"); + } + + } + }); + } @Action(userPermission = 0) public void getSessionID(JsonObject json, ResultCallback resultCallback) { diff --git a/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java b/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java index 3c64a38..8b605cd 100644 --- a/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java +++ b/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java @@ -278,15 +278,17 @@ public class NodeCenterClientController implements NodeCenterConn { String requestID = jo.get("requestID").getAsString(); String requesterNodeID = jo.get("requesterNodeID").getAsString(); String crStr = jo.get("contractRequest").getAsString(); - String cr = - CMActions.manager.executeLocally( - JsonUtil.fromJson(crStr, ContractRequest.class), null); - JsonObject ret = new JsonObject(); - ret.addProperty("action", "onReceiveContractExecution"); - ret.addProperty("requestID", requestID); - ret.addProperty("requesterNodeID", requesterNodeID); - ret.addProperty("contractResult", cr); - sendMsg(JsonUtil.toJson(ret)); + CMActions.manager.executeLocallyAsync(JsonUtil.fromJson(crStr, ContractRequest.class), new ResultCallback() { + @Override + public void onResult(String str) { + JsonObject ret = new JsonObject(); + ret.addProperty("action", "onReceiveContractExecution"); + ret.addProperty("requestID", requestID); + ret.addProperty("requesterNodeID", requesterNodeID); + ret.addProperty("contractResult", str); + sendMsg(JsonUtil.toJson(ret)); + } + },null); } @Action(async = true)