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.resource.mdsal;
25 import java.io.FileInputStream;
26 import java.util.LinkedList;
27 import java.util.Properties;
29 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
31 import org.osgi.framework.BundleActivator;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.ServiceRegistration;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class MdsalResourceActivator implements BundleActivator {
41 private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
43 public LinkedList<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
45 private static final Logger LOG = LoggerFactory
46 .getLogger(MdsalResourceActivator.class);
49 public void start(BundleContext ctx) throws Exception {
52 Properties props = new Properties();
54 String propDir = System.getenv(SDNC_CONFIG_DIR);
55 if (propDir == null) {
57 propDir = "/opt/sdnc/data/properties";
59 String propPath = propDir + "/mdsal-resource.properties";
62 File propFile = new File(propPath);
64 if (!propFile.exists()) {
66 throw new ConfigurationException(
67 "Missing configuration properties file : "
72 props.load(new FileInputStream(propFile));
73 } catch (Exception e) {
74 throw new ConfigurationException(
75 "Could not load properties file " + propPath, e);
79 String sdncUser = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-user", "admin");
80 String sdncPasswd = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-passwd", "admin");
81 String sdncHost = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-host", "localhost");
82 String sdncProtocol = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-protocol", "https");
83 String sdncPort = props.getProperty("org.openecomp.sdnc.sli.resource.mdsal.sdnc-port", "8443");
85 // Advertise MD-SAL resource adaptors
86 SvcLogicResource impl = new ConfigResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd);
88 LOG.debug("Registering MdsalResource service "+impl.getClass().getName());
89 registrations.add(ctx.registerService(impl.getClass().getName(), impl, null));
91 impl = new OperationalResource(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd);
93 LOG.debug("Registering MdsalResource service "+impl.getClass().getName());
94 registrations.add(ctx.registerService(impl.getClass().getName(), impl, null));
98 public void stop(BundleContext ctx) throws Exception {
100 for (ServiceRegistration registration : registrations)
102 registration.unregister();