Search in sources :

Example 6 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method onRemovePrefixShardReplica.

private void onRemovePrefixShardReplica(final RemovePrefixShardReplica message) {
    LOG.debug("{}: onRemovePrefixShardReplica: {}", persistenceId(), message);
    final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), ClusterUtils.getCleanShardName(message.getShardPrefix()));
    final String shardName = shardId.getShardName();
    findPrimary(shardName, new AutoFindPrimaryFailureResponseHandler(getSender(), shardName, persistenceId(), getSelf()) {

        @Override
        public void onRemotePrimaryShardFound(final RemotePrimaryShardFound response) {
            doRemoveShardReplicaAsync(response.getPrimaryPath());
        }

        @Override
        public void onLocalPrimaryFound(final LocalPrimaryShardFound response) {
            doRemoveShardReplicaAsync(response.getPrimaryPath());
        }

        private void doRemoveShardReplicaAsync(final String primaryPath) {
            getSelf().tell((RunnableMessage) () -> removePrefixShardReplica(message, getShardName(), primaryPath, getSender()), getTargetActor());
        }
    });
}
Also used : LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)

Example 7 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManagerGetSnapshotReplyActor method onGetSnapshotReply.

private void onGetSnapshotReply(final GetSnapshotReply getSnapshotReply) {
    LOG.debug("{}: Received {}", params.id, getSnapshotReply);
    ShardIdentifier shardId = ShardIdentifier.fromShardIdString(getSnapshotReply.getId());
    shardSnapshots.add(new ShardSnapshot(shardId.getShardName(), getSnapshotReply.getSnapshot()));
    remainingShardNames.remove(shardId.getShardName());
    if (remainingShardNames.isEmpty()) {
        LOG.debug("{}: All shard snapshots received", params.id);
        DatastoreSnapshot datastoreSnapshot = new DatastoreSnapshot(params.datastoreType, params.shardManagerSnapshot, shardSnapshots);
        params.replyToActor.tell(datastoreSnapshot, getSelf());
        getSelf().tell(PoisonPill.getInstance(), getSelf());
    }
}
Also used : ShardSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot)

Example 8 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardTest method testPeerAddressResolved.

@Test
public void testPeerAddressResolved() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final ShardIdentifier peerID = ShardIdentifier.create("inventory", MemberName.forName("member-2"), "config");
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().peerAddresses(Collections.<String, String>singletonMap(peerID.toString(), null)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testPeerAddressResolved");
            final String address = "akka://foobar";
            shard.tell(new PeerAddressResolved(peerID.toString(), address), ActorRef.noSender());
            shard.tell(GetOnDemandRaftState.INSTANCE, getRef());
            final OnDemandRaftState state = expectMsgClass(OnDemandRaftState.class);
            assertEquals("getPeerAddress", address, state.getPeerAddresses().get(peerID.toString()));
        }
    };
}
Also used : ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) PeerAddressResolved(org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved) Test(org.junit.Test)

Example 9 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardTest method testClusteredDataTreeChangeListenerRegistration.

@Test
public void testClusteredDataTreeChangeListenerRegistration() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final String testName = "testClusteredDataTreeChangeListenerRegistration";
            final ShardIdentifier followerShardID = ShardIdentifier.create("inventory", MemberName.forName(actorFactory.generateActorId(testName + "-follower")), "config");
            final ShardIdentifier leaderShardID = ShardIdentifier.create("inventory", MemberName.forName(actorFactory.generateActorId(testName + "-leader")), "config");
            final TestActorRef<Shard> followerShard = actorFactory.createTestActor(Shard.builder().id(followerShardID).datastoreContext(dataStoreContextBuilder.shardElectionTimeoutFactor(1000).build()).peerAddresses(Collections.singletonMap(leaderShardID.toString(), "akka://test/user/" + leaderShardID.toString())).schemaContextProvider(() -> SCHEMA_CONTEXT).props().withDispatcher(Dispatchers.DefaultDispatcherId()), followerShardID.toString());
            final TestActorRef<Shard> leaderShard = actorFactory.createTestActor(Shard.builder().id(leaderShardID).datastoreContext(newDatastoreContext()).peerAddresses(Collections.singletonMap(followerShardID.toString(), "akka://test/user/" + followerShardID.toString())).schemaContextProvider(() -> SCHEMA_CONTEXT).props().withDispatcher(Dispatchers.DefaultDispatcherId()), leaderShardID.toString());
            leaderShard.tell(TimeoutNow.INSTANCE, ActorRef.noSender());
            final String leaderPath = waitUntilLeader(followerShard);
            assertEquals("Shard leader path", leaderShard.path().toString(), leaderPath);
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, path), actorFactory.generateActorId(testName + "-DataTreeChangeListener"));
            followerShard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), RegisterDataTreeNotificationListenerReply.class);
            assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
            writeToStore(followerShard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
            listener.waitForChangeEvents();
        }
    };
}
Also used : RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) MockDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) Test(org.junit.Test)

Example 10 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class EntityOwnershipShardTest method testDelayedEntityOwnerSelectionWhenMaxPeerRequestsReceived.

@Test
public void testDelayedEntityOwnerSelectionWhenMaxPeerRequestsReceived() throws Exception {
    testLog.info("testDelayedEntityOwnerSelectionWhenMaxPeerRequestsReceived starting");
    ShardTestKit kit = new ShardTestKit(getSystem());
    EntityOwnerSelectionStrategyConfig.Builder builder = EntityOwnerSelectionStrategyConfig.newBuilder().addStrategy(ENTITY_TYPE, LastCandidateSelectionStrategy.class, 500);
    ShardIdentifier leaderId = newShardId(LOCAL_MEMBER_NAME);
    ShardIdentifier peerId = newShardId(PEER_MEMBER_1_NAME);
    TestActorRef<TestEntityOwnershipShard> peer = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId, peerMap(leaderId.toString()), PEER_MEMBER_1_NAME)), peerId.toString());
    peer.underlyingActor().startDroppingMessagesOfType(ElectionTimeout.class);
    TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId, peerMap(peerId.toString()), LOCAL_MEMBER_NAME, builder.build()), leaderId.toString());
    ShardTestKit.waitUntilLeader(leader);
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, ENTITY_ID1);
    // Add a remote candidate
    peer.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Register local
    leader.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Verify the local candidate becomes owner
    verifyCommittedEntityCandidate(leader, entity.getType(), entity.getIdentifier(), PEER_MEMBER_1_NAME);
    verifyCommittedEntityCandidate(leader, entity.getType(), entity.getIdentifier(), LOCAL_MEMBER_NAME);
    verifyOwner(leader, entity.getType(), entity.getIdentifier(), LOCAL_MEMBER_NAME);
    testLog.info("testDelayedEntityOwnerSelectionWhenMaxPeerRequestsReceived ending");
}
Also used : RegisterCandidateLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal) ShardTestKit(org.opendaylight.controller.cluster.datastore.ShardTestKit) EntityOwnerSelectionStrategyConfig(org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) Test(org.junit.Test)

Aggregations

ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)31 Test (org.junit.Test)15 ShardTestKit (org.opendaylight.controller.cluster.datastore.ShardTestKit)11 RegisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal)11 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)11 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 ActorRef (akka.actor.ActorRef)3 Status (akka.actor.Status)3 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)3 Timeout (akka.util.Timeout)3 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)3 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)3 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)3 FlipShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus)3 PeerDown (org.opendaylight.controller.cluster.datastore.messages.PeerDown)3 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)3 TestActorRef (akka.testkit.TestActorRef)2 HashMap (java.util.HashMap)2