mirror of
https://gitee.com/BDWare/cm
synced 2025-01-10 09:54:03 +00:00
front: support startMulitipoint with args
fix: ContractClient missing arguments error update: @Router arguments format fix: ContractStatusRecorder null exception
This commit is contained in:
parent
2f874832b8
commit
2b2f57b7cf
@ -18,9 +18,9 @@ import org.bdware.sc.encrypt.HardwareInfo.OSType;
|
||||
import org.bdware.sc.event.REvent.REventSemantics;
|
||||
import org.bdware.sc.node.AnnotationNode;
|
||||
import org.bdware.sc.node.YjsType;
|
||||
import org.bdware.sc.units.MultiContractMeta;
|
||||
import org.bdware.sc.util.JsonUtil;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
@ -218,7 +218,7 @@ public class ContractClient {
|
||||
// LOGGER.debug("======= registerPort:" + ret + "-->" + ContractManager.startPort);
|
||||
}
|
||||
|
||||
public String startProcess(PrintStream ps) {
|
||||
public String startProcess(PrintStream ps) throws Exception {
|
||||
isRunning = false;
|
||||
port = -1;
|
||||
|
||||
@ -259,30 +259,31 @@ public class ContractClient {
|
||||
// "org.bdware.sc.ContractProcess",
|
||||
// "-port=" + cPort.getPort());
|
||||
int startPort = ContractManager.cPort.getPortAndInc();
|
||||
//(isDebug ? "-Dlog4j.configurationFile=./log4j2.debug.properties" : ""),
|
||||
ProcessBuilder builder =
|
||||
new ProcessBuilder(
|
||||
"java",
|
||||
"-Dfile.encoding=UTF-8",
|
||||
darg, (isDebug ? "-Dlog4j.configurationFile=./log4j2.cp.properties" : ""),
|
||||
darg,
|
||||
"-jar",
|
||||
classpath,
|
||||
"-port=" + startPort,
|
||||
"-cmi=" + cmi, // cmi 区分不同CM的cp
|
||||
(isDebug ? "-debug" : ""));
|
||||
File directory = new File("");
|
||||
File directory = new File("./");
|
||||
LOGGER.debug("[CMD] path: " + directory.getAbsolutePath());
|
||||
LOGGER.debug(JsonUtil.toPrettyJson(builder.command()));
|
||||
|
||||
Map<String, String> map = builder.environment();
|
||||
map.put("java.library.path", jniPath.getAbsolutePath() + osJni);
|
||||
builder.directory(new File("./"));
|
||||
builder.directory(directory);
|
||||
LOGGER.debug("start process:");
|
||||
|
||||
try {
|
||||
|
||||
process = builder.start();
|
||||
|
||||
this.pid = getPid(process);
|
||||
LOGGER.info("[CP PPID ] " + pid);
|
||||
LOGGER.info("[CP PPID] " + pid);
|
||||
PrintStream printStream = new PrintStream(process.getOutputStream());
|
||||
printStream.println("CP PID:" + pid);
|
||||
printStream.close();
|
||||
@ -317,7 +318,7 @@ public class ContractClient {
|
||||
ContractManager.cPort.updateDb(port, true);
|
||||
get = new SocketGet("127.0.0.1", port);
|
||||
get.syncGet("", "setDBInfo", ContractManager.dbPath);
|
||||
if (isDebug) {
|
||||
if (isDebug || get != null) {
|
||||
String tagA = (ps == System.out ? "[Contract_" + port + "_out] " : "");
|
||||
String tagB = (ps == System.out ? "[Contract_" + port + "_err] " : "");
|
||||
outputTracer.track(process, sc, tagA, ps);
|
||||
@ -329,6 +330,14 @@ public class ContractClient {
|
||||
}
|
||||
get.syncGet("", "registerMangerPort", String.valueOf(ContractManager.cPort.getCMPort()));
|
||||
|
||||
MultiContractMeta multiContractMeta =
|
||||
ContractManager.instance.multiContractRecorder.getMultiContractMeta(contractMeta.getID());
|
||||
if (multiContractMeta != null && multiContractMeta.getMembers() != null) {
|
||||
String setMemberResult = get.syncGet(
|
||||
"", "setMembers", JsonUtil.toJson(multiContractMeta.getMembers()));
|
||||
LOGGER.debug("setMember:" + setMemberResult);
|
||||
|
||||
}
|
||||
if (isBundlePath(contractMeta.contract.getScriptStr())) {
|
||||
status =
|
||||
get.syncGet(
|
||||
@ -347,15 +356,12 @@ public class ContractClient {
|
||||
status = JsonUtil.toJson(r);
|
||||
contractMeta.name = get.syncGet("", "getContractName", "");
|
||||
}
|
||||
return status;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||
e.printStackTrace(new PrintStream(bo));
|
||||
ContractResult r =
|
||||
new ContractResult(Status.Exception, new JsonPrimitive(bo.toString()));
|
||||
return JsonUtil.toJson(r);
|
||||
if (r.status != Status.Success) {
|
||||
killProcess();
|
||||
throw new IllegalStateException(r.result.getAsString());
|
||||
}
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
public void updateMemory() {
|
||||
|
@ -423,7 +423,11 @@ public class ContractManager {
|
||||
c.setOwner(pair.getPublicKeyStr());
|
||||
c.setScript("contract analysis_client{}");
|
||||
analysisClient = new ContractClient(c);
|
||||
try {
|
||||
analysisClient.startProcess(System.out);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getContractIDByName(String name) {
|
||||
@ -742,7 +746,6 @@ public class ContractManager {
|
||||
LOGGER.debug("[free memory] " + mem.getFree() + " " + mem.getActualFree());
|
||||
return mem.getFree();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace(System.err);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return memoryLimit + 1;
|
||||
@ -929,7 +932,7 @@ public class ContractManager {
|
||||
return "contract manager can't support:" + c.getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
statusRecorder.killContract(c.getID());
|
||||
r = new ContractResult(Status.Error, new JsonPrimitive("exception occurs: " + e.getMessage()));
|
||||
return JsonUtil.toJson(r);
|
||||
}
|
||||
|
@ -184,6 +184,8 @@ public class ContractStatusRecorder extends StatusRecorder<ContractMeta> {
|
||||
}
|
||||
}
|
||||
for (ContractMeta cc : getStatus().values()) {
|
||||
if (cc.name == null) continue;
|
||||
if (cc.contract == null) continue;
|
||||
if (idOrNameOrDOI.equals(cc.name) || idOrNameOrDOI.equals(cc.contract.getDOI())) {
|
||||
return cc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user