27addbae0617879636b0f667284ce0533a1e5c63
[sdnc/core.git] / sliPluginUtils / provider / src / main / java / org / openecomp / sdnc / sli / SliPluginUtils / SliPluginUtilsActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.openecomp.sdnc.sli.SliPluginUtils;
23
24
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Properties;
28
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;
34
35
36 public class SliPluginUtilsActivator implements BundleActivator {
37
38 //    private static final String SLIPLUGINUTILS_PROP_VAR = "/slipluginutils.properties";
39 //    private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
40
41     @SuppressWarnings("rawtypes")
42     private final List<ServiceRegistration> registrations = new LinkedList<>();
43
44     private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtilsActivator.class);
45
46     @Override
47     public void start(BundleContext ctx) throws Exception {
48         // Read properties
49         Properties props = new Properties();
50
51         // ---uncomment below when adding properties file---
52         /*
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");
57         }
58         String propPath = propDir + SLIPLUGINUTILS_PROP_VAR;
59
60         File propFile = new File(propPath);
61
62         if (!propFile.exists()) {
63             throw new ConfigurationException("Missing configuration properties file : " + propFile);
64         }
65
66         try {
67             props.load(new FileInputStream(propFile));
68         } catch (Exception e) {
69             throw new ConfigurationException("Could not load properties file " + propPath, e);
70         }
71         */
72
73         SliPluginUtils plugin = new SliPluginUtils(props);
74
75         LOG.info("Registering service "+plugin.getClass().getName());
76         registrations.add(ctx.registerService(plugin.getClass().getName(), plugin, null));
77     }
78
79     @Override
80     public void stop(BundleContext ctx) throws Exception {
81
82         for (@SuppressWarnings("rawtypes") ServiceRegistration registration: registrations)
83         {
84             registration.unregister();
85             registration = null;
86         }
87     }
88 }