2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
20 import java.util.Optional;
21 import javax.annotation.Nonnull;
22 import org.opendaylight.mdsal.binding.api.MountPoint;
23 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class NetconfNotification {
33 private static final Logger log = LoggerFactory.getLogger(DeviceManagerImpl.class);
36 * Do the stream creation for the device.
37 * @param nodeId node-id of device
38 * @param mountpoint information
39 * @param streamName to register
41 public static void registerNotificationStream(String nodeId, MountPoint mountpoint, String streamName) {
43 final Optional<RpcConsumerRegistry> optionalRpcConsumerService =
44 mountpoint.getService(RpcConsumerRegistry.class);
45 if (optionalRpcConsumerService.isPresent()) {
46 final RpcConsumerRegistry rpcConsumerRegitry = optionalRpcConsumerService.get();
48 final NotificationsService rpcService = rpcConsumerRegitry.getRpcService(NotificationsService.class);
50 final CreateSubscriptionInputBuilder createSubscriptionInputBuilder = new CreateSubscriptionInputBuilder();
51 createSubscriptionInputBuilder.setStream(new StreamNameType(streamName));
52 log.info("Event listener triggering notification stream {} for node {}", streamName, nodeId);
54 CreateSubscriptionInput createSubscriptionInput = createSubscriptionInputBuilder.build();
55 if (createSubscriptionInput == null) {
56 log.warn("createSubscriptionInput is null for mountpoint {}", nodeId);
58 rpcService.createSubscription(createSubscriptionInput);
60 } catch (NullPointerException e) {
61 log.warn("createSubscription failed");
64 log.warn("No RpcConsumerRegistry avaialble.");