- private boolean ensureListExists(final SettableFuture<RpcResult<ProduceTransactionsOutput>> settableFuture) {
-
- final MapEntryNode entry = ImmutableNodes.mapEntryBuilder(ID_INT, ID, id)
- .withChild(ImmutableNodes.mapNodeBuilder(ITEM).build())
- .build();
- final MapNode mapNode =
- ImmutableNodes.mapNodeBuilder(ID_INT)
- .withChild(entry)
- .build();
-
- final ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new 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));
-
- idListWithKey = ID_INT_YID.node(entry.getIdentifier());
-
- cursor.merge(containerNode.getIdentifier(), containerNode);
- cursor.close();
-
- try {
- tx.submit().checkedGet();
- } catch (TransactionCommitFailedException e) {
- LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
- settableFuture.set(RpcResultBuilder.<ProduceTransactionsOutput>failed()
- .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
- return false;
- } finally {
- try {
- producer.close();
- } catch (DOMDataTreeProducerException e) {
- LOG.warn("Error while closing producer.", e);
- }
- }
-
- return true;
- }
-