use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ResolveDataChangeEventsTask method resolveAnyChangeEvent.
/**
* Resolves data change event for supplied node.
*
* @param path
* Path to current node in tree
* @param listeners
* Collection of Listener registration nodes interested in
* subtree
* @param modification
* Modification of current node
* @param before
* - Original (before) state of current node
* @param after
* - After state of current node
* @return True if the subtree changed, false otherwise
*/
private boolean resolveAnyChangeEvent(final ResolveDataChangeState state, final DataTreeCandidateNode node) {
final Optional<NormalizedNode<?, ?>> maybeBefore = node.getDataBefore();
final Optional<NormalizedNode<?, ?>> maybeAfter = node.getDataAfter();
final ModificationType type = node.getModificationType();
if (type != ModificationType.UNMODIFIED && !maybeAfter.isPresent() && !maybeBefore.isPresent()) {
LOG.debug("Modification at {} has type {}, but no before- and after-data. Assuming unchanged.", state.getPath(), type);
return false;
}
switch(type) {
case SUBTREE_MODIFIED:
return resolveSubtreeChangeEvent(state, node);
case APPEARED:
case WRITE:
Preconditions.checkArgument(maybeAfter.isPresent(), "Modification at {} has type {} but no after-data", state.getPath(), type);
if (!maybeBefore.isPresent()) {
@SuppressWarnings({ "unchecked", "rawtypes" }) final NormalizedNode<PathArgument, ?> afterNode = (NormalizedNode) maybeAfter.get();
resolveSameEventRecursivelly(state, afterNode, DOMImmutableDataChangeEvent.getCreateEventFactory());
return true;
}
return resolveReplacedEvent(state, maybeBefore.get(), maybeAfter.get());
case DISAPPEARED:
case DELETE:
Preconditions.checkArgument(maybeBefore.isPresent(), "Modification at {} has type {} but no before-data", state.getPath(), type);
@SuppressWarnings({ "unchecked", "rawtypes" }) final NormalizedNode<PathArgument, ?> beforeNode = (NormalizedNode) maybeBefore.get();
resolveSameEventRecursivelly(state, beforeNode, DOMImmutableDataChangeEvent.getRemoveEventFactory());
return true;
case UNMODIFIED:
return false;
default:
break;
}
throw new IllegalStateException(String.format("Unhandled node state %s at %s", type, state.getPath()));
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ResolveDataChangeEventsTask method resolveSameEventRecursivelly.
private void resolveSameEventRecursivelly(final ResolveDataChangeState state, final NormalizedNode<PathArgument, ?> node, final SimpleEventFactory eventFactory) {
if (!state.needsProcessing()) {
LOG.trace("Skipping child {}", state.getPath());
return;
}
// to do additional processing
if (node instanceof NormalizedNodeContainer<?, ?, ?>) {
LOG.trace("Resolving subtree recursive event for {}, type {}", state.getPath(), eventFactory);
// Node has children, so we will try to resolve it's children
// changes.
@SuppressWarnings("unchecked") NormalizedNodeContainer<?, PathArgument, NormalizedNode<PathArgument, ?>> container = (NormalizedNodeContainer<?, PathArgument, NormalizedNode<PathArgument, ?>>) node;
for (NormalizedNode<PathArgument, ?> child : container.getValue()) {
final PathArgument childId = child.getIdentifier();
LOG.trace("Resolving event for child {}", childId);
resolveSameEventRecursivelly(state.child(childId), child, eventFactory);
}
}
final DOMImmutableDataChangeEvent event = eventFactory.create(state.getPath(), node);
LOG.trace("Adding event {} at path {}", event, state.getPath());
state.addEvent(event);
state.collectEvents(event.getOriginalSubtree(), event.getUpdatedSubtree(), collectedEvents);
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class RemoteRpcImplementationTest method testInvokeRpcWithNullInput.
/**
* This test method invokes and executes the remote rpc.
*/
@Test
public void testInvokeRpcWithNullInput() throws Exception {
final ContainerNode rpcOutput = makeRPCOutput("bar");
final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
@SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, null);
assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
assertEquals(rpcOutput, result.getResult());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class RemoteRpcImplementationTest method testInvokeRpcWithNoOutput.
/**
* This test method invokes and executes the remote rpc.
*/
@Test
public void testInvokeRpcWithNoOutput() throws Exception {
final ContainerNode rpcOutput = null;
final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
@SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
assertNull(result.getResult());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class RemoteRpcImplementationTest method testInvokeRpc.
/**
* This test method invokes and executes the remote rpc.
*/
@Test
public void testInvokeRpc() throws Exception {
final ContainerNode rpcOutput = makeRPCOutput("bar");
final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
@SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
assertEquals(rpcOutput, result.getResult());
}
Aggregations