Search in sources :

Example 71 with DefaultDOMRpcResult

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));
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) RestConfModule(org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule)

Example 72 with DefaultDOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) OpendaylightKnockKnockRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.OpendaylightKnockKnockRpcService) KnockKnockOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockOutput) KnockKnockOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) Test(org.junit.Test)

Aggregations

DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)72 Test (org.junit.Test)51 QName (org.opendaylight.yangtools.yang.common.QName)27 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)25 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)15 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)15 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)12 Before (org.junit.Before)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)10 NetconfBaseOps (org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps)9 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)5 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)5 RpcError (org.opendaylight.yangtools.yang.common.RpcError)5 ArrayList (java.util.ArrayList)4 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)4