2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.ccadaptor;
28 import java.io.FileInputStream;
29 import java.io.InputStream;
30 import java.util.Properties;
32 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
33 import org.osgi.framework.BundleActivator;
34 import org.osgi.framework.BundleContext;
35 import org.osgi.framework.ServiceRegistration;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
42 public class CCAActivator implements BundleActivator
45 private static final String CCA_PROP_FILE_VAR = "SDNC_CCA_PROPERTIES";
46 private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
48 @SuppressWarnings("rawtypes")
49 private ServiceRegistration registration = null;
51 //private static final Logger log = LoggerFactory.getLogger(CCAActivator.class);
52 private static final EELFLogger log = EELFManager.getInstance().getLogger(CCAActivator.class);
55 public void start(BundleContext ctx) throws Exception
58 Properties props = new Properties();
60 // Read properties from appc-config-adaptor.properties
61 String propFileName = System.getenv(CCA_PROP_FILE_VAR);
62 if (propFileName == null)
64 String propDir = System.getenv(SDNC_CONFIG_DIR_VAR);
66 throw new ConfigurationException(
67 "Cannot find config file - " + CCA_PROP_FILE_VAR + " and " + SDNC_CONFIG_DIR_VAR + " unset");
69 propFileName = propDir + "/appc-config-adaptor.properties";
70 log.warn("Environment variable " + CCA_PROP_FILE_VAR + " unset - defaulting to " + propFileName);
73 File propFile = new File(propFileName);
74 if (!propFile.exists())
75 throw new ConfigurationException("Missing configuration properties file: " + propFile);
77 try(InputStream in = new FileInputStream(propFile)) {
79 log.info("Loaded properties: ");
83 throw new ConfigurationException("Could not load properties file " + propFileName, e);
87 ConfigComponentAdaptor adaptor = new ConfigComponentAdaptor(props);
88 if (registration == null)
90 log.info("Registering service " + ConfigComponentAdaptor.class.getName());
91 registration = ctx.registerService(ConfigComponentAdaptor.class.getName(), adaptor, null);
97 public void stop(BundleContext ctx) throws Exception
99 if (registration != null)
101 registration.unregister();