Search in sources :

Example 6 with DOMDataTreeIdentifier

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

the class DistributedShardFrontend method createProducer.

@Override
public synchronized DOMDataTreeShardProducer createProducer(final Collection<DOMDataTreeIdentifier> paths) {
    for (final DOMDataTreeIdentifier prodPrefix : paths) {
        Preconditions.checkArgument(shardRoot.contains(prodPrefix), "Prefix %s is not contained under shard root", prodPrefix, paths);
    }
    final ShardProxyProducer ret = new ShardProxyProducer(shardRoot, paths, client, createModificationFactory(paths));
    producers.add(ret);
    return ret;
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)

Example 7 with DOMDataTreeIdentifier

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

the class ConfigurationImpl method getShardNameForPrefix.

@Nullable
@Override
public String getShardNameForPrefix(@Nonnull final DOMDataTreeIdentifier prefix) {
    Preconditions.checkNotNull(prefix, "prefix should not be null");
    Entry<DOMDataTreeIdentifier, PrefixShardConfiguration> bestMatchEntry = new SimpleEntry<>(new DOMDataTreeIdentifier(prefix.getDatastoreType(), YangInstanceIdentifier.EMPTY), null);
    for (Entry<DOMDataTreeIdentifier, PrefixShardConfiguration> entry : prefixConfigMap.entrySet()) {
        if (entry.getKey().contains(prefix) && entry.getKey().getRootIdentifier().getPathArguments().size() > bestMatchEntry.getKey().getRootIdentifier().getPathArguments().size()) {
            bestMatchEntry = entry;
        }
    }
    // TODO we really should have mapping based on prefix instead of Strings
    return ClusterUtils.getCleanShardName(bestMatchEntry.getKey().getRootIdentifier());
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) SimpleEntry(java.util.AbstractMap.SimpleEntry) Nullable(javax.annotation.Nullable)

Example 8 with DOMDataTreeIdentifier

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

the class DataTreeCohortIntegrationTest method testCanCommitWithListEntries.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testCanCommitWithListEntries() throws Exception {
    final DOMDataTreeCommitCohort cohort = mock(DOMDataTreeCommitCohort.class);
    doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
    try (AbstractDataStore dataStore = kit.setupAbstractDataStore(DistributedDataStore.class, "testCanCommitWithMultipleListEntries", "cars-1")) {
        final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME)), cohort);
        assertNotNull(cohortReg);
        IntegrationTestKit.verifyShardState(dataStore, "cars-1", state -> assertEquals("Cohort registrations", 1, state.getCommitCohortActors().size()));
        // First write an empty base container and verify the cohort isn't invoked.
        DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
        writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
        writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
        kit.doCommit(writeTx.ready());
        verifyNoMoreInteractions(cohort);
        // Write a single car entry and verify the cohort is invoked.
        writeTx = dataStore.newWriteOnlyTransaction();
        final YangInstanceIdentifier optimaPath = CarsModel.newCarPath("optima");
        final MapEntryNode optimaNode = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
        writeTx.write(optimaPath, optimaNode);
        kit.doCommit(writeTx.ready());
        ArgumentCaptor<Collection> candidateCapture = ArgumentCaptor.forClass(Collection.class);
        verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
        assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapture.getValue().iterator().next(), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.WRITE, Optional.of(optimaNode), Optional.absent());
        // Write replace the cars container with 2 new car entries. The cohort should get invoked with 3
        // DOMDataTreeCandidates: once for each of the 2 new car entries (WRITE mod) and once for the deleted prior
        // car entry (DELETE mod).
        reset(cohort);
        doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
        writeTx = dataStore.newWriteOnlyTransaction();
        final YangInstanceIdentifier sportagePath = CarsModel.newCarPath("sportage");
        final MapEntryNode sportageNode = CarsModel.newCarEntry("sportage", BigInteger.valueOf(20000));
        final YangInstanceIdentifier soulPath = CarsModel.newCarPath("soul");
        final MapEntryNode soulNode = CarsModel.newCarEntry("soul", BigInteger.valueOf(20000));
        writeTx.write(CarsModel.BASE_PATH, CarsModel.newCarsNode(CarsModel.newCarsMapNode(sportageNode, soulNode)));
        kit.doCommit(writeTx.ready());
        candidateCapture = ArgumentCaptor.forClass(Collection.class);
        verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
        assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.WRITE, Optional.of(sportageNode), Optional.absent());
        assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.WRITE, Optional.of(soulNode), Optional.absent());
        assertDataTreeCandidate(findCandidate(candidateCapture, optimaPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.DELETE, Optional.absent(), Optional.of(optimaNode));
        // Delete the cars container - cohort should be invoked for the 2 deleted car entries.
        reset(cohort);
        doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
        writeTx = dataStore.newWriteOnlyTransaction();
        writeTx.delete(CarsModel.BASE_PATH);
        kit.doCommit(writeTx.ready());
        candidateCapture = ArgumentCaptor.forClass(Collection.class);
        verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
        assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.DELETE, Optional.absent(), Optional.of(sportageNode));
        assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.DELETE, Optional.absent(), Optional.of(soulNode));
    }
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DOMDataTreeCommitCohort(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 9 with DOMDataTreeIdentifier

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

the class DistributedShardedDOMDataTreeRemotingTest method testMultipleShardRegistrations.

@Test
public void testMultipleShardRegistrations() throws Exception {
    LOG.info("testMultipleShardRegistrations starting");
    initEmptyDatastores();
    final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    final DistributedShardRegistration reg2 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_CONTAINER_PATH), Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    final DistributedShardRegistration reg3 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.INNER_LIST_PATH), Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    final DistributedShardRegistration reg4 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.JUNK_PATH), Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.OUTER_CONTAINER_PATH));
    leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.INNER_LIST_PATH));
    leaderTestKit.waitUntilLeader(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.JUNK_PATH));
    // check leader has local shards
    assertNotNull(findLocalShard(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
    assertNotNull(findLocalShard(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.OUTER_CONTAINER_PATH)));
    assertNotNull(findLocalShard(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.INNER_LIST_PATH)));
    assertNotNull(findLocalShard(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)));
    // check follower has local shards
    assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
    assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.OUTER_CONTAINER_PATH)));
    assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.INNER_LIST_PATH)));
    assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)));
    LOG.debug("Closing registrations");
    reg1.close().toCompletableFuture().get();
    reg2.close().toCompletableFuture().get();
    reg3.close().toCompletableFuture().get();
    reg4.close().toCompletableFuture().get();
    waitUntilShardIsDown(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    waitUntilShardIsDown(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.OUTER_CONTAINER_PATH));
    waitUntilShardIsDown(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.INNER_LIST_PATH));
    waitUntilShardIsDown(leaderConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.JUNK_PATH));
    LOG.debug("All leader shards gone");
    waitUntilShardIsDown(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    waitUntilShardIsDown(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.OUTER_CONTAINER_PATH));
    waitUntilShardIsDown(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.INNER_LIST_PATH));
    waitUntilShardIsDown(followerConfigDatastore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.JUNK_PATH));
    LOG.debug("All follower shards gone");
    LOG.info("testMultipleShardRegistrations ending");
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 10 with DOMDataTreeIdentifier

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

the class DistributedShardedDOMDataTreeTest method testMultipleShardLevels.

// top level shard at TEST element, with subshards on each outer-list map entry
@Test
@Ignore
public void testMultipleShardLevels() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration testShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, SINGLE_MEMBER), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    final ArrayList<DistributedShardRegistration> registrations = new ArrayList<>();
    final int listSize = 5;
    for (int i = 0; i < listSize; i++) {
        final YangInstanceIdentifier entryYID = getOuterListIdFor(i);
        final CompletionStage<DistributedShardRegistration> future = leaderShardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, entryYID), SINGLE_MEMBER);
        registrations.add(waitOnAsyncTask(future, DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION));
    }
    final DOMDataTreeIdentifier rootId = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singletonList(rootId));
    DOMDataTreeCursorAwareTransaction transaction = producer.createTransaction(false);
    DOMDataTreeWriteCursor cursor = transaction.createCursor(rootId);
    assertNotNull(cursor);
    final MapNode outerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
    final ContainerNode testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
    cursor.write(testNode.getIdentifier(), testNode);
    cursor.close();
    transaction.submit().checkedGet();
    final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
    doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
    final MapNode wholeList = ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build();
    transaction = producer.createTransaction(false);
    cursor = transaction.createCursor(TEST_ID);
    assertNotNull(cursor);
    cursor.write(wholeList.getIdentifier(), wholeList);
    cursor.close();
    transaction.submit().checkedGet();
    leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList());
    verify(mockedDataTreeListener, timeout(35000).atLeast(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
    verifyNoMoreInteractions(mockedDataTreeListener);
    final List<Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>>> allSubtrees = captorForSubtrees.getAllValues();
    final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> lastSubtree = allSubtrees.get(allSubtrees.size() - 1);
    final NormalizedNode<?, ?> actual = lastSubtree.get(TEST_ID);
    assertNotNull(actual);
    final NormalizedNode<?, ?> expected = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableMapNodeBuilder.create(outerList).withValue(createOuterEntries(listSize, "testing-values")).build()).build();
    for (final DistributedShardRegistration registration : registrations) {
        waitOnAsyncTask(registration.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    }
    waitOnAsyncTask(testShardReg.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    assertEquals(expected, actual);
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) DOMDataTreeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeListener) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Aggregations

DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)24 Test (org.junit.Test)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)6 ActorRef (akka.actor.ActorRef)5 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)5 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)5 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)5 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)5 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)4 ArrayList (java.util.ArrayList)3 DOMDataTreeProducerException (org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 Status (akka.actor.Status)2 Success (akka.actor.Status.Success)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Collection (java.util.Collection)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2