From 131cb46f6109a6099a445cb8e1b12ff5b68ae6de Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Thu, 1 Feb 2018 16:57:00 -0500 Subject: Upgrade sli/core to Nitrogen Use Apache derby for dblib SingleFeatureTest Change-Id: I6b41f7ede1a98b33824fceea9100e75c1ce8dda4 Issue-ID: CCSDK-175 Signed-off-by: Dan Timoney Generalization of CCSDK core/utils framework Changes made: * Created generalized version of core/utils/dblib as core/utils/common * Deprecated core/utils/dblib package Change-Id: I0992c43910278fbe254674d1e39d7e4fcad0a592 Issue-ID: CCSDK-168 Signed-off-by: Rich Tabedzki Use Apache derby for dblib test Use Apache derby for dblib SingleFeatureTest Change-Id: Ie497557f162e203fa5c5c82c17ddc55ba0c11b38 Issue-ID: CCSDK-175 Signed-off-by: Dan Timoney --- .../features/ccsdk-sliPluginUtils/pom.xml | 65 ++++ .../features/features-sliPluginUtils/pom.xml | 29 ++ sliPluginUtils/features/pom.xml | 130 +------ .../features/src/main/resources/features.xml | 38 -- sliPluginUtils/installer/pom.xml | 23 +- sliPluginUtils/pom.xml | 38 +- sliPluginUtils/provider/pom.xml | 47 +-- .../slipluginutils/Dme2PropertiesProvider.java | 421 ++++++++++++--------- .../provider/src/main/resources/dme2.properties | 7 + 9 files changed, 388 insertions(+), 410 deletions(-) create mode 100644 sliPluginUtils/features/ccsdk-sliPluginUtils/pom.xml create mode 100644 sliPluginUtils/features/features-sliPluginUtils/pom.xml delete mode 100644 sliPluginUtils/features/src/main/resources/features.xml create mode 100644 sliPluginUtils/provider/src/main/resources/dme2.properties (limited to 'sliPluginUtils') diff --git a/sliPluginUtils/features/ccsdk-sliPluginUtils/pom.xml b/sliPluginUtils/features/ccsdk-sliPluginUtils/pom.xml new file mode 100644 index 00000000..8ea5ca86 --- /dev/null +++ b/sliPluginUtils/features/ccsdk-sliPluginUtils/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + + org.onap.ccsdk.parent + single-feature-parent + 1.0.1-SNAPSHOT + + + + org.onap.ccsdk.sli.core + ccsdk-sliPluginUtils + 0.2.1-SNAPSHOT + feature + + ccsdk-sli-core :: sliPluginUtils :: ${project.artifactId} + + + + + org.opendaylight.mdsal.model + mdsal-model-artifacts + 0.11.1 + pom + import + + + org.opendaylight.controller + mdsal-artifacts + 1.6.1 + pom + import + + + + + + org.opendaylight.controller + odl-mdsal-broker + xml + features + + + + ${project.groupId} + ccsdk-sli + ${project.version} + xml + features + + + + ${project.groupId} + sliPluginUtils-provider + ${project.version} + + + equinoxSDK381 + org.eclipse.osgi + ${equinox.osgi.version} + provided + + + diff --git a/sliPluginUtils/features/features-sliPluginUtils/pom.xml b/sliPluginUtils/features/features-sliPluginUtils/pom.xml new file mode 100644 index 00000000..004277dd --- /dev/null +++ b/sliPluginUtils/features/features-sliPluginUtils/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + org.onap.ccsdk.parent + feature-repo-parent + 1.0.1-SNAPSHOT + + + + org.onap.ccsdk.sli.core + features-sliPluginUtils + 0.2.1-SNAPSHOT + feature + + ccsdk-sli-core :: sliPluginUtils :: ${project.artifactId} + + + + ${project.groupId} + ccsdk-sliPluginUtils + ${project.version} + xml + features + + + + diff --git a/sliPluginUtils/features/pom.xml b/sliPluginUtils/features/pom.xml index 19d32f7a..4a1f8994 100755 --- a/sliPluginUtils/features/pom.xml +++ b/sliPluginUtils/features/pom.xml @@ -1,127 +1,23 @@ - - sliPluginUtils-features - jar 4.0.0 - sliPluginUtils - org.onap.ccsdk.sli.core - 0.2.0-SNAPSHOT + org.onap.ccsdk.parent + odlparent-lite + 1.0.1-SNAPSHOT + - SliPluginUtils Plugin - Features - - - - org.onap.ccsdk.sli.core - sliPluginUtils-provider - ${project.version} - - - commons-lang - commons-lang - ${commons.lang.version} - compile - - - org.opendaylight.mdsal - features-mdsal - ${odl.mdsal.features.version} - features - xml - runtime - - - - 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.onap.ccsdk.sli.core + sliPluginUtils-features + 0.2.1-SNAPSHOT + pom - + ccsdk-sli-core :: sliPluginUtils :: ${project.artifactId} - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - attach-artifact - - package - - - - ${project.build.directory}/classes/${features.file} - xml - features - - - - - - - - + + features-sliPluginUtils + ccsdk-sliPluginUtils + diff --git a/sliPluginUtils/features/src/main/resources/features.xml b/sliPluginUtils/features/src/main/resources/features.xml deleted file mode 100644 index f59cea42..00000000 --- a/sliPluginUtils/features/src/main/resources/features.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features - - - - - odl-mdsal-broker - sdnc-sli - mvn:org.onap.ccsdk.sli.core/sliPluginUtils-provider/${project.version} - - - diff --git a/sliPluginUtils/installer/pom.xml b/sliPluginUtils/installer/pom.xml index 736d2220..1c0704af 100755 --- a/sliPluginUtils/installer/pom.xml +++ b/sliPluginUtils/installer/pom.xml @@ -1,18 +1,24 @@ 4.0.0 + - sliPluginUtils - org.onap.ccsdk.sli.core - 0.2.0-SNAPSHOT + org.onap.ccsdk.parent + odlparent-lite + 1.0.1-SNAPSHOT + + + org.onap.ccsdl.sli.core sliPluginUtils-installer - SLI Plugin Utilities - Karaf Installer + 0.2.1-SNAPSHOT pom + ccsdk-sli-core :: sliPluginUtils :: ${project.artifactId} + - sdnc-sliPluginUtils - sdnc-sliPluginUtils + ccsdk-sliPluginUtils + ${application.name} mvn:org.onap.ccsdk.sli.core/sliPluginUtils-features/${project.version}/xml/features false @@ -21,10 +27,10 @@ org.onap.ccsdk.sli.core - sliPluginUtils-features + ${application.name} ${project.version} - features xml + features * @@ -134,5 +140,4 @@ - diff --git a/sliPluginUtils/pom.xml b/sliPluginUtils/pom.xml index 21efb170..45be684f 100755 --- a/sliPluginUtils/pom.xml +++ b/sliPluginUtils/pom.xml @@ -1,38 +1,22 @@ - + + 4.0.0 + + + org.onap.ccsdk.parent + odlparent-lite + 1.0.1-SNAPSHOT + + org.onap.ccsdk.sli.core sliPluginUtils - 0.2.0-SNAPSHOT + 0.2.1-SNAPSHOT pom - 4.0.0 - - - org.onap.ccsdk.sli.core - ccsdk-sli-core - 0.2.0-SNAPSHOT - - Service Logic Interface Plugin Utilities + ccsdk-sli-core :: sliPluginUtils A package of static utility functions to be used when developing SLI plugins - - - - org.onap.ccsdk.sli.core - SliPluginUtils-features - features - xml - ${project.version} - - - org.onap.ccsdk.sli.core - SliPluginUtils-provider - ${project.version} - - - - provider features diff --git a/sliPluginUtils/provider/pom.xml b/sliPluginUtils/provider/pom.xml index 61b5e958..0a274edd 100755 --- a/sliPluginUtils/provider/pom.xml +++ b/sliPluginUtils/provider/pom.xml @@ -1,17 +1,20 @@ - - sliPluginUtils-provider - bundle 4.0.0 - org.onap.ccsdk.sli.core - sliPluginUtils - 0.2.0-SNAPSHOT + org.onap.ccsdk.parent + binding-parent + 1.0.1-SNAPSHOT + - SliPluginUtils Plugin - Provider + org.onap.ccsdk.sli.core + sliPluginUtils-provider + 0.2.1-SNAPSHOT + bundle + + ccsdk-sli-core :: sliPluginUtils :: ${project.artifactId} http://maven.apache.org @@ -22,11 +25,10 @@ junit junit - ${junit.version} test - org.onap.ccsdk.sli.core + ${project.groupId} sli-common ${project.version} compile @@ -34,22 +36,18 @@ equinoxSDK381 org.eclipse.osgi - ${equinox.osgi.version} org.slf4j slf4j-api - ${slf4j.version} org.slf4j jcl-over-slf4j - ${slf4j.version} org.apache.commons commons-lang3 - 3.1 org.hamcrest @@ -68,27 +66,4 @@ 1.1 - - - - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - true - - - org.onap.ccsdk.sli.core.slipluginutils - org.onap.ccsdk.sli.core.slipluginutils - org.onap.ccsdk.sli.core.*,org.osgi.framework.*,org.slf4j.*,java.net.* - *;scope=compile|runtime;artifactId=!sli-common|org.eclipse.osgi|mariadb-java-client|slf4j-api|jcl-over-slf4j - true - - - - - - - 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 index 07c84c66..6802c9a8 100644 --- 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 @@ -8,9 +8,9 @@ * 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. @@ -31,193 +31,248 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; import java.util.Properties; +import java.util.Vector; +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.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver; +import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Immutable properties container for dme2 properties. Since the initial design decision was made to - * utilize Properties instead of an OSGi ManagedService, it was decided - * to make these properties immutable. + * Immutable properties container for dme2 properties. Since the initial design + * decision was made to utilize Properties instead of an OSGi + * ManagedService, 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 proxyUrl, 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 aafUserName - */ - static final String AAF_USERNAME_KEY = "aafUserName"; - - /** - * the key for aafPassword - */ - static final String AAF_PASSWORD_KEY = "aafPassword"; - - /** - * the key for envContext - */ - static final String ENV_CONTEXT_KEY = "envContext"; - - /** - * the key for routeOffer - */ - static final String ROUTE_OFFER_KEY = "routeOffer"; - - /** - * the key for commonServiceVersion - */ - static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion"; - - /** - * the key for partner - */ - static final String PARTNER_KEY = "partner"; - - private Optional proxyUrls = Optional.empty(); - - private Optional aafUsername = Optional.empty(); - - private Optional aafPassword = Optional.empty(); - - private Optional envContext = Optional.empty(); - - private Optional routeOffer = Optional.empty(); - - private Optional commonServiceVersion = Optional.empty(); - - private Optional 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 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 getProxyUrls() { - return this.proxyUrls; - } - - private Optional getAafUsername(final Properties properties) { - final String aafUsernameValue = properties.getProperty(AAF_USERNAME_KEY); - return Optional.ofNullable(aafUsernameValue); - } - - Optional getAafUsername() { - return this.aafUsername; - } - - private Optional getAafPassword(final Properties properties) { - final String aafPassword = properties.getProperty(AAF_PASSWORD_KEY); - return Optional.ofNullable(aafPassword); - } - - Optional getAafPassword() { - return this.aafPassword; - } - - private Optional getEnvContext(final Properties properties) { - final String envContext = properties.getProperty(ENV_CONTEXT_KEY); - return Optional.ofNullable(envContext); - } - - Optional getEnvContext() { - return this.envContext; - } - - private Optional getRouteOffer(final Properties properties) { - final String routeOffer = properties.getProperty(ROUTE_OFFER_KEY); - return Optional.ofNullable(routeOffer); - } - - Optional getRouteOffer() { - return this.routeOffer; - } - - private Optional getCommonServiceVersion(final Properties properties) { - final String commonServiceVersion = properties.getProperty(COMMON_SERVICE_VERSION_KEY); - return Optional.ofNullable(commonServiceVersion); - } - - Optional getCommonServiceVersion() { - return this.commonServiceVersion; - } - - private Optional getPartner(final Properties properties) { - final String partner = properties.getProperty(PARTNER_KEY); - return Optional.ofNullable(partner); - } - - Optional getPartner() { - return this.partner; - } + 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 proxyUrl, 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 aafUserName + */ + static final String AAF_USERNAME_KEY = "aafUserName"; + + /** + * the key for aafPassword + */ + static final String AAF_PASSWORD_KEY = "aafPassword"; + + /** + * the key for envContext + */ + static final String ENV_CONTEXT_KEY = "envContext"; + + /** + * the key for routeOffer + */ + static final String ROUTE_OFFER_KEY = "routeOffer"; + + /** + * the key for commonServiceVersion + */ + static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion"; + + /** + * the key for partner + */ + static final String PARTNER_KEY = "partner"; + + private Optional proxyUrls = Optional.empty(); + + private Optional aafUsername = Optional.empty(); + + private Optional aafPassword = Optional.empty(); + + private Optional envContext = Optional.empty(); + + private Optional routeOffer = Optional.empty(); + + private Optional commonServiceVersion = Optional.empty(); + + private Optional partner = Optional.empty(); + + /** + * A prioritized list of strategies for resolving dme2 properties files. + */ + private Vector dme2PropertiesFileResolvers = new Vector<>(); + + /** + * Instantiates the properties provider, which involves loading the appropriate + * properties for dme2. + */ + public Dme2PropertiesProvider() { + this(DME2_PROPERTIES_FILE_NAME); + } + + /** + * Instantiates the properties provider, which involves loading the appropriate + * properties for dme2. + * + * @param dme2Path + * location of the dme2.properties file + */ + @VisibleForTesting + Dme2PropertiesProvider(final String dme2FileName) { + dme2PropertiesFileResolvers + .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); + dme2PropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory")); + + dme2PropertiesFileResolvers + .add(new JREFileResolver("Using property file (3) from JRE argument", Dme2PropertiesProvider.class)); + dme2PropertiesFileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); + + File dme2File = getDme2File(dme2FileName); + + init(dme2File); + } + + private void init(final File 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); + } + } + + /** + * Reports the method chosen for properties resolution to the + * Logger. + * + * @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 fileOptional) { + if (fileOptional.isPresent()) { + final File file = fileOptional.get(); + LOG.info("{} {}", message, file.getPath()); + return file; + } + return null; + } + + private File getDme2File(final String dme2Filename) { + + for (final PropertiesFileResolver dblibPropertiesFileResolver : dme2PropertiesFileResolvers) { + final Optional fileOptional = dblibPropertiesFileResolver.resolveFile(dme2Filename); + if (fileOptional.isPresent()) { + return reportSuccess(dblibPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); + } + } + return (new File(dme2Filename)); + } + + private static Properties getProperties(final File dme2File) throws IOException { + + 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 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 getProxyUrls() { + return this.proxyUrls; + } + + private Optional getAafUsername(final Properties properties) { + final String aafUsernameValue = properties.getProperty(AAF_USERNAME_KEY); + return Optional.ofNullable(aafUsernameValue); + } + + Optional getAafUsername() { + return this.aafUsername; + } + + private Optional getAafPassword(final Properties properties) { + final String aafPassword = properties.getProperty(AAF_PASSWORD_KEY); + return Optional.ofNullable(aafPassword); + } + + Optional getAafPassword() { + return this.aafPassword; + } + + private Optional getEnvContext(final Properties properties) { + final String envContext = properties.getProperty(ENV_CONTEXT_KEY); + return Optional.ofNullable(envContext); + } + + Optional getEnvContext() { + return this.envContext; + } + + private Optional getRouteOffer(final Properties properties) { + final String routeOffer = properties.getProperty(ROUTE_OFFER_KEY); + return Optional.ofNullable(routeOffer); + } + + Optional getRouteOffer() { + return this.routeOffer; + } + + private Optional getCommonServiceVersion(final Properties properties) { + final String commonServiceVersion = properties.getProperty(COMMON_SERVICE_VERSION_KEY); + return Optional.ofNullable(commonServiceVersion); + } + + Optional getCommonServiceVersion() { + return this.commonServiceVersion; + } + + private Optional getPartner(final Properties properties) { + final String partner = properties.getProperty(PARTNER_KEY); + return Optional.ofNullable(partner); + } + + Optional getPartner() { + return this.partner; + } } diff --git a/sliPluginUtils/provider/src/main/resources/dme2.properties b/sliPluginUtils/provider/src/main/resources/dme2.properties new file mode 100644 index 00000000..37344844 --- /dev/null +++ b/sliPluginUtils/provider/src/main/resources/dme2.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 -- cgit 1.2.3-korg