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