2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Update Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=======================================================
25 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl;
27 import java.util.Optional;
28 import org.eclipse.jdt.annotation.NonNull;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorConfigChangeListener;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeConnectListener;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateListener;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev240911.netconf.node.augment.NetconfNode;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 public class MountpointStateProviderImpl implements VESCollectorConfigChangeListener, NetconfNodeConnectListener,
45 NetconfNodeStateListener, AutoCloseable {
47 private static final Logger LOG = LoggerFactory.getLogger(MountpointStateProviderImpl.class);
48 private static final String APPLICATION_NAME = "mountpoint-state-provider";
50 private NetconfNodeStateService netconfNodeStateService;
51 private NetconfNetworkElementService netconfNetworkElementService;
52 private VESCollectorService vesCollectorService;
53 private boolean vesCollectorEnabled = false; //Current value
54 private MountpointStateVESMessageFormatter vesMessageFormatter;
56 public MountpointStateProviderImpl() {
57 LOG.info("Creating provider class for {}", APPLICATION_NAME);
61 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
62 this.netconfNodeStateService = netconfNodeStateService;
65 public void setNetconfNetworkElementService(NetconfNetworkElementService netconfNetworkElementService) {
66 this.netconfNetworkElementService = netconfNetworkElementService;
70 LOG.info("Init call for {}", APPLICATION_NAME);
71 this.vesCollectorService = netconfNetworkElementService.getServiceProvider().getVESCollectorService();
72 this.vesCollectorEnabled = vesCollectorService.getConfig().isVESCollectorEnabled();
73 this.vesMessageFormatter = new MountpointStateVESMessageFormatter(vesCollectorService);
74 // regsiter for live configuration changes
75 vesCollectorService.registerForChanges(this);
76 // register for node changes
77 netconfNodeStateService.registerNetconfNodeConnectListener(this);
78 netconfNodeStateService.registerNetconfNodeStateListener(this);
83 * Reflect status for Unit Tests
85 * @return Text with status
87 public String isInitializationOk() {
88 return "No implemented";
92 public void close() throws Exception {
93 LOG.info("{} closing ...", this.getClass().getName());
94 vesCollectorService.deregister(this);
95 LOG.info("{} closing done", APPLICATION_NAME);
99 private void publishStateChange(String nodeId, String connectionStatus) {
100 this.vesCollectorService.publishVESMessage(
101 vesMessageFormatter.createVESMessage(nodeId, connectionStatus, java.time.Clock.systemUTC().instant()));
105 public void notify(VESCollectorCfgService cfg) {
106 boolean vesCollectorEnabledPV = cfg.isVESCollectorEnabled(); // Pending value a.k.a new value
107 if (vesCollectorEnabledPV != vesCollectorEnabled) {
108 this.vesCollectorEnabled = vesCollectorEnabledPV;
113 public void onEnterConnected(@NonNull NetconfAccessor accessor) {
114 if (!this.vesCollectorEnabled) {
117 NodeId nNodeId = accessor.getNodeId();
118 NetconfNode netconfNode = accessor.getNetconfNode();
120 Ipv4Address ipv4Address = netconfNode.getHost().getIpAddress().getIpv4Address();
121 Ipv6Address ipv6Address = netconfNode.getHost().getIpAddress().getIpv6Address();
122 LOG.debug("In onEnterConnected of MountpointNodeConnectListenerImpl - nNodeId = {}, IP Address = {}",
124 , ipv4Address != null ? ipv4Address.getValue() : ipv6Address.getValue());
125 this.publishStateChange(nNodeId.getValue(), netconfNode.getConnectionStatus().toString());
129 public void onLeaveConnected(NodeId nNodeId, Optional<NetconfNode> optionalNetconfNode) {
130 if (!this.vesCollectorEnabled) {
133 LOG.debug("In onLeaveConnected of MountpointNodeConnectListenerImpl - nNodeId = {}", nNodeId);
134 this.publishStateChange(nNodeId.getValue(), "Unmounted");
138 public void onCreated(NodeId nNodeId, NetconfNode netconfNode) {
139 if (!this.vesCollectorEnabled) {
142 Ipv4Address ipv4Address = netconfNode.getHost().getIpAddress().getIpv4Address();
143 Ipv6Address ipv6Address = netconfNode.getHost().getIpAddress().getIpv6Address();
144 LOG.debug("In onCreated of MountpointNodeStateListenerImpl - nNodeId = {}, IP Address = {}", nNodeId.getValue(),
145 ipv4Address != null ? ipv4Address.getValue() : ipv6Address.getValue());
146 this.publishStateChange(nNodeId.getValue(), netconfNode.getConnectionStatus().toString());
152 public void onStateChange(NodeId nNodeId, NetconfNode netconfNode) {
153 if (!this.vesCollectorEnabled) {
156 Ipv4Address ipv4Address = netconfNode.getHost().getIpAddress().getIpv4Address();
157 Ipv6Address ipv6Address = netconfNode.getHost().getIpAddress().getIpv6Address();
158 LOG.debug("In onStateChange of MountpointNodeStateListenerImpl - nNodeId = {}, IP Address = {}",
160 ipv4Address != null ? ipv4Address.getValue() : ipv6Address.getValue());
161 this.publishStateChange(nNodeId.getValue(), netconfNode.getConnectionStatus().toString());
167 public void onRemoved(NodeId nNodeId) {
168 if (!this.vesCollectorEnabled) {
171 LOG.debug("In onRemoved of MountpointNodeStateListenerImpl - nNodeId = {}", nNodeId);
172 this.publishStateChange(nNodeId.getValue(), "Removed");