All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.ypkdeploy.BDRepoTool Maven / Gradle / Ivy

The newest version!
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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy