Search in sources :

Example 16 with MapEntryNode

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

the class TxchainDomWrite method executeList.

@Override
public void executeList() {
    final LogicalDatastoreType dsType = getDataStoreType();
    final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
    final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
    DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
    int txSubmitted = 0;
    int writeCnt = 0;
    for (MapEntryNode element : this.list) {
        YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues()));
        if (oper == StartTestInput.Operation.PUT) {
            tx.put(dsType, yid, element);
        } else {
            tx.merge(dsType, yid, element);
        }
        writeCnt++;
        // Start performing the operation; submit the transaction at every n-th operation
        if (writeCnt == writesPerTx) {
            txSubmitted++;
            Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

                @Override
                public void onSuccess(final Void result) {
                    txOk++;
                }

                @Override
                public void onFailure(final Throwable t) {
                    LOG.error("Transaction failed, {}", t);
                    txError++;
                }
            });
            tx = chain.newWriteOnlyTransaction();
            writeCnt = 0;
        }
    }
    try {
        txSubmitted++;
        tx.submit().checkedGet();
        txOk++;
    } catch (final TransactionCommitFailedException e) {
        LOG.error("Transaction failed", e);
        txError++;
    }
    try {
        chain.close();
    } catch (final IllegalStateException e) {
        LOG.error("Transaction close failed,", e);
    }
    LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError));
}
Also used : DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 17 with MapEntryNode

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

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

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

Example 20 with MapEntryNode

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

the class ProduceTransactionsHandler method execWrite.

@Override
ListenableFuture<Void> execWrite(final long txId) {
    final int i = random.nextInt(MAX_ITEM + 1);
    final DOMDataTreeCursorAwareTransaction tx = itemProducer.createTransaction(false);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(idListItem);
    final NodeIdentifierWithPredicates entryId = new NodeIdentifierWithPredicates(ITEM, NUMBER, i);
    if (usedValues.contains(i)) {
        LOG.debug("Deleting item: {}", i);
        deleteTx++;
        cursor.delete(entryId);
        usedValues.remove(i);
    } else {
        LOG.debug("Inserting item: {}", i);
        insertTx++;
        final MapEntryNode entry = ImmutableNodes.mapEntryBuilder().withNodeIdentifier(entryId).withChild(ImmutableNodes.leafNode(NUMBER, i)).build();
        cursor.write(entryId, entry);
        usedValues.add(i);
    }
    cursor.close();
    return tx.submit();
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) 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