ac4b8565e30d4fda2a6328ca1f475aa64ab4b04b
[ccsdk/features.git] /
1 /**
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
19
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;
30
31 public class NetconfNotification {
32
33     private static final Logger log = LoggerFactory.getLogger(DeviceManagerImpl.class);
34
35     /**
36      * Do the stream creation for the device.
37      * @param nodeId node-id of device
38      * @param mountpoint information
39      * @param streamName to register
40      */
41     public static void registerNotificationStream(String nodeId, MountPoint mountpoint, String streamName) {
42
43         final Optional<RpcConsumerRegistry> optionalRpcConsumerService =
44                 mountpoint.getService(RpcConsumerRegistry.class);
45         if (optionalRpcConsumerService.isPresent()) {
46             final RpcConsumerRegistry rpcConsumerRegitry = optionalRpcConsumerService.get();
47             @Nonnull
48             final NotificationsService rpcService = rpcConsumerRegitry.getRpcService(NotificationsService.class);
49
50             final CreateSubscriptionInputBuilder createSubscriptionInputBuilder = new CreateSubscriptionInputBuilder();
51             createSubscriptionInputBuilder.setStream(new StreamNameType(streamName));
52             log.info("Event listener triggering notification stream {} for node {}", streamName, nodeId);
53             try {
54                 CreateSubscriptionInput createSubscriptionInput = createSubscriptionInputBuilder.build();
55                 if (createSubscriptionInput == null) {
56                     log.warn("createSubscriptionInput is null for mountpoint {}", nodeId);
57                 } else {
58                     rpcService.createSubscription(createSubscriptionInput);
59                 }
60             } catch (NullPointerException e) {
61                 log.warn("createSubscription failed");
62             }
63         } else {
64             log.warn("No RpcConsumerRegistry avaialble.");
65         }
66
67     }
68
69 }