Search in sources :

Example 1 with DOMEntityOwnershipCandidateRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testOwnerSelectedOnRapidRegisteringAndUnregisteringOfCandidates.

@Test
public void testOwnerSelectedOnRapidRegisteringAndUnregisteringOfCandidates() throws Exception {
    String name = "testOwnerSelectedOnRapidRegisteringAndUnregisteringOfCandidates";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Register leader candidate for entity1 and verify it becomes owner
    final DOMEntityOwnershipCandidateRegistration leaderEntity1Reg = leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-1");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-1");
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    leaderEntity1Reg.close();
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-2");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Example 2 with DOMEntityOwnershipCandidateRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testOwnerSelectedOnRapidUnregisteringAndRegisteringOfCandidates.

@Test
public void testOwnerSelectedOnRapidUnregisteringAndRegisteringOfCandidates() throws Exception {
    String name = "testOwnerSelectedOnRapidUnregisteringAndRegisteringOfCandidates";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Register leader candidate for entity1 and verify it becomes owner
    DOMEntityOwnershipCandidateRegistration leaderEntity1Reg = leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-1");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-1");
    leaderEntity1Reg.close();
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-2");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Example 3 with DOMEntityOwnershipCandidateRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testCloseCandidateRegistrationInQuickSuccession.

/**
 * Reproduces bug <a href="https://bugs.opendaylight.org/show_bug.cgi?id=4554">4554</a>.
 */
@Test
public void testCloseCandidateRegistrationInQuickSuccession() throws Exception {
    String name = "testCloseCandidateRegistrationInQuickSuccession";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    final DOMEntityOwnershipService follower2EntityOwnershipService = newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    leaderEntityOwnershipService.registerListener(ENTITY_TYPE1, leaderMockListener);
    follower1EntityOwnershipService.registerListener(ENTITY_TYPE1, follower1MockListener);
    follower2EntityOwnershipService.registerListener(ENTITY_TYPE1, follower2MockListener);
    final DOMEntityOwnershipCandidateRegistration candidate1 = leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, true, true));
    final DOMEntityOwnershipCandidateRegistration candidate2 = follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verify(follower1MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
    final DOMEntityOwnershipCandidateRegistration candidate3 = follower2EntityOwnershipService.registerCandidate(ENTITY1);
    verify(follower2MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
    Mockito.reset(leaderMockListener, follower1MockListener, follower2MockListener);
    ArgumentCaptor<DOMEntityOwnershipChange> leaderChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
    ArgumentCaptor<DOMEntityOwnershipChange> follower1ChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
    ArgumentCaptor<DOMEntityOwnershipChange> follower2ChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
    doNothing().when(leaderMockListener).ownershipChanged(leaderChangeCaptor.capture());
    doNothing().when(follower1MockListener).ownershipChanged(follower1ChangeCaptor.capture());
    doNothing().when(follower2MockListener).ownershipChanged(follower2ChangeCaptor.capture());
    candidate1.close();
    candidate2.close();
    candidate3.close();
    boolean passed = false;
    for (int i = 0; i < 100; i++) {
        Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        final Optional<EntityOwnershipState> leaderState = leaderEntityOwnershipService.getOwnershipState(ENTITY1);
        final Optional<EntityOwnershipState> follower1State = follower1EntityOwnershipService.getOwnershipState(ENTITY1);
        final Optional<EntityOwnershipState> follower2State = follower2EntityOwnershipService.getOwnershipState(ENTITY1);
        final Optional<DOMEntityOwnershipChange> leaderChange = getValueSafely(leaderChangeCaptor);
        final Optional<DOMEntityOwnershipChange> follower1Change = getValueSafely(follower1ChangeCaptor);
        final Optional<DOMEntityOwnershipChange> follower2Change = getValueSafely(follower2ChangeCaptor);
        if (!leaderState.isPresent() || leaderState.get() == EntityOwnershipState.NO_OWNER && follower1State.isPresent() && follower1State.get() == EntityOwnershipState.NO_OWNER && follower2State.isPresent() && follower2State.get() == EntityOwnershipState.NO_OWNER && leaderChange.isPresent() && !leaderChange.get().getState().hasOwner() && follower1Change.isPresent() && !follower1Change.get().getState().hasOwner() && follower2Change.isPresent() && !follower2Change.get().getState().hasOwner()) {
            passed = true;
            break;
        }
    }
    assertTrue("No ownership change message was sent with hasOwner=false", passed);
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) DOMEntityOwnershipChange(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange) EntityOwnershipState(org.opendaylight.mdsal.eos.common.api.EntityOwnershipState) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

Example 4 with DOMEntityOwnershipCandidateRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration in project controller by opendaylight.

the class LegacyEntityOwnershipServiceAdapterTest method testRegisterCandidate.

@Test
public void testRegisterCandidate() throws Exception {
    DOMEntityOwnershipCandidateRegistration mockDOMReg = mock(DOMEntityOwnershipCandidateRegistration.class);
    doNothing().when(mockDOMReg).close();
    doReturn(mockDOMReg).when(mockDOMService).registerCandidate(DOM_ENTITY);
    EntityOwnershipCandidateRegistration reg = adapter.registerCandidate(LEGACY_ENTITY);
    assertNotNull("registerCandidate returned null", reg);
    assertEquals("getInstance", LEGACY_ENTITY, reg.getInstance());
    reg.close();
    verify(mockDOMReg).close();
}
Also used : DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) EntityOwnershipCandidateRegistration(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration) Test(org.junit.Test)

Example 5 with DOMEntityOwnershipCandidateRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testEntityOwnershipShardBootstrapping.

/**
 * Tests bootstrapping the entity-ownership shard when there's no shards initially configured for local
 * member. The entity-ownership shard is initially created as inactive (ie remains a follower), requiring
 * an AddShardReplica request to join it to an existing leader.
 */
@Test
public void testEntityOwnershipShardBootstrapping() throws Exception {
    String name = "testEntityOwnershipShardBootstrapping";
    String moduleShardsConfig = MODULE_SHARDS_MEMBER_1_CONFIG;
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore follower1DistributedDataStore = follower1Node.configDataStore();
    follower1DistributedDataStore.waitTillReady();
    leaderNode.waitForMembersUp("member-2");
    follower1Node.waitForMembersUp("member-1");
    DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1DistributedDataStore);
    leaderEntityOwnershipService.registerListener(ENTITY_TYPE1, leaderMockListener);
    // Register a candidate for follower1 - should get queued since follower1 has no leader
    final DOMEntityOwnershipCandidateRegistration candidateReg = follower1EntityOwnershipService.registerCandidate(ENTITY1);
    Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
    verify(leaderMockListener, never()).ownershipChanged(ownershipChange(ENTITY1));
    // Add replica in follower1
    AddShardReplica addReplica = new AddShardReplica(ENTITY_OWNERSHIP_SHARD_NAME);
    follower1DistributedDataStore.getActorContext().getShardManager().tell(addReplica, follower1Node.kit().getRef());
    Object reply = follower1Node.kit().expectMsgAnyClassOf(follower1Node.kit().duration("5 sec"), Success.class, Failure.class);
    if (reply instanceof Failure) {
        throw new AssertionError("AddShardReplica failed", ((Failure) reply).cause());
    }
    // The queued candidate registration should proceed
    verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
    reset(leaderMockListener);
    candidateReg.close();
    verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, false));
    reset(leaderMockListener);
    // Restart follower1 and verify the entity ownership shard is re-instated by registering.
    Cluster.get(leaderNode.kit().getSystem()).down(Cluster.get(follower1Node.kit().getSystem()).selfAddress());
    follower1Node.cleanup();
    follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verify(leaderMockListener, timeout(20000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
    verifyRaftState(follower1Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME, raftState -> {
        assertNull("Custom RaftPolicy class name", raftState.getCustomRaftPolicyClassName());
        assertEquals("Peer count", 1, raftState.getPeerAddresses().keySet().size());
        assertThat("Peer Id", Iterables.<String>getLast(raftState.getPeerAddresses().keySet()), org.hamcrest.CoreMatchers.containsString("member-1"));
    });
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DOMEntityOwnershipCandidateRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration)8 AbstractDataStore (org.opendaylight.controller.cluster.datastore.AbstractDataStore)5 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)5 DOMEntityOwnershipService (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService)5 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)2 Failure (akka.actor.Status.Failure)1 UnregisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterCandidateLocal)1 AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)1 EntityOwnershipCandidateRegistration (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration)1 CandidateAlreadyRegisteredException (org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException)1 EntityOwnershipState (org.opendaylight.mdsal.eos.common.api.EntityOwnershipState)1 DOMEntityOwnershipChange (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1