ORAN A1 Adapter YANG Model Update
[ccsdk/features.git] / sdnr / wt / netconfnode-state-service / model / src / main / java / org / onap / ccsdk / features / sdnr / wt / netconfnodestateservice / NetconfAccessor.java
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.netconfnodestateservice;
19
20 import java.util.Optional;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.MountPoint;
24 import org.opendaylight.mdsal.binding.api.NotificationService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.binding.NotificationListener;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class NetconfAccessor implements INetconfAcessor {
34
35     private static final Logger log = LoggerFactory.getLogger(NetconfAccessor.class);
36
37     private final NodeId nodeId;
38     private final DataBroker dataBroker;
39     private final TransactionUtils transactionUtils;
40     private final MountPoint mountpoint;
41     private final NetconfNode netconfNode;
42     private final Capabilities capabilities;
43
44     /**
45      * @param nodeId     of managed netconf node
46      * @param dataBroker to access node
47      */
48     public NetconfAccessor(NodeId nodeId, NetconfNode netconfNode, DataBroker dataBroker, MountPoint mountpoint,
49             TransactionUtils transactionUtils) {
50         super();
51         this.nodeId = nodeId;
52         this.netconfNode = netconfNode;
53         this.dataBroker = dataBroker;
54         this.mountpoint = mountpoint;
55         this.transactionUtils = transactionUtils;
56
57         ConnectionStatus csts = netconfNode != null ? netconfNode.getConnectionStatus() : null;
58         this.capabilities = Capabilities.getAvailableCapabilities(csts != null ? netconfNode : null);
59     }
60
61     /**
62      * @param nodeId     with uuid of managed netconf node
63      * @param dataBroker to access node
64      */
65     public NetconfAccessor(String nodeId, NetconfNode netconfNode, DataBroker dataBroker, MountPoint mountpoint,
66             TransactionUtils transactionUtils) {
67         this(new NodeId(nodeId), netconfNode, dataBroker, mountpoint, transactionUtils);
68     }
69
70     @Override
71     public NodeId getNodeId() {
72         return nodeId;
73     }
74
75     @Override
76     public DataBroker getDataBroker() {
77         return dataBroker;
78     }
79     @Override
80     public MountPoint getMountpoint() {
81         return mountpoint;
82     }
83     @Override
84     public TransactionUtils getTransactionUtils() {
85         return transactionUtils;
86     }
87     @Override
88     public NetconfNode getNetconfNode() {
89         return netconfNode;
90     }
91     @Override
92     public Capabilities getCapabilites() {
93         return capabilities;
94     }
95
96     @Override
97     public @NonNull <T extends NotificationListener> ListenerRegistration<NotificationListener> doRegisterNotificationListener(@NonNull T listener) {
98         log.info("Begin register listener for Mountpoint {}", mountpoint.getIdentifier().toString());
99         final Optional<NotificationService> optionalNotificationService = mountpoint
100                 .getService(NotificationService.class);
101         final NotificationService notificationService = optionalNotificationService.get();
102         final ListenerRegistration<NotificationListener> ranListenerRegistration = notificationService
103                 .registerNotificationListener(listener);
104         log.info("End registration listener for Mountpoint {} Listener: {} Result: {}",
105                 mountpoint.getIdentifier().toString(), optionalNotificationService, ranListenerRegistration);
106         return ranListenerRegistration;
107     }
108
109 }