feat: support createParam

feat: docker script
This commit is contained in:
CaiHQ 2022-04-21 10:18:47 +08:00
parent 0a24986907
commit 5a4fdb8a13
8 changed files with 119 additions and 71 deletions

View File

@ -19,7 +19,9 @@
"textFileSuffixes":".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv",
"withBdledgerClient":"./runnable/bdledger_mac",
"withBdledgerServer":false,
"consistencyPlugins": "./libs/custom-plugin.jar"
"consistencyPlugins": "./libs/custom-plugin.jar",
"startContract": [],
"datachainConf": "021.node.internetapi.cn:21121"
}
```
## consistencyPlugins 配置
@ -35,4 +37,29 @@
1. wsPluginActions: WS端,包括contractManagerFrameHandler和CMHttpHandler
2. clientToAgentPlugins: client -> cluster 包括MasterClientFrameHandler
3. clientToClusterPlugins:[], client -> NodeCenterClientHandler
4. tcpPlugins:tcp 包括TcpserverFrameHandler
4. tcpPlugins:tcp 包括TcpserverFrameHandler
## startContract配置说明
其中startConfig.json为json数组结构格式如下
```json
[
{
"path": "./BDWareProjectDir/publicCompiled/xxx.ypk",
"owner": "",
"createParam": {}
},
{
...
}
]
path为必填配置项。表示启动的ypk的路径。
owner为可选配置不填时使用NodeManger的key作为Owner。
createParam为可选配置。表示合约的启动参数。
```
## datachainConf 配置说明
1.针对Window Docker/Mac Docker
可使用`"datachainConf":"host.docker.internal:2401"`进行配置。
2.针对Linux Docker可通过查看`docker 0`的网卡IP进行设置。
如:`"datachainConf":"172.16.10.1:2401"`。
3.如果是在同一dockercompose.yml下启动可以使用
`"datachainConf":"bdledger:2401"`进行配置。

View File

@ -1,5 +1,7 @@
package org.bdware.server;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.*;
@ -137,7 +139,6 @@ public class CMHttpServer {
TCPClientFrameHandler.clientToAgentPlugins = parseStrAsList(cmdConf.clientToAgentPlugins);
NodeCenterClientHandler.clientToClusterPlugins = parseStrAsList(cmdConf.clientToClusterPlugins);
org.bdware.units.tcp.TCPClientFrameHandler.tcpPlugins = parseStrAsList(cmdConf.tcpPlugins);
if (!cmdConf.debug.isEmpty()) {
try {
String[] classes = cmdConf.debug.split(",");
@ -153,26 +154,41 @@ public class CMHttpServer {
LOGGER.warn(e.getMessage());
}
}
if (cmdConf.overwrite) {
cmdConf.write(CONFIG_PATH);
}
if (cmdConf.startContract != null && cmdConf.startContract.length() > 0) {
if (cmdConf.startContract != null && cmdConf.startContract.size() > 0) {
ContractManager.scheduledThreadPool.schedule(
() -> {
String[] paths = cmdConf.startContract.split(",");
for (String path : paths) {
File f = new File(path);
if (!f.getName().endsWith(".ypk") || !f.exists())
continue;
Contract c = new Contract();
c.setScript(f.getAbsolutePath());
c.setType(ContractExecType.Sole);
c.setOwner(UserManagerAction.getNodeManager());
ContractManager.instance.startContract(c);
try {
for (JsonElement je : cmdConf.startContract) {
JsonObject jo = je.getAsJsonObject();
String path = jo.get("path").getAsString();
File f = new File(path);
if (!f.getName().endsWith(".ypk") || !f.exists())
continue;
Contract c = new Contract();
c.setScript(f.getAbsolutePath());
c.setType(ContractExecType.Sole);
if (jo.has("owner"))
c.setOwner(jo.get("owner").getAsString());
else
c.setOwner(UserManagerAction.getNodeManager());
if (jo.has("createParam"))
c.setCreateParam(jo.get("createParam"));
ContractManager.instance.startContract(c);
}
} catch (Exception e) {
e.printStackTrace();
}
},
10, TimeUnit.SECONDS);
}
if (cmdConf.datachainConf!=null){
GlobalConf.resetDataChain(cmdConf.datachainConf);
}
if (cmdConf.overwrite) {
cmdConf.write(CONFIG_PATH);
}
}
private static String[] parseStrAsList(String str) {

View File

@ -47,7 +47,6 @@ public class CongestionControl {
jo.addProperty("slaveConn", slaveCounter.get());
jo.addProperty("slaveQueue", masterProxyLoad.get());
jo.addProperty("masterQueue", masterServerLoad.get());
jo.addProperty("maxConnCount", maxHttpConnCount);
jo.addProperty("httpMaxQueue", currHttpMax);
jo.addProperty("slaveMaxQueue", maxMasterProxyLoad);

View File

@ -815,7 +815,7 @@ public class GRPCPool implements ChainOpener {
logType.put("branch", "branch log failure");
}
} else if (info.equals("Result")) {
s = jo.get("result").getAsString();
s = jo.get("result").toString();
s = JsonUtil.toJson(s);
if (s.length() > 2) {
s = s.substring(1, s.length() - 1);

View File

@ -733,7 +733,9 @@ public class CMActions implements OnHashCallback {
c.setOwner(GlobalConf.instance.keyPair.getPublicKeyStr());
c.doSignature(GlobalConf.instance.keyPair);
}
if (args.has("createParam")) {
c.setCreateParam(args.get("createParam"));
}
// if (!c.verifySignature()) {
// ret.put("data", "verify failed");
// resultCallback.onResult(gson.toJson(ret));
@ -831,6 +833,9 @@ public class CMActions implements OnHashCallback {
c.setOwner(GlobalConf.instance.keyPair.getPublicKeyStr());
c.doSignature(GlobalConf.instance.keyPair);
}
if (args.has("createParam")) {
c.setCreateParam(args.get("createParam"));
}
// 上面那些有空再整理一下
c.setDebug(false);
c.setOwner(args.get("verifiedPubKey").getAsString());
@ -956,6 +961,9 @@ public class CMActions implements OnHashCallback {
}
c.setDebug(true);
System.out.println(c.isDebug());
if (args.has("createParam")) {
c.setCreateParam(args.get("createParam"));
}
// 上面那些有空再整理一下
c.setOwner(args.get("verifiedPubKey").getAsString());
@ -1266,6 +1274,53 @@ public class CMActions implements OnHashCallback {
}
}
@Action(userPermission = 1L << 26, async = true)
public void restartContractProcess(JsonObject args, ResultCallback resultCallback) {
LOGGER.debug("[CMActions] killContractProcess : " + args.has("verifiedPubKey"));
if (args.has("verifiedPubKey") && (args.has("id") || args.has("name"))) {
ContractRequest rc = new ContractRequest();
long s = System.currentTimeMillis();
if (args.has("id")) {
// stop unit contract using contract name
rc.setContractID(args.get("id").getAsString());
} else {
// stop unit contract using contract name
rc.setContractID(args.get("name").getAsString());
}
ContractMeta meta = manager.statusRecorder.getContractMeta(rc.getContractID());
Contract contract = meta.contract;
killContractProcess(args, resultCallback);
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 {
ReplyUtil.simpleReply(resultCallback, "onRestartContractProcess", "Failed: Illegal parameters");
}
}
@Action(userPermission = 1L << 26, async = true)
public void pruneKilledContract(JsonObject args, ResultCallback resultCallback) {
Map<String, ContractMeta> map = CMActions.manager.statusRecorder.getStatus();
LOGGER.info("pruneKilledContract!!!");
Set<ContractMeta> toRemove = new HashSet<>();
for (ContractMeta meta : map.values()) {
if (meta.getStatus().equals(ContractStatusEnum.KILLED))
toRemove.add(meta);
}
LOGGER.info("pruneKilledContract!!! size:" + toRemove.size());
for (ContractMeta key : toRemove) {
CMActions.manager.statusRecorder.remove(key);
MultiContractMeta multiMeta = CMActions.manager.multiContractRecorder.getMultiContractMeta(key.getID());
CMActions.manager.multiContractRecorder.remove(multiMeta);
}
resultCallback.onResult("size:" + toRemove.size());
}
@Action(userPermission = 1L << 26, async = true)
public void queryContractInstanceDOI(JsonObject args, ResultCallback resultCallback) {
long s = System.currentTimeMillis();
@ -1356,39 +1411,6 @@ public class CMActions implements OnHashCallback {
resultCallback.onResult(r);
}
@Action(async = true, userPermission = 1L << 26)
public void startContractInTempZips(JsonObject args, ResultCallback resultCallback) {
long start = System.currentTimeMillis();
Contract c = new Contract();
// c.setType(Type.Algorithm);
c.setType(ContractExecType.Sole);
String pubkey = args.get("owner").getAsString();
// SCManagerServlet.registerCCCallback(json.getString("requestID"), this);
Map<String, Object> r = new HashMap<>();
r.put("action", "onStartContract");
String path = args.get("path").getAsString();
path =
new File(new File(GlobalConf.instance.projectDir, "tempZips"), path)
.getAbsolutePath();
c.setScript(path);
c.setSignature(args.get("signature").getAsString());
c.setOwner(pubkey);
if (!c.verifySignature()) {
r.put("data", "verify failed");
resultCallback.onResult(r);
return;
}
r.put("data", manager.startContractAndRedirect(c, System.out));
r.put("cid", c.getID());
r.put("executeTime", System.currentTimeMillis() - start);
resultCallback.onResult(r);
if (args.has("dumpPeriod")) {
LOGGER.debug("[CMActions]启动后设置dump周期" + args.get("dumpPeriod").getAsString());
manager.changeDumpPeriod(c.getID(), args.get("dumpPeriod").getAsString());
}
}
@Action(userPermission = 1L << 26, async = true, httpAccess = false)
public void killAllContract(JsonObject args, ResultCallback resultCallback) {
if (args.has("verifiedPubKey")) {

View File

@ -402,7 +402,6 @@ public class FileActions {
}
public static void startIfManifestDetected(File targetDir) {
try {
String contractName = targetDir.getName();
String owner = targetDir.getParentFile().getName();

View File

@ -92,6 +92,8 @@ public class MasterWSAction {
} else if (args.has("projectName")) {
contract.setScript("/" + args.get("projectName").getAsString());
}
if (args.has("createParam"))
contract.setCreateParam(args.get("createParam"));
// contract.setScript("/" + args.get("projectName").getAsString() + "/manifest.json");
// String toVerify =

View File

@ -176,24 +176,7 @@ public class TemporyTestAction {
resultCallback.onResult(jo.toString());
}
@Action(async = true)
public void pruneKilledContract(JsonObject args, ResultCallback resultCallback) {
Map<String, ContractMeta> map = CMActions.manager.statusRecorder.getStatus();
LOGGER.info("pruneKilledContract!!!");
Set<ContractMeta> toRemove = new HashSet<>();
for (ContractMeta meta : map.values()) {
if (meta.getStatus().equals(ContractStatusEnum.KILLED))
toRemove.add(meta);
}
LOGGER.info("pruneKilledContract!!! size:" + toRemove.size());
for (ContractMeta key : toRemove) {
CMActions.manager.statusRecorder.remove(key);
MultiContractMeta multiMeta = CMActions.manager.multiContractRecorder.getMultiContractMeta(key.getID());
CMActions.manager.multiContractRecorder.remove(multiMeta);
}
resultCallback.onResult("size:" + toRemove.size());
}
@Action(async = true)
public void reconnectPort(JsonObject args, ResultCallback resultCallback) {