add update node manager

This commit is contained in:
CaiHQ 2022-11-29 15:14:58 +08:00
parent e93c07ed84
commit 7c91416350
5 changed files with 90 additions and 44 deletions

View File

@ -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进行设置。

View File

@ -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) {

View File

@ -76,8 +76,9 @@ 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);
CMActions.manager.executeLocallyAsync(request, new ResultCallback() {
@Override
public void onResult(String str) {
Map<String, String> ret = new HashMap<>();
ret.put("action", "receiveTrustfullyResult");
SM2KeyPair keyPair = GlobalConf.instance.keyPair;
@ -86,13 +87,13 @@ public class MultiRequestInfo {
ret.put("responseID", uniID);
ret.put("executeTime", (System.currentTimeMillis() - start) + "");
ret.put("data", data2);
ret.put("data", str);
mri.countIncrease();
//logger.info("返回 uniID=" + uniID + " 的结果");
mri.callbackMap.get(uniID).onResult(JsonUtil.toJson(ret));
}
}, null);
}
public synchronized void countIncrease() {
int tmp = count.incrementAndGet();

View File

@ -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) {

View File

@ -278,16 +278,18 @@ 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);
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", cr);
ret.addProperty("contractResult", str);
sendMsg(JsonUtil.toJson(ret));
}
},null);
}
@Action(async = true)
public void onReceiveContractExecution(JsonObject jo, ResultCallback resultCallback) {