From 3000ba5874585efc02898be8f65ceb6fdbcc6b18 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Thu, 5 May 2022 13:28:28 +0800 Subject: [PATCH] update docker configs --- build.gradle | 4 +- script/cmconfig.json.template | 37 +++++++++-------- script/cmstart.sh | 2 +- script/cmvar.json | 3 ++ .../{generatekey.sh => genKeyAndCMConfig.sh} | 4 +- script/log4j2.properties | 40 +++++++++++++++++++ src/main/java/org/bdware/server/GRPCPool.java | 10 ++--- .../org/bdware/server/action/CMActions.java | 11 +++-- .../org/bdware/server/action/FileActions.java | 1 - src/main/resources/log4j2.properties | 39 ++++++++++++++---- .../org/bdware/server/PermissionHelper.java | 2 + 11 files changed, 114 insertions(+), 39 deletions(-) create mode 100644 script/cmvar.json rename script/{generatekey.sh => genKeyAndCMConfig.sh} (54%) create mode 100644 script/log4j2.properties diff --git a/build.gradle b/build.gradle index 8b8635a..24dd3ce 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,9 @@ task copyScript(type: Copy) { include 'cmstop.sh' include 'cmconfig.json.template' include 'killContracts.sh' - include 'generatekey.sh' + include 'genKeyAndCMConfig.sh' + include 'cmvar.json' + include 'log4j2.properties' } into "./build/output" println("copyScript done !") diff --git a/script/cmconfig.json.template b/script/cmconfig.json.template index 65b49cf..3d6a064 100644 --- a/script/cmconfig.json.template +++ b/script/cmconfig.json.template @@ -1,19 +1,22 @@ { - "ip": "127.0.0.1", - "servicePort": 21030, - "isLAN" : true, - "disableDoRepo": false, - "doipPort": 21032, - "doipCertPath": "", - "doipUserHandle": "", - "doipLhsAddress": "", - "withBdledgerServer": false, - "withBdledgerClient": "", - "enableEventPersistence": false, - "enableSsl": "./ssl/chained.pem:./ssl/domain.pem", - "textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv", - "wsPluginActions": "org.bdware.metering.MeteringAction", - "clientToAgentPlugins": "", - "clientToClusterPlugins": "", - "tcpPlugins": "" + "cmi":"", + "debug":"", + "disableDoRepo":false, + "disableLocalLhs":false, + "doipCertPath":"", + "doipLhsAddress":"", + "doipPort":21032, + "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", + "datachainConf": "_LEDGERHOSTCONF" + } \ No newline at end of file diff --git a/script/cmstart.sh b/script/cmstart.sh index 1ceda2a..bce7c1a 100755 --- a/script/cmstart.sh +++ b/script/cmstart.sh @@ -18,7 +18,7 @@ fi # ps -ef | grep java | grep bdserver | grep CM | awk '{print $2}' | xargs kill -9 -java -Dfile.encoding=UTF-8 -Djava.library.path="./dynamicLibrary" -cp "./libs/*:bdagent.jar" org.bdware.server.CMHttpServer 1>./log/cm.log 2>./log/cm.err & +java -Dfile.encoding=UTF-8 -Djava.library.path="./dynamicLibrary" -Dlog4j.configurationFile=./log4j2.properties -cp "./libs/*:bdagent.jar" org.bdware.server.CMHttpServer 1>/dev/null 2>/dev/null & #-Xmx3550m -Xms3550m -Xmn2g #-XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 # 以下可启用https/wss,其中,./ssl/xxx.pfx为ssl证书的路径,:后面的123456是密码。 diff --git a/script/cmvar.json b/script/cmvar.json new file mode 100644 index 0000000..b6f6a0c --- /dev/null +++ b/script/cmvar.json @@ -0,0 +1,3 @@ +{ + "_LEDGERHOSTCONF": "localhost:2401" +} \ No newline at end of file diff --git a/script/generatekey.sh b/script/genKeyAndCMConfig.sh similarity index 54% rename from script/generatekey.sh rename to script/genKeyAndCMConfig.sh index c045928..700657f 100755 --- a/script/generatekey.sh +++ b/script/genKeyAndCMConfig.sh @@ -1,3 +1,5 @@ #!/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 +java -cp cp/libs:cp/yjs.jar org.bdware.sc.SM2Helper generateKeyToFile +echo "generate CMConfig!" +java -cp cp/libs/*:cp/yjs.jar org.bdware.sc.SM2Helper generateCMConfig \ No newline at end of file diff --git a/script/log4j2.properties b/script/log4j2.properties new file mode 100644 index 0000000..c7e74a5 --- /dev/null +++ b/script/log4j2.properties @@ -0,0 +1,40 @@ +filter.threshold.type=ThresholdFilter +filter.threshold.level=debug +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White} + +appender.logrolling.type=RollingFile +appender.logrolling.name=infoLogFile +appender.logrolling.append=true +appender.logrolling.fileName=./log/cm.log +appender.logrolling.filePattern=./log/cm-%i.log +appender.logrolling.layout.type=PatternLayout +appender.logrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.logrolling.policies.type = Policies +appender.logrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.logrolling.policies.size.size = 100MB +appender.logrolling.strategy.type = DefaultRolloverStrategy +appender.logrolling.strategy.max = 5 + +appender.errrolling.type=RollingFile +appender.errrolling.name=errorLogFile +appender.errrolling.append=true +appender.errrolling.fileName=./log/cm.err +appender.errrolling.filePattern=./log/cm-%i.err +appender.errrolling.layout.type=PatternLayout +appender.errrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.errrolling.policies.type = Policies +appender.errrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.errrolling.policies.size.size = 100MB +appender.errrolling.strategy.type = DefaultRolloverStrategy +appender.errrolling.strategy.max = 5 + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT +rootLogger.appenderRef.errorFile.ref=errorLogFile +rootLogger.appenderRef.errorFile.level=error +rootLogger.appenderRef.infoFile.ref=infoLogFile +rootLogger.appenderRef.infoFile.level=info +rootLogger.appenderRef.log.ref=log diff --git a/src/main/java/org/bdware/server/GRPCPool.java b/src/main/java/org/bdware/server/GRPCPool.java index 889b72b..b881710 100644 --- a/src/main/java/org/bdware/server/GRPCPool.java +++ b/src/main/java/org/bdware/server/GRPCPool.java @@ -67,12 +67,12 @@ public class GRPCPool implements ChainOpener { RocksDB hash2Data; private String dataNodeIP; private int dataNodePort; - + static final String DBDir = "ContractManagerDB/GRPCPool"; // public static OnHashCallback callback; //for CM write on chain GRPCPool() { - logIndex = new LenVarTimeSerialIndex("./log/hashToData.index", 20); - requestID2Hash = openDB("./log/requestIDToHash", "req2Hash"); - hash2Data = openDB("./log/hashToData", "hash2Data"); + logIndex = new LenVarTimeSerialIndex("./"+DBDir+"/hashToData.index", 20); + requestID2Hash = openDB("./"+DBDir+"/requestIDToHash", "req2Hash"); + hash2Data = openDB("./"+DBDir+"/hashToData", "hash2Data"); contractName2LogIndex = new HashMap<>(); instances = new ArrayList<>(); for (int i = 0; i < WORKER_COUNT; ++i) { @@ -622,7 +622,7 @@ public class GRPCPool implements ChainOpener { if (index == null) { index = new LenVarTimeSerialIndex( - "./log/hashByContract/" + contractName + ".index", 20); + "./"+DBDir+"/hashByContract/" + contractName + ".index", 20); contractName2LogIndex.put(contractName, index); } return index; diff --git a/src/main/java/org/bdware/server/action/CMActions.java b/src/main/java/org/bdware/server/action/CMActions.java index d0a4dbb..9055187 100644 --- a/src/main/java/org/bdware/server/action/CMActions.java +++ b/src/main/java/org/bdware/server/action/CMActions.java @@ -722,7 +722,6 @@ public class CMActions implements OnHashCallback { } else { c.setScript(args.get("script").getAsString()); } - if (args.has("publicKey")) { c.setOwner(args.get("publicKey").getAsString()); c.setSignature(args.get("signature").getAsString()); @@ -1262,11 +1261,11 @@ public class CMActions implements OnHashCallback { ret, args.has("requestID") ? args.get("requestID").getAsString() : null, ""); - Map r = new HashMap<>(); - r.put("action", "onKillContractProcess"); - r.put("data", ret); - r.put("executeTime", System.currentTimeMillis() - s); - resultCallback.onResult(JsonUtil.toJson(r)); + JsonObject r = new JsonObject(); + r.addProperty("action", "onKillContractProcess"); + r.addProperty("data", ret); + r.addProperty("executeTime", System.currentTimeMillis() - s); + resultCallback.onResult(r); ExecutionManager.instance.updateLocalContractToNodeCenter(); } } else { diff --git a/src/main/java/org/bdware/server/action/FileActions.java b/src/main/java/org/bdware/server/action/FileActions.java index 610fa71..916937a 100644 --- a/src/main/java/org/bdware/server/action/FileActions.java +++ b/src/main/java/org/bdware/server/action/FileActions.java @@ -382,7 +382,6 @@ public class FileActions { } ContractManager.threadPool.execute( () -> { - // manifestFile...... try { GRPCPool.instance.reRegister(jo.get("doi").getAsString()); } catch (Exception e) { diff --git a/src/main/resources/log4j2.properties b/src/main/resources/log4j2.properties index 3c01bc8..c7e74a5 100644 --- a/src/main/resources/log4j2.properties +++ b/src/main/resources/log4j2.properties @@ -4,12 +4,37 @@ appender.console.type=Console appender.console.name=STDOUT appender.console.layout.type=PatternLayout appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White} -appender.rolling.type=File -appender.rolling.name=log -appender.rolling.append=true -appender.rolling.fileName=./log/cm.log -appender.rolling.layout.type=PatternLayout -appender.rolling.layout.pattern=%d-%m%n + +appender.logrolling.type=RollingFile +appender.logrolling.name=infoLogFile +appender.logrolling.append=true +appender.logrolling.fileName=./log/cm.log +appender.logrolling.filePattern=./log/cm-%i.log +appender.logrolling.layout.type=PatternLayout +appender.logrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.logrolling.policies.type = Policies +appender.logrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.logrolling.policies.size.size = 100MB +appender.logrolling.strategy.type = DefaultRolloverStrategy +appender.logrolling.strategy.max = 5 + +appender.errrolling.type=RollingFile +appender.errrolling.name=errorLogFile +appender.errrolling.append=true +appender.errrolling.fileName=./log/cm.err +appender.errrolling.filePattern=./log/cm-%i.err +appender.errrolling.layout.type=PatternLayout +appender.errrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.errrolling.policies.type = Policies +appender.errrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.errrolling.policies.size.size = 100MB +appender.errrolling.strategy.type = DefaultRolloverStrategy +appender.errrolling.strategy.max = 5 + rootLogger.level=info rootLogger.appenderRef.stdout.ref=STDOUT -rootLogger.appenderRef.log.ref=log \ No newline at end of file +rootLogger.appenderRef.errorFile.ref=errorLogFile +rootLogger.appenderRef.errorFile.level=error +rootLogger.appenderRef.infoFile.ref=infoLogFile +rootLogger.appenderRef.infoFile.level=info +rootLogger.appenderRef.log.ref=log diff --git a/src/test/java/org/bdware/server/PermissionHelper.java b/src/test/java/org/bdware/server/PermissionHelper.java index f85da5c..a3a94df 100644 --- a/src/test/java/org/bdware/server/PermissionHelper.java +++ b/src/test/java/org/bdware/server/PermissionHelper.java @@ -1,5 +1,6 @@ package org.bdware.server; +import org.bdware.sc.ContractManager; import org.bdware.server.action.Action; import org.bdware.server.action.ActionExecutor; import org.bdware.server.http.CMHttpHandler; @@ -82,6 +83,7 @@ public class PermissionHelper { @Test public void listFrontAgentHttpAPIAction() { + ContractManager manager = new ContractManager(); CMHttpHandler handler = new CMHttpHandler(); parse(handler.actionExecutor.getHandlers(), true); }