use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class RestconfImpl method invokeSalRemoteRpcNotifiStrRPC.
/**
* Prepare stream for notification.
*
* @param payload
* contains list of qnames of notifications
* @return - checked future object
*/
private ListenableFuture<DOMRpcResult> invokeSalRemoteRpcNotifiStrRPC(final NormalizedNodeContext payload) {
final ContainerNode data = (ContainerNode) payload.getData();
LeafSetNode leafSet = null;
String outputType = "XML";
for (final DataContainerChild dataChild : data.body()) {
if (dataChild instanceof LeafSetNode) {
leafSet = (LeafSetNode) dataChild;
} else if (dataChild instanceof AugmentationNode) {
outputType = (String) ((AugmentationNode) dataChild).body().iterator().next().body();
}
}
final Collection<LeafSetEntryNode<?>> entryNodes = leafSet.body();
final List<SchemaPath> paths = new ArrayList<>();
String streamName = CREATE_NOTIFICATION_STREAM + "/";
StringBuilder streamNameBuilder = new StringBuilder(streamName);
final Iterator<LeafSetEntryNode<?>> iterator = entryNodes.iterator();
while (iterator.hasNext()) {
final QName valueQName = QName.create((String) iterator.next().body());
final XMLNamespace namespace = valueQName.getModule().getNamespace();
final Module module = controllerContext.findModuleByNamespace(namespace);
checkNotNull(module, "Module for namespace %s does not exist", namespace);
NotificationDefinition notifiDef = null;
for (final NotificationDefinition notification : module.getNotifications()) {
if (notification.getQName().equals(valueQName)) {
notifiDef = notification;
break;
}
}
final String moduleName = module.getName();
checkNotNull(notifiDef, "Notification %s does not exist in module %s", valueQName, moduleName);
paths.add(SchemaPath.of(Absolute.of(notifiDef.getQName())));
streamNameBuilder.append(moduleName).append(':').append(valueQName.getLocalName());
if (iterator.hasNext()) {
streamNameBuilder.append(',');
}
}
streamName = streamNameBuilder.toString();
final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
final QName outputQname = QName.create(rpcQName, "output");
final QName streamNameQname = QName.create(rpcQName, "notification-stream-identifier");
final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname)).withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
if (!Notificator.existNotificationListenerFor(streamName)) {
Notificator.createNotificationListener(paths, streamName, outputType, controllerContext);
}
return Futures.immediateFuture(new DefaultDOMRpcResult(output));
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project mdsal by opendaylight.
the class BindingDOMRpcIntegrationTest method testDOMRegistrationWithBindingInvocation.
@Test
public void testDOMRegistrationWithBindingInvocation() throws InterruptedException, ExecutionException, TimeoutException {
KnockKnockOutput baKnockKnockOutput = new KnockKnockOutputBuilder().setAnswer("open").build();
biRpcProviderService.registerRpcImplementation((rpc, input) -> FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(testContext.getCodec().currentSerializer().toNormalizedNodeRpcData(baKnockKnockOutput))), DOMRpcIdentifier.create(KNOCK_KNOCK_QNAME, testContext.getCodec().currentSerializer().toYangInstanceIdentifier(BA_NODE_ID)));
final OpendaylightKnockKnockRpcService baKnockService = baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
Future<RpcResult<KnockKnockOutput>> baResult = baKnockService.knockKnock(knockKnock(BA_NODE_ID).setQuestion("Who's there?").build());
assertNotNull(baResult);
assertEquals(baKnockKnockOutput, baResult.get(5, TimeUnit.SECONDS).getResult());
}
Aggregations