Search in sources :

Example 1 with RaftClientProtocol

use of io.atomix.protocols.raft.protocol.RaftClientProtocol in project atomix by atomix.

the class RaftPerformanceTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
    Node node = nextNode(Node.Type.CLIENT);
    RaftClientProtocol protocol;
    if (USE_NETTY) {
        MessagingService messagingService = NettyMessagingService.builder().withEndpoint(node.endpoint()).build().start().join();
        protocol = new RaftClientMessagingProtocol(messagingService, protocolSerializer, endpointMap::get);
    } else {
        protocol = protocolFactory.newClientProtocol(node.id());
    }
    RaftClient client = RaftClient.builder().withNodeId(node.id()).withProtocol(protocol).withThreadModel(ThreadModel.THREAD_PER_SERVICE).build();
    client.connect(members.stream().map(Node::id).collect(Collectors.toList())).join();
    clients.add(client);
    return client;
}
Also used : RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Node(io.atomix.cluster.Node) RaftClientMessagingProtocol(io.atomix.protocols.raft.protocol.RaftClientMessagingProtocol) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) ManagedMessagingService(io.atomix.messaging.ManagedMessagingService) MessagingService(io.atomix.messaging.MessagingService)

Example 2 with RaftClientProtocol

use of io.atomix.protocols.raft.protocol.RaftClientProtocol in project atomix by atomix.

the class RaftFuzzTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
    NodeId nodeId = nextNodeId();
    RaftClientProtocol protocol;
    if (USE_NETTY) {
        Endpoint endpoint = new Endpoint(InetAddress.getLocalHost(), ++port);
        MessagingService messagingManager = NettyMessagingService.builder().withEndpoint(endpoint).build().start().join();
        endpointMap.put(nodeId, endpoint);
        protocol = new RaftClientMessagingProtocol(messagingManager, protocolSerializer, endpointMap::get);
    } else {
        protocol = protocolFactory.newClientProtocol(nodeId);
    }
    RaftClient client = RaftClient.builder().withNodeId(nodeId).withProtocol(protocol).build();
    client.connect(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).join();
    clients.add(client);
    return client;
}
Also used : RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Endpoint(io.atomix.messaging.Endpoint) NodeId(io.atomix.cluster.NodeId) RaftClientMessagingProtocol(io.atomix.protocols.raft.protocol.RaftClientMessagingProtocol) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) MessagingService(io.atomix.messaging.MessagingService)

Example 3 with RaftClientProtocol

use of io.atomix.protocols.raft.protocol.RaftClientProtocol in project zeppelin by apache.

the class ClusterManager method start.

public void start() {
    if (!zConf.isClusterMode()) {
        return;
    }
    // RaftClient Thread
    new Thread(new Runnable() {

        @Override
        public void run() {
            LOGGER.info("RaftClientThread run() >>>");
            int raftClientPort = 0;
            try {
                raftClientPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
            } catch (IOException e) {
                LOGGER.error(e.getMessage());
            }
            MemberId memberId = MemberId.from(zeplServerHost + ":" + raftClientPort);
            Address address = Address.from(zeplServerHost, raftClientPort);
            raftAddressMap.put(memberId, address);
            MessagingService messagingManager = NettyMessagingService.builder().withAddress(address).build().start().join();
            RaftClientProtocol protocol = new RaftClientMessagingProtocol(messagingManager, protocolSerializer, raftAddressMap::get);
            raftClient = RaftClient.builder().withMemberId(memberId).withPartitionId(PartitionId.from("partition", 1)).withProtocol(protocol).build();
            raftClient.connect(clusterMemberIds).join();
            raftSessionClient = createProxy(raftClient);
            LOGGER.info("RaftClientThread run() <<<");
        }
    }).start();
    // Cluster Meta Consume Thread
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                while (getRunning().get()) {
                    ClusterMetaEntity metaEntity = clusterMetaQueue.peek();
                    if (null != metaEntity) {
                        // Determine whether the client is connected
                        int retry = 0;
                        while (!raftInitialized()) {
                            retry++;
                            if (0 == retry % 30) {
                                LOGGER.warn("Raft incomplete initialization! retry[{}]", retry);
                            }
                            Thread.sleep(100);
                        }
                        boolean success = false;
                        switch(metaEntity.getOperation()) {
                            case DELETE_OPERATION:
                                success = deleteClusterMeta(metaEntity);
                                break;
                            case PUT_OPERATION:
                                success = putClusterMeta(metaEntity);
                                break;
                        }
                        if (true == success) {
                            // The operation was successfully deleted
                            clusterMetaQueue.remove(metaEntity);
                            LOGGER.info("Cluster Meta Consume success! {}", metaEntity);
                        } else {
                            LOGGER.error("Cluster Meta Consume faild!");
                        }
                    } else {
                        Thread.sleep(100);
                    }
                }
            } catch (InterruptedException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }).start();
}
Also used : RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Address(io.atomix.utils.net.Address) InetAddress(java.net.InetAddress) IOException(java.io.IOException) MessagingService(io.atomix.cluster.messaging.MessagingService) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) MemberId(io.atomix.cluster.MemberId) ClusterMetaEntity(org.apache.zeppelin.cluster.meta.ClusterMetaEntity) RaftClientMessagingProtocol(org.apache.zeppelin.cluster.protocol.RaftClientMessagingProtocol)

Aggregations

RaftClientProtocol (io.atomix.protocols.raft.protocol.RaftClientProtocol)3 MessagingService (io.atomix.messaging.MessagingService)2 NettyMessagingService (io.atomix.messaging.impl.NettyMessagingService)2 RaftClientMessagingProtocol (io.atomix.protocols.raft.protocol.RaftClientMessagingProtocol)2 MemberId (io.atomix.cluster.MemberId)1 Node (io.atomix.cluster.Node)1 NodeId (io.atomix.cluster.NodeId)1 MessagingService (io.atomix.cluster.messaging.MessagingService)1 NettyMessagingService (io.atomix.cluster.messaging.impl.NettyMessagingService)1 Endpoint (io.atomix.messaging.Endpoint)1 ManagedMessagingService (io.atomix.messaging.ManagedMessagingService)1 Address (io.atomix.utils.net.Address)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 ClusterMetaEntity (org.apache.zeppelin.cluster.meta.ClusterMetaEntity)1 RaftClientMessagingProtocol (org.apache.zeppelin.cluster.protocol.RaftClientMessagingProtocol)1