2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.ccsdk.sli.adaptors.resource.mdsal;
27 import java.io.FileInputStream;
28 import java.util.LinkedList;
29 import java.util.Properties;
31 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
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 public class MdsalResourceActivator implements BundleActivator {
43 private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
45 public LinkedList<ServiceRegistration> registrations = new LinkedList<>();
47 private static final Logger LOG = LoggerFactory
48 .getLogger(MdsalResourceActivator.class);
51 public void start(BundleContext ctx) throws Exception {
54 Properties props = new Properties();
56 String propDir = System.getenv(SDNC_CONFIG_DIR);
57 if (propDir == null) {
59 propDir = "/opt/sdnc/data/properties";
61 String propPath = propDir + "/mdsal-resource.properties";
64 File propFile = new File(propPath);
66 if (!propFile.exists()) {
68 throw new ConfigurationException(
69 "Missing configuration properties file : "
74 props.load(new FileInputStream(propFile));
75 } catch (Exception e) {
76 throw new ConfigurationException(
77 "Could not load properties file " + propPath, e);
81 String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin");
82 String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin");
83 String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost");
84 String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https");
85 String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443");
87 // Advertise MD-SAL resource adaptors
88 SvcLogicResource impl = new ConfigResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd);
90 LOG.debug("Registering MdsalResource service "+impl.getClass().getName());
91 registrations.add(ctx.registerService(impl.getClass().getName(), impl, null));
93 impl = new OperationalResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd);
95 LOG.debug("Registering MdsalResource service "+impl.getClass().getName());
96 registrations.add(ctx.registerService(impl.getClass().getName(), impl, null));
100 public void stop(BundleContext ctx) throws Exception {
102 for (ServiceRegistration registration : registrations)
104 registration.unregister();