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
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.mountpointstateprovider.impl;
21 import java.util.Objects;
22 import java.util.Optional;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.json.JSONObject;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeConnectListener;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
32 import org.opendaylight.yangtools.concepts.ListenerRegistration;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class MountpointNodeConnectListenerImpl implements NetconfNodeConnectListener, AutoCloseable {
37 private static final Logger LOG = LoggerFactory.getLogger(MountpointNodeConnectListenerImpl.class);
38 private NetconfNodeStateService netconfNodeStateService;
39 private MountpointStatePublisher mountpointStatePublisher;
40 private ListenerRegistration<MountpointNodeConnectListenerImpl> registeredNodeConnectListener;
42 public MountpointNodeConnectListenerImpl(NetconfNodeStateService netconfNodeStateService) {
43 this.netconfNodeStateService = netconfNodeStateService;
46 public void start(MountpointStatePublisher mountpointStatePublisher) {
47 this.mountpointStatePublisher = mountpointStatePublisher;
48 registeredNodeConnectListener = netconfNodeStateService.registerNetconfNodeConnectListener(this);
52 public void onEnterConnected(@NonNull NetconfAccessor accessor) {
53 NodeId nNodeId = accessor.getNodeId();
54 NetconfNode netconfNode = accessor.getNetconfNode();
56 Ipv4Address ipv4Address = netconfNode.getHost().getIpAddress().getIpv4Address();
57 Ipv6Address ipv6Address = netconfNode.getHost().getIpAddress().getIpv6Address();
58 LOG.debug("In onEnterConnected of MountpointNodeConnectListenerImpl - nNodeId = {}, IP Address = {}",nNodeId.getValue()
59 ,ipv4Address != null?ipv4Address.getValue():ipv6Address.getValue());
61 JSONObject obj = new JSONObject();
62 obj.put(Constants.NODEID, nNodeId.getValue());
63 obj.put(Constants.NETCONFNODESTATE, netconfNode.getConnectionStatus().toString());
64 obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant());
66 mountpointStatePublisher.addToPublish(obj);
70 public void onLeaveConnected(NodeId nNodeId, Optional<NetconfNode> optionalNetconfNode) {
72 LOG.debug("In onLeaveConnected of MountpointNodeConnectListenerImpl - nNodeId = {}",nNodeId);
74 JSONObject obj = new JSONObject();
75 obj.put(Constants.NODEID, nNodeId.getValue());
76 obj.put(Constants.NETCONFNODESTATE, "Unmounted");
77 obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant());
79 mountpointStatePublisher.addToPublish(obj);
82 public void stop() throws Exception {
87 public void close() throws Exception {
88 LOG.debug("In close of MountpointNodeConnectListenerImpl");
89 if (!Objects.isNull(registeredNodeConnectListener))
90 registeredNodeConnectListener.close();