Search in sources :

Example 16 with DOMDataTreeIdentifier

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

the class ProduceTransactionsHandler method start.

public static ListenableFuture<RpcResult<ProduceTransactionsOutput>> start(final DOMDataTreeService domDataTreeService, final ProduceTransactionsInput input) {
    final String id = input.getId();
    LOG.debug("Filling the item list {} with initial values.", id);
    final YangInstanceIdentifier idListWithKey = ID_INT_YID.node(new NodeIdentifierWithPredicates(ID_INT, ID, id));
    final DOMDataTreeProducer itemProducer = domDataTreeService.createProducer(Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey)));
    final DOMDataTreeCursorAwareTransaction tx = itemProducer.createTransaction(false);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey));
    final MapNode list = ImmutableNodes.mapNodeBuilder(ITEM).build();
    cursor.write(list.getIdentifier(), list);
    cursor.close();
    try {
        tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.warn("Unable to fill the initial item list.", e);
        closeProducer(itemProducer);
        return Futures.immediateFuture(RpcResultBuilder.<ProduceTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
    }
    final ProduceTransactionsHandler handler = new ProduceTransactionsHandler(itemProducer, new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, idListWithKey.node(list.getIdentifier()).toOptimized()), input);
    // It is handler's responsibility to close itemProducer when the work is finished.
    handler.doStart();
    return handler.future;
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ProduceTransactionsOutput(org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.ProduceTransactionsOutput) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with DOMDataTreeIdentifier

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

the class DistributedShardedDOMDataTreeTest method testMultipleWritesIntoSingleMapEntry.

@Test
public void testMultipleWritesIntoSingleMapEntry() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration shardRegistration = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
    LOG.warn("Got after waiting for nonleader");
    final ActorRef leaderShardManager = leaderDistributedDataStore.getActorContext().getShardManager();
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    final YangInstanceIdentifier oid1 = getOuterListIdFor(0);
    final DOMDataTreeIdentifier outerListPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1);
    final DistributedShardRegistration outerListShardReg = waitOnAsyncTask(leaderShardFactory.createDistributedShard(outerListPath, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(outerListPath.getRootIdentifier()));
    final DOMDataTreeProducer shardProducer = leaderShardFactory.createProducer(Collections.singletonList(outerListPath));
    final DOMDataTreeCursorAwareTransaction tx = shardProducer.createTransaction(false);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
    assertNotNull(cursor);
    MapNode innerList = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME)).build();
    cursor.write(new NodeIdentifier(TestModel.INNER_LIST_QNAME), innerList);
    cursor.close();
    tx.submit().checkedGet();
    final ArrayList<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        final Collection<MapEntryNode> innerListMapEntries = createInnerListMapEntries(1000, "run-" + i);
        for (final MapEntryNode innerListMapEntry : innerListMapEntries) {
            final DOMDataTreeCursorAwareTransaction tx1 = shardProducer.createTransaction(false);
            final DOMDataTreeWriteCursor cursor1 = tx1.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1.node(new NodeIdentifier(TestModel.INNER_LIST_QNAME))));
            cursor1.write(innerListMapEntry.getIdentifier(), innerListMapEntry);
            cursor1.close();
            futures.add(tx1.submit());
        }
    }
    futures.get(futures.size() - 1).checkedGet();
    final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
    doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
    leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_LIST_ID), true, Collections.emptyList());
    verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
    verifyNoMoreInteractions(mockedDataTreeListener);
    final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
    final NormalizedNode<?, ?> expected = ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME)).withValue(createInnerListMapEntries(1000, "run-999")).build();
    assertEquals("List values dont match the expected values from the last run", expected, capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get());
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) ActorRef(akka.actor.ActorRef) 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) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) Matchers.anyCollection(org.mockito.Matchers.anyCollection) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 18 with DOMDataTreeIdentifier

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

the class DistributedShardedDOMDataTreeTest method testCDSDataTreeProducer.

@Test
public void testCDSDataTreeProducer() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
    final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
    assertTrue(producer instanceof CDSDataTreeProducer);
    final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
    CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
    assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
    shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
    assertEquals(TEST_ID, shardAccess.getShardIdentifier());
    shardAccess = cdsProducer.getShardAccess(configRoot);
    assertEquals(configRoot, shardAccess.getShardIdentifier());
    waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) CDSShardAccess(org.opendaylight.controller.cluster.dom.api.CDSShardAccess) CDSDataTreeProducer(org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 19 with DOMDataTreeIdentifier

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

the class DistributedShardedDOMDataTree method initDefaultShard.

@SuppressWarnings("checkstyle:IllegalCatch")
private void initDefaultShard(final LogicalDatastoreType logicalDatastoreType) throws ExecutionException, InterruptedException {
    final PrefixedShardConfigWriter writer = writerMap.get(logicalDatastoreType);
    if (writer.checkDefaultIsPresent()) {
        LOG.debug("{}: Default shard for {} is already present in the config. Possibly saved in snapshot.", memberName, logicalDatastoreType);
    } else {
        try {
            // Currently the default shard configuration is present in the out-of-box modules.conf and is
            // expected to be present. So look up the local default shard here and create the frontend.
            // TODO we don't have to do it for config and operational default shard separately. Just one of them
            // should be enough
            final ActorContext actorContext = logicalDatastoreType == LogicalDatastoreType.CONFIGURATION ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
            final Optional<ActorRef> defaultLocalShardOptional = actorContext.findLocalShard(ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
            if (defaultLocalShardOptional.isPresent()) {
                LOG.debug("{}: Default shard for {} is already started, creating just frontend", memberName, logicalDatastoreType);
                createShardFrontend(new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY));
            }
        // The local shard isn't present - we assume that means the local member isn't in the replica list
        // and will be dynamically created later via an explicit add-shard-replica request. This is the
        // bootstrapping mechanism to add a new node into an existing cluster. The following code to create
        // the default shard as a prefix shard is problematic in this scenario so it is commented out. Since
        // the default shard is a module-based shard by default, it makes sense to always treat it as such,
        // ie bootstrap it in the same manner as the special prefix-configuration and EOS shards.
        // final Collection<MemberName> names = distributedConfigDatastore.getActorContext().getConfiguration()
        // .getUniqueMemberNamesForAllShards();
        // Await.result(FutureConverters.toScala(createDistributedShard(
        // new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY), names)),
        // SHARD_FUTURE_TIMEOUT_DURATION);
        // } catch (DOMDataTreeShardingConflictException e) {
        // LOG.debug("{}: Default shard for {} already registered, possibly due to other node doing it faster",
        // memberName, logicalDatastoreType);
        } catch (Exception e) {
            LOG.error("{}: Default shard initialization for {} failed", memberName, logicalDatastoreType, e);
            throw new RuntimeException(e);
        }
    }
}
Also used : ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) TimeoutException(java.util.concurrent.TimeoutException) DOMDataTreeLoopException(org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException) DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) ExecutionException(java.util.concurrent.ExecutionException) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Example 20 with DOMDataTreeIdentifier

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

the class ShardedDataTreeActor method onLookupPrefixShard.

@SuppressWarnings("checkstyle:IllegalCatch")
private void onLookupPrefixShard(final LookupPrefixShard message) {
    LOG.debug("Member: {}, Received LookupPrefixShard: {}", clusterWrapper.getCurrentMemberName(), message);
    final DOMDataTreeIdentifier prefix = message.getPrefix();
    final ActorContext context = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
    // schedule a notification task for the reply
    actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL, new ShardCreationLookupTask(actorSystem, getSender(), clusterWrapper, context, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

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