From 37d6468cc670045ab4ff1ee23315739a429aa5e3 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Thu, 21 Sep 2017 16:07:02 -0400 Subject: Install sdnc-core utils as karaf package New utils jar was added in another change, but wasn't bundled as a karaf feature and was not being installed in container. This broke odlsli docker container. This change wraps that util package as a new feature (sdnc-core-utils). Change-Id: Ie8c1d608e2c67aa1635837bc400cec942761c81c Issue-ID: CCSDK-54 Signed-off-by: Dan Timoney --- utils/features/pom.xml | 138 +++++++++++++++++++++ utils/features/src/main/resources/features.xml | 16 +++ utils/installer/pom.xml | 138 +++++++++++++++++++++ .../src/assembly/assemble_installer_zip.xml | 39 ++++++ .../src/assembly/assemble_mvnrepo_zip.xml | 29 +++++ .../src/main/resources/scripts/install-feature.sh | 19 +++ utils/pom.xml | 105 ++++++++++------ utils/provider/pom.xml | 56 +++++++++ .../ccsdk/sli/core/utils/DefaultFileResolver.java | 61 +++++++++ .../ccsdk/sli/core/utils/EnvVarFileResolver.java | 70 +++++++++++ .../onap/ccsdk/sli/core/utils/JREFileResolver.java | 74 +++++++++++ .../sli/core/utils/KarafRootFileResolver.java | 63 ++++++++++ .../sli/core/utils/PropertiesFileResolver.java | 45 +++++++ .../core/utils/dblib/DblibDefaultFileResolver.java | 17 +++ .../core/utils/dblib/DblibEnvVarFileResolver.java | 15 +++ .../ccsdk/sli/core/utils/JREFileResolverTest.java | 15 +++ .../sli/core/utils/KarafRootFileResolverTest.java | 14 +++ .../utils/dblib/DblibDefaultFileResolverTest.java | 25 ++++ .../utils/dblib/DblibEnvVarFileResolverTest.java | 24 ++++ .../ccsdk/sli/core/utils/DefaultFileResolver.java | 61 --------- .../ccsdk/sli/core/utils/EnvVarFileResolver.java | 70 ----------- .../onap/ccsdk/sli/core/utils/JREFileResolver.java | 74 ----------- .../sli/core/utils/KarafRootFileResolver.java | 63 ---------- .../sli/core/utils/PropertiesFileResolver.java | 45 ------- .../core/utils/dblib/DblibDefaultFileResolver.java | 17 --- .../core/utils/dblib/DblibEnvVarFileResolver.java | 15 --- .../ccsdk/sli/core/utils/JREFileResolverTest.java | 15 --- .../sli/core/utils/KarafRootFileResolverTest.java | 14 --- .../utils/dblib/DblibDefaultFileResolverTest.java | 25 ---- .../utils/dblib/DblibEnvVarFileResolverTest.java | 24 ---- 30 files changed, 922 insertions(+), 464 deletions(-) create mode 100755 utils/features/pom.xml create mode 100755 utils/features/src/main/resources/features.xml create mode 100755 utils/installer/pom.xml create mode 100755 utils/installer/src/assembly/assemble_installer_zip.xml create mode 100755 utils/installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100644 utils/installer/src/main/resources/scripts/install-feature.sh mode change 100644 => 100755 utils/pom.xml create mode 100644 utils/provider/pom.xml create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java create mode 100644 utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java create mode 100644 utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java create mode 100644 utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java create mode 100644 utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java create mode 100644 utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java delete mode 100644 utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java delete mode 100644 utils/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java delete mode 100644 utils/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java delete mode 100644 utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java delete mode 100644 utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java (limited to 'utils') diff --git a/utils/features/pom.xml b/utils/features/pom.xml new file mode 100755 index 00000000..6871d8eb --- /dev/null +++ b/utils/features/pom.xml @@ -0,0 +1,138 @@ + + + 4.0.0 + + utils + org.onap.ccsdk.sli.core + 0.1.2-SNAPSHOT + + utils-features + DBLIB Adaptor - Features + + jar + + + + + + org.onap.ccsdk.sli.core + utils-provider + ${project.version} + + + + commons-lang + commons-lang + 2.6 + compile + + + + org.opendaylight.mdsal + features-mdsal + ${odl.mdsal.features.version} + features + xml + + runtime + + + + org.apache.tomcat + tomcat-jdbc + ${tomcat-jdbc.version} + + + + + org.opendaylight.odlparent + opendaylight-karaf-empty + ${odl.karaf.empty.distro.version} + zip + + + + + org.opendaylight.odlparent + features-test + ${odl.commons.opendaylight.version} + test + + + + org.opendaylight.yangtools + features-yangtools + ${odl.yangtools.version} + features + xml + runtime + + + + + + + true + src/main/resources + + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + + resources + + generate-resources + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/${features.file} + xml + features + + + + + + + + + diff --git a/utils/features/src/main/resources/features.xml b/utils/features/src/main/resources/features.xml new file mode 100755 index 00000000..409f8c48 --- /dev/null +++ b/utils/features/src/main/resources/features.xml @@ -0,0 +1,16 @@ + + + + + mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features + + + + + odl-mdsal-broker + mvn:org.onap.ccsdk.sli.core/util-provider/${project.version} + + + diff --git a/utils/installer/pom.xml b/utils/installer/pom.xml new file mode 100755 index 00000000..b6f7f825 --- /dev/null +++ b/utils/installer/pom.xml @@ -0,0 +1,138 @@ + + + 4.0.0 + + utils + org.onap.ccsdk.sli.core + 0.1.2-SNAPSHOT + + utils-installer + SLI core utils - Karaf Installer + pom + + + sdnc-core-utils + sdnc-core-utils + mvn:org.onap.ccsdk.sli.core/utils-features/${project.version}/xml/features + false + + + + + + org.onap.ccsdk.sli.core + utils-features + ${project.version} + features + xml + + + * + * + + + + + + org.onap.ccsdk.sli.core + utils-provider + ${project.version} + + + + + + + + + maven-assembly-plugin + + + maven-repo-zip + + single + + package + + false + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + false + + + + installer-zip + + single + + package + + true + ${application.name}-${project.version}-installer + + src/assembly/assemble_installer_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.onap.ccsdk.sli,org.apache.tomcat + sli-common,sli-provider + provided + + + + + + maven-resources-plugin + 2.6 + + + copy-version + + copy-resources + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + + + + + + + + + diff --git a/utils/installer/src/assembly/assemble_installer_zip.xml b/utils/installer/src/assembly/assemble_installer_zip.xml new file mode 100755 index 00000000..a6a22a9b --- /dev/null +++ b/utils/installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,39 @@ + + + + bin + + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + + diff --git a/utils/installer/src/assembly/assemble_mvnrepo_zip.xml b/utils/installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100755 index 00000000..d96c9f40 --- /dev/null +++ b/utils/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,29 @@ + + + + bin + + + zip + + + + false + + + + target/assembly/ + . + + + + + + + + diff --git a/utils/installer/src/main/resources/scripts/install-feature.sh b/utils/installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 00000000..16b5be8c --- /dev/null +++ b/utils/installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +ODL_KARAF_CLIENT_OPTS=${ODL_KARAF_CLIENT_OPTS:-"-u karaf"} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:install ${features.boot} diff --git a/utils/pom.xml b/utils/pom.xml old mode 100644 new mode 100755 index 93326a9d..cf7dbc50 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -1,56 +1,79 @@ - - + org.onap.ccsdk.sli.core ccsdk-sli-core 0.1.2-SNAPSHOT + 4.0.0 - bundle + pom + org.onap.ccsdk.sli.core utils - SLI Core Utilities Package - - - The SLI Core Utilities Package provides common functionality for setting up SLI connectivity. - - - - - com.google.guava - guava - - - equinoxSDK381 - org.eclipse.osgi - ${equinox.osgi.version} - - - - - org.mockito - mockito-core - test - - - junit - junit - test - - + + + SLI Utils + Utilities used across sli-core + + 0.1.2-SNAPSHOT - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - - + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compile.plugin.version} + + ${java.version.source} + ${java.version.target} + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10 + + + + aggregate + + aggregate + + site + + + + + + maven-source-plugin + 2.1.1 + + + bundle-sources + package + + + jar-no-fork + + + test-jar-no-fork + + + + + + + - Inocybe Technologies and Others + AT&T + + provider + features + installer + diff --git a/utils/provider/pom.xml b/utils/provider/pom.xml new file mode 100644 index 00000000..41527f0e --- /dev/null +++ b/utils/provider/pom.xml @@ -0,0 +1,56 @@ + + + + + org.onap.ccsdk.sli.core + ccsdk-sli-core + 0.1.2-SNAPSHOT + + + 4.0.0 + bundle + utils-provider + SLI Core Utilities Package + + + The SLI Core Utilities Package provides common functionality for setting up SLI connectivity. + + + + + com.google.guava + guava + + + equinoxSDK381 + org.eclipse.osgi + ${equinox.osgi.version} + + + + + org.mockito + mockito-core + test + + + junit + junit + test + + + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + + + + + Inocybe Technologies and Others + + 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 00000000..8938aa6e --- /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: + * /opt/sdnc/data/properties + */ +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 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 00000000..3e438d1a --- /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 SDNC_CONFIG_DIR + * 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 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 00000000..5cd6c360 --- /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 + * dblib.properties. + */ +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 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 00000000..0cb75450 --- /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 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 00000000..bfb417dc --- /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 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 00000000..56b4ca1b --- /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 00000000..9eef4cee --- /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 00000000..e5051d65 --- /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 00000000..5e407daf --- /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 00000000..4b28d449 --- /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 = 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 00000000..bae4168d --- /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 = 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 diff --git a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java deleted file mode 100644 index 8938aa6e..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/DefaultFileResolver.java +++ /dev/null @@ -1,61 +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.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: - * /opt/sdnc/data/properties - */ -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 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/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java deleted file mode 100644 index 3e438d1a..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java +++ /dev/null @@ -1,70 +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.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 SDNC_CONFIG_DIR - * 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 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/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java deleted file mode 100644 index 5cd6c360..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java +++ /dev/null @@ -1,74 +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.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 - * dblib.properties. - */ -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 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/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.java deleted file mode 100644 index 0cb75450..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolver.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.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 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/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.java deleted file mode 100644 index bfb417dc..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/PropertiesFileResolver.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.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 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/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java deleted file mode 100644 index 56b4ca1b..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java +++ /dev/null @@ -1,17 +0,0 @@ -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/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java b/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java deleted file mode 100644 index 9eef4cee..00000000 --- a/utils/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java +++ /dev/null @@ -1,15 +0,0 @@ -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/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java b/utils/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java deleted file mode 100644 index e5051d65..00000000 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/JREFileResolverTest.java +++ /dev/null @@ -1,15 +0,0 @@ -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/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java b/utils/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java deleted file mode 100644 index 5e407daf..00000000 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/KarafRootFileResolverTest.java +++ /dev/null @@ -1,14 +0,0 @@ -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/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java b/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java deleted file mode 100644 index 4b28d449..00000000 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolverTest.java +++ /dev/null @@ -1,25 +0,0 @@ -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 = 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/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java b/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java deleted file mode 100644 index bae4168d..00000000 --- a/utils/src/test/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolverTest.java +++ /dev/null @@ -1,24 +0,0 @@ -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 = 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 -- cgit 1.2.3-korg