Search in sources :

Example 6 with RemoveServerReply

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

the class RaftActorServerConfigurationSupportTest method testRemoveServerNonExistentServer.

@Test
public void testRemoveServerNonExistentServer() {
    LOG.info("testRemoveServerNonExistentServer starting");
    RaftActorContext initialActorContext = new MockRaftActorContext();
    TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString()), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
    leaderActor.tell(new RemoveServer(NEW_SERVER_ID), testKit.getRef());
    RemoveServerReply removeServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), RemoveServerReply.class);
    assertEquals("getStatus", ServerChangeStatus.DOES_NOT_EXIST, removeServerReply.getStatus());
    LOG.info("testRemoveServerNonExistentServer ending");
}
Also used : RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply) Test(org.junit.Test)

Example 7 with RemoveServerReply

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

the class ShardManagerTest method testRemoveShardReplicaLocal.

@Test
public /**
 * Primary is Local.
 */
void testRemoveShardReplicaLocal() throws Exception {
    new TestKit(getSystem()) {

        {
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            final ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, RemoveServer.class, new RemoveServerReply(ServerChangeStatus.OK, null)), memberId);
            ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), respondActor);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), getRef());
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), respondActor);
            shardManager.tell(new RemoveShardReplica(Shard.DEFAULT_NAME, MEMBER_1), getRef());
            final RemoveServer removeServer = MessageCollectorActor.expectFirstMatching(respondActor, RemoveServer.class);
            assertEquals(ShardIdentifier.create("default", MEMBER_1, shardMrgIDSuffix).toString(), removeServer.getServerId());
            expectMsgClass(duration("5 seconds"), Success.class);
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 8 with RemoveServerReply

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

the class RaftActorServerConfigurationSupport method onRemoveServer.

private void onRemoveServer(final RemoveServer removeServer, final ActorRef sender) {
    LOG.debug("{}: onRemoveServer: {}, state: {}", raftContext.getId(), removeServer, currentOperationState);
    boolean isSelf = removeServer.getServerId().equals(raftContext.getId());
    if (isSelf && !raftContext.hasFollowers()) {
        sender.tell(new RemoveServerReply(ServerChangeStatus.NOT_SUPPORTED, raftActor.getLeaderId()), raftActor.getSelf());
    } else if (!isSelf && !raftContext.getPeerIds().contains(removeServer.getServerId())) {
        sender.tell(new RemoveServerReply(ServerChangeStatus.DOES_NOT_EXIST, raftActor.getLeaderId()), raftActor.getSelf());
    } else {
        String serverAddress = isSelf ? raftActor.self().path().toString() : raftContext.getPeerAddress(removeServer.getServerId());
        onNewOperation(new RemoveServerContext(removeServer, serverAddress, sender));
    }
}
Also used : RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply)

Aggregations

RemoveServerReply (org.opendaylight.controller.cluster.raft.messages.RemoveServerReply)8 Test (org.junit.Test)7 RemoveServer (org.opendaylight.controller.cluster.raft.messages.RemoveServer)7 ActorRef (akka.actor.ActorRef)4 TestActorRef (akka.testkit.TestActorRef)4 FiniteDuration (scala.concurrent.duration.FiniteDuration)3 AddressFromURIString (akka.actor.AddressFromURIString)2 TestKit (akka.testkit.javadsl.TestKit)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)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 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)2 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)2 ActorSystem (akka.actor.ActorSystem)1 Status (akka.actor.Status)1 List (java.util.List)1 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)1