Search in sources :

Example 6 with CliClientServiceImpl

use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Raft method waitConsensusNodeStarted.

private boolean waitConsensusNodeStarted(ParticipantContext context, NetworkAddress changeConsensusNodeAddress) {
    CliClientServiceImpl rpcClient = createRpcClient(context);
    Endpoint changeNode = new Endpoint(changeConsensusNodeAddress.getHost(), changeConsensusNodeAddress.getPort());
    int i = 0;
    while (i <= MAX_RETRY_TIMES) {
        i++;
        try {
            Thread.sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (rpcClient.connect(changeNode)) {
            return true;
        }
    }
    return false;
}
Also used : Endpoint(com.alipay.sofa.jraft.util.Endpoint) CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) Endpoint(com.alipay.sofa.jraft.util.Endpoint)

Example 7 with CliClientServiceImpl

use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Raft method createRpcClient.

private CliClientServiceImpl createRpcClient(ParticipantContext context) {
    if (context.getProperty(RPC_CLIENT) != null) {
        return (CliClientServiceImpl) context.getProperty(RPC_CLIENT);
    }
    RaftConsensusSettings consensusSetting = (RaftConsensusSettings) getConsensusSetting(context);
    RaftNetworkSettings networkSettings = consensusSetting.getNetworkSettings();
    SSLSecurity sslSecurity = context.sslSecurity();
    // 启用TLS
    if (sslSecurity != null && sslSecurity.getKeyStore() != null) {
        GmSSLProvider.enableGMSupport(sslSecurity.getProtocol());
        setSystemProperty("bolt.client.ssl.enable", "true");
        setSystemProperty("bolt.client.ssl.keystore", sslSecurity.getTrustStore());
        setSystemProperty("bolt.client.ssl.keystore.password", sslSecurity.getTrustStorePassword());
        setSystemProperty("bolt.client.ssl.keystore.type", sslSecurity.getTrustStoreType() == null ? "JKS" : sslSecurity.getTrustStoreType());
        setSystemProperty("bolt.ssl.protocol", sslSecurity.getProtocol());
        setSystemProperty("bolt.server.ssl.enable", "true");
        setSystemProperty("bolt.server.ssl.keystore", sslSecurity.getKeyStore());
        setSystemProperty("bolt.server.ssl.keyalias", sslSecurity.getKeyAlias());
        setSystemProperty("bolt.server.ssl.keystore.password", sslSecurity.getKeyStorePassword());
        setSystemProperty("bolt.server.ssl.keystore.type", sslSecurity.getKeyStoreType());
        if (sslSecurity.getEnabledProtocols() != null && sslSecurity.getEnabledProtocols().length > 0) {
            setSystemProperty("bolt.ssl.enabled-protocols", String.join(",", sslSecurity.getEnabledProtocols()));
        }
        if (sslSecurity.getCiphers() != null && sslSecurity.getCiphers().length > 0) {
            setSystemProperty("bolt.ssl.ciphers", String.join(",", sslSecurity.getCiphers()));
        }
    }
    CliOptions cliOptions = new CliOptions();
    cliOptions.setRpcConnectTimeoutMs(networkSettings.getRpcConnectTimeoutMs());
    cliOptions.setRpcDefaultTimeout(networkSettings.getRpcDefaultTimeoutMs());
    cliOptions.setRpcInstallSnapshotTimeout(networkSettings.getRpcSnapshotTimeoutMs());
    cliOptions.setTimeoutMs(networkSettings.getRpcRequestTimeoutMs() * 2);
    cliOptions.setMaxRetry(MAX_RETRY_TIMES);
    CliClientServiceImpl clientService = new CliClientServiceImpl();
    clientService.init(cliOptions);
    context.setProperty(RPC_CLIENT, clientService);
    context.setProperty(RPC_QUEST_TIMEOUT_MS, networkSettings.getRpcRequestTimeoutMs() * 2);
    return clientService;
}
Also used : RaftNetworkSettings(com.jd.blockchain.consensus.raft.settings.RaftNetworkSettings) CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) RaftConsensusSettings(com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings) SSLSecurity(utils.net.SSLSecurity) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Aggregations

CliClientServiceImpl (com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl)7 CliOptions (com.alipay.sofa.jraft.option.CliOptions)4 PeerId (com.alipay.sofa.jraft.entity.PeerId)3 Endpoint (com.alipay.sofa.jraft.util.Endpoint)2 RouteTable (com.alipay.sofa.jraft.RouteTable)1 Status (com.alipay.sofa.jraft.Status)1 Configuration (com.alipay.sofa.jraft.conf.Configuration)1 TestCluster (com.alipay.sofa.jraft.core.TestCluster)1 NodeSettings (com.jd.blockchain.consensus.NodeSettings)1 RaftConsensusSettings (com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings)1 RaftNetworkSettings (com.jd.blockchain.consensus.raft.settings.RaftNetworkSettings)1 RaftNodeSettings (com.jd.blockchain.consensus.raft.settings.RaftNodeSettings)1 File (java.io.File)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Before (org.junit.Before)1 SSLSecurity (utils.net.SSLSecurity)1