Search in sources :

Example 11 with PeerId

use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.

the class RemovePeerRequestProcessorTest method verify.

@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
    assertEquals(interest, RemovePeerRequest.class.getName());
    Mockito.verify(node).removePeer(eq(new PeerId("localhost", 8082)), doneArg.capture());
    Closure done = doneArg.getValue();
    assertNotNull(done);
    done.run(Status.OK());
    assertNotNull(this.asyncContext.getResponseObject());
    assertEquals("[localhost:8081, localhost:8082, localhost:8083]", this.asyncContext.as(RemovePeerResponse.class).getOldPeersList().toString());
    assertEquals("[localhost:8081, localhost:8083]", this.asyncContext.as(RemovePeerResponse.class).getNewPeersList().toString());
}
Also used : Closure(com.alipay.sofa.jraft.Closure) RemovePeerResponse(com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerResponse) RemovePeerRequest(com.alipay.sofa.jraft.rpc.CliRequests.RemovePeerRequest) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 12 with PeerId

use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.

the class DefaultRheaKVStore method getLeaderByRegionEngine.

private Endpoint getLeaderByRegionEngine(final long regionId) {
    final RegionEngine regionEngine = getRegionEngine(regionId);
    if (regionEngine != null) {
        final PeerId leader = regionEngine.getLeaderId();
        if (leader != null) {
            final String raftGroupId = JRaftHelper.getJRaftGroupId(this.pdClient.getClusterName(), regionId);
            RouteTable.getInstance().updateLeader(raftGroupId, leader);
            return leader.getEndpoint();
        }
    }
    return null;
}
Also used : RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 13 with PeerId

use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.

the class NodeRequestProcessorTest method testOK.

@Test
public void testOK() {
    Node node = Mockito.mock(Node.class, withSettings().extraInterfaces(RaftServerService.class));
    Mockito.when(node.getGroupId()).thenReturn("test");
    PeerId peerId = new PeerId("localhost", 8081);
    Mockito.when(node.getNodeId()).thenReturn(new NodeId("test", peerId));
    NodeManager.getInstance().addAddress(peerId.getEndpoint());
    NodeManager.getInstance().add(node);
    this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
    ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
    assertNotNull(resp);
    assertEquals(0, resp.getErrorCode());
}
Also used : Node(com.alipay.sofa.jraft.Node) NodeId(com.alipay.sofa.jraft.entity.NodeId) RaftServerService(com.alipay.sofa.jraft.rpc.RaftServerService) PeerId(com.alipay.sofa.jraft.entity.PeerId) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 14 with PeerId

use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.

the class StoreEngine method inConfiguration.

private boolean inConfiguration(final String curr, final String all) {
    final PeerId currPeer = new PeerId();
    if (!currPeer.parse(curr)) {
        return false;
    }
    final Configuration allConf = new Configuration();
    if (!allConf.parse(all)) {
        return false;
    }
    return allConf.contains(currPeer) || allConf.getLearners().contains(currPeer);
}
Also used : Configuration(com.alipay.sofa.jraft.conf.Configuration) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 15 with PeerId

use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.

the class RegionEngine method transferLeadershipTo.

public boolean transferLeadershipTo(final Endpoint endpoint) {
    final PeerId peerId = new PeerId(endpoint, 0);
    final Status status = this.node.transferLeadershipTo(peerId);
    final boolean isOk = status.isOk();
    if (isOk) {
        LOG.info("Transfer-leadership succeeded: [{} --> {}].", this.storeEngine.getSelfEndpoint(), endpoint);
    } else {
        LOG.error("Transfer-leadership failed: {}, [{} --> {}].", status, this.storeEngine.getSelfEndpoint(), endpoint);
    }
    return isOk;
}
Also used : Status(com.alipay.sofa.jraft.Status) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Aggregations

PeerId (com.alipay.sofa.jraft.entity.PeerId)236 Test (org.junit.Test)107 Node (com.alipay.sofa.jraft.Node)70 Configuration (com.alipay.sofa.jraft.conf.Configuration)54 Status (com.alipay.sofa.jraft.Status)49 Endpoint (com.alipay.sofa.jraft.util.Endpoint)43 ArrayList (java.util.ArrayList)32 CountDownLatch (java.util.concurrent.CountDownLatch)28 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)24 LogId (com.alipay.sofa.jraft.entity.LogId)17 Message (com.google.protobuf.Message)15 ByteBuffer (java.nio.ByteBuffer)15 Task (com.alipay.sofa.jraft.entity.Task)13 File (java.io.File)12 SynchronizedClosure (com.alipay.sofa.jraft.closure.SynchronizedClosure)11 LogEntry (com.alipay.sofa.jraft.entity.LogEntry)11 JRaftException (com.alipay.sofa.jraft.error.JRaftException)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 RpcServer (com.alipay.sofa.jraft.rpc.RpcServer)9 RaftGroupService (com.alipay.sofa.jraft.RaftGroupService)8