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.io.FileNotFoundException;
26 import java.io.FileReader;
27 import java.io.IOException;
28 import java.util.LinkedList;
29 import java.util.List;
30 import java.util.Properties;
32 import org.osgi.framework.BundleActivator;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.framework.ServiceRegistration;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class SliPluginUtilsActivator implements BundleActivator {
39 @SuppressWarnings("rawtypes") private List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
41 private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtilsActivator.class);
42 private static final String SDNC_ROOT_DIR = "SDNC_CONFIG_DIR";
43 private static final String DME2_PROPERTIES_FILE_NAME = "dme2.properties";
46 public void start(BundleContext ctx) throws Exception {
47 SliPluginUtils plugin = new SliPluginUtils(new Properties());
48 LOG.info("Registering service " + plugin.getClass().getName());
49 registrations.add(ctx.registerService(plugin.getClass().getName(), plugin, null));
51 SliStringUtils sliStringUtils_Plugin = new SliStringUtils();
52 LOG.info("Registering service " + sliStringUtils_Plugin.getClass().getName());
53 registrations.add(ctx.registerService(sliStringUtils_Plugin.getClass().getName(), sliStringUtils_Plugin, null));
56 String path = System.getenv(SDNC_ROOT_DIR) + File.separator + DME2_PROPERTIES_FILE_NAME;
57 DME2 dmePlugin = initDme2(path);
58 if (dmePlugin != null) {
59 LOG.info("Registering service " + dmePlugin.getClass().getName());
60 registrations.add(ctx.registerService(dmePlugin.getClass().getName(), dmePlugin, null));
62 } catch (Exception e) {
63 LOG.error("DME2 plugin could not be started", e);
67 public DME2 initDme2(String pathToDmeProperties) {
68 Properties dme2properties = new Properties();
69 String loadPropertiesErrorMessage = "Couldn't load DME2 properties at path " + pathToDmeProperties;
70 File dme2propertiesFile = new File(pathToDmeProperties);
73 dme2properties.load(new FileReader(dme2propertiesFile));
74 String proxyUrlProperty = dme2properties.getProperty("proxyUrl");
75 String[] proxyUrls = proxyUrlProperty.split(",");
76 DME2 dmePlugin = new DME2(dme2properties.getProperty("aafUserName"), dme2properties.getProperty("aafPassword"), dme2properties.getProperty("envContext"), dme2properties.getProperty("routeOffer"), proxyUrls, dme2properties.getProperty("commonServiceVersion"));
77 dmePlugin.setPartner(dme2properties.getProperty("partner"));
79 } catch (FileNotFoundException e) {
80 LOG.error(loadPropertiesErrorMessage);
81 } catch (IOException e) {
82 LOG.error(loadPropertiesErrorMessage);
84 LOG.error("Couldn't create DME2 plugin");
89 public void stop(BundleContext ctx) throws Exception {
90 for (@SuppressWarnings("rawtypes") ServiceRegistration registration : registrations) {
91 registration.unregister();