Search in sources :

Example 1 with FindPrimary

use of org.opendaylight.controller.cluster.datastore.messages.FindPrimary in project controller by opendaylight.

the class ActorContext method findPrimaryShardAsync.

public Future<PrimaryShardInfo> findPrimaryShardAsync(final String shardName) {
    Future<PrimaryShardInfo> ret = primaryShardInfoCache.getIfPresent(shardName);
    if (ret != null) {
        return ret;
    }
    Future<Object> future = executeOperationAsync(shardManager, new FindPrimary(shardName, true), shardInitializationTimeout);
    return future.transform(new Mapper<Object, PrimaryShardInfo>() {

        @Override
        public PrimaryShardInfo checkedApply(Object response) throws UnknownMessageException {
            if (response instanceof RemotePrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                RemotePrimaryShardFound found = (RemotePrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), found.getPrimaryVersion(), null);
            } else if (response instanceof LocalPrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                LocalPrimaryShardFound found = (LocalPrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), DataStoreVersions.CURRENT_VERSION, found.getLocalShardDataTree());
            } else if (response instanceof NotInitializedException) {
                throw (NotInitializedException) response;
            } else if (response instanceof PrimaryNotFoundException) {
                throw (PrimaryNotFoundException) response;
            } else if (response instanceof NoShardLeaderException) {
                throw (NoShardLeaderException) response;
            }
            throw new UnknownMessageException(String.format("FindPrimary returned unkown response: %s", response));
        }
    }, FIND_PRIMARY_FAILURE_TRANSFORMER, getClientDispatcher());
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) UnknownMessageException(org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)

Example 2 with FindPrimary

use of org.opendaylight.controller.cluster.datastore.messages.FindPrimary in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryWaitForReadyWithCandidateShard.

@Test
public void testOnReceiveFindPrimaryWaitForReadyWithCandidateShard() throws Exception {
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithCandidateShard starting");
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            shardManager.tell(new RoleChangeNotification("member-1-shard-default-" + shardMrgIDSuffix, null, RaftState.Candidate.name()), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
            expectMsgClass(duration("2 seconds"), NoShardLeaderException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithCandidateShard ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) 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) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 3 with FindPrimary

use of org.opendaylight.controller.cluster.datastore.messages.FindPrimary in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryForRemoteShard.

@Test
public void testOnReceiveFindPrimaryForRemoteShard() throws Exception {
    LOG.info("testOnReceiveFindPrimaryForRemoteShard starting");
    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"));
    final TestActorRef<TestShardManager> shardManager1 = TestActorRef.create(system1, newTestShardMgrBuilderWithMockShardActor().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"));
    final ActorRef mockShardActor2 = newMockShardActor(system2, "astronauts", "member-2");
    MockConfiguration mockConfig2 = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).build());
    final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig2).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    new TestKit(system1) {

        {
            shardManager1.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new ActorInitialized(), mockShardActor2);
            String memberId2 = "member-2-shard-astronauts-" + shardMrgIDSuffix;
            short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
            shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), leaderVersion), mockShardActor2);
            shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor2);
            shardManager1.underlyingActor().waitForMemberUp();
            shardManager1.tell(new FindPrimary("astronauts", false), getRef());
            RemotePrimaryShardFound found = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
            String path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path, path.contains("member-2-shard-astronauts-config"));
            assertEquals("getPrimaryVersion", leaderVersion, found.getPrimaryVersion());
            shardManager2.underlyingActor().verifyFindPrimary();
        // This part times out quite a bit on jenkins for some reason
        // Cluster.get(system2).down(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
        // 
        // shardManager1.underlyingActor().waitForMemberRemoved();
        // 
        // shardManager1.tell(new FindPrimary("astronauts", false), getRef());
        // 
        // expectMsgClass(duration("5 seconds"), PrimaryNotFoundException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryForRemoteShard ending");
}
Also used : ActorSystem(akka.actor.ActorSystem) ClusterWrapperImpl(org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl) 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) AddressFromURIString(akka.actor.AddressFromURIString) TestKit(akka.testkit.javadsl.TestKit) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 4 with FindPrimary

use of org.opendaylight.controller.cluster.datastore.messages.FindPrimary in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryWaitForShardLeader.

@Test
public void testOnReceiveFindPrimaryWaitForShardLeader() throws Exception {
    LOG.info("testOnReceiveFindPrimaryWaitForShardLeader starting");
    datastoreContextBuilder.shardInitializationTimeout(10, TimeUnit.SECONDS);
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            // We're passing waitUntilInitialized = true to FindPrimary so
            // the response should be
            // delayed until we send ActorInitialized and
            // RoleChangeNotification.
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
            expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
            shardManager.tell(new ActorInitialized(), mockShardActor);
            expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
            expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
            DataTree mockDataTree = mock(DataTree.class);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
            assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
            expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
        }
    };
    LOG.info("testOnReceiveFindPrimaryWaitForShardLeader ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) 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) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 5 with FindPrimary

use of org.opendaylight.controller.cluster.datastore.messages.FindPrimary in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryWaitForReadyWithNoRoleShard.

@Test
public void testOnReceiveFindPrimaryWaitForReadyWithNoRoleShard() throws Exception {
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithNoRoleShard starting");
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
            expectMsgClass(duration("2 seconds"), NoShardLeaderException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryWaitForReadyWithNoRoleShard ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)18 ActorRef (akka.actor.ActorRef)16 TestActorRef (akka.testkit.TestActorRef)16 TestKit (akka.testkit.javadsl.TestKit)16 Test (org.junit.Test)16 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)16 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)15 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)14 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)11 AddressFromURIString (akka.actor.AddressFromURIString)9 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)9 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)7 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)6 ActorSystem (akka.actor.ActorSystem)4 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)4 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)4 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)3 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)3 PrimaryShardInfoFutureCache (org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache)2 Timeout (akka.util.Timeout)1