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.onap.ccsdk.sli.adaptors.resource.sql;
 
  25 import java.io.FileInputStream;
 
  26 import java.util.Properties;
 
  28 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
 
  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;
 
  35 public class SqlResourceActivator implements BundleActivator {
 
  37         private static final String SQLRESOURCE_PROP_PATH = "/sql-resource.properties";
 
  39         private ServiceRegistration registration = null;
 
  41         private static final Logger LOG = LoggerFactory
 
  42                         .getLogger(SqlResourceActivator.class);
 
  45         public void start(BundleContext ctx) throws Exception {
 
  47                 String cfgDir = System.getenv("SDNC_CONFIG_DIR");
 
  49                 if ((cfgDir == null) || (cfgDir.length() == 0)) {
 
  50                         cfgDir = "/opt/sdnc/data/properties";
 
  51                         LOG.warn("SDNC_CONFIG_DIR unset - defaulting to "+cfgDir);
 
  56                 File sqlResourcePropFile = new File(cfgDir+SQLRESOURCE_PROP_PATH);
 
  57                 Properties sqlResourceProps = new Properties();
 
  58                 if (sqlResourcePropFile.exists()) {
 
  61                                 sqlResourceProps.load(new FileInputStream(sqlResourcePropFile));
 
  63                                 cryptKey = sqlResourceProps.getProperty("org.openecomp.sdnc.resource.sql.cryptkey");
 
  64                         } catch (Exception e) {
 
  66                                                 "Could not load properties file " + sqlResourcePropFile.getAbsolutePath(), e);
 
  69                         LOG.warn("Cannot read "+sqlResourcePropFile.getAbsolutePath()+" to find encryption key - using default");
 
  72                 SqlResource.setCryptKey(cryptKey);
 
  74                 // Advertise Sql resource adaptor
 
  75                 SvcLogicResource impl = new SqlResource();
 
  76                 String regName = impl.getClass().getName();
 
  78                 if (registration == null)
 
  80                         LOG.debug("Registering SqlResource service "+regName);
 
  81                         registration =ctx.registerService(regName, impl, null);
 
  87         public void stop(BundleContext ctx) throws Exception {
 
  89                 if (registration != null)
 
  91                         registration.unregister();