diff --git a/src/main/java/org/bdware/server/action/CMActions.java b/src/main/java/org/bdware/server/action/CMActions.java index 9055187..e16163d 100644 --- a/src/main/java/org/bdware/server/action/CMActions.java +++ b/src/main/java/org/bdware/server/action/CMActions.java @@ -903,7 +903,8 @@ public class CMActions implements OnHashCallback { } } - ret.put("data", manager.startContractAndRedirect(c, System.out)); // createPS() + ret.put("data", manager.startContractAndRedirect(c, System.out)); + ret.put("status", true); ret.put("cid", c.getID()); ret.put("executeTime", System.currentTimeMillis() - start); resultCallback.onResult(ret); @@ -924,7 +925,7 @@ public class CMActions implements OnHashCallback { manager.changeDumpPeriod(c.getID(), args.get("dumpPeriod").getAsString()); } } else { - ReplyUtil.simpleReply(resultCallback, "onStartContract", "Failed: Illegal user"); + ReplyUtil.replyWithStatus(resultCallback, "onStartContract", false, "Failed: Illegal user"); } ExecutionManager.instance.updateLocalContractToNodeCenter(); } @@ -1289,13 +1290,13 @@ public class CMActions implements OnHashCallback { ContractMeta meta = manager.statusRecorder.getContractMeta(rc.getContractID()); Contract contract = meta.contract; killContractProcess(args, resultCallback); - manager.startContractAndRedirect(contract,System.out); + manager.startContractAndRedirect(contract, System.out); String data = manager.listContractsWithOwner( args.get("verifiedPubKey").getAsString(), null, args.has("filters") ? args.get("filters").getAsInt() : 0); ReplyUtil.simpleReply(resultCallback, "onListContractProcess", data); - }else { + } else { ReplyUtil.simpleReply(resultCallback, "onRestartContractProcess", "Failed: Illegal parameters"); } } @@ -1308,6 +1309,8 @@ public class CMActions implements OnHashCallback { for (ContractMeta meta : map.values()) { if (meta.getStatus().equals(ContractStatusEnum.KILLED)) toRemove.add(meta); + if (meta.getName() == null || meta.getName().length() == 0) + toRemove.add(meta); } LOGGER.info("pruneKilledContract!!! size:" + toRemove.size()); for (ContractMeta key : toRemove) { @@ -1452,14 +1455,14 @@ public class CMActions implements OnHashCallback { e.printStackTrace(); } ExecutionManager.instance.updateLocalContractToNodeCenter(); - ReplyUtil.simpleReply(resultCallback, "onKillAllContract", sb.toString()); + ReplyUtil.replyWithStatus(resultCallback, "onKillAllContract", true, sb.toString()); manager.stopAllContracts(); } else { manager.stopAllContractsWithOwner(args.get(("verifiedPubKey")).getAsString()); - ReplyUtil.simpleReply(resultCallback, "onKillAllContract", "Success"); + ReplyUtil.replyWithStatus(resultCallback, "onKillAllContract", true, "Success"); } } else { - ReplyUtil.simpleReply(resultCallback, "onKillAllContract", "Failed: Illegal user"); + ReplyUtil.replyWithStatus(resultCallback, "onKillAllContract", false, "Failed: Illegal user"); } } diff --git a/src/main/java/org/bdware/server/action/FileActions.java b/src/main/java/org/bdware/server/action/FileActions.java index 2d4b321..4d7fe89 100644 --- a/src/main/java/org/bdware/server/action/FileActions.java +++ b/src/main/java/org/bdware/server/action/FileActions.java @@ -629,7 +629,6 @@ public class FileActions { String pubKey = args.get("pubKey").getAsString(); KeyValueDBUtil.instance.setValue(CMTables.LockedUser.toString(), pubKey, "locked"); ReplyUtil.replyWithStatus(resultCallback, "onLockEdit", true, pubKey); - } @Action(userPermission = 1 << 10) diff --git a/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java b/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java index 3742b2d..028fb11 100644 --- a/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java +++ b/src/main/java/org/bdware/server/action/p2p/MasterClientTCPAction.java @@ -84,7 +84,7 @@ public class MasterClientTCPAction { args.put("nodeSize", contract.getNumOfCopies()); args.put("masterPubkey", masterPubkey); args.put("members", members); - return ConsistencyPluginManager.getInstance().createContractExecutor(contract.getType(), args); + return ConsistencyPluginManager.getInstance().createContractExecutor(contract.getType().name(), args); } public static void dealRequests(String contractID) { @@ -298,9 +298,9 @@ public class MasterClientTCPAction { } //TODO master连接 // contractID2MasterInfo.put(contractID, this); // 记录contractID 和 master之间的对应关系 - MultiContractMeta cei = + MultiContractMeta multiContractMeta = CMActions.manager.multiContractRecorder.createIfNotExist(contractID); - cei.setLastExeSeq(-1); + multiContractMeta.setLastExeSeq(-1); if (!contract.getScriptStr().startsWith("/")) { contract.setScript(dumpToDisk(contract, jo)); } @@ -308,21 +308,21 @@ public class MasterClientTCPAction { String[] pp = contract.getScriptStr().split("/"); String parPath = GlobalConf.instance.publicCompiledDir; - synchronized (cei) { // 合约执行信息 - cei.setYpkName(pp[pp.length - 1]); - cei.setMembers(jo.get("members").getAsJsonArray()); - cei.type = contract.getType(); - cei.key = contract.getKey(); - cei.publicKey = contract.getPublicKey(); + synchronized (multiContractMeta) { // 合约执行信息 + multiContractMeta.setYpkName(pp[pp.length - 1]); + multiContractMeta.setMembers(jo.get("members").getAsJsonArray()); + multiContractMeta.type = contract.getType(); + multiContractMeta.key = contract.getKey(); + multiContractMeta.publicKey = contract.getPublicKey(); if (jo.has("isPrivate") && jo.get("isPrivate").getAsBoolean()) { parPath = GlobalConf.instance.privateCompiledDir + "/" + jo.get("pubKey").getAsString(); - cei.setIsPrivate(true); - cei.setPubKeyPath(jo.get("pubKey").getAsString()); - cei.setYpkName(pp[pp.length - 1]); + multiContractMeta.setIsPrivate(true); + multiContractMeta.setPubKeyPath(jo.get("pubKey").getAsString()); + multiContractMeta.setYpkName(pp[pp.length - 1]); } } @@ -342,21 +342,21 @@ public class MasterClientTCPAction { e.printStackTrace(); } // 这个地方判定,从参数中的master数据 和 globalConf中的数据 进行对比,如果一致的话,说明该节点为master - cei.setMaster(jo.get("master").getAsString()); + multiContractMeta.setMaster(jo.get("master").getAsString()); if (contract.getType().needSeq()) - cei.setIsMaster(GlobalConf.getNodeID().equals(jo.get("master").getAsString())); + multiContractMeta.setIsMaster(GlobalConf.getNodeID().equals(jo.get("master").getAsString())); else { - cei.setIsMaster(true); + multiContractMeta.setIsMaster(true); } LOGGER.debug("startup arguments: " + JsonUtil.toJson(contract)); String ret = CMActions.manager.startContract(contract); // 调用CMActions 里的启动合约的方法,启动结果 LOGGER.debug("startup result: " + ret); - CMActions.manager.multiContractRecorder.updateValue(cei); + CMActions.manager.multiContractRecorder.updateValue(multiContractMeta); ContractMeta meta = CMActions.manager.statusRecorder.createIfNotExist(contractID); - meta.setContractExecutor(createContractExecutor(contract, contractID, jo.get("master").getAsString(), cei.getMembers())); // 分配不同的Executor + meta.setContractExecutor(createContractExecutor(contract, contractID, jo.get("master").getAsString(), multiContractMeta.getMembers())); // 分配不同的Executor // TODO 合约终止后从数据库中移除,但是为了测试可以人为制造合约终止但不从数据库中移除(异常停止) KeyValueDBUtil.instance.setValue(CMTables.UnitContracts.toString(), contractID, "exist"); diff --git a/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java b/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java index 247f126..c37a62b 100644 --- a/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java +++ b/src/main/java/org/bdware/server/tcp/TCPClientFrameHandler.java @@ -119,7 +119,6 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler { } Response response; try { - //LOGGER.info("====== TCPClientFrameHandler:" + arg.toString()); final String action = arg.get("action").getAsString(); PubkeyResultCallback pc = new PubkeyResultCallback(master, new ResultCallback() { @Override diff --git a/src/main/resources/log4j2debug.properties b/src/main/resources/log4j2debug.properties new file mode 100644 index 0000000..0c8b886 --- /dev/null +++ b/src/main/resources/log4j2debug.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=debug +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