diff options
Diffstat (limited to 'mdsal-resource')
12 files changed, 325 insertions, 6 deletions
diff --git a/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml b/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml index 58f26d75..902e0d14 100644 --- a/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml +++ b/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>single-feature-parent</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.2</version> <relativePath /> </parent> diff --git a/mdsal-resource/features/features-mdsal-resource/pom.xml b/mdsal-resource/features/features-mdsal-resource/pom.xml index 49a644ea..40231ed8 100755 --- a/mdsal-resource/features/features-mdsal-resource/pom.xml +++ b/mdsal-resource/features/features-mdsal-resource/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>feature-repo-parent</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.2</version> <relativePath /> </parent> diff --git a/mdsal-resource/features/pom.xml b/mdsal-resource/features/pom.xml index b4ae2d19..11a59771 100755 --- a/mdsal-resource/features/pom.xml +++ b/mdsal-resource/features/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.2</version> <relativePath /> </parent> diff --git a/mdsal-resource/installer/pom.xml b/mdsal-resource/installer/pom.xml index 50b18832..a8d92d0b 100755 --- a/mdsal-resource/installer/pom.xml +++ b/mdsal-resource/installer/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.2</version> <relativePath /> </parent> diff --git a/mdsal-resource/pom.xml b/mdsal-resource/pom.xml index f81e973e..1b4e458a 100755 --- a/mdsal-resource/pom.xml +++ b/mdsal-resource/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-lite</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.2</version> <relativePath /> </parent> diff --git a/mdsal-resource/provider/pom.xml b/mdsal-resource/provider/pom.xml index b528442b..84801c03 100755 --- a/mdsal-resource/provider/pom.xml +++ b/mdsal-resource/provider/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>binding-parent</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.2</version> <relativePath /> </parent> diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java index d02530fe..66604468 100644 --- a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/ConfigResource.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.sli.adaptors.resource.mdsal; import java.util.Map; +import java.util.Properties; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; @@ -37,6 +38,20 @@ public class ConfigResource implements SvcLogicResource { private RestService restService; + public ConfigResource(MdsalResourcePropertiesProvider propProvider) { + LOG.info("Loading ConfigResource using property provider"); + Properties props = propProvider.getProperties(); + + String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin"); + String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin"); + String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost"); + String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https"); + String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443"); + + restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); + + } + public ConfigResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) { restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java new file mode 100755 index 00000000..e433a4c1 --- /dev/null +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProvider.java @@ -0,0 +1,28 @@ +/*- + * ============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.adaptors.resource.mdsal; + +import java.util.Properties; + +public interface MdsalResourcePropertiesProvider { + + public Properties getProperties(); +} diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java new file mode 100755 index 00000000..e9e006f1 --- /dev/null +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/MdsalResourcePropertiesProviderImpl.java @@ -0,0 +1,186 @@ +/*- + * ============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.adaptors.resource.mdsal; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import java.util.Properties; +import java.util.Vector; + +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +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; + +/** + * Responsible for determining the properties file to use and instantiating the + * <code>SqlResource</code> Service. The priority for properties file + * resolution is as follows: + * + * <ol> + * <li>A directory identified by the system environment variable + * <code>SDNC_CONFIG_DIR</code></li> + * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li> + * <li>A directory identified by the JRE argument + * <code>sql-resource.properties</code></li> + * <li>A <code>sql-resource.properties</code> file located in the karaf root + * directory</li> + * </ol> + */ +public class MdsalResourcePropertiesProviderImpl implements MdsalResourcePropertiesProvider { + + private static final Logger LOG = LoggerFactory.getLogger(MdsalResourcePropertiesProviderImpl.class); + + /** + * The name of the properties file for database configuration + */ + private static final String MDSALRESOURCE_PROP_FILE_NAME = "mdsal-resource.properties"; + + /** + * A prioritized list of strategies for resolving sql-resource properties files. + */ + private Vector<PropertiesFileResolver> mdsalResourcePropertiesFileResolvers = new Vector<>(); + + /** + * The configuration properties for the db connection. + */ + private Properties properties; + + /** + * Set up the prioritized list of strategies for resolving dblib properties + * files. + */ + public MdsalResourcePropertiesProviderImpl() { + mdsalResourcePropertiesFileResolvers + .add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); + mdsalResourcePropertiesFileResolvers.add(new CoreDefaultFileResolver("Using property file (2) from default directory")); + + mdsalResourcePropertiesFileResolvers.add( + new JREFileResolver("Using property file (3) from JRE argument", MdsalResourcePropertiesProviderImpl.class)); + mdsalResourcePropertiesFileResolvers.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 + final File propertiesFile = determinePropertiesFile(this); + if (propertiesFile != null) { + try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { + properties = new Properties(); + properties.load(fileInputStream); + } catch (final IOException e) { + LOG.error("Failed to load properties for file: {}", propertiesFile.toString(), + new ConfigurationException("Failed to load properties for file: " + propertiesFile.toString(), + e)); + } + } else { + // Try to read properties as resource + + InputStream propStr = getClass().getResourceAsStream("/" + MDSALRESOURCE_PROP_FILE_NAME); + if (propStr != null) { + properties = new Properties(); + try { + properties.load(propStr); + propStr.close(); + } catch (IOException e) { + properties = null; + } + } + + } + + if (properties == null) { + reportFailure("Missing configuration properties resource(3)", new ConfigurationException( + "Missing configuration properties resource(3): " + MDSALRESOURCE_PROP_FILE_NAME)); + } + } + + /** + * Extract svclogic config properties. + * + * @return the svclogic config properties + */ + public Properties getProperties() { + return properties; + } + + /** + * Reports the method chosen for properties resolution to the + * <code>Logger</code>. + * + * @param message + * Some user friendly message + * @param fileOptional + * The file location of the chosen properties file + * @return the file location of the chosen properties file + */ + private static File reportSuccess(final String message, final Optional<File> fileOptional) { + if (fileOptional.isPresent()) { + final File file = fileOptional.get(); + LOG.info("{} {}", message, file.getPath()); + return file; + } + return null; + } + + /** + * Reports fatal errors. This is the case in which no properties file could be + * found. + * + * @param message + * An appropriate fatal error message + * @param configurationException + * An exception describing what went wrong during resolution + */ + private static void reportFailure(final String message, final ConfigurationException configurationException) { + + LOG.error("{}", message, configurationException); + } + + /** + * Determines the sql-resource properties file to use based on the following priority: + * <ol> + * <li>A directory identified by the system environment variable + * <code>SDNC_CONFIG_DIR</code></li> + * <li>The default directory <code>DEFAULT_DBLIB_PROP_DIR</code></li> + * <li>A directory identified by the JRE argument + * <code>mdsal-resource.properties</code></li> + * <li>A <code>sql-resource.properties</code> file located in the karaf root + * directory</li> + * </ol> + */ + File determinePropertiesFile(final MdsalResourcePropertiesProviderImpl resourceProvider) { + + for (final PropertiesFileResolver sliPropertiesFileResolver : mdsalResourcePropertiesFileResolvers) { + final Optional<File> fileOptional = sliPropertiesFileResolver.resolveFile(MDSALRESOURCE_PROP_FILE_NAME); + if (fileOptional.isPresent()) { + return reportSuccess(sliPropertiesFileResolver.getSuccessfulResolutionMessage(), fileOptional); + } + } + + return null; + } +} diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java index 63fe8c6a..7cd8a80a 100644 --- a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/OperationalResource.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.sli.adaptors.resource.mdsal; import java.util.Map; +import java.util.Properties; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; @@ -37,6 +38,19 @@ public class OperationalResource implements SvcLogicResource { private RestService restService; + public OperationalResource(MdsalResourcePropertiesProvider propProvider) { + Properties props = propProvider.getProperties(); + + String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin"); + String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin"); + String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost"); + String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https"); + String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443"); + + restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); + + } + public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) { restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML); diff --git a/mdsal-resource/provider/src/main/resources/mdsal-resource.properties b/mdsal-resource/provider/src/main/resources/mdsal-resource.properties new file mode 100644 index 00000000..47c8ebf7 --- /dev/null +++ b/mdsal-resource/provider/src/main/resources/mdsal-resource.properties @@ -0,0 +1,27 @@ +### +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights +# reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user=admin +org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U +org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host=localhost +org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol=http +org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port=8181 + diff --git a/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml b/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml new file mode 100755 index 00000000..9c691263 --- /dev/null +++ b/mdsal-resource/provider/src/main/resources/org/opendaylight/blueprint/mdsal-resource-blueprint.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + openECOMP : SDN-C + ================================================================================ + Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights + reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> + +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" + odl:use-default-for-reference-types="true"> + + <bean id="propProvider" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.MdsalResourcePropertiesProviderImpl" /> + + + <bean id="configResourceInstance" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource"> + <argument ref="propProvider"/> + </bean> + + <bean id="operResourceInstance" class="org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource"> + <argument ref="propProvider"/> + </bean> + + <service ref="configResourceInstance"> + <interfaces> + <value>org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource</value> + </interfaces> + </service> + + <service ref="operResourceInstance"> + <interfaces> + <value>org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource</value> + </interfaces> + </service> +</blueprint> |