Search in sources :

Example 1 with StreamNameType

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

the class CreateSubscription method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    operationElement.checkName(CREATE_SUBSCRIPTION);
    operationElement.checkNamespace(CreateSubscriptionInput.QNAME.getNamespace().toString());
    // FIXME reimplement using CODEC_REGISTRY and parse everything into generated class instance
    // Binding doesn't support anyxml nodes yet, so filter could not be retrieved
    // xml -> normalized node -> CreateSubscriptionInput conversion could be slower than current approach
    final Optional<XmlElement> filter = operationElement.getOnlyChildElementWithSameNamespaceOptionally("filter");
    // Replay not supported
    final Optional<XmlElement> startTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
    checkArgument(startTime.isEmpty(), "StartTime element not yet supported");
    // Stop time not supported
    final Optional<XmlElement> stopTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
    checkArgument(stopTime.isEmpty(), "StopTime element not yet supported");
    final StreamNameType streamNameType = parseStreamIfPresent(operationElement);
    requireNonNull(netconfSession);
    // Premature streams are allowed (meaning listener can register even if no provider is available yet)
    if (!notifications.isStreamAvailable(streamNameType)) {
        LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType, getNetconfSessionIdForReporting());
    }
    final NotificationListenerRegistration notificationListenerRegistration = notifications.registerNotificationListener(streamNameType, new NotificationSubscription(netconfSession, filter));
    subscriptions.add(notificationListenerRegistration);
    return document.createElement(XmlNetconfConstants.OK);
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) NotificationListenerRegistration(org.opendaylight.netconf.notifications.NotificationListenerRegistration)

Example 2 with StreamNameType

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

the class NetconfNotificationManager method registerNotificationPublisher.

@Override
public synchronized NotificationPublisherRegistration registerNotificationPublisher(final Stream stream) {
    final StreamNameType streamName = requireNonNull(stream).getName();
    LOG.debug("Notification publisher registered for stream: {}", streamName);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Notification publisher registered for stream: {}", stream);
    }
    if (streamMetadata.containsKey(streamName)) {
        LOG.warn("Notification stream {} already registered as: {}. Will be reused", streamName, streamMetadata.get(streamName));
    } else {
        streamMetadata.put(streamName, stream);
    }
    availableStreams.add(streamName);
    final GenericNotificationPublisherReg reg = new GenericNotificationPublisherReg(this, streamName) {

        @Override
        public void close() {
            synchronized (NetconfNotificationManager.this) {
                super.close();
            }
        }
    };
    notificationPublishers.add(reg);
    notifyStreamAdded(stream);
    return reg;
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)

Example 3 with StreamNameType

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType 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)

Example 4 with StreamNameType

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

the class NetconfNotificationManagerTest method testCustomNotificationListeners.

@Test
public void testCustomNotificationListeners() throws Exception {
    final NetconfNotificationManager netconfNotificationManager = createManager();
    final StreamNameType testStreamName = new StreamNameType("TEST_STREAM");
    final Stream testStream = new StreamBuilder().setName(testStreamName).build();
    final NetconfNotificationListener listenerBase = mock(NetconfNotificationListener.class);
    netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listenerBase);
    final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
    netconfNotificationManager.registerNotificationListener(testStream.getName(), listener);
    doNothing().when(listener).onNotification(eq(testStreamName), any(NetconfNotification.class));
    final NetconfNotification notification = new NetconfNotification(XmlUtil.readXmlToDocument("<notification/>"));
    netconfNotificationManager.onNotification(testStream.getName(), notification);
    verify(listener).onNotification(eq(testStream.getName()), eq(notification));
    netconfNotificationManager.close();
    netconfNotificationManager.onNotification(testStream.getName(), notification);
    verifyNoMoreInteractions(listener);
    verify(listenerBase, never()).onNotification(eq(testStream.getName()), eq(notification));
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) NetconfNotificationListener(org.opendaylight.netconf.notifications.NetconfNotificationListener) Stream(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream) StreamBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification) Test(org.junit.Test)

Example 5 with StreamNameType

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

the class NotificationToMdsalWriterTest method testStreamRegisteration.

@Test
public void testStreamRegisteration() {
    final StreamNameType testStreamName = new StreamNameType("TESTSTREAM");
    final Stream testStream = new StreamBuilder().setName(testStreamName).build();
    final InstanceIdentifier<Stream> streamIdentifier = InstanceIdentifier.create(Netconf.class).child(Streams.class).child(Stream.class, testStream.key());
    writer.onStreamRegistered(testStream);
    verify(dataBroker.newWriteOnlyTransaction()).merge(LogicalDatastoreType.OPERATIONAL, streamIdentifier, testStream);
    writer.onStreamUnregistered(testStreamName);
    verify(dataBroker.newWriteOnlyTransaction()).delete(LogicalDatastoreType.OPERATIONAL, streamIdentifier);
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) Stream(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream) StreamBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder) Streams(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams) Test(org.junit.Test)

Aggregations

StreamNameType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)5 Stream (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream)3 Test (org.junit.Test)2 StreamBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder)2 ExecutionException (java.util.concurrent.ExecutionException)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 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 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)1 NetconfNotification (org.opendaylight.netconf.notifications.NetconfNotification)1 NetconfNotificationListener (org.opendaylight.netconf.notifications.NetconfNotificationListener)1 NotificationListenerRegistration (org.opendaylight.netconf.notifications.NotificationListenerRegistration)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 Streams (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams)1 StreamKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1