2  * ============LICENSE_START========================================================================
 
   3  * ONAP : ccsdk feature sdnr wt
 
   4  * =================================================================================================
 
   5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
 
   6  * Copyright (C) 2021 Samsung Electronics 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==========================================================================
 
  20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
 
  22 import java.util.HashMap;
 
  23 import java.util.List;
 
  25 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
 
  26 import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
 
  27 import org.slf4j.Logger;
 
  28 import org.slf4j.LoggerFactory;
 
  30 public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedListener {
 
  32     private static final Logger LOG = LoggerFactory.getLogger(MountpointRegistrarImpl.class);
 
  33     private static final String APPLICATION_NAME = "mountpoint-registrar";
 
  34     private static final String CONFIGURATIONFILE = "etc/mountpoint-registrar.properties";
 
  36     private Thread dmaapVESMsgConsumerMain = null;
 
  38     private GeneralConfig generalConfig;
 
  39     private boolean dmaapEnabled = false;
 
  40     private Map<String, MessageConfig> configMap = new HashMap<>();
 
  41     private DMaaPVESMsgConsumerMain dmaapConsumerMain = null;
 
  44     public MountpointRegistrarImpl() {
 
  45         LOG.info("Creating provider class for {}", APPLICATION_NAME);
 
  49         LOG.info("Init call for {}", APPLICATION_NAME);
 
  51         ConfigurationFileRepresentation configFileRepresentation =
 
  52                 new ConfigurationFileRepresentation(CONFIGURATIONFILE);
 
  53         configFileRepresentation.registerConfigChangedListener(this);
 
  55         generalConfig = new GeneralConfig(configFileRepresentation);
 
  56         PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
 
  57         FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
 
  58         ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation);
 
  60         configMap.put("pnfRegistration", pnfRegConfig);
 
  61         configMap.put("fault", faultConfig);
 
  62         configMap.put("provisioning", provisioningConfig);
 
  64         dmaapEnabled = generalConfig.getEnabled();
 
  65         if (dmaapEnabled) { // start dmaap consumer thread only if dmaapEnabled=true
 
  66             LOG.info("DMaaP seems to be enabled, starting consumer(s)");
 
  67             dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
 
  68             dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain);
 
  69             dmaapVESMsgConsumerMain.start();
 
  71             LOG.info("DMaaP seems to be disabled, not starting any consumer(s)");
 
  76      * Reflect status for Unit Tests
 
  78      * @return Text with status
 
  80     public String isInitializationOk() {
 
  81         return "No implemented";
 
  85     public void onConfigChanged() {
 
  86         if (generalConfig == null) { // Included as NullPointerException observed once in docker logs
 
  87                 LOG.warn("onConfigChange cannot be handled. Unexpected Null");
 
  90         LOG.info("Service configuration state changed. Enabled: {}", generalConfig.getEnabled());
 
  91         boolean dmaapEnabledNewVal = generalConfig.getEnabled();
 
  92         if (!dmaapEnabled && dmaapEnabledNewVal) { // Dmaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s)
 
  93             LOG.info("DMaaP is enabled, starting consumer(s)");
 
  94             dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig);
 
  95             dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain);
 
  96             dmaapVESMsgConsumerMain.start();
 
  97         } else if (dmaapEnabled && !dmaapEnabledNewVal) { // Dmaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s)
 
  98             LOG.info("DMaaP is disabled, stopping consumer(s)");
 
  99             List<DMaaPVESMsgConsumer> consumers = dmaapConsumerMain.getConsumers();
 
 100             for (DMaaPVESMsgConsumer consumer : consumers) {
 
 101                 // stop all consumers
 
 102                 consumer.stopConsumer();
 
 105         dmaapEnabled = dmaapEnabledNewVal;
 
 109     public void close() throws Exception {
 
 110         LOG.info("{} closing ...", this.getClass().getName());
 
 111         LOG.info("{} closing done", APPLICATION_NAME);
 
 115      * Used to close all Services, that should support AutoCloseable Pattern
 
 120     @SuppressWarnings("unused")
 
 121     private void close(AutoCloseable... toCloseList) throws Exception {
 
 122         for (AutoCloseable element : toCloseList) {
 
 123             if (element != null) {