summaryrefslogtreecommitdiffstats
path: root/utils/provider
diff options
context:
space:
mode:
Diffstat (limited to 'utils/provider')
-rw-r--r--utils/provider/pom.xml56
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java61
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java70
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java74
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java63
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java45
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java17
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java15
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java15
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java14
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java25
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java24
12 files changed, 479 insertions, 0 deletions
diff --git a/utils/provider/pom.xml b/utils/provider/pom.xml
new file mode 100644
index 000000000..41527f0e4
--- /dev/null
+++ b/utils/provider/pom.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>ccsdk-sli-core</artifactId>
+ <version>0.1.2-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <artifactId>utils-provider</artifactId>
+ <name>SLI Core Utilities Package</name>
+
+ <description>
+ The SLI Core Utilities Package provides common functionality for setting up SLI connectivity.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>${equinox.osgi.version}</version>
+ </dependency>
+
+ <!-- Testing Dependencies -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ </plugin>
+ </plugins>
+ </build>
+ <organization>
+ <name>Inocybe Technologies and Others</name>
+ </organization>
+</project>
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java
new file mode 100644
index 000000000..8938aa6e7
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java
@@ -0,0 +1,61 @@
+/*-
+ * ============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.utils;
+
+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 abstract class DefaultFileResolver implements PropertiesFileResolver {
+
+ private final String successMessage;
+
+ private final Path propertyPath;
+
+ public DefaultFileResolver(final String successMessage, final Path propertyPath) {
+ this.successMessage = successMessage;
+ this.propertyPath = propertyPath;
+ }
+
+ /**
+ * 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 filename) {
+ final File fileFromDefaultDblibDir = propertyPath.resolve(filename).toFile();
+ if (fileFromDefaultDblibDir.exists()) {
+ return Optional.of(fileFromDefaultDblibDir);
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
new file mode 100644
index 000000000..3e438d1a9
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
@@ -0,0 +1,70 @@
+/*-
+ * ============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.utils;
+
+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 abstract class EnvVarFileResolver implements PropertiesFileResolver {
+
+ /**
+ * Key for environment variable representing the configuration directory
+ */
+ private final String propertyKey;
+
+ private final String successMessage;
+
+ public EnvVarFileResolver(final String successMessage, final String propertyKey) {
+ this.successMessage = successMessage;
+ this.propertyKey = propertyKey;
+ }
+
+ /**
+ * 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 filename) {
+ // attempt to resolve the property directory from the corresponding environment variable
+ final String propDirectoryFromEnvVariable = System.getenv(propertyKey);
+ final File fileFromEnvVariable;
+ if (!Strings.isNullOrEmpty(propDirectoryFromEnvVariable)) {
+ fileFromEnvVariable = Paths.get(propDirectoryFromEnvVariable).resolve(filename).toFile();
+ if(fileFromEnvVariable.exists()) {
+ return Optional.of(fileFromEnvVariable);
+ }
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
new file mode 100644
index 000000000..5cd6c3606
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
@@ -0,0 +1,74 @@
+/*-
+ * ============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.utils;
+
+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.osgi.framework.FrameworkUtil;
+
+/**
+ * Resolves dblib properties files relative to the directory identified by the JRE property
+ * <code>dblib.properties</code>.
+ */
+public class JREFileResolver implements PropertiesFileResolver {
+
+ /**
+ * Key for JRE argument representing the configuration directory
+ */
+ private static final String DBLIB_JRE_PROPERTY_KEY = "dblib.properties";
+
+ private final String successMessage;
+ private final Class clazz;
+
+ public JREFileResolver(final String successMessage, final Class clazz) {
+ this.successMessage = successMessage;
+ this.clazz = clazz;
+ }
+
+ /**
+ * 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 filename) {
+ final URL jreArgumentUrl = FrameworkUtil.getBundle(this.clazz)
+ .getResource(DBLIB_JRE_PROPERTY_KEY);
+ try {
+ if (jreArgumentUrl == null) {
+ return Optional.empty();
+ }
+ final Path dblibPath = Paths.get(jreArgumentUrl.toURI());
+ return Optional.of(dblibPath.resolve(filename).toFile());
+ } catch(final URISyntaxException e) {
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java
new file mode 100644
index 000000000..0cb754504
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.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.utils;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Optional;
+
+/**
+ * Resolves dblib properties files relative to the karaf root directory.
+ */
+public class KarafRootFileResolver implements PropertiesFileResolver {
+
+ final Object provider;
+
+ private final String successMessage;
+
+ public KarafRootFileResolver(final String successMessage, final Object provider) {
+ this.successMessage = successMessage;
+ this.provider = provider;
+ }
+
+ /**
+ * 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 filename) {
+ final URL fromKarafRoot = provider.getClass().getResource(filename);
+ 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/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java
new file mode 100644
index 000000000..bfb417dca
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.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.utils;
+
+import java.io.File;
+import java.util.Optional;
+
+/**
+ * Strategy for resolving dblib properties.
+ */
+public interface PropertiesFileResolver {
+
+ /**
+ * Resolve dblib properties file.
+ *
+ * @param filename the name of the file to look for at the specific location.
+ * @return An optional File or empty.
+ */
+ Optional<File> resolveFile(final String filename);
+
+ /**
+ * A success message, used only for logging now.
+ *
+ * @return a success message, used only for logging now.
+ */
+ String getSuccessfulResolutionMessage();
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java
new file mode 100644
index 000000000..56b4ca1b6
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java
@@ -0,0 +1,17 @@
+package org.onap.ccsdk.sli.core.utils.dblib;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.onap.ccsdk.sli.core.utils.DefaultFileResolver;
+
+public class DblibDefaultFileResolver extends DefaultFileResolver {
+
+ /**
+ * Default path to look for the configuration directory
+ */
+ private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("opt", "sdnc", "data", "properties");
+
+ public DblibDefaultFileResolver(final String successMessage) {
+ super(successMessage, DEFAULT_DBLIB_PROP_DIR);
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java
new file mode 100644
index 000000000..9eef4cee2
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java
@@ -0,0 +1,15 @@
+package org.onap.ccsdk.sli.core.utils.dblib;
+
+import org.onap.ccsdk.sli.core.utils.EnvVarFileResolver;
+
+public class DblibEnvVarFileResolver extends EnvVarFileResolver {
+
+ /**
+ * Key for environment variable representing the configuration directory
+ */
+ private static final String SDNC_CONFIG_DIR_PROP_KEY = "SDNC_CONFIG_DIR";
+
+ public DblibEnvVarFileResolver(final String successMessage) {
+ super(successMessage, SDNC_CONFIG_DIR_PROP_KEY);
+ }
+}
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java
new file mode 100644
index 000000000..e5051d65a
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java
@@ -0,0 +1,15 @@
+package org.onap.ccsdk.sli.core.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class JREFileResolverTest {
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new JREFileResolver("success", JREFileResolverTest.class);
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java
new file mode 100644
index 000000000..5e407daf6
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java
@@ -0,0 +1,14 @@
+package org.onap.ccsdk.sli.core.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class KarafRootFileResolverTest {
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new KarafRootFileResolver("success", null);
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java
new file mode 100644
index 000000000..4b28d449d
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java
@@ -0,0 +1,25 @@
+package org.onap.ccsdk.sli.core.utils.dblib;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+
+public class DblibDefaultFileResolverTest {
+
+ @Test
+ public void resolveFile() throws Exception {
+ final PropertiesFileResolver resolver = new DblibDefaultFileResolver("success");
+ final Optional<File> file = resolver.resolveFile("doesnotexist.cfg");
+ assertFalse(file.isPresent());
+ }
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new DblibDefaultFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java
new file mode 100644
index 000000000..bae4168d8
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java
@@ -0,0 +1,24 @@
+package org.onap.ccsdk.sli.core.utils.dblib;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+
+public class DblibEnvVarFileResolverTest {
+ @Test
+ public void resolveFile() throws Exception {
+ final PropertiesFileResolver resolver = new DblibEnvVarFileResolver("success");
+ final Optional<File> file = resolver.resolveFile("doesnotexist.cfg");
+ assertFalse(file.isPresent());
+ }
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new DblibEnvVarFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file