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.util;
20 import java.util.Optional;
21 import javax.annotation.Nonnull;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl;
23 import org.opendaylight.mdsal.binding.api.MountPoint;
24 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class NetconfNotification {
34 private static final Logger log = LoggerFactory.getLogger(DeviceManagerImpl.class);
37 * Do the stream creation for the device.
38 * @param nodeId node-id of device
39 * @param mountpoint information
40 * @param streamName to register
42 public static void registerNotificationStream(String nodeId, MountPoint mountpoint, String streamName) {
44 final Optional<RpcConsumerRegistry> optionalRpcConsumerService =
45 mountpoint.getService(RpcConsumerRegistry.class);
46 if (optionalRpcConsumerService.isPresent()) {
47 final RpcConsumerRegistry rpcConsumerRegitry = optionalRpcConsumerService.get();
49 final NotificationsService rpcService = rpcConsumerRegitry.getRpcService(NotificationsService.class);
51 final CreateSubscriptionInputBuilder createSubscriptionInputBuilder = new CreateSubscriptionInputBuilder();
52 createSubscriptionInputBuilder.setStream(new StreamNameType(streamName));
53 log.info("Event listener triggering notification stream {} for node {}", streamName, nodeId);
55 CreateSubscriptionInput createSubscriptionInput = createSubscriptionInputBuilder.build();
56 if (createSubscriptionInput == null) {
57 log.warn("createSubscriptionInput is null for mountpoint {}", nodeId);
59 rpcService.createSubscription(createSubscriptionInput);
61 } catch (NullPointerException e) {
62 log.warn("createSubscription failed");
65 log.warn("No RpcConsumerRegistry avaialble.");