Search in sources :

Example 1 with SystemMapNode

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

the class DistributedDataStoreRemotingIntegrationTest method verifyCars.

private static void verifyCars(final DOMStoreReadTransaction readTx, final MapEntryNode... entries) throws Exception {
    final Optional<NormalizedNode> optional = readTx.read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
    assertTrue("isPresent", optional.isPresent());
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listBuilder = ImmutableNodes.mapNodeBuilder(CarsModel.CAR_QNAME);
    for (final NormalizedNode entry : entries) {
        listBuilder.withChild((MapEntryNode) entry);
    }
    assertEquals("Car list node", listBuilder.build(), optional.get());
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 2 with SystemMapNode

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

the class WriteTransactionsHandler method start.

public static ListenableFuture<RpcResult<WriteTransactionsOutput>> start(final DOMDataBroker domDataBroker, final WriteTransactionsInput input) {
    LOG.info("Starting write transactions with input {}", input);
    final String id = input.getId();
    final MapEntryNode entry = ImmutableNodes.mapEntryBuilder(ID_INT, ID, id).withChild(ImmutableNodes.mapNodeBuilder(ITEM).build()).build();
    final YangInstanceIdentifier idListItem = ID_INT_YID.node(entry.getIdentifier());
    final ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ID_INTS)).withChild(ImmutableNodes.mapNodeBuilder(ID_INT).build()).build();
    DOMDataTreeWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
    // write only the top list
    tx.merge(LogicalDatastoreType.CONFIGURATION, ID_INTS_YID, containerNode);
    try {
        tx.commit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | TimeoutException e) {
        LOG.error("Error writing top-level path {}: {}", ID_INTS_YID, containerNode, e);
        return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, String.format("Could not start write transactions - error writing top-level path %s:  %s", ID_INTS_YID, containerNode), e).buildFuture();
    } catch (ExecutionException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof OptimisticLockFailedException) {
            // when multiple write-transactions are executed concurrently we need to ignore this.
            // If we get optimistic lock here it means id-ints already exists and we can continue.
            LOG.debug("Got an optimistic lock when writing initial top level list element.", e);
        } else {
            LOG.error("Error writing top-level path {}: {}", ID_INTS_YID, containerNode, e);
            return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, String.format("Could not start write transactions - error writing top-level path %s:  %s", ID_INTS_YID, containerNode), e).buildFuture();
        }
    }
    tx = domDataBroker.newWriteOnlyTransaction();
    tx.merge(LogicalDatastoreType.CONFIGURATION, idListItem, entry);
    try {
        tx.commit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.error("Error writing top-level path {}: {}", idListItem, entry, e);
        return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, String.format("Could not start write transactions - error writing list entry path %s: %s", idListItem, entry), e).buildFuture();
    }
    LOG.debug("Filling the item list with initial values.");
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ITEM);
    final YangInstanceIdentifier itemListId = idListItem.node(ITEM);
    tx = domDataBroker.newWriteOnlyTransaction();
    final MapNode itemListNode = mapBuilder.build();
    tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, itemListNode);
    try {
        tx.commit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.error("Error filling initial item list path {}: {}", itemListId, itemListNode, e);
        return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION, String.format("Could not start write transactions - error filling initial item list path %s: %s", itemListId, itemListNode), e).buildFuture();
    }
    final WriteTransactionsHandler handler;
    if (input.getChainedTransactions()) {
        handler = new Chained(domDataBroker, idListItem, input);
    } else {
        handler = new Simple(domDataBroker, idListItem, input);
    }
    handler.doStart();
    LOG.info("Write transactions successfully started");
    return handler.completionFuture;
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) 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) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ExecutionException(java.util.concurrent.ExecutionException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with SystemMapNode

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

the class CarsModel method create.

public static ContainerNode create() {
    // Create a list builder
    CollectionNodeBuilder<MapEntryNode, SystemMapNode> 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, Uint64.valueOf(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, Uint64.valueOf("2000"))).build();
    cars.withChild(altima);
    cars.withChild(honda);
    return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME)).withChild(cars.build()).build();
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 4 with SystemMapNode

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

the class PeopleModel method create.

public static ContainerNode create() {
    // Create a list builder
    CollectionNodeBuilder<MapEntryNode, SystemMapNode> 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 : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 5 with SystemMapNode

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

the class NormalizedNodeStreamReaderWriterTest method testHugeEntries.

/*
     * This tests the encoding of a MapNode with a lot of entries, each of them having the key leaf (a string)
     * and an integer.
     */
@Test
public void testHugeEntries() throws IOException {
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME));
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entryBuilder = Builders.mapEntryBuilder().withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, (byte) 42));
    for (int i = 0; i < 100_000; ++i) {
        final String key = "xyzzy" + i;
        mapBuilder.addChild(entryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(TestModel.TEST_QNAME, TestModel.CHILD_NAME_QNAME, key)).withChild(ImmutableNodes.leafNode(TestModel.CHILD_NAME_QNAME, key)).build());
    }
    final SystemMapNode expected = mapBuilder.build();
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (NormalizedNodeDataOutput nnout = version.newDataOutput(ByteStreams.newDataOutput(bos))) {
        nnout.writeNormalizedNode(expected);
    }
    final byte[] bytes = bos.toByteArray();
    assertEquals(hugeEntriesSize, bytes.length);
    NormalizedNodeDataInput nnin = NormalizedNodeDataInput.newDataInput(ByteStreams.newDataInput(bytes));
    assertEquals(expected, nnin.readNormalizedNode());
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) Test(org.junit.Test)

Aggregations

SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)34 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)23 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 Test (org.junit.Test)11 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)8 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)7 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)6 CollectionNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder)5 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)5 QName (org.opendaylight.yangtools.yang.common.QName)4 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)4