diff --git a/build.gradle b/build.gradle index 15bb5a6..2b36235 100755 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'signing' } group "org.bdware.bdcontract" -version "0.7.3" +version "0.7.4" sourceCompatibility = 1.8 repositories { mavenCentral() diff --git a/src/main/java/org/bdware/ypkdeploy/BDRepoConfig.java b/src/main/java/org/bdware/ypkdeploy/BDRepoConfig.java new file mode 100644 index 0000000..f85a6d2 --- /dev/null +++ b/src/main/java/org/bdware/ypkdeploy/BDRepoConfig.java @@ -0,0 +1,15 @@ +package org.bdware.ypkdeploy; + +import com.google.gson.JsonObject; + +public class BDRepoConfig { + public String bdRepoId; + public String bcoId; + public JsonObject deployKeyPair; + public JsonObject accessKeyPair; + + public JsonObject createParam; + public int shardingID; + public int doipStartPort; + +} \ No newline at end of file diff --git a/src/main/java/org/bdware/ypkdeploy/BDRepoTool.java b/src/main/java/org/bdware/ypkdeploy/BDRepoTool.java new file mode 100644 index 0000000..9e2246f --- /dev/null +++ b/src/main/java/org/bdware/ypkdeploy/BDRepoTool.java @@ -0,0 +1,74 @@ +package org.bdware.ypkdeploy; + +import com.google.gson.Gson; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bdware.bdosclient.BDRepoClient; +import org.bdware.doip.audit.EndpointConfig; +import org.bdware.doip.audit.client.AuditIrpClient; +import org.bdware.doip.audit.config.FileStorage; +import org.bdware.doip.codec.doipMessage.DoipMessage; +import org.bdware.doip.endpoint.client.DoipMessageCallback; +import org.zz.gmhelper.SM2KeyPair; + +import java.util.concurrent.atomic.AtomicInteger; + +public class BDRepoTool { + static Logger LOGGER = LogManager.getLogger(BDRepoTool.class); + + public static void deploy(String publishConfig, String bcoId) throws Exception { + FileStorage storage = new FileStorage(publishConfig); + EndpointConfig endpointConfig = storage.loadAsEndpointConfig(); + AuditIrpClient irpClient = new AuditIrpClient(endpointConfig); + BDRepoConfig bdosConfig = new Gson().fromJson(storage.load(), BDRepoConfig.class); + BDRepoClient client = new BDRepoClient(bdosConfig.bdRepoId, irpClient, SM2KeyPair.fromJson(bdosConfig.accessKeyPair.toString())); + AtomicInteger result = new AtomicInteger(0); + if (bcoId == null) + bcoId = bdosConfig.bcoId; + LOGGER.info("deploy: " + bcoId + " @" + bdosConfig.bdRepoId); + client.createBDO(bcoId, bdosConfig.shardingID, bdosConfig.createParam, bdosConfig.doipStartPort, SM2KeyPair.fromJson(bdosConfig.deployKeyPair.toString()), + new BDRepoClient.StartBDOResultCallback() { + @Override + public void onResult(BDRepoClient.StartBDOResult ret) { + LOGGER.info("[BDRepoTool] " + new Gson().toJson(ret)); + LOGGER.info("[BDRepoTool] " + new Gson().toJson(ret.originalMessage.header)); + LOGGER.info("[BDRepoTool] doipMsg:" + ret.originalMessage.body.getDataAsJsonString()); + result.incrementAndGet(); + } + }); + for (; result.get() == 0; ) { + Thread.yield(); + } + } + + public static void deploy(String publishConfig) throws Exception { + deploy(publishConfig, null); + } + + public static void kill(String config) throws Exception { + kill(config, null); + } + + public static void kill(String publishConfig, String bdoId) throws Exception { + FileStorage storage = new FileStorage(publishConfig); + EndpointConfig endpointConfig = storage.loadAsEndpointConfig(); + AuditIrpClient irpClient = new AuditIrpClient(endpointConfig); + BDRepoConfig bdosConfig = new Gson().fromJson(storage.load(), BDRepoConfig.class); + BDRepoClient client = new BDRepoClient(bdosConfig.bdRepoId, irpClient, SM2KeyPair.fromJson(bdosConfig.accessKeyPair.toString())); + AtomicInteger result = new AtomicInteger(0); + if (bdoId == null) + bdoId = bdosConfig.bdRepoId + "/" + bdosConfig.deployKeyPair.get("publicKey").getAsString().hashCode(); + LOGGER.info("kill:" + bdoId); + client.deleteBDO(bdoId, new DoipMessageCallback() { + @Override + public void onResult(DoipMessage ret) { + LOGGER.info("[BDRepoTool] " + new Gson().toJson(ret.header)); + LOGGER.info("[BDRepoTool] doipMsg:" + ret.body.getDataAsJsonString()); + result.incrementAndGet(); + } + }); + for (; result.get() == 0; ) { + Thread.yield(); + } + } +} diff --git a/src/main/java/org/bdware/ypkdeploy/CodeRepoConfig.java b/src/main/java/org/bdware/ypkdeploy/CodeRepoConfig.java new file mode 100644 index 0000000..5dcbb48 --- /dev/null +++ b/src/main/java/org/bdware/ypkdeploy/CodeRepoConfig.java @@ -0,0 +1,6 @@ +package org.bdware.ypkdeploy; + +public class CodeRepoConfig { + public String codeRepoId; + public String ypkPath; +} \ No newline at end of file diff --git a/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java b/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java index ed4cce1..50eb77a 100644 --- a/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java +++ b/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java @@ -1,5 +1,6 @@ package org.bdware.ypkdeploy; +import com.google.gson.Gson; import com.google.gson.JsonObject; import org.bdware.bdosclient.CodeRepoClient; import org.bdware.doip.audit.EndpointConfig; @@ -11,18 +12,24 @@ import org.zz.gmhelper.SM2KeyPair; import java.util.concurrent.atomic.AtomicInteger; public class CodeRepoTool { - static class Config { - - } public static void publish(String publishConfig, String ypkPath) throws Exception { FileStorage storage = new FileStorage(publishConfig); EndpointConfig endpointConfig = storage.loadAsEndpointConfig(); AuditIrpClient irpClient = new AuditIrpClient(endpointConfig); + CodeRepoConfig bdosConfig = new Gson().fromJson(storage.load(), CodeRepoConfig.class); JsonObject arg = storage.load(); - CodeRepoClient client = new CodeRepoClient(arg.get("codeRepoId").getAsString(), irpClient, SM2KeyPair.fromJson(arg.toString())); + if (bdosConfig.codeRepoId == null) { + System.out.println("[CodeRepoTool] error: missing codeRepoId"); + return; + } + CodeRepoClient client = new CodeRepoClient(bdosConfig.codeRepoId, irpClient, SM2KeyPair.fromJson(arg.toString())); if (ypkPath == null) - ypkPath = arg.get("ypkPath").getAsString(); + ypkPath = bdosConfig.ypkPath; + if (ypkPath == null) { + System.out.println("[CodeRepoTool] error: missing ypkPath"); + return; + } AtomicInteger result = new AtomicInteger(0); client.createAndUpload(ypkPath, new CodeRepoClient.ProgressCallback() { @Override