Search in sources :

Example 46 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.

the class WriteTransactionsHandler method execWrite.

@Override
ListenableFuture<Void> execWrite(final long txId) {
    final int i = nextInt(MAX_ITEM + 1);
    final YangInstanceIdentifier entryId = idListItem.node(ITEM).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(ITEM, NUMBER, i));
    final DOMDataWriteTransaction tx = createTransaction();
    if (usedValues.contains(i)) {
        LOG.debug("Deleting item: {}", i);
        deleteTx++;
        tx.delete(LogicalDatastoreType.CONFIGURATION, entryId);
        usedValues.remove(i);
    } else {
        LOG.debug("Inserting item: {}", i);
        insertTx++;
        final MapEntryNode entry = ImmutableNodes.mapEntry(ITEM, NUMBER, i);
        tx.put(LogicalDatastoreType.CONFIGURATION, entryId, entry);
        usedValues.add(i);
    }
    return tx.submit();
}
Also used : MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 47 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.

the class DistributedShardFrontendTest method createCrossShardContainer.

private static ContainerNode createCrossShardContainer() {
    final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(createInnerMapNode(1)).build();
    final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).withChild(createInnerMapNode(2)).build();
    final MapNode outerList = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry1).withChild(outerListEntry2).build();
    final ContainerNode testContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
    return testContainer;
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 48 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode 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 49 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.

the class PrefixedShardConfigWriter method doWrite.

private DOMStoreThreePhaseCommitCohort doWrite(final YangInstanceIdentifier path, final Collection<MemberName> replicas) {
    final ListNodeBuilder<Object, LeafSetEntryNode<Object>> replicaListBuilder = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_REPLICA_QNAME));
    replicas.forEach(name -> replicaListBuilder.withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(ClusterUtils.SHARD_REPLICA_QNAME, name.getName())).withValue(name.getName()).build()));
    final MapEntryNode newEntry = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifierWithPredicates(ClusterUtils.SHARD_LIST_QNAME, ClusterUtils.SHARD_PREFIX_QNAME, path)).withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_PREFIX_QNAME)).withValue(path).build()).withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_REPLICAS_QNAME)).withChild(replicaListBuilder.build()).build()).build();
    final ClientTransaction tx = history.createTransaction();
    final DOMDataTreeWriteCursor cursor = tx.openCursor();
    ClusterUtils.SHARD_LIST_PATH.getPathArguments().forEach(cursor::enter);
    cursor.write(newEntry.getIdentifier(), newEntry);
    cursor.close();
    return tx.ready();
}
Also used : LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ClientTransaction(org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 50 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.

the class DistributedEntityOwnershipService method getOwnershipState.

@Override
public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
    Preconditions.checkNotNull(forEntity, "forEntity cannot be null");
    DataTree dataTree = getLocalEntityOwnershipShardDataTree();
    if (dataTree == null) {
        return Optional.absent();
    }
    java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(entityPath(forEntity.getType(), forEntity.getIdentifier()));
    if (!entityNode.isPresent()) {
        return Optional.absent();
    }
    // Check if there are any candidates, if there are none we do not really have ownership state
    final MapEntryNode entity = (MapEntryNode) entityNode.get();
    final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
    final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
    if (!hasCandidates) {
        return Optional.absent();
    }
    MemberName localMemberName = context.getCurrentMemberName();
    java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
    String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
    boolean hasOwner = !Strings.isNullOrEmpty(owner);
    boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
    return Optional.of(EntityOwnershipState.from(isOwner, hasOwner));
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Aggregations

MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)95 Test (org.junit.Test)55 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)50 ArrayList (java.util.ArrayList)39 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)34 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder)34 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)29 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand)20 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)17 DestinationFlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv4.DestinationFlowspecBuilder)12 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)11 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)10 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)7 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)6 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)6 BitmaskOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.BitmaskOperand)6 BigInteger (java.math.BigInteger)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5