summaryrefslogtreecommitdiffstats
path: root/dblib/provider/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'dblib/provider/src/main/java')
-rw-r--r--dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java20
-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.java69
-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
6 files changed, 10 insertions, 324 deletions
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
index 062cd8408..8e0b534f0 100644
--- 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
@@ -27,11 +27,11 @@ 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.onap.ccsdk.sli.core.utils.dblib.DblibDefaultFileResolver;
+import org.onap.ccsdk.sli.core.utils.dblib.DblibEnvVarFileResolver;
+import org.onap.ccsdk.sli.core.utils.JREFileResolver;
+import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,7 +58,7 @@ public class DBLIBResourceProvider {
/**
* A prioritized list of strategies for resolving dblib properties files.
*/
- private Vector<DblibPropertiesFileResolver> dblibPropertiesFileResolvers = new Vector();
+ private Vector<PropertiesFileResolver> dblibPropertiesFileResolvers = new Vector();
/**
* The configuration properties for the db connection.
@@ -75,10 +75,10 @@ public class DBLIBResourceProvider {
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 JREFileResolver(
+ "Using property file (2) from JRE argument", DBLIBResourceProvider.class
));
- dblibPropertiesFileResolvers.add(new DblibKarafRootFileResolver(
+ dblibPropertiesFileResolvers.add(new KarafRootFileResolver(
"Using property file (4) from karaf root", this));
// determines properties file as according to the priority described in the class header comment
@@ -141,7 +141,7 @@ public class DBLIBResourceProvider {
*/
File determinePropertiesFile(final DBLIBResourceProvider dblibResourceProvider) {
- for (final DblibPropertiesFileResolver dblibPropertiesFileResolver : dblibPropertiesFileResolvers) {
+ for (final PropertiesFileResolver dblibPropertiesFileResolver : dblibPropertiesFileResolvers) {
final Optional<File> fileOptional = dblibPropertiesFileResolver.resolveFile(DBLIB_PROP_FILE_NAME);
if (fileOptional.isPresent()) {
return reportSuccess(dblibPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional);
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
deleted file mode 100644
index a7797d9f7..000000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolver.java
+++ /dev/null
@@ -1,63 +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.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
deleted file mode 100644
index 0b69109f9..000000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolver.java
+++ /dev/null
@@ -1,69 +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.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
deleted file mode 100644
index 673ccbf03..000000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolver.java
+++ /dev/null
@@ -1,73 +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.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
deleted file mode 100644
index d2b164e3b..000000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolver.java
+++ /dev/null
@@ -1,64 +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.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
deleted file mode 100644
index 97ab08acf..000000000
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibPropertiesFileResolver.java
+++ /dev/null
@@ -1,45 +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.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();
-}