Support for PM (Performance Management)
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / adapter-manager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / adaptermanager / impl / NtsNetworkElement.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 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.adaptermanager.impl;
19
20 import java.util.Optional;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.binding.NotificationListener;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * @author herbert
37  *
38  */
39 public class NtsNetworkElement implements NetworkElement {
40
41     private static final Logger LOG = LoggerFactory.getLogger(NtsNetworkElement.class);
42
43     private final NetconfBindingAccessor netconfAccessor;
44
45     @SuppressWarnings("unused")
46     private final DataProvider databaseService;
47     private final NotificationListenerImpl notificationListener;
48
49     private @NonNull ListenerRegistration<NotificationListener> listenerRegistrationresult;
50
51     NtsNetworkElement(NetconfBindingAccessor netconfAccess, DeviceManagerServiceProvider serviceProvider) {
52         LOG.debug("Create {}", NtsNetworkElement.class.getSimpleName());
53         this.netconfAccessor = netconfAccess;
54         this.databaseService = serviceProvider.getDataProvider();
55         this.notificationListener = new NotificationListenerImpl(netconfAccess,serviceProvider);
56         this.listenerRegistrationresult = null;
57     }
58
59     @Override
60     public void deregister() {
61         if(this.listenerRegistrationresult!=null) {
62             this.listenerRegistrationresult.close();
63         }
64     }
65
66     @Override
67     public NodeId getNodeId() {
68         return netconfAccessor.getNodeId();
69     }
70
71     @Override
72     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
73         return Optional.empty();
74     }
75
76     @Override
77     public void warmstart() {
78     }
79
80     @Override
81     public void register() {
82         if (netconfAccessor.isNotificationsRFC5277Supported()) {
83             listenerRegistrationresult = netconfAccessor.doRegisterNotificationListener(this.notificationListener);
84             // Register default (NETCONF) stream
85             netconfAccessor.registerNotificationsStream();
86             LOG.debug("registered for notifications");
87         } else {
88             LOG.warn("unable to register for notifications. RFC5277 not supported");
89         }
90     }
91
92     @Override
93     public NetworkElementDeviceType getDeviceType() {
94         return NetworkElementDeviceType.NtsManager;
95     }
96
97     @Override
98     public Optional<NetconfAccessor> getAcessor() {
99         return Optional.of(this.netconfAccessor);
100     }
101 }