1 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl;
2 /*******************************************************************************
3 * ============LICENSE_START========================================================================
4 * ONAP : ccsdk feature sdnr wt
5 * =================================================================================================
6 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
7 * =================================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software distributed under the License
14 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15 * or implied. See the License for the specific language governing permissions and limitations under
17 * ============LICENSE_END==========================================================================
18 ******************************************************************************/
20 import java.io.IOException;
22 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
23 import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
24 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 @SuppressWarnings("deprecation")
29 public class MountpointStateProviderImpl implements AutoCloseable, IConfigChangedListener {
31 private static final Logger LOG = LoggerFactory.getLogger(MountpointStateProviderImpl.class);
32 private static final String APPLICATION_NAME = "mountpoint-state-provider";
33 private static final String CONFIGURATIONFILE = "etc/mountpoint-state-provider.properties";
35 private NetconfNodeStateService netconfNodeStateService;
37 private GeneralConfig generalConfig;
38 private boolean dmaapEnabled = false;
39 private Thread mountpointStatePublisher = null;
41 MountpointNodeConnectListenerImpl nodeConnectListener = new MountpointNodeConnectListenerImpl();
42 MountpointNodeStateListenerImpl nodeStateListener = new MountpointNodeStateListenerImpl();
44 public MountpointStateProviderImpl() {
45 LOG.info("Creating provider class for {}", APPLICATION_NAME);
48 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
49 this.netconfNodeStateService = netconfNodeStateService;
53 LOG.info("Init call for {}", APPLICATION_NAME);
54 ConfigurationFileRepresentation configFileRepresentation = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
55 configFileRepresentation.registerConfigChangedListener(this);
57 generalConfig = new GeneralConfig(configFileRepresentation);
58 if (generalConfig.getEnabled()) { //dmaapEnabled
59 mountpointStatePublisher = new Thread(new MountpointStatePublisher(generalConfig));
60 mountpointStatePublisher.start();
61 netconfNodeStateService.registerNetconfNodeConnectListener(nodeConnectListener);
62 netconfNodeStateService.registerNetconfNodeStateListener(nodeStateListener);
67 * Reflect status for Unit Tests
68 * @return Text with status
70 public String isInitializationOk() {
71 return "No implemented";
75 public void onConfigChanged() {
76 LOG.info("Service configuration state changed. Enabled: {}", generalConfig.getEnabled());
77 boolean dmaapEnabledNewVal = generalConfig.getEnabled();
79 // DMaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s)
80 if (!dmaapEnabled && dmaapEnabledNewVal) {
81 LOG.info("DMaaP is enabled, starting Publisher");
82 mountpointStatePublisher = new Thread(new MountpointStatePublisher(generalConfig));
83 mountpointStatePublisher.start();
84 netconfNodeStateService.registerNetconfNodeConnectListener(nodeConnectListener);
85 netconfNodeStateService.registerNetconfNodeStateListener(nodeStateListener);
86 } else if (dmaapEnabled && !dmaapEnabledNewVal) {
87 // DMaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s)
88 LOG.info("DMaaP is disabled, stop publisher");
90 MountpointStatePublisher.stopPublisher();
91 } catch (IOException | InterruptedException e) {
92 LOG.error("Exception while stopping publisher ", e);
95 dmaapEnabled = dmaapEnabledNewVal;
99 public void close() throws Exception {
100 LOG.info("{} closing ...", this.getClass().getName());
101 //close(updateService, configService, mwtnService); issue#1
103 MountpointStatePublisher.stopPublisher();
104 } catch (IOException | InterruptedException e) {
105 LOG.error("Exception while stopping publisher ", e);
107 //close(updateService, mwtnService);
108 LOG.info("{} closing done",APPLICATION_NAME);
112 * Used to close all Services, that should support AutoCloseable Pattern
117 @SuppressWarnings("unused")
118 private void close(AutoCloseable... toCloseList) throws Exception {
119 for (AutoCloseable element : toCloseList) {
120 if (element != null) {