Search in sources :

Example 1 with CreateSubscriptionInputBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder in project netconf by opendaylight.

the class MountedDeviceListener method trackNotificationsPerformance.

private void trackNotificationsPerformance(final YangInstanceIdentifier path) {
    // 1. get nodeId from the path
    final String nodeId = TestUtils.getNodeId(path).get();
    // 2. extract needed services from the mount point
    final DOMMountPoint mountPoint = mountPointService.getMountPoint(path).orElseThrow(() -> new RuntimeException("Unable to get mountpoint"));
    final DOMRpcService rpcService = mountPoint.getService(DOMRpcService.class).orElseThrow(() -> new RuntimeException("Unable to get RPC Service from the mountpoint"));
    final DOMNotificationService notificationService = mountPoint.getService(DOMNotificationService.class).orElseThrow(() -> new RuntimeException("Unable to get NotificationService from the mountpoint"));
    // 3. create a listener for the notifications
    listeners.put(path, notificationService.registerNotificationListener(new NotificationsCounter(nodeId, serializer), Absolute.of(VrfRouteNotification.QNAME)));
    // 4. send 'create-subscription' request to the device
    final StreamNameType streamNameType = new StreamNameType(STREAM_DEFAULT_NAME);
    final CreateSubscriptionInputBuilder subscriptionInputBuilder = new CreateSubscriptionInputBuilder();
    subscriptionInputBuilder.setStream(streamNameType);
    final CreateSubscriptionInput input = subscriptionInputBuilder.build();
    final ContainerNode inputNode = serializer.toNormalizedNodeRpcData(input);
    final ListenableFuture<? extends DOMRpcResult> resultFuture = rpcService.invokeRpc(CREATE_SUBSCRIPTION_QNAME, inputNode);
    Futures.addCallback(resultFuture, new FutureCallback<DOMRpcResult>() {

        @Override
        public void onSuccess(@Nullable final DOMRpcResult rpcResult) {
            LOG.info("Notification stream subscription succesfully completed");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Notification stream subscription failed");
        }
    }, MoreExecutors.directExecutor());
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMNotificationService(org.opendaylight.mdsal.dom.api.DOMNotificationService) NotificationsCounter(org.opendaylight.netconf.test.perf.notifications.NotificationsCounter) CreateSubscriptionInput(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) CreateSubscriptionInputBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder)

Aggregations

DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)1 DOMNotificationService (org.opendaylight.mdsal.dom.api.DOMNotificationService)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)1 NotificationsCounter (org.opendaylight.netconf.test.perf.notifications.NotificationsCounter)1 CreateSubscriptionInput (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput)1 CreateSubscriptionInputBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder)1 StreamNameType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1