mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 09:54:07 +00:00
refactor: add bdledger dependencies
feat: IRPUtil feat: support debug in docker
This commit is contained in:
parent
c9b5a32e46
commit
1229c9ce4c
@ -5,10 +5,11 @@ plugins {
|
|||||||
id 'signing'
|
id 'signing'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group = "org.bdware.sc"
|
||||||
|
version = "1.5.7"
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
}
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
@ -57,7 +58,7 @@ jar {
|
|||||||
}
|
}
|
||||||
from {
|
from {
|
||||||
// uncomment this when publish!
|
// uncomment this when publish!
|
||||||
// configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
|
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
}
|
}
|
||||||
manifest {
|
manifest {
|
||||||
attributes 'Manifest-Version': project.version
|
attributes 'Manifest-Version': project.version
|
||||||
|
BIN
lib/bdledger-java-sdk-dev-201104.2ce17584.jar
Normal file
BIN
lib/bdledger-java-sdk-dev-201104.2ce17584.jar
Normal file
Binary file not shown.
@ -16,27 +16,46 @@ import org.bdware.sc.util.JsonUtil;
|
|||||||
import org.zz.gmhelper.SM2KeyPair;
|
import org.zz.gmhelper.SM2KeyPair;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class DebugMain {
|
public class DebugMain {
|
||||||
static Logger LOGGER = LogManager.getLogger(DebugMain.class);
|
static Logger LOGGER = LogManager.getLogger(DebugMain.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void runWithConf(String configPath) {
|
||||||
String content = FileUtil.getFileContent("./debugconf.json");
|
String content = FileUtil.getFileContent(configPath);
|
||||||
DebugConfig config = JsonUtil.fromJson(content, DebugConfig.class);
|
DebugConfig config = JsonUtil.fromJson(content, DebugConfig.class);
|
||||||
inject(config);
|
inject(config);
|
||||||
String keyPairStr = "{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}";
|
String keyPairStr = "{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}";
|
||||||
SM2KeyPair pair = SM2KeyPair.fromJson(String.format(keyPairStr, config.pubKey, config.privKey));
|
SM2KeyPair pair = SM2KeyPair.fromJson(String.format(keyPairStr, config.publicKey, config.privateKey));
|
||||||
String uriFormat = "ws://%s/SCIDE/SCExecutor";
|
String uriFormat = "ws://%s/SCIDE/SCExecutor";
|
||||||
if (config.killContract != null && config.killContract.length() > 0) {
|
if (config.killBeforeStart != null && config.killBeforeStart.length() > 0) {
|
||||||
SmartContractClient client = new SmartContractClient(String.format(uriFormat, config.agentHttpAddr), pair);
|
AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
|
SmartContractClient client = new SmartContractClient(String.format(uriFormat, config.agentAddress), pair) {
|
||||||
|
public void onLogin(JsonObject obj) {
|
||||||
|
counter.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onKillContractProcess(JsonObject obj) {
|
||||||
|
counter.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
client.waitForConnect();
|
client.waitForConnect();
|
||||||
client.login();
|
client.login();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
for (; counter.get() == 0; )
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
client.sendMsg("{\"action\":\"killContractProcess\",\"name\":\"" + config.killBeforeStart + "\"}");
|
||||||
|
try {
|
||||||
|
for (; counter.get() == 1; )
|
||||||
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
client.sendMsg("{\"action\":\"killContractProcess\",\"contractName\":\"" + config.killContract + "\"}");
|
|
||||||
}
|
}
|
||||||
config.contract.setCreateParam(config.createParam);
|
config.contract.setCreateParam(config.createParam);
|
||||||
ContractProcess.main(new String[]{"-port=" + config.port, "-cmi=" + config.cmi, "-disablePID"});
|
ContractProcess.main(new String[]{"-port=" + config.port, "-cmi=" + config.cmi, "-disablePID"});
|
||||||
@ -51,10 +70,13 @@ public class DebugMain {
|
|||||||
ContractProcess.instance.handler.registerMangerPort(wrap("", Integer.valueOf(config.cPort)), printCallback);
|
ContractProcess.instance.handler.registerMangerPort(wrap("", Integer.valueOf(config.cPort)), printCallback);
|
||||||
|
|
||||||
ContractProcess.instance.handler.setContractBundle(wrap("", config.contract), printCallback);
|
ContractProcess.instance.handler.setContractBundle(wrap("", config.contract), printCallback);
|
||||||
String urlFormat = ("http://%s/SCIDE/SCManager?action=reconnectPort&owner=%s&port=%d");
|
|
||||||
|
|
||||||
String url = String.format(urlFormat, config.agentHttpAddr,
|
String urlFormat = "http://%s/SCIDE/SCManager?action=reconnectPort&owner=%s&port=%d%s";
|
||||||
config.pubKey, ContractProcess.instance.server.mainPort.get());
|
String cpHost = "";
|
||||||
|
if (config.cpHost != null && config.cpHost.length() > 0)
|
||||||
|
cpHost = "&host=" + config.cpHost;
|
||||||
|
String url = String.format(urlFormat, config.agentAddress,
|
||||||
|
config.publicKey, ContractProcess.instance.server.mainPort.get(), cpHost);
|
||||||
Map<String, Object> resp = HttpUtil.httpGet(url);
|
Map<String, Object> resp = HttpUtil.httpGet(url);
|
||||||
|
|
||||||
String data = (String) resp.get("response");
|
String data = (String) resp.get("response");
|
||||||
@ -62,9 +84,13 @@ public class DebugMain {
|
|||||||
LOGGER.info("start done!");
|
LOGGER.info("start done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
runWithConf("./debugconf.json");
|
||||||
|
}
|
||||||
|
|
||||||
private static void inject(DebugConfig config) {
|
private static void inject(DebugConfig config) {
|
||||||
String urlFormat = ("http://%s/SCIDE/SCManager?action=%s&arg=%s");
|
String urlFormat = ("http://%s/SCIDE/SCManager?action=%s&arg=%s");
|
||||||
String url = String.format(urlFormat, config.agentHttpAddr, "getAgentConfig", "");
|
String url = String.format(urlFormat, config.agentAddress, "getAgentConfig", "");
|
||||||
Map<String, Object> resp = HttpUtil.httpGet(url);
|
Map<String, Object> resp = HttpUtil.httpGet(url);
|
||||||
String data = (String
|
String data = (String
|
||||||
) resp.get("response");
|
) resp.get("response");
|
||||||
@ -74,8 +100,8 @@ public class DebugMain {
|
|||||||
config.cPort = jsonObject.get("cPort").getAsInt();
|
config.cPort = jsonObject.get("cPort").getAsInt();
|
||||||
config.port = jsonObject.get("port").getAsInt();
|
config.port = jsonObject.get("port").getAsInt();
|
||||||
JsonObject ownerAndScript = new JsonObject();
|
JsonObject ownerAndScript = new JsonObject();
|
||||||
String arg = "abc&owner=" + config.pubKey + "&script=" + config.script;
|
String arg = "abc&owner=" + config.publicKey + "&script=" + config.ypkPath;
|
||||||
url = String.format(urlFormat, config.agentHttpAddr, "allocateKeyPair", arg);
|
url = String.format(urlFormat, config.agentAddress, "allocateKeyPair", arg);
|
||||||
resp = HttpUtil.httpGet(url);
|
resp = HttpUtil.httpGet(url);
|
||||||
LOGGER.info(url);
|
LOGGER.info(url);
|
||||||
String contractStr = (String) resp.get("response");
|
String contractStr = (String) resp.get("response");
|
||||||
@ -97,12 +123,13 @@ public class DebugMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class DebugConfig {
|
static class DebugConfig {
|
||||||
String killContract;
|
String agentAddress;
|
||||||
public JsonElement createParam;
|
public JsonElement createParam;
|
||||||
String script;
|
String publicKey;
|
||||||
String agentHttpAddr;
|
String privateKey;
|
||||||
String pubKey;
|
String killBeforeStart;
|
||||||
String privKey;
|
String ypkPath;
|
||||||
|
String cpHost;
|
||||||
//AutoAppend
|
//AutoAppend
|
||||||
int port;
|
int port;
|
||||||
String cmi;
|
String cmi;
|
||||||
|
94
src/main/java/org/bdware/sc/boundry/utils/IRPUtil.java
Normal file
94
src/main/java/org/bdware/sc/boundry/utils/IRPUtil.java
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package org.bdware.sc.boundry.utils;
|
||||||
|
|
||||||
|
import com.google.api.client.json.Json;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.bdware.doip.audit.EndpointConfig;
|
||||||
|
import org.bdware.doip.audit.client.AuditIrpClient;
|
||||||
|
import org.bdware.doip.audit.config.TempConfigStorage;
|
||||||
|
import org.bdware.doip.codec.digitalObject.DigitalObject;
|
||||||
|
import org.bdware.doip.codec.digitalObject.Element;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
|
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
||||||
|
import org.bdware.doip.codec.operations.BasicOperations;
|
||||||
|
import org.bdware.doip.endpoint.client.ClientConfig;
|
||||||
|
import org.bdware.doip.endpoint.client.DoipClientImpl;
|
||||||
|
import org.bdware.doip.endpoint.client.DoipMessageCallback;
|
||||||
|
import org.bdware.irp.exception.IrpClientException;
|
||||||
|
import org.bdware.irp.stateinfo.StateInfoBase;
|
||||||
|
import org.bdware.sc.compiler.PermissionStub;
|
||||||
|
import org.bdware.sc.engine.JSONTool;
|
||||||
|
import org.bdware.sc.node.Permission;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@PermissionStub(permission = Permission.IRP)
|
||||||
|
public class IRPUtil {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(IRPUtil.class);
|
||||||
|
private final AuditIrpClient auditIrpClient;
|
||||||
|
|
||||||
|
private IRPUtil(String config) {
|
||||||
|
TempConfigStorage configStorage = new TempConfigStorage(config);
|
||||||
|
JsonObject jo = configStorage.load();
|
||||||
|
EndpointConfig endpointConfig = configStorage.loadAsEndpointConfig();
|
||||||
|
|
||||||
|
if (jo.has("clientDoId")) {
|
||||||
|
this.auditIrpClient = new AuditIrpClient(jo.get("clientDoId").getAsString(), endpointConfig);
|
||||||
|
} else {
|
||||||
|
this.auditIrpClient = new AuditIrpClient(endpointConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IRPUtil createClient(String jsonObject) {
|
||||||
|
return new IRPUtil(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String test(String doi) {
|
||||||
|
return "create DOClient And hello " + doi + " World";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object resolve(String doId) {
|
||||||
|
try {
|
||||||
|
StateInfoBase result = auditIrpClient.resolve(doId);
|
||||||
|
JsonObject r = new JsonObject();
|
||||||
|
r.addProperty("code", 0);
|
||||||
|
r.add("handleValues", result.handleValues);
|
||||||
|
return JSONTool.convertJsonElementToMirror(result.handleValues);
|
||||||
|
} catch (Exception e) {
|
||||||
|
JsonObject r = new JsonObject();
|
||||||
|
r.addProperty("code", 1);
|
||||||
|
r.addProperty("msg", e.getMessage());
|
||||||
|
return JSONTool.convertJsonElementToMirror(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object register(ScriptObjectMirror mirror) {
|
||||||
|
JsonObject jo = JSONTool.convertMirrorToJson(mirror).getAsJsonObject();
|
||||||
|
StateInfoBase base = new StateInfoBase();
|
||||||
|
JsonObject result = new JsonObject();
|
||||||
|
if (jo.has("identifier"))
|
||||||
|
base.identifier = jo.get("identifier").getAsString();
|
||||||
|
base.handleValues = jo.get("handleValues").getAsJsonObject();
|
||||||
|
try {
|
||||||
|
String val = auditIrpClient.register(base);
|
||||||
|
result.addProperty("code", 0);
|
||||||
|
result.addProperty("doId", val);
|
||||||
|
if (val == null || val.length() == 0) {
|
||||||
|
result.addProperty("code", 1);
|
||||||
|
result.addProperty("msg", auditIrpClient.getLastResponse().getResponseMessage());
|
||||||
|
}
|
||||||
|
return JSONTool.convertJsonElementToMirror(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.addProperty("code", 1);
|
||||||
|
result.addProperty("msg", e.getMessage());
|
||||||
|
return JSONTool.convertJsonElementToMirror(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user