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
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==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
21 import java.util.List;
22 import java.util.Objects;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.onap.ccsdk.features.sdnr.wt.common.HtAssert;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.OdlClusterSingleton;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateListener;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
32 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
35 import org.opendaylight.yangtools.concepts.ListenerRegistration;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 public class DeviceManagerNetconfNotConnectHandler implements NetconfNodeStateListener {
41 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerNetconfNotConnectHandler.class);
43 private final @NonNull ListenerRegistration<NetconfNodeStateListener> registerNetconfNodeStateListener;
45 private final @NonNull ODLEventListenerHandler odlEventListenerHandler;
46 private final @NonNull DeviceMonitor deviceMonitor;
47 private final @NonNull List<NetworkElementFactory> factoryList;
48 private final @NonNull DeviceManagerServiceProvider serviceProvider;
51 private final boolean odlEventListenerHandlerEnabled;
52 private final boolean deviceMonitorEnabled;
54 private final OdlClusterSingleton singleton;
56 public DeviceManagerNetconfNotConnectHandler(@NonNull NetconfNodeStateService netconfNodeStateService,
57 @NonNull ClusterSingletonServiceProvider clusterSingletonServiceProvider,
58 @NonNull ODLEventListenerHandler odlEventListenerHandler, @NonNull DeviceMonitor deviceMonitor,
59 @NonNull DeviceManagerServiceProvider serviceProvider, @NonNull List<NetworkElementFactory> factoryList) {
61 HtAssert.nonnull(netconfNodeStateService, this.odlEventListenerHandler = odlEventListenerHandler,
62 this.deviceMonitor = deviceMonitor, this.serviceProvider = serviceProvider,
63 this.factoryList = factoryList, odlEventListenerHandler);
65 /* Used for debug purpose */
66 this.odlEventListenerHandlerEnabled = true;
67 this.deviceMonitorEnabled = false;
69 this.singleton = new OdlClusterSingleton(clusterSingletonServiceProvider);
70 this.registerNetconfNodeStateListener = netconfNodeStateService.registerNetconfNodeStateListener(this);
75 public void onCreated(NodeId nNodeId, NetconfNode netconfNode) {
76 LOG.info("onCreated {}", nNodeId);
77 if (isOdlEventListenerHandlerMaster()) {
78 odlEventListenerHandler.registration(nNodeId, netconfNode);
80 if (deviceMonitorEnabled) {
81 deviceMonitor.deviceDisconnectIndication(nNodeId.getValue());
86 public void onStateChange(NodeId nNodeId, NetconfNode netconfNode) {
87 LOG.info("onStateChange {}", nNodeId);
88 if (isOdlEventListenerHandlerMaster()) {
89 odlEventListenerHandler.onStateChangeIndication(nNodeId, netconfNode);
94 public void onRemoved(NodeId nNodeId) {
95 LOG.info("mountpointNodeRemoved {}", nNodeId.getValue());
97 if (deviceMonitorEnabled) {
98 deviceMonitor.removeMountpointIndication(nNodeId.getValue());
100 if (isOdlEventListenerHandlerMaster()) {
101 odlEventListenerHandler.deRegistration(nNodeId); //Additional indication for log
106 public void close() {
107 if (Objects.nonNull(registerNetconfNodeStateListener)) {
108 registerNetconfNodeStateListener.close();
112 /*--------------------------------------------
116 private boolean isOdlEventListenerHandlerMaster() {
117 return odlEventListenerHandlerEnabled && singleton.isMaster();
120 protected @NonNull DeviceManagerServiceProvider getServiceProvider() {
121 return serviceProvider;
124 protected @NonNull List<NetworkElementFactory> getFactoryList() {
129 protected boolean isDeviceMonitorEnabled() {
130 return deviceMonitorEnabled;
133 protected @NonNull DeviceMonitor getDeviceMonitor() {
134 return deviceMonitor;
137 protected boolean isOdlEventListenerHandlerEnabled() {
138 return odlEventListenerHandlerEnabled;
141 protected @NonNull ODLEventListenerHandler getOdlEventListenerHandler() {
142 return odlEventListenerHandler;