2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.ccadaptor;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.io.FileInputStream;
30 import java.io.InputStream;
31 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;
37 public class CCAActivator implements BundleActivator
40 private static final String CCA_PROP_FILE_VAR = "SDNC_CCA_PROPERTIES";
41 private static final String APPC_CONFIG_DIR_VAR = "APPC_CONFIG_DIR";
43 @SuppressWarnings("rawtypes")
44 private ServiceRegistration registration = null;
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(CCAActivator.class);
49 public void start(BundleContext ctx) throws Exception
52 Properties props = new Properties();
54 // Read properties from appc-config-adaptor.properties
55 String propFileName = System.getenv(CCA_PROP_FILE_VAR);
56 if (propFileName == null)
58 String propDir = System.getenv(APPC_CONFIG_DIR_VAR);
60 throw new ConfigurationException(
61 "Cannot find config file - " + CCA_PROP_FILE_VAR + " and " + APPC_CONFIG_DIR_VAR + " unset");
63 propFileName = propDir + "/appc-config-adaptor.properties";
64 log.warn("Environment variable " + CCA_PROP_FILE_VAR + " unset - defaulting to " + propFileName);
67 File propFile = new File(propFileName);
68 if (!propFile.exists())
69 throw new ConfigurationException("Missing configuration properties file: " + propFile);
71 try (InputStream in = new FileInputStream(propFile))
77 throw new ConfigurationException("Could not load properties file " + propFileName, e);
80 log.info("Loaded properties: ");
83 ConfigComponentAdaptor adaptor = new ConfigComponentAdaptor(props);
84 if (registration == null)
86 log.info("Registering service " + ConfigComponentAdaptor.class.getName());
87 registration = ctx.registerService(ConfigComponentAdaptor.class.getName(), adaptor, null);
93 public void stop(BundleContext ctx) throws Exception
95 if (registration != null)
97 registration.unregister();