summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdblib/provider/pom.xml13
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceActivator.java130
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java164
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java83
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolver.java63
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java68
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolver.java73
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolver.java64
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibPropertiesFileResolver.java45
-rw-r--r--dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml13
-rw-r--r--dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java24
-rw-r--r--dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java23
-rw-r--r--dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java17
-rw-r--r--dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java14
-rwxr-xr-xpom.xml2
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java2
-rwxr-xr-xsliPluginUtils/provider/pom.xml1
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java49
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2PropertiesProvider.java223
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java2
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtilsActivator.java95
-rw-r--r--sliPluginUtils/provider/src/main/resources/org/opendaylight/blueprint/slipluginutils-blueprint.xml19
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2Test.java16
-rw-r--r--sliPluginUtils/provider/src/test/resources/dme2.e2e.properties7
-rw-r--r--sliPluginUtils/provider/src/test/resources/dme2.prod.properties7
25 files changed, 929 insertions, 288 deletions
diff --git a/dblib/provider/pom.xml b/dblib/provider/pom.xml
index 1f9a5d47..11e0ff74 100755
--- a/dblib/provider/pom.xml
+++ b/dblib/provider/pom.xml
@@ -52,6 +52,17 @@
<artifactId>tomcat-jdbc</artifactId>
<version>${tomcat-jdbc.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <!-- Testing related dependencies -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -64,9 +75,7 @@
<configuration>
<instructions>
<Bundle-SymbolicName>org.onap.ccsdk.sli.core.dblib</Bundle-SymbolicName>
- <Bundle-Activator>org.onap.ccsdk.sli.core.dblib.DBLIBResourceActivator</Bundle-Activator>
<Export-Package>org.onap.ccsdk.sli.core.dblib;version=${project.version}</Export-Package>
- <Import-Package>*</Import-Package>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceActivator.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceActivator.java
deleted file mode 100644
index 8ae9a266..00000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceActivator.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * onap
- * ================================================================================
- * Copyright (C) 2016 - 2017 ONAP
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.dblib;
-
-import java.io.File;
-import java.net.URL;
-import java.util.Properties;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DBLIBResourceActivator implements BundleActivator {
-
- private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
-
- private static final String DBLIB_PROP_PATH = "/dblib.properties";
-
- private ServiceRegistration registration = null;
-
- private static final Logger LOG = LoggerFactory.getLogger(DBLIBResourceActivator.class);
-
- @Override
- public void start(BundleContext ctx) throws Exception {
- LOG.info("entering DBLIBResourceActivator.start");
-
- DbLibService jdbcDataSource = null;
- // Read properties
- Properties props = new Properties();
-
- File file = null;
- URL propURL = null;
- String propDir = System.getenv(SDNC_CONFIG_DIR);
- if ((propDir == null) || (propDir.length() == 0)) {
- propDir = "/opt/sdnc/data/properties";
- }
- file = new File(propDir + DBLIB_PROP_PATH);
- if(file.exists()) {
- propURL = file.toURI().toURL();
- LOG.info("Using property file (1): " + file.toString());
- } else {
- propURL = ctx.getBundle().getResource("dblib.properties");
- URL tmp = null;
- if (propURL == null) {
- file = new File(DBLIB_PROP_PATH);
- tmp = this.getClass().getResource(DBLIB_PROP_PATH);
-// if(!file.exists()) {
- if(tmp == null) {
- throw new DblibConfigurationException("Missing configuration properties resource(3) : " + DBLIB_PROP_PATH);
- } else {
- propURL = tmp; //file.toURI().toURL();
- LOG.info("Using property file (4): " + file.toString());
- }
- } else {
- LOG.info("Using property file (2): " + propURL.toString());
- }
- }
-
-
- try {
- props.load(propURL.openStream());
- } catch (Exception e) {
- throw new DblibConfigurationException("Could not load properties at URL " + propURL.toString(), e);
-
- }
-
-
-
- try {
- jdbcDataSource = DBResourceManager.create(props);
- } catch (Exception exc) {
- throw new DblibConfigurationException("Could not get initialize database", exc);
- }
-
- String regName = jdbcDataSource.getClass().getName();
-
- LOG.info("Registering DBResourceManager service "+regName);
- registration = ctx.registerService(new String[] { regName, DbLibService.class.getName(), "javax.sql.DataSource" }, jdbcDataSource, null);
- }
-
- @Override
- public void stop(BundleContext ctx) throws Exception {
- LOG.info("entering DBLIBResourceActivator.stop");
- if (registration != null)
- {
- try {
- ServiceReference sref = ctx.getServiceReference(DbLibService.class.getName());
-
- if (sref == null) {
- LOG.warn("Could not find service reference for DBLIB service (" + DbLibService.class.getName() + ")");
- } else {
- DBResourceManager dblibSvc = (DBResourceManager) ctx.getService(sref);
- if (dblibSvc == null) {
- LOG.warn("Could not find service reference for DBLIB service (" + DbLibService.class.getName() + ")");
- } else {
- dblibSvc.cleanUp();
- }
- }
- } catch(Throwable exc) {
- LOG.warn("Cleanup", exc);
- }
-
- registration.unregister();
- registration = null;
- LOG.debug("Deregistering DBResourceManager service");
- }
- }
-
-}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java
new file mode 100644
index 00000000..201cc401
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java
@@ -0,0 +1,164 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibDefaultFileResolver;
+import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibEnvVarFileResolver;
+import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibJREFileResolver;
+import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibKarafRootFileResolver;
+import org.onap.ccsdk.sli.core.dblib.propertiesfileresolver.DblibPropertiesFileResolver;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Responsible for determining the properties file to use and instantiating the <code>DBResourceManager</code>
+ * Service. The priority for properties file resolution is as follows:
+ *
+ * <ol>
+ * <li>A directory identified by the system environment variable <code>SDNC_CONFIG_DIR</code></li>
+ * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
+ * <li>A directory identified by the JRE argument <code>dblib.properties</code></li>
+ * <li>A <code>dblib.properties</code> file located in the karaf root directory</li>
+ * </ol>
+ */
+public class DBLIBResourceProvider {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DBLIBResourceProvider.class);
+
+ /**
+ * The name of the properties file for database configuration
+ */
+ private static final String DBLIB_PROP_FILE_NAME = "dblib.properties";
+
+ /**
+ * A prioritized list of strategies for resolving dblib properties files.
+ */
+ private Vector<DblibPropertiesFileResolver> dblibPropertiesFileResolvers = new Vector();
+
+ /**
+ * The configuration properties for the db connection.
+ */
+ private Properties properties;
+
+ /**
+ * Set up the prioritized list of strategies for resolving dblib properties files.
+ */
+ public DBLIBResourceProvider() {
+ dblibPropertiesFileResolvers.add(new DblibEnvVarFileResolver(
+ "Using property file (1) from environment variable"
+ ));
+ dblibPropertiesFileResolvers.add(new DblibDefaultFileResolver(
+ "Using property file (1) from default directory"
+ ));
+ dblibPropertiesFileResolvers.add(new DblibJREFileResolver(
+ "Using property file (2) from JRE argument"
+ ));
+ dblibPropertiesFileResolvers.add(new DblibKarafRootFileResolver(
+ "Using property file (4) from karaf root", this));
+
+ // determines properties file as according to the priority described in the class header comment
+ final File propertiesFile = determinePropertiesFile(this);
+ if (propertiesFile != null) {
+ try {
+ final FileInputStream fileInputStream = new FileInputStream(propertiesFile);
+ properties = new Properties();
+ properties.load(fileInputStream);
+ } catch (final IOException e) {
+ LOG.error("Failed to load properties for file: {}", propertiesFile.toString(),
+ new DblibConfigurationException("Failed to load properties for file: "
+ + propertiesFile.toString(), e));
+ }
+ }
+ }
+
+ /**
+ * Extract db config properties.
+ *
+ * @return the db config properties
+ */
+ public Properties getProperties() {
+ return properties;
+ }
+
+ /**
+ * Reports the method chosen for properties resolution to the <code>Logger</code>.
+ *
+ * @param message Some user friendly message
+ * @param fileOptional The file location of the chosen properties file
+ * @return the file location of the chosen properties file
+ */
+ private static File reportSuccess(final String message, final Optional<File> fileOptional) {
+ final File file = fileOptional.get();
+ LOG.info("{} {}", message, file.getPath());
+ return file;
+ }
+
+ /**
+ * Reports fatal errors. This is the case in which no properties file could be found.
+ *
+ * @param message An appropriate fatal error message
+ * @param dblibConfigurationException An exception describing what went wrong during resolution
+ */
+ private static void reportFailure(final String message,
+ final DblibConfigurationException dblibConfigurationException) {
+
+ LOG.error("{}", message, dblibConfigurationException);
+ }
+
+ /**
+ * Determines the dblib properties file to use based on the following priority:
+ * <ol>
+ * <li>A directory identified by the system environment variable <code>SDNC_CONFIG_DIR</code></li>
+ * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li>
+ * <li>A directory identified by the JRE argument <code>dblib.properties</code></li>
+ * <li>A <code>dblib.properties</code> file located in the karaf root directory</li>
+ * </ol>
+ */
+ @VisibleForTesting
+ File determinePropertiesFile(final DBLIBResourceProvider dblibResourceProvider) {
+
+ for (final DblibPropertiesFileResolver dblibPropertiesFileResolver : dblibPropertiesFileResolvers) {
+ final Optional<File> fileOptional = dblibPropertiesFileResolver.resolveFile(DBLIB_PROP_FILE_NAME);
+ if (fileOptional.isPresent()) {
+ return reportSuccess(dblibPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional);
+ }
+ }
+
+ reportFailure("Missing configuration properties resource(3)",
+ new DblibConfigurationException("Missing configuration properties resource(3): "
+ + DBLIB_PROP_FILE_NAME));
+ return null;
+ }
+}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
index 78b970bf..46c003a5 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
@@ -105,67 +105,72 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
protected final long expectedCompletionTime;
protected final long unprocessedFailoverThreshold;
- public DBResourceManager(Properties props){
- this.configProps = props;
+ public DBResourceManager(final DBLIBResourceProvider configuration) {
+ this(configuration.getProperties());
+ }
+
+ public DBResourceManager(final Properties properties) {
+ this.configProps = properties;
// get retry interval value
- retryInterval = getLongFromProperties(props, "org.onap.dblib.connection.retry", 10000L);
+ retryInterval = getLongFromProperties(properties, "org.onap.dblib.connection.retry", 10000L);
// get recovery mode flag
- recoveryMode = getBooleanFromProperties(props, "org.onap.dblib.connection.recovery", true);
+ recoveryMode = getBooleanFromProperties(properties, "org.onap.dblib.connection.recovery", true);
if(!recoveryMode)
{
recoveryMode = false;
LOGGER.info("Recovery Mode disabled");
}
// get time out value for thread cleanup
- terminationTimeOut = getLongFromProperties(props, "org.onap.dblib.termination.timeout", 300000L);
+ terminationTimeOut = getLongFromProperties(properties, "org.onap.dblib.termination.timeout", 300000L);
// get properties for monitoring
- monitorDbResponse = getBooleanFromProperties(props, "org.onap.dblib.connection.monitor", false);
- monitoringInterval = getLongFromProperties(props, "org.onap.dblib.connection.monitor.interval", 1000L);
- monitoringInitialDelay = getLongFromProperties(props, "org.onap.dblib.connection.monitor.startdelay", 5000L);
- expectedCompletionTime = getLongFromProperties(props, "org.onap.dblib.connection.monitor.expectedcompletiontime", 5000L);
- unprocessedFailoverThreshold = getLongFromProperties(props, "org.onap.dblib.connection.monitor.unprocessedfailoverthreshold", 3L);
+ monitorDbResponse = getBooleanFromProperties(properties, "org.onap.dblib.connection.monitor", false);
+ monitoringInterval = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.interval", 1000L);
+ monitoringInitialDelay = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.startdelay", 5000L);
+ expectedCompletionTime = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.expectedcompletiontime", 5000L);
+ unprocessedFailoverThreshold = getLongFromProperties(properties, "org.onap.dblib.connection.monitor.unprocessedfailoverthreshold", 3L);
// initialize performance monitor
- PollingWorker.createInistance(props);
+ PollingWorker.createInistance(properties);
// initialize recovery thread
worker = new RecoveryMgr();
worker.setName("DBResourcemanagerWatchThread");
worker.setDaemon(true);
worker.start();
+
+ try {
+ this.config(properties);
+ } catch (final Exception e) {
+ // TODO: config throws <code>Exception</code> which is poor practice. Eliminate this in a separate patch.
+ LOGGER.error("Fatal Exception encountered while configuring DBResourceManager", e);
+ }
}
- private void config(Properties ctx) throws Exception {
+ private void config(Properties configProps) throws Exception {
- DbConfigPool dbConfig = DBConfigFactory.createConfig(this.configProps);
+ final DbConfigPool dbConfig = DBConfigFactory.createConfig(configProps);
+ final AbstractResourceManagerFactory factory =
+ AbstractDBResourceManagerFactory.getFactory(dbConfig.getType());
+ LOGGER.info("Default DB config is : {}", dbConfig.getType());
+ LOGGER.info("Using factory : {}", factory.getClass().getName());
- try {
- AbstractResourceManagerFactory factory = AbstractDBResourceManagerFactory.getFactory(dbConfig.getType());
- if(LOGGER.isInfoEnabled()){
- LOGGER.info("Default DB config is : " + dbConfig.getType());
- LOGGER.info("Using factory : " + factory.getClass().getName());
- }
- CachedDataSource[] cachedDS = factory.initDBResourceManager(dbConfig, this);
- if(cachedDS == null || cachedDS.length == 0) {
- LOGGER.error("Initialization of CachedDataSources failed. No instance was created.");
- throw new Exception("Failed to initialize DB Library. No data source was created.");
- }
+ final CachedDataSource[] cachedDS = factory.initDBResourceManager(dbConfig, this);
+ if (cachedDS == null || cachedDS.length == 0) {
+ LOGGER.error("Initialization of CachedDataSources failed. No instance was created.");
+ throw new Exception("Failed to initialize DB Library. No data source was created.");
+ }
- for(int i=0; i<cachedDS.length; i++){
- if(cachedDS[i] != null && cachedDS[i].isInitialized()){
- setDataSource(cachedDS[i]);
- cachedDS[i].setInterval(monitoringInterval);
- cachedDS[i].setInitialDelay(monitoringInitialDelay);
- cachedDS[i].setExpectedCompletionTime(expectedCompletionTime);
- cachedDS[i].setUnprocessedFailoverThreshold(unprocessedFailoverThreshold);
- cachedDS[i].addObserver(this);
- }
+ for (final CachedDataSource ds : cachedDS) {
+ if(ds != null && ds.isInitialized()){
+ setDataSource(ds);
+ ds.setInterval(monitoringInterval);
+ ds.setInitialDelay(monitoringInitialDelay);
+ ds.setExpectedCompletionTime(expectedCompletionTime);
+ ds.setUnprocessedFailoverThreshold(unprocessedFailoverThreshold);
+ ds.addObserver(this);
}
-
- } catch(Exception exc){
- throw exc;
}
}
@@ -664,12 +669,6 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
}
- public static DBResourceManager create(Properties props) throws Exception {
- DBResourceManager dbmanager = new DBResourceManager(props);
- dbmanager.config(props);
- return dbmanager;
- }
-
public PrintWriter getLogWriter() throws SQLException {
return ((CachedDataSource)this.dsQueue.peek()).getLogWriter();
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolver.java
new file mode 100644
index 00000000..a7797d9f
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolver.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
+
+/**
+ * Resolves dblib properties files relative to the default file path. In Unix, this is represented by:
+ * <code>/opt/sdnc/data/properties</code>
+ */
+public class DblibDefaultFileResolver implements DblibPropertiesFileResolver {
+
+ /**
+ * Default path to look for the configuration directory
+ */
+ private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("opt", "sdnc", "data", "properties");
+
+ private final String successMessage;
+
+ public DblibDefaultFileResolver(final String successMessage) {
+ this.successMessage = successMessage;
+ }
+
+ /**
+ * Parse a properties file location based on the default properties location
+ *
+ * @return an Optional File containing the location if it exists, or an empty Optional
+ */
+ @Override
+ public Optional<File> resolveFile(final String dblibFileName) {
+ final File fileFromDefaultDblibDir = DEFAULT_DBLIB_PROP_DIR.resolve(dblibFileName).toFile();
+ if (fileFromDefaultDblibDir.exists()) {
+ Optional.of(fileFromDefaultDblibDir);
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java
new file mode 100644
index 00000000..17c42ec8
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import com.google.common.base.Strings;
+import java.io.File;
+import java.nio.file.Paths;
+import java.util.Optional;
+
+/**
+ * Resolves dblib properties files relative to the directory identified by the <code>SDNC_CONFIG_DIR</code>
+ * environment variable.
+ */
+public class DblibEnvVarFileResolver implements DblibPropertiesFileResolver {
+
+ /**
+ * Key for environment variable representing the configuration directory
+ */
+ private static final String SDNC_CONFIG_DIR_PROP_KEY = "SDNC_CONFIG_DIR";
+
+ private final String successMessage;
+
+ public DblibEnvVarFileResolver(final String successMessage) {
+ this.successMessage = successMessage;
+ }
+
+ /**
+ * Parse a properties file location based on System environment variable
+ *
+ * @return an Optional File containing the location if it exists, or an empty Optional
+ */
+ @Override
+ public Optional<File> resolveFile(final String dblibFileName) {
+ // attempt to resolve the property directory from the corresponding environment variable
+ final String propDirectoryFromEnvVariable = System.getenv(SDNC_CONFIG_DIR_PROP_KEY);
+ final File fileFromEnvVariable;
+ if (!Strings.isNullOrEmpty(propDirectoryFromEnvVariable)) {
+ fileFromEnvVariable = Paths.get(propDirectoryFromEnvVariable).resolve(dblibFileName).toFile();
+ if(fileFromEnvVariable.exists()) {
+ return Optional.of(fileFromEnvVariable);
+ }
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolver.java
new file mode 100644
index 00000000..673ccbf0
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolver.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
+import org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * Resolves dblib properties files relative to the directory identified by the JRE property
+ * <code>dblib.properties</code>.
+ */
+public class DblibJREFileResolver implements DblibPropertiesFileResolver {
+
+ /**
+ * Key for JRE argument representing the configuration directory
+ */
+ private static final String DBLIB_JRE_PROPERTY_KEY = "dblib.properties";
+
+ private final String successMessage;
+
+ public DblibJREFileResolver(final String successMessage) {
+ this.successMessage = successMessage;
+ }
+
+ /**
+ * Parse a properties file location based on JRE argument
+ *
+ * @return an Optional File containing the location if it exists, or an empty Optional
+ */
+ @Override
+ public Optional<File> resolveFile(final String dblibFileName) {
+ final URL jreArgumentUrl = FrameworkUtil.getBundle(DBLIBResourceProvider.class)
+ .getResource(DBLIB_JRE_PROPERTY_KEY);
+ try {
+ if (jreArgumentUrl == null) {
+ return Optional.empty();
+ }
+ final Path dblibPath = Paths.get(jreArgumentUrl.toURI());
+ return Optional.of(dblibPath.resolve(dblibFileName).toFile());
+ } catch(final URISyntaxException e) {
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolver.java
new file mode 100644
index 00000000..d2b164e3
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolver.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Optional;
+import org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider;
+
+/**
+ * Resolves dblib properties files relative to the karaf root directory.
+ */
+public class DblibKarafRootFileResolver implements DblibPropertiesFileResolver {
+
+ final DBLIBResourceProvider dblibResourceProvider;
+
+ private final String successMessage;
+
+ public DblibKarafRootFileResolver(final String successMessage, final DBLIBResourceProvider dblibResourceProvider) {
+ this.successMessage = successMessage;
+ this.dblibResourceProvider = dblibResourceProvider;
+ }
+
+ /**
+ * Parse a properties file location relative to the karaf root
+ *
+ * @return an Optional File containing the location if it exists, or an empty Optional
+ */
+ @Override
+ public Optional<File> resolveFile(final String dblibFileName) {
+ final URL fromKarafRoot = dblibResourceProvider.getClass().getResource(dblibFileName);
+ if (fromKarafRoot != null) {
+ final File propertiesFile = new File(fromKarafRoot.getFile());
+ if (propertiesFile.exists()) {
+ return Optional.of(propertiesFile);
+ }
+ return Optional.empty();
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibPropertiesFileResolver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibPropertiesFileResolver.java
new file mode 100644
index 00000000..97ab08ac
--- /dev/null
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibPropertiesFileResolver.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import java.io.File;
+import java.util.Optional;
+
+/**
+ * Strategy for resolving dblib properties.
+ */
+public interface DblibPropertiesFileResolver {
+
+ /**
+ * Resolve dblib properties file.
+ *
+ * @param dblibFileName the name of the file to look for at the specific location.
+ * @return An optional File or empty.
+ */
+ Optional<File> resolveFile(final String dblibFileName);
+
+ /**
+ * A success message, used only for logging now.
+ *
+ * @return a success message, used only for logging now.
+ */
+ String getSuccessfulResolutionMessage();
+}
diff --git a/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml b/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml
new file mode 100644
index 00000000..ee3e0f03
--- /dev/null
+++ b/dblib/provider/src/main/resources/org/opendaylight/blueprint/dblib-blueprint.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <bean id="provider" class="org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider" />
+
+ <bean id="dbResourceManager" class="org.onap.ccsdk.sli.core.dblib.DBResourceManager">
+ <argument ref="provider" />
+ </bean>
+ <service ref="dbResourceManager" interface="org.onap.ccsdk.sli.core.dblib.DbLibService" />
+
+</blueprint> \ No newline at end of file
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java
new file mode 100644
index 00000000..41011e55
--- /dev/null
+++ b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java
@@ -0,0 +1,24 @@
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+
+public class DblibDefaultFileResolverTest {
+
+ @Test
+ public void resolveFile() throws Exception {
+ final DblibPropertiesFileResolver resolver = new DblibDefaultFileResolver("success");
+ final Optional<File> file = resolver.resolveFile("doesnotexist.cfg");
+ assertFalse(file.isPresent());
+ }
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final DblibPropertiesFileResolver resolver = new DblibDefaultFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java
new file mode 100644
index 00000000..77589893
--- /dev/null
+++ b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java
@@ -0,0 +1,23 @@
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+
+public class DblibEnvVarFileResolverTest {
+ @Test
+ public void resolveFile() throws Exception {
+ final DblibPropertiesFileResolver resolver = new DblibEnvVarFileResolver("success");
+ final Optional<File> file = resolver.resolveFile("doesnotexist.cfg");
+ assertFalse(file.isPresent());
+ }
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final DblibPropertiesFileResolver resolver = new DblibEnvVarFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java
new file mode 100644
index 00000000..117492d0
--- /dev/null
+++ b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java
@@ -0,0 +1,17 @@
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+
+public class DblibJREFileResolverTest {
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final DblibPropertiesFileResolver resolver = new DblibJREFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java
new file mode 100644
index 00000000..0a032e8b
--- /dev/null
+++ b/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java
@@ -0,0 +1,14 @@
+package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class DblibKarafRootFileResolverTest {
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final DblibPropertiesFileResolver resolver = new DblibKarafRootFileResolver("success", null);
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 645e6b53..eba735f5 100755
--- a/pom.xml
+++ b/pom.xml
@@ -100,7 +100,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
- <skipTests>true</skipTests>
+ <skipTests>false</skipTests>
</configuration>
</plugin>
<plugin>
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
index 2aed6511..de3682d8 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
@@ -498,7 +498,7 @@ public class SvcLogicDblibStore implements SvcLogicStore {
}
try {
- dblibSvc = DBResourceManager.create(dblibProps);
+ dblibSvc = new DBResourceManager(dblibProps);
JavaSingleton.setInstance(dblibSvc);
} catch (Exception e) {
LOG.warn("Caught exception trying to create DBResourceManager", e);
diff --git a/sliPluginUtils/provider/pom.xml b/sliPluginUtils/provider/pom.xml
index 1af88e82..430221fc 100755
--- a/sliPluginUtils/provider/pom.xml
+++ b/sliPluginUtils/provider/pom.xml
@@ -70,7 +70,6 @@
<configuration>
<instructions>
<Bundle-SymbolicName>org.onap.ccsdk.sli.core.slipluginutils</Bundle-SymbolicName>
- <Bundle-Activator>org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtilsActivator</Bundle-Activator>
<Export-Package>org.onap.ccsdk.sli.core.slipluginutils</Export-Package>
<Import-Package>org.onap.ccsdk.sli.core.*,org.osgi.framework.*,org.slf4j.*,java.net.*</Import-Package>
<Embed-Dependency>*;scope=compile|runtime;artifactId=!sli-common|org.eclipse.osgi|mysql-connector-java|slf4j-api|jcl-over-slf4j</Embed-Dependency>
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java
index 105ae954..326490d9 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/DME2.java
@@ -23,6 +23,7 @@ package org.onap.ccsdk.sli.core.slipluginutils;
import java.util.Map;
+import java.util.Optional;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
@@ -35,16 +36,19 @@ import org.slf4j.LoggerFactory;
* A SvcLogicJavaPlugin that generates DME2 proxy urls using parameters from context memory.
*/
public class DME2 implements SvcLogicJavaPlugin {
- String aafUserName;
- String aafPassword;
- String envContext;
- String routeOffer;
- String[] proxyUrls;
+
+ private static final Logger LOG = LoggerFactory.getLogger(DME2.class);
+
+ final String aafUserName;
+ final String aafPassword;
+ final String envContext;
+ final String routeOffer;
+ final String[] proxyUrls;
+ final String commonServiceVersion;
+
Integer index;
- String commonServiceVersion;
String partner;
- private static final Logger LOG = LoggerFactory.getLogger(DME2.class);
public void setPartner(String partner) {
if (partner != null && partner.length() > 0) {
@@ -62,6 +66,37 @@ public class DME2 implements SvcLogicJavaPlugin {
this.commonServiceVersion = commonServiceVersion;
}
+ public DME2(final Dme2PropertiesProvider provider) {
+ this.aafUserName = useProperty(provider.getAafUsername(), Dme2PropertiesProvider.AAF_USERNAME_KEY);
+ this.aafPassword = useProperty(provider.getAafPassword(), Dme2PropertiesProvider.AAF_PASSWORD_KEY);
+ this.envContext = useProperty(provider.getEnvContext(), Dme2PropertiesProvider.ENV_CONTEXT_KEY);
+ this.routeOffer = useProperty(provider.getRouteOffer(), Dme2PropertiesProvider.ROUTE_OFFER_KEY);
+ this.index = 0;
+ this.commonServiceVersion = useProperty(provider.getCommonServiceVersion(),
+ Dme2PropertiesProvider.COMMON_SERVICE_VERSION_KEY);
+
+ final Optional<String []> maybeProxyUrls = provider.getProxyUrls();
+ if (maybeProxyUrls.isPresent()) {
+ this.proxyUrls = maybeProxyUrls.get();
+ } else {
+ warnOfMissingProperty(Dme2PropertiesProvider.PROXY_URL_KEY);
+ this.proxyUrls = null;
+ }
+ this.setPartner(useProperty(provider.getPartner(), Dme2PropertiesProvider.PARTNER_KEY));
+ }
+
+ private String useProperty(final Optional<String> propertyOptional, final String propertyKey) {
+ if (propertyOptional.isPresent()) {
+ return propertyOptional.get();
+ }
+ warnOfMissingProperty(propertyKey);
+ return null;
+ }
+
+ private void warnOfMissingProperty(final String propertyName) {
+ LOG.warn("Utilizing null for {} since it was left unassigned in the properties file");
+ }
+
// constructs a URL to contact the proxy which contacts a DME2 service
public String constructUrl(String service, String version, String subContext) {
StringBuilder sb = new StringBuilder();
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2PropertiesProvider.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2PropertiesProvider.java
new file mode 100644
index 00000000..07c84c66
--- /dev/null
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2PropertiesProvider.java
@@ -0,0 +1,223 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.slipluginutils;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Immutable properties container for dme2 properties. Since the initial design decision was made to
+ * utilize <code>Properties</code> instead of an OSGi <code>ManagedService</code>, it was decided
+ * to make these properties immutable.
+ */
+public final class Dme2PropertiesProvider {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Dme2PropertiesProvider.class);
+
+ /**
+ * The name of the environment variable to specify the configuration directory.
+ */
+ private static final String SDNC_ROOT_DIR_ENV_VAR_KEY = "SDNC_CONFIG_DIR";
+
+ /**
+ * the dme2 properties file name.
+ */
+ private static final String DME2_PROPERTIES_FILE_NAME = "dme2.properties";
+
+ /**
+ * the key for <code>proxyUrl</code>, which represents a CSV list of urls
+ */
+ static final String PROXY_URL_KEY = "proxyUrl";
+
+ /**
+ * indicates that proxy urls are separated by commas
+ */
+ private static final String PROXY_URLS_VALUE_SEPARATOR = ",";
+
+ /**
+ * the key for <code>aafUserName</code>
+ */
+ static final String AAF_USERNAME_KEY = "aafUserName";
+
+ /**
+ * the key for <code>aafPassword</code>
+ */
+ static final String AAF_PASSWORD_KEY = "aafPassword";
+
+ /**
+ * the key for <code>envContext</code>
+ */
+ static final String ENV_CONTEXT_KEY = "envContext";
+
+ /**
+ * the key for <code>routeOffer</code>
+ */
+ static final String ROUTE_OFFER_KEY = "routeOffer";
+
+ /**
+ * the key for <code>commonServiceVersion</code>
+ */
+ static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion";
+
+ /**
+ * the key for <code>partner</code>
+ */
+ static final String PARTNER_KEY = "partner";
+
+ private Optional<String []> proxyUrls = Optional.empty();
+
+ private Optional<String> aafUsername = Optional.empty();
+
+ private Optional<String> aafPassword = Optional.empty();
+
+ private Optional<String> envContext = Optional.empty();
+
+ private Optional<String> routeOffer = Optional.empty();
+
+ private Optional<String> commonServiceVersion = Optional.empty();
+
+ private Optional<String> partner = Optional.empty();
+
+
+ /**
+ * Instantiates the properties provider, which involves loading the appropriate properties for dme2.
+ */
+ public Dme2PropertiesProvider() {
+ this(getDme2Path(SDNC_ROOT_DIR_ENV_VAR_KEY, DME2_PROPERTIES_FILE_NAME).toString());
+ }
+
+ /**
+ * Instantiates the properties provider, which involves loading the appropriate properties for dme2.
+ *
+ * @param dme2Path location of the dme2.properties file
+ */
+ @VisibleForTesting
+ Dme2PropertiesProvider(final String dme2Path) {
+ final Properties properties;
+ try {
+ properties = getProperties(dme2Path);
+ this.proxyUrls = getProxyUrls(properties);
+ this.aafUsername = getAafUsername(properties);
+ this.aafPassword = getAafPassword(properties);
+ this.envContext = getEnvContext(properties);
+ this.routeOffer = getRouteOffer(properties);
+ this.commonServiceVersion = getCommonServiceVersion(properties);
+ this.partner = getPartner(properties);
+ } catch (final FileNotFoundException e) {
+ LOG.error("dme2.properties file could not be found at path: {}", dme2Path, e);
+ } catch (final IOException e) {
+ LOG.error("fatal error reading dme2.properties at path: {}", dme2Path, e);
+ }
+ }
+
+ private static Path getDme2Path(final String sdncRootDirectory, final String dme2Filename) {
+ return Paths.get(sdncRootDirectory, dme2Filename);
+ }
+
+ private static Properties getProperties(final String dme2Path) throws IOException {
+ final File dme2File = new File(dme2Path);
+ final Properties properties = new Properties();
+ properties.load(new FileReader(dme2File));
+ return properties;
+ }
+
+ private String getProxyUrl(final Properties properties) {
+ return properties.getProperty(PROXY_URL_KEY);
+ }
+
+ private Optional<String []> getProxyUrls(final Properties properties) {
+ final String proxyUrlsValue = getProxyUrl(properties);
+ if (!Strings.isNullOrEmpty(proxyUrlsValue)) {
+ return Optional.ofNullable(proxyUrlsValue.split(PROXY_URLS_VALUE_SEPARATOR));
+ }
+ return Optional.empty();
+ }
+
+ public Optional<String []> getProxyUrls() {
+ return this.proxyUrls;
+ }
+
+ private Optional<String> getAafUsername(final Properties properties) {
+ final String aafUsernameValue = properties.getProperty(AAF_USERNAME_KEY);
+ return Optional.ofNullable(aafUsernameValue);
+ }
+
+ Optional<String> getAafUsername() {
+ return this.aafUsername;
+ }
+
+ private Optional<String> getAafPassword(final Properties properties) {
+ final String aafPassword = properties.getProperty(AAF_PASSWORD_KEY);
+ return Optional.ofNullable(aafPassword);
+ }
+
+ Optional<String> getAafPassword() {
+ return this.aafPassword;
+ }
+
+ private Optional<String> getEnvContext(final Properties properties) {
+ final String envContext = properties.getProperty(ENV_CONTEXT_KEY);
+ return Optional.ofNullable(envContext);
+ }
+
+ Optional<String> getEnvContext() {
+ return this.envContext;
+ }
+
+ private Optional<String> getRouteOffer(final Properties properties) {
+ final String routeOffer = properties.getProperty(ROUTE_OFFER_KEY);
+ return Optional.ofNullable(routeOffer);
+ }
+
+ Optional<String> getRouteOffer() {
+ return this.routeOffer;
+ }
+
+ private Optional<String> getCommonServiceVersion(final Properties properties) {
+ final String commonServiceVersion = properties.getProperty(COMMON_SERVICE_VERSION_KEY);
+ return Optional.ofNullable(commonServiceVersion);
+ }
+
+ Optional<String> getCommonServiceVersion() {
+ return this.commonServiceVersion;
+ }
+
+ private Optional<String> getPartner(final Properties properties) {
+ final String partner = properties.getProperty(PARTNER_KEY);
+ return Optional.ofNullable(partner);
+ }
+
+ Optional<String> getPartner() {
+ return this.partner;
+ }
+}
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
index 8a2aa6d6..e6811e78 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
@@ -60,8 +60,6 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
public SliPluginUtils() {}
- public SliPluginUtils( Properties props ) {}
-
// ========== CONTEXT MEMORY FUNCTIONS ==========
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtilsActivator.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtilsActivator.java
deleted file mode 100644
index 89eb4f23..00000000
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtilsActivator.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.slipluginutils;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SliPluginUtilsActivator implements BundleActivator {
- @SuppressWarnings("rawtypes") private List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
-
- private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtilsActivator.class);
- private static final String SDNC_ROOT_DIR = "SDNC_CONFIG_DIR";
- private static final String DME2_PROPERTIES_FILE_NAME = "dme2.properties";
-
- @Override
- public void start(BundleContext ctx) throws Exception {
- SliPluginUtils plugin = new SliPluginUtils(new Properties());
- LOG.info("Registering service " + plugin.getClass().getName());
- registrations.add(ctx.registerService(plugin.getClass().getName(), plugin, null));
-
- SliStringUtils sliStringUtils_Plugin = new SliStringUtils();
- LOG.info("Registering service " + sliStringUtils_Plugin.getClass().getName());
- registrations.add(ctx.registerService(sliStringUtils_Plugin.getClass().getName(), sliStringUtils_Plugin, null));
-
- try {
- String path = System.getenv(SDNC_ROOT_DIR) + File.separator + DME2_PROPERTIES_FILE_NAME;
- DME2 dmePlugin = initDme2(path);
- if (dmePlugin != null) {
- LOG.info("Registering service " + dmePlugin.getClass().getName());
- registrations.add(ctx.registerService(dmePlugin.getClass().getName(), dmePlugin, null));
- }
- } catch (Exception e) {
- LOG.error("DME2 plugin could not be started", e);
- }
- }
-
- public DME2 initDme2(String pathToDmeProperties) {
- Properties dme2properties = new Properties();
- String loadPropertiesErrorMessage = "Couldn't load DME2 properties at path " + pathToDmeProperties;
- File dme2propertiesFile = new File(pathToDmeProperties);
-
- try {
- dme2properties.load(new FileReader(dme2propertiesFile));
- String proxyUrlProperty = dme2properties.getProperty("proxyUrl");
- String[] proxyUrls = proxyUrlProperty.split(",");
- DME2 dmePlugin = new DME2(dme2properties.getProperty("aafUserName"), dme2properties.getProperty("aafPassword"), dme2properties.getProperty("envContext"), dme2properties.getProperty("routeOffer"), proxyUrls, dme2properties.getProperty("commonServiceVersion"));
- dmePlugin.setPartner(dme2properties.getProperty("partner"));
- return dmePlugin;
- } catch (FileNotFoundException e) {
- LOG.error(loadPropertiesErrorMessage);
- } catch (IOException e) {
- LOG.error(loadPropertiesErrorMessage);
- }
- LOG.error("Couldn't create DME2 plugin");
- return null;
- }
-
- @Override
- public void stop(BundleContext ctx) throws Exception {
- for (@SuppressWarnings("rawtypes") ServiceRegistration registration : registrations) {
- registration.unregister();
- registration = null;
- }
- }
-}
diff --git a/sliPluginUtils/provider/src/main/resources/org/opendaylight/blueprint/slipluginutils-blueprint.xml b/sliPluginUtils/provider/src/main/resources/org/opendaylight/blueprint/slipluginutils-blueprint.xml
new file mode 100644
index 00000000..c0952d2a
--- /dev/null
+++ b/sliPluginUtils/provider/src/main/resources/org/opendaylight/blueprint/slipluginutils-blueprint.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+
+ <bean id="sliPluginUtils" class="org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils" />
+ <service ref="sliPluginUtils" interface="org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils" />
+
+ <bean id="sliStringUtils" class="org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils" />
+ <service ref="sliStringUtils" interface="org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils" />
+
+ <bean id="dme2Properties" class="org.onap.ccsdk.sli.core.slipluginutils.Dme2PropertiesProvider" />
+ <bean id="dme2" class="org.onap.ccsdk.sli.core.slipluginutils.DME2">
+ <argument ref="dme2Properties" />
+ </bean>
+ <service ref="dme2" interface="org.onap.ccsdk.sli.core.slipluginutils.DME2" />
+
+</blueprint> \ No newline at end of file
diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2Test.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2Test.java
index 48c32f45..d19fbec4 100644
--- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2Test.java
+++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/Dme2Test.java
@@ -34,7 +34,7 @@ public class Dme2Test {
@Test
public void createInstarUrl() {
- String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com";
+ String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true";
DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
assertEquals(instarUrl, constructedUrl);
@@ -42,7 +42,7 @@ public class Dme2Test {
@Test
public void createInstarUrlNoSubContext() {
- String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT?dme2.password=fake&dme2.username=user@sample.com";
+ String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true";
DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
Map<String, String> parameters = new HashMap<String, String>();
String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", parameters.get(null));
@@ -52,7 +52,7 @@ public class Dme2Test {
@Test
public void testRoundRobin() {
String[] proxyHostNames = new String[] { "http://one:25055", "http://two:25055", "http://three:25055" };
- String urlSuffix = "/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com";
+ String urlSuffix = "/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true";
DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNames, "common");
String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
@@ -72,8 +72,9 @@ public class Dme2Test {
@Test
public void createDme2EndtoEnd() {
- SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
- DME2 dme2 = activator.initDme2("src/test/resources/dme2.e2e.properties");
+ Dme2PropertiesProvider provider =
+ new Dme2PropertiesProvider("src/test/resources/dme2.e2e.properties");
+ DME2 dme2 = new DME2(provider);
assertEquals("user@sample.com", dme2.aafUserName);
assertEquals("fake", dme2.aafPassword);
assertEquals("UAT", dme2.envContext);
@@ -89,8 +90,9 @@ public class Dme2Test {
@Test
public void createDme2Prod() {
- SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
- DME2 dme2 = activator.initDme2("src/test/resources/dme2.prod.properties");
+ Dme2PropertiesProvider provider =
+ new Dme2PropertiesProvider("src/test/resources/dme2.prod.properties");
+ DME2 dme2 = new DME2(provider);
assertEquals("user@sample.com", dme2.aafUserName);
assertEquals("fake", dme2.aafPassword);
assertEquals("PROD", dme2.envContext);
diff --git a/sliPluginUtils/provider/src/test/resources/dme2.e2e.properties b/sliPluginUtils/provider/src/test/resources/dme2.e2e.properties
new file mode 100644
index 00000000..37344844
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/resources/dme2.e2e.properties
@@ -0,0 +1,7 @@
+aafUserName=user@sample.com
+aafPassword=fake
+envContext=UAT
+routeOffer=UAT
+proxyUrl=http://sample.com:25055,http://sample.com:25055
+commonServiceVersion=1702.0
+partner= \ No newline at end of file
diff --git a/sliPluginUtils/provider/src/test/resources/dme2.prod.properties b/sliPluginUtils/provider/src/test/resources/dme2.prod.properties
new file mode 100644
index 00000000..4326b004
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/resources/dme2.prod.properties
@@ -0,0 +1,7 @@
+aafUserName=user@sample.com
+aafPassword=fake
+envContext=PROD
+routeOffer=
+proxyUrl=http://sample.com:25055,http://sample.com:25055
+commonServiceVersion=1.0
+partner=LPP_PROD \ No newline at end of file