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));
}
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();
}
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();
}
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;
}
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();
}
Aggregations