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.io.IOException;
29 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
30 import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 @SuppressWarnings("deprecation")
36 public class MountpointStateProviderImpl implements AutoCloseable, IConfigChangedListener {
38 private static final Logger LOG = LoggerFactory.getLogger(MountpointStateProviderImpl.class);
39 private static final String APPLICATION_NAME = "mountpoint-state-provider";
40 private static final String CONFIGURATIONFILE = "etc/mountpoint-state-provider.properties";
42 private NetconfNodeStateService netconfNodeStateService;
44 private GeneralConfig generalConfig;
45 private boolean dmaapEnabled = false;
46 private Thread mountpointStatePublisher = null;
48 MountpointNodeConnectListenerImpl nodeConnectListener = new MountpointNodeConnectListenerImpl();
49 MountpointNodeStateListenerImpl nodeStateListener = new MountpointNodeStateListenerImpl();
51 public MountpointStateProviderImpl() {
52 LOG.info("Creating provider class for {}", APPLICATION_NAME);
55 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
56 this.netconfNodeStateService = netconfNodeStateService;
60 LOG.info("Init call for {}", APPLICATION_NAME);
61 ConfigurationFileRepresentation configFileRepresentation = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
62 configFileRepresentation.registerConfigChangedListener(this);
64 generalConfig = new GeneralConfig(configFileRepresentation);
65 if (generalConfig.getEnabled()) { //dmaapEnabled
66 mountpointStatePublisher = new Thread(new MountpointStatePublisher(generalConfig));
67 mountpointStatePublisher.start();
68 netconfNodeStateService.registerNetconfNodeConnectListener(nodeConnectListener);
69 netconfNodeStateService.registerNetconfNodeStateListener(nodeStateListener);
74 * Reflect status for Unit Tests
75 * @return Text with status
77 public String isInitializationOk() {
78 return "No implemented";
82 public void onConfigChanged() {
83 LOG.info("Service configuration state changed. Enabled: {}", generalConfig.getEnabled());
84 boolean dmaapEnabledNewVal = generalConfig.getEnabled();
86 // DMaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s)
87 if (!dmaapEnabled && dmaapEnabledNewVal) {
88 LOG.info("DMaaP is enabled, starting Publisher");
89 mountpointStatePublisher = new Thread(new MountpointStatePublisher(generalConfig));
90 mountpointStatePublisher.start();
91 netconfNodeStateService.registerNetconfNodeConnectListener(nodeConnectListener);
92 netconfNodeStateService.registerNetconfNodeStateListener(nodeStateListener);
93 } else if (dmaapEnabled && !dmaapEnabledNewVal) {
94 // DMaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s)
95 LOG.info("DMaaP is disabled, stop publisher");
97 MountpointStatePublisher.stopPublisher();
98 } catch (IOException | InterruptedException e) {
99 LOG.error("Exception while stopping publisher ", e);
102 dmaapEnabled = dmaapEnabledNewVal;
106 public void close() throws Exception {
107 LOG.info("{} closing ...", this.getClass().getName());
108 //close(updateService, configService, mwtnService); issue#1
110 MountpointStatePublisher.stopPublisher();
111 } catch (IOException | InterruptedException e) {
112 LOG.error("Exception while stopping publisher ", e);
114 //close(updateService, mwtnService);
115 LOG.info("{} closing done",APPLICATION_NAME);
119 * Used to close all Services, that should support AutoCloseable Pattern
124 @SuppressWarnings("unused")
125 private void close(AutoCloseable... toCloseList) throws Exception {
126 for (AutoCloseable element : toCloseList) {
127 if (element != null) {