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 public class MountpointStateProviderImpl implements AutoCloseable, IConfigChangedListener {
 
  37     private static final Logger LOG = LoggerFactory.getLogger(MountpointStateProviderImpl.class);
 
  38     private static final String APPLICATION_NAME = "mountpoint-state-provider";
 
  39     private static final String CONFIGURATIONFILE = "etc/mountpoint-state-provider.properties";
 
  41     private NetconfNodeStateService netconfNodeStateService;
 
  42     private GeneralConfig generalConfig;
 
  43     private boolean dmaapEnabled = false;
 
  45     private MountpointNodeConnectListenerImpl nodeConnectListener;
 
  46     private MountpointNodeStateListenerImpl nodeStateListener;
 
  47     private MountpointStatePublisherMain mountpointStatePublisher;
 
  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;
 
  60         LOG.info("Init call for {}", APPLICATION_NAME);
 
  61         ConfigurationFileRepresentation configFileRepresentation =
 
  62                 new ConfigurationFileRepresentation(CONFIGURATIONFILE);
 
  63         configFileRepresentation.registerConfigChangedListener(this);
 
  65         nodeConnectListener = new MountpointNodeConnectListenerImpl(netconfNodeStateService);
 
  66         nodeStateListener = new MountpointNodeStateListenerImpl(netconfNodeStateService);
 
  68         generalConfig = new GeneralConfig(configFileRepresentation);
 
  69         if (generalConfig.getEnabled()) { //dmaapEnabled
 
  75      * Reflect status for Unit Tests
 
  77      * @return Text with status
 
  79     public String isInitializationOk() {
 
  80         return "No implemented";
 
  84     public void onConfigChanged() {
 
  85         LOG.info("Service configuration state changed. Enabled: {}", generalConfig.getEnabled());
 
  86         boolean dmaapEnabledNewVal = generalConfig.getEnabled();
 
  88         // DMaap disabled earlier (or during bundle startup) but enabled later, start publisher(s)
 
  89         if (!dmaapEnabled && dmaapEnabledNewVal) {
 
  90             LOG.info("DMaaP is enabled, starting Publisher");
 
  92         } else if (dmaapEnabled && !dmaapEnabledNewVal) {
 
  93             // DMaap enabled earlier (or during bundle startup) but disabled later, stop publisher(s)
 
  94             LOG.info("DMaaP is disabled, stop publisher");
 
  97         dmaapEnabled = dmaapEnabledNewVal;
 
 100     public void startPublishing() {
 
 101         mountpointStatePublisher = new MountpointStatePublisherMain(generalConfig);
 
 102         mountpointStatePublisher.start();
 
 104         nodeConnectListener.start(mountpointStatePublisher);
 
 105         nodeStateListener.start(mountpointStatePublisher);
 
 108     public void stopPublishing() {
 
 110             nodeConnectListener.stop();
 
 111             nodeStateListener.stop();
 
 112             mountpointStatePublisher.stop();
 
 113         } catch (Exception e) {
 
 114             LOG.error("Exception while stopping publisher ", e);
 
 119     public void close() throws Exception {
 
 120         LOG.info("{} closing ...", this.getClass().getName());
 
 122             mountpointStatePublisher.stop();
 
 123         } catch (IOException | InterruptedException e) {
 
 124             LOG.error("Exception while stopping publisher ", e);
 
 126         close(nodeConnectListener, nodeStateListener);
 
 127         LOG.info("{} closing done", APPLICATION_NAME);
 
 131      * Used to close all Services, that should support AutoCloseable Pattern
 
 136     private void close(AutoCloseable... toCloseList) throws Exception {
 
 137         for (AutoCloseable element : toCloseList) {
 
 138             if (element != null) {