mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
support debug run
This commit is contained in:
parent
32c882ec07
commit
bb6c816119
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
/recoverTestFiles/
|
||||
/build/
|
||||
debugconf.json
|
||||
/ContractDB/
|
||||
/defaultLog/
|
||||
/log/
|
@ -8,7 +8,7 @@ mainClassName = 'org.bdware.sc.ContractProcess'
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDirs 'src/main/java', 'src/main/analysis', 'src/main/data-mask'
|
||||
srcDirs 'src/main/java', 'src/main/debugger', 'src/main/data-mask'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/main/resources'
|
||||
|
6
debugconf.json.template
Normal file
6
debugconf.json.template
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"agentHttpAddr": "127.0.0.1:18000",
|
||||
"script": "/Users/huaqiancai/BDWare/datanet/datanet-gateway-bundle/datanet-gateway-backend/build/gateway.ypk",
|
||||
"pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
|
||||
"privKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8"
|
||||
}
|
93
src/main/debugger/org/bdware/sc/debugger/DebugMain.java
Normal file
93
src/main/debugger/org/bdware/sc/debugger/DebugMain.java
Normal file
@ -0,0 +1,93 @@
|
||||
package org.bdware.sc.debugger;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bdware.sc.ContractProcess;
|
||||
import org.bdware.sc.YJSPacker;
|
||||
import org.bdware.sc.bean.Contract;
|
||||
import org.bdware.sc.bean.ContractExecType;
|
||||
import org.bdware.sc.conn.ResultCallback;
|
||||
import org.bdware.sc.get.GetMessage;
|
||||
import org.bdware.sc.http.HttpUtil;
|
||||
import org.bdware.sc.util.FileUtil;
|
||||
import org.bdware.sc.util.JsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class DebugMain {
|
||||
static class DebugConfig {
|
||||
String script;
|
||||
String agentHttpAddr;
|
||||
String pubKey;
|
||||
String privKey;
|
||||
//AutoAppend
|
||||
|
||||
int port;
|
||||
String cmi;
|
||||
String dbPath;
|
||||
int cPort;
|
||||
Contract contract;
|
||||
}
|
||||
|
||||
static Logger LOGGER = LogManager.getLogger(DebugMain.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
String content = FileUtil.getFileContent("./debugconf.json");
|
||||
DebugConfig config = JsonUtil.fromJson(content, DebugConfig.class);
|
||||
inject(config);
|
||||
ContractProcess.main(new String[]{"-port=" + config.port, "-cmi=" + config.cmi, "-disablePID"});
|
||||
ResultCallback printCallback
|
||||
= new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(String str) {
|
||||
LOGGER.info(str);
|
||||
}
|
||||
};
|
||||
ContractProcess.instance.handler.setDBInfo(wrap("", config.dbPath), printCallback);
|
||||
ContractProcess.instance.handler.registerMangerPort(wrap("", Integer.valueOf(config.cPort)), printCallback);
|
||||
ContractProcess.instance.handler.setContractBundle(wrap("", config.contract), printCallback);
|
||||
String urlFormat = ("http://%s/SCIDE/SCManager?action=reconnectAll&owner=%s");
|
||||
|
||||
String url = String.format(urlFormat, config.agentHttpAddr, config.pubKey);
|
||||
Map<String, Object> resp = HttpUtil.httpGet(url);
|
||||
String data = (String)resp.get("response");
|
||||
LOGGER.info(JsonUtil.toPrettyJson(JsonUtil.parseString(data)));
|
||||
LOGGER.info("start done!");
|
||||
}
|
||||
|
||||
private static void inject(DebugConfig config) {
|
||||
String urlFormat = ("http://%s/SCIDE/SCManager?action=%s&arg=%s");
|
||||
String url = String.format(urlFormat, config.agentHttpAddr, "getAgentConfig", "");
|
||||
Map<String, Object> resp = HttpUtil.httpGet(url);
|
||||
String data = (String
|
||||
) resp.get("response");
|
||||
JsonObject jsonObject = JsonUtil.parseString(data);
|
||||
config.cmi = jsonObject.get("cmi").getAsString();
|
||||
config.dbPath = jsonObject.get("dbPath").getAsString();
|
||||
config.cPort = jsonObject.get("cPort").getAsInt();
|
||||
config.port = jsonObject.get("port").getAsInt();
|
||||
JsonObject ownerAndScript = new JsonObject();
|
||||
String arg = "abc&owner=" + config.pubKey + "&script=" + config.script;
|
||||
url = String.format(urlFormat, config.agentHttpAddr, "allocateKeyPair", arg);
|
||||
resp = HttpUtil.httpGet(url);
|
||||
LOGGER.info(url);
|
||||
String contractStr = (String) resp.get("response");
|
||||
LOGGER.info("[ContratStr] " + contractStr);
|
||||
Contract contract = JsonUtil.fromJson(contractStr, Contract.class);
|
||||
config.contract = contract;
|
||||
contract.setType(ContractExecType.Sole);
|
||||
}
|
||||
|
||||
private static GetMessage wrap(String operation, Object arg) {
|
||||
return wrap(operation, JsonUtil.toJson(arg));
|
||||
}
|
||||
|
||||
private static GetMessage wrap(String operation, String arg) {
|
||||
GetMessage msg = new GetMessage();
|
||||
msg.method = operation;
|
||||
msg.arg = arg;
|
||||
return msg;
|
||||
}
|
||||
}
|
@ -47,6 +47,7 @@ import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipFile;
|
||||
@ -60,6 +61,7 @@ public class ContractProcess {
|
||||
|
||||
public final String cmi;
|
||||
private final Set<String> cachedRequests = new HashSet<>();
|
||||
public final ContractHandler handler;
|
||||
public ServiceServer server;
|
||||
public DesktopEngine engine;
|
||||
String dbPath;
|
||||
@ -81,7 +83,7 @@ public class ContractProcess {
|
||||
private String pid;
|
||||
|
||||
public ContractProcess(int port, String cmi) {
|
||||
ContractHandler handler = new ContractHandler(this);
|
||||
handler = new ContractHandler(this);
|
||||
this.server = new ServiceServer(handler, port);
|
||||
this.cmi = cmi;
|
||||
}
|
||||
@ -89,6 +91,7 @@ public class ContractProcess {
|
||||
public static void main(String[] args) {
|
||||
int port = 1616;
|
||||
String cmi = "";
|
||||
InputStream pidInput = System.in;
|
||||
for (String arg : args) {
|
||||
if (arg.startsWith("-port")) {
|
||||
String portStr = arg.substring(6);
|
||||
@ -99,9 +102,11 @@ public class ContractProcess {
|
||||
cmi = arg.substring(5);
|
||||
} else if (arg.startsWith("-debug")) {
|
||||
Configurator.setRootLevel(Level.DEBUG);
|
||||
} else if (arg.startsWith("-disablePID")) {
|
||||
pidInput = new ByteArrayInputStream("CP PID:-1".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
Scanner sc = new Scanner(System.in);
|
||||
Scanner sc = new Scanner(pidInput);
|
||||
for (String str; sc.hasNextLine(); ) {
|
||||
str = sc.nextLine();
|
||||
System.out.println("[CP From STDIN] " + str);
|
||||
|
@ -67,7 +67,7 @@ public class YJSCompiler {
|
||||
final ErrorManager errors = new ErrorManager(werr);
|
||||
// Set up options.
|
||||
final Options options = new Options("nashorn", werr);
|
||||
options.process(new String[] {});
|
||||
options.process(new String[]{});
|
||||
// detect scripting mode by any source's first character being '#'
|
||||
options.set("persistent.code.cache", true);
|
||||
options.set("print.code", "true");
|
||||
@ -105,7 +105,10 @@ public class YJSCompiler {
|
||||
ContractZipBundle czb = new ContractZipBundle();
|
||||
ZipEntry manifest = zf.getEntry("/manifest.json");
|
||||
if (null == manifest) {
|
||||
throw new IllegalStateException("manifest.json is not exists!");
|
||||
manifest = zf.getEntry("manifest.json");
|
||||
if (null == manifest) {
|
||||
throw new IllegalStateException("manifest.json is not exists!");
|
||||
}
|
||||
}
|
||||
InputStream manifestInput = zf.getInputStream(manifest);
|
||||
// Gson gson = new GsonBuilder().registerTypeAdapter(Contract.Type.class,
|
||||
@ -213,7 +216,7 @@ public class YJSCompiler {
|
||||
Class<?> clz = Class.forName(clzName);
|
||||
return (AnnotationProcessor) clz.getConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user