Search in sources :

Example 1 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer in project controller by opendaylight.

the class ShardManager method removePrefixShardReplica.

private void removePrefixShardReplica(final RemovePrefixShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    // inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 2 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer in project controller by opendaylight.

the class ShardManager method removeShardReplica.

private void removeShardReplica(final RemoveShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    // inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 3 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer in project controller by opendaylight.

the class RaftActorServerConfigurationSupportTest method testRemoveServer.

@Test
public void testRemoveServer() throws Exception {
    LOG.info("testRemoveServer starting");
    DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
    configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    configParams.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
    final String follower1ActorId = actorFactory.generateActorId(FOLLOWER_ID);
    final String follower1ActorPath = actorFactory.createTestActorPath(follower1ActorId);
    final String follower2ActorId = actorFactory.generateActorId(FOLLOWER_ID2);
    final String follower2ActorPath = actorFactory.createTestActorPath(follower2ActorId);
    RaftActorContext initialActorContext = new MockRaftActorContext();
    final String downNodeId = "downNode";
    TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath, downNodeId, ""), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
    final ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor());
    ActorRef follower1Collector = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("collector"));
    final TestActorRef<CollectingMockRaftActor> follower1Actor = actorFactory.createTestActor(CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath, downNodeId, ""), configParams, NO_PERSISTENCE, follower1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId);
    ActorRef follower2Collector = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("collector"));
    final TestActorRef<CollectingMockRaftActor> follower2Actor = actorFactory.createTestActor(CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath, downNodeId, ""), configParams, NO_PERSISTENCE, follower2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), follower2ActorId);
    leaderActor.underlyingActor().waitForInitializeBehaviorComplete();
    follower1Actor.underlyingActor().waitForInitializeBehaviorComplete();
    follower2Actor.underlyingActor().waitForInitializeBehaviorComplete();
    leaderActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef());
    RemoveServerReply removeServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), RemoveServerReply.class);
    assertEquals("getStatus", ServerChangeStatus.OK, removeServerReply.getStatus());
    ApplyState applyState = MessageCollectorActor.expectFirstMatching(leaderCollector, ApplyState.class);
    assertEquals(0L, applyState.getReplicatedLogEntry().getIndex());
    verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(LEADER_ID), votingServer(FOLLOWER_ID2), votingServer(downNodeId));
    applyState = MessageCollectorActor.expectFirstMatching(follower2Collector, ApplyState.class);
    assertEquals(0L, applyState.getReplicatedLogEntry().getIndex());
    verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(LEADER_ID), votingServer(FOLLOWER_ID2), votingServer(downNodeId));
    RaftActorBehavior currentBehavior = leaderActor.underlyingActor().getCurrentBehavior();
    assertTrue("Expected Leader", currentBehavior instanceof Leader);
    assertEquals("Follower ids size", 2, ((Leader) currentBehavior).getFollowerIds().size());
    MessageCollectorActor.expectFirstMatching(follower1Collector, ServerRemoved.class);
    LOG.info("testRemoveServer ending");
}
Also used : AbstractLeader(org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader) Leader(org.opendaylight.controller.cluster.raft.behaviors.Leader) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RaftActorBehavior(org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior) FiniteDuration(scala.concurrent.duration.FiniteDuration) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) ApplyState(org.opendaylight.controller.cluster.raft.base.messages.ApplyState) RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply) Test(org.junit.Test)

Example 4 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer in project controller by opendaylight.

the class RaftActorServerConfigurationSupportTest method testRemoveServerForwardToLeader.

@Test
public void testRemoveServerForwardToLeader() {
    LOG.info("testRemoveServerForwardToLeader starting");
    DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
    configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    ActorRef leaderActor = actorFactory.createTestActor(MessageCollectorActor.props(), actorFactory.generateActorId(LEADER_ID));
    TestActorRef<MockRaftActor> followerRaftActor = actorFactory.createTestActor(MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(ImmutableMap.of(LEADER_ID, leaderActor.path().toString())).config(configParams).persistent(Optional.of(false)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(FOLLOWER_ID));
    followerRaftActor.underlyingActor().waitForInitializeBehaviorComplete();
    followerRaftActor.tell(new AppendEntries(1, LEADER_ID, 0, 1, Collections.<ReplicatedLogEntry>emptyList(), -1, -1, (short) 0), leaderActor);
    followerRaftActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef());
    expectFirstMatching(leaderActor, RemoveServer.class);
    LOG.info("testRemoveServerForwardToLeader ending");
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FiniteDuration(scala.concurrent.duration.FiniteDuration) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) Test(org.junit.Test)

Example 5 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer in project controller by opendaylight.

the class RaftActorServerConfigurationSupportTest method testRemoveServerWithNoLeader.

@Test
public void testRemoveServerWithNoLeader() {
    LOG.info("testRemoveServerWithNoLeader starting");
    DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
    configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    TestActorRef<MockRaftActor> leaderActor = actorFactory.createTestActor(MockRaftActor.builder().id(LEADER_ID).peerAddresses(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString())).config(configParams).persistent(Optional.of(false)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
    leaderActor.underlyingActor().waitForInitializeBehaviorComplete();
    leaderActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef());
    RemoveServerReply removeServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), RemoveServerReply.class);
    assertEquals("getStatus", ServerChangeStatus.NO_LEADER, removeServerReply.getStatus());
    LOG.info("testRemoveServerWithNoLeader ending");
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply) Test(org.junit.Test)

Aggregations

RemoveServer (org.opendaylight.controller.cluster.raft.messages.RemoveServer)10 Test (org.junit.Test)8 RemoveServerReply (org.opendaylight.controller.cluster.raft.messages.RemoveServerReply)7 ActorRef (akka.actor.ActorRef)5 TestActorRef (akka.testkit.TestActorRef)5 FiniteDuration (scala.concurrent.duration.FiniteDuration)4 AddressFromURIString (akka.actor.AddressFromURIString)2 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)2 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)2 TestKit (akka.testkit.javadsl.TestKit)2 Timeout (akka.util.Timeout)2 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)2 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)2 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)2 RemoveShardReplica (org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica)2 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)2 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)2 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)2