1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21 import java.util.HashMap;
22 import java.util.List;
25 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
26 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
27 import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
28 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedListener {
34 private static final Logger LOG = LoggerFactory.getLogger(MountpointRegistrarImpl.class);
35 private static final String APPLICATION_NAME = "mountpoint-registrar";
36 private static final String CONFIGURATIONFILE = "etc/mountpoint-registrar.properties";
38 private Thread dmaapVESMsgConsumerMain = null;
40 private GeneralConfig generalConfig;
41 private boolean dmaapEnabled = false;
42 Map<String, Configuration> configMap = new HashMap<>();
45 public MountpointRegistrarImpl() {
46 LOG.info("Creating provider class for {}", APPLICATION_NAME);
50 LOG.info("Init call for {}", APPLICATION_NAME);
52 ConfigurationFileRepresentation configFileRepresentation = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
53 configFileRepresentation.registerConfigChangedListener(this);
55 generalConfig = new GeneralConfig(configFileRepresentation);
56 PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation);
57 FaultConfig faultConfig = new FaultConfig(configFileRepresentation);
59 configMap.put("pnfRegistration", pnfRegConfig);
60 configMap.put("fault", faultConfig);
62 dmaapEnabled = generalConfig.getEnabled();
63 if (dmaapEnabled) { // start dmaap consumer thread only if dmaapEnabled=true
64 LOG.info("DMaaP seems to be enabled, starting consumer(s)");
65 dmaapVESMsgConsumerMain = new Thread(new DMaaPVESMsgConsumerMain(configMap));
66 dmaapVESMsgConsumerMain.start();
68 LOG.info("DMaaP seems to be disabled, not starting any consumer(s)");
73 * Reflect status for Unit Tests
74 * @return Text with status
76 public String isInitializationOk() {
77 return "No implemented";
81 public void onConfigChanged() {
82 LOG.info("Service configuration state changed. Enabled: {}", generalConfig.getEnabled());
83 boolean dmaapEnabledNewVal = generalConfig.getEnabled();
84 if (!dmaapEnabled && dmaapEnabledNewVal) { // Dmaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s)
85 LOG.info("DMaaP is enabled, starting consumer(s)");
86 dmaapVESMsgConsumerMain = new Thread(new DMaaPVESMsgConsumerMain(configMap));
87 dmaapVESMsgConsumerMain.start();
88 } else if (dmaapEnabled && !dmaapEnabledNewVal) { // Dmaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s)
89 LOG.info("DMaaP is disabled, stopping consumer(s)");
90 List<DMaaPVESMsgConsumer> consumers = DMaaPVESMsgConsumerMain.getConsumers();
91 for (DMaaPVESMsgConsumer consumer : consumers) {
93 consumer.stopConsumer();
96 dmaapEnabled = dmaapEnabledNewVal;
100 public void close() throws Exception {
101 LOG.info("{} closing ...", this.getClass().getName());
102 //close(updateService, configService, mwtnService); issue#1
103 //close(updateService, mwtnService);
104 LOG.info("{} closing done",APPLICATION_NAME);
108 * Used to close all Services, that should support AutoCloseable Pattern
113 @SuppressWarnings("unused")
114 private void close(AutoCloseable... toCloseList) throws Exception {
115 for (AutoCloseable element : toCloseList) {
116 if (element != null) {