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 org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorConfigChangeListener;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class MountpointStateProviderImpl implements VESCollectorConfigChangeListener, AutoCloseable {
37 private static final Logger LOG = LoggerFactory.getLogger(MountpointStateProviderImpl.class);
38 private static final String APPLICATION_NAME = "mountpoint-state-provider";
40 private NetconfNodeStateService netconfNodeStateService;
41 private NetconfNetworkElementService netconfNetworkElementService;
43 private MountpointNodeConnectListenerImpl nodeConnectListener;
44 private MountpointNodeStateListenerImpl nodeStateListener;
45 private MountpointStatePublisher mountpointStatePublisher;
46 private VESCollectorService vesCollectorService;
47 private boolean vesCollectorEnabledCV = false; //Current value
49 public MountpointStateProviderImpl() {
50 LOG.info("Creating provider class for {}", APPLICATION_NAME);
51 nodeConnectListener = null;
52 nodeStateListener = null;
55 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
56 this.netconfNodeStateService = netconfNodeStateService;
59 public void setNetconfNetworkElementService(NetconfNetworkElementService netconfNetworkElementService) {
60 this.netconfNetworkElementService = netconfNetworkElementService;
64 LOG.info("Init call for {}", APPLICATION_NAME);
66 nodeConnectListener = new MountpointNodeConnectListenerImpl(netconfNodeStateService);
67 nodeStateListener = new MountpointNodeStateListenerImpl(netconfNodeStateService);
68 vesCollectorService = netconfNetworkElementService.getServiceProvider().getVESCollectorService();
69 vesCollectorService.registerForChanges(this);
70 boolean vesCollectorEnabled = vesCollectorService.getConfig().isVESCollectorEnabled();
72 if (vesCollectorEnabled) {
78 * Reflect status for Unit Tests
80 * @return Text with status
82 public String isInitializationOk() {
83 return "No implemented";
86 public void startPublishing() {
87 mountpointStatePublisher = new MountpointStatePublisher(
88 netconfNetworkElementService.getServiceProvider().getVESCollectorService());
89 Thread t = new Thread(mountpointStatePublisher);
92 nodeConnectListener.start(mountpointStatePublisher);
93 nodeStateListener.start(mountpointStatePublisher);
96 public void stopPublishing() throws Exception {
97 mountpointStatePublisher.stop();
98 close(nodeConnectListener, nodeStateListener);
102 public void close() throws Exception {
103 LOG.info("{} closing ...", this.getClass().getName());
104 mountpointStatePublisher.stop();
105 vesCollectorService.deregister(this);
106 close(nodeConnectListener, nodeStateListener);
107 LOG.info("{} closing done", APPLICATION_NAME);
111 * Used to close all Services, that should support AutoCloseable Pattern
116 private void close(AutoCloseable... toCloseList) throws Exception {
117 for (AutoCloseable element : toCloseList) {
118 if (element != null) {
125 public void notify(VESCollectorCfgService cfg) {
126 boolean vesCollectorEnabledPV = cfg.isVESCollectorEnabled(); // Pending value a.k.a new value
127 if (vesCollectorEnabledPV != vesCollectorEnabledCV) {
128 vesCollectorEnabledCV = vesCollectorEnabledPV;
129 if (vesCollectorEnabledPV) {
134 } catch (Exception e) {