use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class RpcServiceAdapter method transformFuture.
private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc, final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
return Futures.transform(domFuture, input -> {
final NormalizedNode<?, ?> domData = input.getResult();
final DataObject bindingResult;
if (domData != null) {
final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
} else {
bindingResult = null;
}
// DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking
// at reported errors and checking whether they are just warnings.
final Collection<RpcError> errors = input.getErrors();
return RpcResult.class.cast(RpcResultBuilder.status(errors.stream().noneMatch(error -> error.getSeverity() == ErrorSeverity.ERROR)).withResult(bindingResult).withRpcErrors(errors).build());
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class PruningDataTreeModificationTest method testMergeWithInvalidChildNodeNames.
@Test
public void testMergeWithInvalidChildNodeNames() throws DataValidationFailedException {
ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild(ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build();
DataContainerChild<?, ?> outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two")));
ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).build();
YangInstanceIdentifier path = TestModel.TEST_PATH;
pruningDataTreeModification.merge(path, normalizedNode);
dataTree.commit(getCandidate());
ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).build();
Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(path);
assertTrue("After pruning present", actual.isPresent());
assertEquals("After pruning", prunedNode, actual.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class DistributedShardFrontendTest method createCrossShardContainer.
private static ContainerNode createCrossShardContainer() {
final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(createInnerMapNode(1)).build();
final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).withChild(createInnerMapNode(2)).build();
final MapNode outerList = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry1).withChild(outerListEntry2).build();
final ContainerNode testContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
return testContainer;
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.
@Test
public void testToAndFromBinary() throws NotSerializableException {
DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
DataTreeModification modification = dataTree.takeSnapshot().newModification();
ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
TransactionIdentifier txId = nextTransactionId();
ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
final Object deserialized;
try {
final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
final byte[] bytes = serializer.toBinary(readyMessage);
deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
} finally {
JavaTestKit.shutdownActorSystem(system);
}
assertNotNull("fromBinary returned null", deserialized);
assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
BatchedModifications batched = (BatchedModifications) deserialized;
assertEquals("getTransactionID", txId, batched.getTransactionId());
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
List<Modification> batchedMods = batched.getModifications();
assertEquals("getModifications size", 2, batchedMods.size());
Modification mod = batchedMods.get(0);
assertEquals("Modification type", WriteModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
mod = batchedMods.get(1);
assertEquals("Modification type", MergeModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class ClientTransactionCursorTest method testMerge.
@Test
public void testMerge() throws Exception {
final YangInstanceIdentifier.NodeIdentifier path = YangInstanceIdentifier.NodeIdentifier.create(NODE_1);
final ContainerNode data = createData(path.getNodeType());
cursor.merge(path, data);
final YangInstanceIdentifier expected = createId(NODE_1);
verify(transaction).merge(expected, data);
}
Aggregations