2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.SliPluginUtils;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Properties;
29 import org.osgi.framework.BundleActivator;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.ServiceRegistration;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 public class SliPluginUtilsActivator implements BundleActivator {
38 // private static final String SLIPLUGINUTILS_PROP_VAR = "/slipluginutils.properties";
39 // private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
41 @SuppressWarnings("rawtypes")
42 private final List<ServiceRegistration> registrations = new LinkedList<>();
44 private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtilsActivator.class);
47 public void start(BundleContext ctx) throws Exception {
49 Properties props = new Properties();
51 // ---uncomment below when adding properties file---
53 String propDir = System.getenv(SDNC_CONFIG_DIR);
54 if (propDir == null) {
55 throw new ConfigurationException(
56 "Cannot find config file - " + SLIPLUGINUTILS_PROP_VAR + " and " + SDNC_CONFIG_DIR + " unset");
58 String propPath = propDir + SLIPLUGINUTILS_PROP_VAR;
60 File propFile = new File(propPath);
62 if (!propFile.exists()) {
63 throw new ConfigurationException("Missing configuration properties file : " + propFile);
67 props.load(new FileInputStream(propFile));
68 } catch (Exception e) {
69 throw new ConfigurationException("Could not load properties file " + propPath, e);
73 SliPluginUtils plugin = new SliPluginUtils(props);
75 LOG.info("Registering service "+plugin.getClass().getName());
76 registrations.add(ctx.registerService(plugin.getClass().getName(), plugin, null));
80 public void stop(BundleContext ctx) throws Exception {
82 for (@SuppressWarnings("rawtypes") ServiceRegistration registration: registrations)
84 registration.unregister();