Search in sources :

Example 11 with MapNode

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

the class BindingContext method parseDataElement.

public NormalizedNode<?, ?> parseDataElement(final Element element, final DataSchemaNode dataSchema, final SchemaContext schemaContext) throws XMLStreamException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
    final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
    final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
    final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext, dataSchema);
    xmlParser.traverse(new DOMSource(element));
    final NormalizedNode<?, ?> result = resultHolder.getResult();
    if (result instanceof MapNode) {
        final MapNode mapNode = (MapNode) result;
        final MapEntryNode mapEntryNode = mapNode.getValue().iterator().next();
        return mapEntryNode;
    }
    return result;
}
Also used : XmlParserStream(org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream) DOMSource(javax.xml.transform.dom.DOMSource) NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) ImmutableNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 12 with MapNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapNode 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)

Example 13 with MapNode

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

the class CarsModel method create.

public static NormalizedNode<?, ?> create() {
    // Create a list builder
    CollectionNodeBuilder<MapEntryNode, MapNode> cars = ImmutableMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CAR_QNAME));
    // Create an entry for the car altima
    MapEntryNode altima = ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "altima").withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "altima")).withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, new BigInteger("1000"))).build();
    // Create an entry for the car accord
    MapEntryNode honda = ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "accord").withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "accord")).withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, new BigInteger("2000"))).build();
    cars.withChild(altima);
    cars.withChild(honda);
    return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME)).withChild(cars.build()).build();
}
Also used : BigInteger(java.math.BigInteger) 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)

Example 14 with MapNode

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

the class PeopleModel method create.

public static NormalizedNode<?, ?> create() {
    // Create a list builder
    CollectionNodeBuilder<MapEntryNode, MapNode> cars = ImmutableMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(PERSON_QNAME));
    // Create an entry for the person jack
    MapEntryNode jack = ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jack").withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, "jack")).withChild(ImmutableNodes.leafNode(PERSON_AGE_QNAME, 100L)).build();
    // Create an entry for the person jill
    MapEntryNode jill = ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jill").withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, "jill")).withChild(ImmutableNodes.leafNode(PERSON_AGE_QNAME, 200L)).build();
    cars.withChild(jack);
    cars.withChild(jill);
    return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME)).withChild(cars.build()).build();
}
Also used : 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)

Example 15 with MapNode

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

the class PrefixShardHandler method ensureListExists.

private ListenableFuture<Void> ensureListExists() {
    final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ID_INT);
    // hardcoded initial list population for parallel produce-transactions testing on multiple nodes
    for (int i = 1; i < MAX_PREFIX; i++) {
        mapBuilder.withChild(ImmutableNodes.mapEntryBuilder(ID_INT, ID, PREFIX_TEMPLATE + i).withChild(ImmutableNodes.mapNodeBuilder(ITEM).build()).build());
    }
    final MapNode mapNode = mapBuilder.build();
    final ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ID_INTS)).withChild(mapNode).build();
    final DOMDataTreeProducer producer = domDataTreeService.createProducer(Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY)));
    final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY));
    cursor.merge(containerNode.getIdentifier(), containerNode);
    cursor.close();
    final ListenableFuture<Void> future = tx.submit();
    Futures.addCallback(future, new FutureCallback<Void>() {

        @Override
        public void onSuccess(@Nullable final Void result) {
            try {
                LOG.debug("Closing producer for initial list.");
                producer.close();
            } catch (DOMDataTreeProducerException e) {
                LOG.warn("Error while closing producer.", e);
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
        // NOOP handled by the caller of this method.
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) 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) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)

Aggregations

MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)29 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)17 Test (org.junit.Test)12 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)12 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)8 ExecutionException (java.util.concurrent.ExecutionException)6 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)5 DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)5 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)3 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)3 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)3 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)3 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3