mirror of
https://gitee.com/BDWare/ypk-deploy-tool
synced 2025-01-09 17:34:02 +00:00
update support for bdrepo
This commit is contained in:
parent
3e15dc9d07
commit
698c8cf569
@ -5,7 +5,7 @@ plugins {
|
||||
id 'signing'
|
||||
}
|
||||
group "org.bdware.bdcontract"
|
||||
version "0.7.3"
|
||||
version "0.7.4"
|
||||
sourceCompatibility = 1.8
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
15
src/main/java/org/bdware/ypkdeploy/BDRepoConfig.java
Normal file
15
src/main/java/org/bdware/ypkdeploy/BDRepoConfig.java
Normal file
@ -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;
|
||||
|
||||
}
|
74
src/main/java/org/bdware/ypkdeploy/BDRepoTool.java
Normal file
74
src/main/java/org/bdware/ypkdeploy/BDRepoTool.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
6
src/main/java/org/bdware/ypkdeploy/CodeRepoConfig.java
Normal file
6
src/main/java/org/bdware/ypkdeploy/CodeRepoConfig.java
Normal file
@ -0,0 +1,6 @@
|
||||
package org.bdware.ypkdeploy;
|
||||
|
||||
public class CodeRepoConfig {
|
||||
public String codeRepoId;
|
||||
public String ypkPath;
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user