Search in sources :

Example 6 with RemoveServer

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

the class ShardManagerTest method testRemoveShardReplicaRemote.

@Test
public void testRemoveShardReplicaRemote() throws Exception {
    MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-1")).build());
    String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    // Create an ActorSystem ShardManager actor for member-1.
    final ActorSystem system1 = newActorSystem("Member1");
    Cluster.get(system1).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    ActorRef mockDefaultShardActor = newMockShardActor(system1, Shard.DEFAULT_NAME, "member-1");
    final TestActorRef<TestShardManager> newReplicaShardManager = TestActorRef.create(system1, newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockDefaultShardActor).cluster(new ClusterWrapperImpl(system1)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Create an ActorSystem ShardManager actor for member-2.
    final ActorSystem system2 = newActorSystem("Member2");
    Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    String name = ShardIdentifier.create("default", MEMBER_2, shardMrgIDSuffix).toString();
    String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
    final TestActorRef<MockRespondActor> mockShardLeaderActor = TestActorRef.create(system2, Props.create(MockRespondActor.class, RemoveServer.class, new RemoveServerReply(ServerChangeStatus.OK, memberId2)), name);
    LOG.error("Mock Shard Leader Actor : {}", mockShardLeaderActor);
    final TestActorRef<TestShardManager> leaderShardManager = TestActorRef.create(system2, newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockShardLeaderActor).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Because mockShardLeaderActor is created at the top level of the actor system it has an address like so,
    // akka://cluster-test@127.0.0.1:2559/user/member-2-shard-default-config1
    // However when a shard manager has a local shard which is a follower and a leader that is remote it will
    // try to compute an address for the remote shard leader using the ShardPeerAddressResolver. This address will
    // look like so,
    // akka://cluster-test@127.0.0.1:2559/user/shardmanager-config1/member-2-shard-default-config1
    // In this specific case if we did a FindPrimary for shard default from member-1 we would come up
    // with the address of an actor which does not exist, therefore any message sent to that actor would go to
    // dead letters.
    // To work around this problem we create a ForwardingActor with the right address and pass to it the
    // mockShardLeaderActor. The ForwardingActor simply forwards all messages to the mockShardLeaderActor and every
    // thing works as expected
    final ActorRef actorRef = leaderShardManager.underlyingActor().context().actorOf(Props.create(ForwardingActor.class, mockShardLeaderActor), "member-2-shard-default-" + shardMrgIDSuffix);
    LOG.error("Forwarding actor : {}", actorRef);
    new TestKit(system1) {

        {
            newReplicaShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            leaderShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            leaderShardManager.tell(new ActorInitialized(), mockShardLeaderActor);
            newReplicaShardManager.tell(new ActorInitialized(), mockShardLeaderActor);
            short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
            leaderShardManager.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), leaderVersion), mockShardLeaderActor);
            leaderShardManager.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardLeaderActor);
            String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
            newReplicaShardManager.tell(new ShardLeaderStateChanged(memberId1, memberId2, mock(DataTree.class), leaderVersion), mockShardActor);
            newReplicaShardManager.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            newReplicaShardManager.underlyingActor().waitForMemberUp();
            leaderShardManager.underlyingActor().waitForMemberUp();
            // construct a mock response message
            newReplicaShardManager.tell(new RemoveShardReplica("default", MEMBER_1), getRef());
            RemoveServer removeServer = MessageCollectorActor.expectFirstMatching(mockShardLeaderActor, RemoveServer.class);
            String removeServerId = ShardIdentifier.create("default", MEMBER_1, shardMrgIDSuffix).toString();
            assertEquals("RemoveServer serverId", removeServerId, removeServer.getServerId());
            expectMsgClass(duration("5 seconds"), Status.Success.class);
        }
    };
}
Also used : ActorSystem(akka.actor.ActorSystem) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) ClusterWrapperImpl(org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ForwardingActor(org.opendaylight.controller.cluster.datastore.utils.ForwardingActor) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) AddressFromURIString(akka.actor.AddressFromURIString) TestKit(akka.testkit.javadsl.TestKit) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) 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 7 with RemoveServer

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

the class RaftActorServerConfigurationSupportTest method testRemoveServerLeader.

@Test
public void testRemoveServerLeader() {
    LOG.info("testRemoveServerLeader starting");
    DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
    configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    configParams.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
    final String followerActorId = actorFactory.generateActorId(FOLLOWER_ID);
    final String followerActorPath = actorFactory.createTestActorPath(followerActorId);
    RaftActorContext initialActorContext = new MockRaftActorContext();
    TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActorPath), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
    final ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor());
    final ActorRef followerCollector = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("collector"));
    actorFactory.createTestActor(CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString()), configParams, NO_PERSISTENCE, followerCollector).withDispatcher(Dispatchers.DefaultDispatcherId()), followerActorId);
    leaderActor.tell(new RemoveServer(LEADER_ID), testKit.getRef());
    RemoveServerReply removeServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), RemoveServerReply.class);
    assertEquals("getStatus", ServerChangeStatus.OK, removeServerReply.getStatus());
    final ApplyState applyState = MessageCollectorActor.expectFirstMatching(followerCollector, ApplyState.class);
    assertEquals(0L, applyState.getReplicatedLogEntry().getIndex());
    verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(FOLLOWER_ID));
    MessageCollectorActor.expectFirstMatching(leaderCollector, ServerRemoved.class);
    LOG.info("testRemoveServerLeader ending");
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) FiniteDuration(scala.concurrent.duration.FiniteDuration) 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 8 with RemoveServer

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

the class RaftActorServerConfigurationSupportTest method testRemoveServerLeaderWithNoFollowers.

@Test
public void testRemoveServerLeaderWithNoFollowers() {
    LOG.info("testRemoveServerLeaderWithNoFollowers starting");
    TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props(Collections.<String, String>emptyMap(), new MockRaftActorContext()).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID));
    leaderActor.tell(new RemoveServer(LEADER_ID), testKit.getRef());
    RemoveServerReply removeServerReply = testKit.expectMsgClass(testKit.duration("5 seconds"), RemoveServerReply.class);
    assertEquals("getStatus", ServerChangeStatus.NOT_SUPPORTED, removeServerReply.getStatus());
    LOG.info("testRemoveServerLeaderWithNoFollowers ending");
}
Also used : RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply) Test(org.junit.Test)

Example 9 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer 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 10 with RemoveServer

use of org.opendaylight.controller.cluster.raft.messages.RemoveServer 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)

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