From aacd9394086cff0210bb71bf6e8770847b3e9041 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Tue, 22 Mar 2022 23:52:01 +0800 Subject: [PATCH] support ledgerparams add startContract at cmconfig.json add docker scripts --- build.gradle | 12 +++--- cmconfig.readme.md | 41 +++++++++++++++---- script/generatekey.sh | 3 ++ .../java/org/bdware/server/CMHttpServer.java | 20 +++++++++ src/main/java/org/bdware/server/GRPCPool.java | 22 ++++++++++ .../org/bdware/server/action/CMActions.java | 5 --- 6 files changed, 85 insertions(+), 18 deletions(-) create mode 100755 script/generatekey.sh diff --git a/build.gradle b/build.gradle index 1f3b7b5..8b8635a 100644 --- a/build.gradle +++ b/build.gradle @@ -81,6 +81,7 @@ task copyScript(type: Copy) { include 'cmstop.sh' include 'cmconfig.json.template' include 'killContracts.sh' + include 'generatekey.sh' } into "./build/output" println("copyScript done !") @@ -110,8 +111,12 @@ task copyDynamicLibrary(type: Copy) { from './dynamicLibrary/' into './build/output/dynamicLibrary' } +task copyCustomPlugin(type: Copy) { + from '../custom-plugin/build/libs/custom-plugin.jar' + into "./build/output/libs/" +} -task copyLibs(type: Copy, dependsOn: ["copyScript", 'copySsl']) { +task copyLibs(type: Copy, dependsOn: ["copyScript", 'copySsl', 'copyCustomPlugin']) { from configurations.runtimeClasspath into "./build/output/libs/" } @@ -154,11 +159,6 @@ task copyDockerfile(type: Copy) { into "./build/" } -//task copyCP(type: Copy, dependsOn: ":cp:buildBundle") { -// from "../cp/build/output" -// into "./build/output" -//} - task copyKeys(type: Copy) { from "./keys" into "./build/output/keys" diff --git a/cmconfig.readme.md b/cmconfig.readme.md index ec2644d..529a04e 100644 --- a/cmconfig.readme.md +++ b/cmconfig.readme.md @@ -1,11 +1,38 @@ # 配置项 -## wsPluginActions: WS端,包括contractManagerFrameHandler和CMHttpHandler -## clientToAgentPlugins: client -> cluster 包括MasterClientFrameHandler -## clientToClusterPlugins:[], client -> NodeCenterClientHandler -## tcpPlugins:tcp 包括TcpserverFrameHandler - -# 配置说明 -## 使用字符串分割,如需添加多项,在agent-backend/script/config.json.template里修改如: +## 示例格式 +```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, + "consistencyPlugins": "./libs/custom-plugin.jar" +} +``` +## 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 \ No newline at end of file diff --git a/script/generatekey.sh b/script/generatekey.sh new file mode 100755 index 0000000..c045928 --- /dev/null +++ b/script/generatekey.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "generate manger.key, manager.keypair!" +java -cp cp/libs:cp/yjs.jar org.bdware.sc.SM2Helper generateKeyToFile \ No newline at end of file diff --git a/src/main/java/org/bdware/server/CMHttpServer.java b/src/main/java/org/bdware/server/CMHttpServer.java index 4f7369d..7cc8389 100644 --- a/src/main/java/org/bdware/server/CMHttpServer.java +++ b/src/main/java/org/bdware/server/CMHttpServer.java @@ -22,12 +22,15 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.config.Configurator; import org.bdware.sc.*; +import org.bdware.sc.bean.Contract; +import org.bdware.sc.bean.ContractExecType; import org.bdware.sc.db.CMTables; import org.bdware.sc.db.KeyValueDBUtil; import org.bdware.sc.db.MultiIndexTimeRocksDBUtil; import org.bdware.sc.util.ExceptionUtil; import org.bdware.sdk.consistency.ConsistencyPluginManager; import org.bdware.server.action.FileActions; +import org.bdware.server.action.UserManagerAction; import org.bdware.server.doip.ContractRepositoryMain; import org.bdware.server.http.CMHttpHandler; import org.bdware.server.nodecenter.client.NodeCenterClientHandler; @@ -153,6 +156,23 @@ public class CMHttpServer { if (cmdConf.overwrite) { cmdConf.write(CONFIG_PATH); } + if (cmdConf.startContract != null && cmdConf.startContract.length() > 0) { + ContractManager.scheduledThreadPool.schedule( + () -> { + String[] paths = cmdConf.startContract.split(","); + for (String path : paths) { + File f = new File(path); + if (!f.getName().endsWith(".ypk")) + continue; + Contract c = new Contract(); + c.setScript(f.getAbsolutePath()); + c.setType(ContractExecType.Sole); + c.setOwner(UserManagerAction.getNodeManager()); + ContractManager.instance.startContract(c); + } + }, + 10, TimeUnit.SECONDS); + } } private static String[] parseStrAsList(String str) { diff --git a/src/main/java/org/bdware/server/GRPCPool.java b/src/main/java/org/bdware/server/GRPCPool.java index e66b7f3..40c54ee 100644 --- a/src/main/java/org/bdware/server/GRPCPool.java +++ b/src/main/java/org/bdware/server/GRPCPool.java @@ -1,6 +1,7 @@ package org.bdware.server; import com.google.common.util.concurrent.ListenableFuture; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; @@ -247,6 +248,27 @@ public class GRPCPool implements ChainOpener { } } + @Override + public JsonObject getLedgerParams() { + JsonObject jo = new JsonObject(); + JsonArray jsonArray = new JsonArray(); + String conf = GlobalConf.instance.datachainConf; + conf = conf.replaceAll(",", "\n"); + Scanner sc = new Scanner(new ByteArrayInputStream(conf.getBytes())); + while (sc.hasNextLine()) { + String str = sc.nextLine(); + String[] ipAndPort = str.split(":"); + String ip = ipAndPort[0]; + int port = Integer.parseInt(ipAndPort[1]); + JsonObject client = new JsonObject(); + client.addProperty("ip", ip); + client.addProperty("port", port); + jsonArray.add(client); + } + jo.add("nodes", jsonArray); + return jo; + } + @Override public void reRegister(String doid) { //TODO just success diff --git a/src/main/java/org/bdware/server/action/CMActions.java b/src/main/java/org/bdware/server/action/CMActions.java index 5f7502a..00523cf 100644 --- a/src/main/java/org/bdware/server/action/CMActions.java +++ b/src/main/java/org/bdware/server/action/CMActions.java @@ -84,11 +84,6 @@ public class CMActions implements OnHashCallback { } } - LOGGER.info( - "reconnectDone! " - + (System.currentTimeMillis() - start) - + " --> " - + contractManager.getContractDespList().size()); NetworkManager.instance.waitForNodeCenterConnected(); ExecutionManager.instance.updateLocalContractToNodeCenter(); });