summaryrefslogtreecommitdiffstats
path: root/sql-resource
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-07-18 20:23:07 -0400
committerDan Timoney <dtimoney@att.com>2017-08-01 14:46:48 -0400
commit5363b2782d906a6c6067eb840392f959ed4dfe4b (patch)
treeb8061a4875ea11c6af51ce065c300ef2dd4746ef /sql-resource
parentbbe551f0d98ca20f604c03a24c1b8e7bad27008a (diff)
[CCSDK-6] Populate seed code
Add seed code for sli/adaptors repository Update code to use org.onap.ccsdk.sli.core Change-Id: I477c7a24f2cc1fed8fb0975fe9f33733411c27f9 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sql-resource')
-rwxr-xr-xsql-resource/.gitignore34
-rwxr-xr-xsql-resource/features/pom.xml134
-rw-r--r--sql-resource/features/src/main/resources/features.xml39
-rwxr-xr-xsql-resource/installer/pom.xml138
-rw-r--r--sql-resource/installer/src/assembly/assemble_installer_zip.xml59
-rw-r--r--sql-resource/installer/src/assembly/assemble_mvnrepo_zip.xml49
-rw-r--r--sql-resource/installer/src/main/resources/scripts/install-feature.sh40
-rwxr-xr-xsql-resource/pom.xml43
-rwxr-xr-xsql-resource/provider/pom.xml105
-rw-r--r--sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResource.java516
-rw-r--r--sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceActivator.java96
-rw-r--r--sql-resource/provider/src/main/resources/svclogic.properties34
-rw-r--r--sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java218
-rwxr-xr-xsql-resource/provider/src/test/resources/delete.tests2
-rwxr-xr-xsql-resource/provider/src/test/resources/query.tests5
-rwxr-xr-xsql-resource/provider/src/test/resources/save.tests13
-rw-r--r--sql-resource/provider/src/test/resources/simplelogger.properties22
-rw-r--r--sql-resource/provider/src/test/resources/svclogic.properties34
18 files changed, 1581 insertions, 0 deletions
diff --git a/sql-resource/.gitignore b/sql-resource/.gitignore
new file mode 100755
index 000000000..b73caf31e
--- /dev/null
+++ b/sql-resource/.gitignore
@@ -0,0 +1,34 @@
+#####standard .git ignore entries#####
+
+## IDE Specific Files ##
+org.eclipse.core.resources.prefs
+.classpath
+.project
+.settings
+.idea
+.externalToolBuilders
+maven-eclipse.xml
+workspace
+
+## Compilation Files ##
+*.class
+**/target
+target
+target-ide
+MANIFEST.MF
+
+## Misc Ignores (OS specific etc) ##
+bin/
+dist
+*~
+*.ipr
+*.iml
+*.iws
+classes
+out/
+.DS_STORE
+.metadata
+
+## Folders which contain auto generated source code ##
+yang-gen-config
+yang-gen-sal
diff --git a/sql-resource/features/pom.xml b/sql-resource/features/pom.xml
new file mode 100755
index 000000000..1f75be2f4
--- /dev/null
+++ b/sql-resource/features/pom.xml
@@ -0,0 +1,134 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>sql-resource</artifactId>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>sql-resource-features</artifactId>
+ <name>Sql Resource Adaptor - Features</name>
+
+ <packaging>jar</packaging>
+
+ <dependencies>
+
+
+ <dependency>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>features-mdsal</artifactId>
+ <version>${odl.mdsal.features.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+
+ <scope>runtime</scope>
+ </dependency>
+
+
+ <!-- dependency for opendaylight-karaf-empty for use by testing -->
+ <dependency>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>opendaylight-karaf-empty</artifactId>
+ <version>${odl.karaf.empty.distro.version}</version>
+ <type>zip</type>
+ </dependency>
+
+
+ <dependency>
+ <!-- Required for launching the feature tests -->
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>features-test</artifactId>
+ <version>${odl.commons.opendaylight.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>features-yangtools</artifactId>
+ <version>${odl.yangtools.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <filtering>true</filtering>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>filter</id>
+ <goals>
+ <goal>resources</goal>
+ </goals>
+ <phase>generate-resources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- launches the feature test, which validates that your karaf feature
+ can be installed inside of a karaf container. It doesn't validate that your
+ functionality works correctly, just that you have all of the dependent bundles
+ defined correctly.
+ <plugin>
+
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.16</version>
+ <configuration>
+ <systemPropertyVariables>
+ <karaf.distro.groupId>org.opendaylight.controller</karaf.distro.groupId>
+ <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
+ <karaf.distro.version>${odl.karaf.empty.distro.version}</karaf.distro.version>
+ </systemPropertyVariables>
+ <dependenciesToScan>
+ <dependency>org.opendaylight.yangtools:features-test</dependency>
+ </dependenciesToScan>
+ </configuration>
+ </plugin>
+ -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>${project.build.directory}/classes/${features.file}</file>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/sql-resource/features/src/main/resources/features.xml b/sql-resource/features/src/main/resources/features.xml
new file mode 100644
index 000000000..adf51f4a6
--- /dev/null
+++ b/sql-resource/features/src/main/resources/features.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 ONAP 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=========================================================
+ -->
+
+
+<features name="sdnc-sql-resource-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
+
+ <repository>mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features</repository>
+
+
+ <feature name='sdnc-sql-resource' description="sdnc-sql-resource" version='${project.version}'>
+ <!-- Most applications will have a dependency on the ODL MD-SAL Broker -->
+ <feature version="${odl.mdsal.version}">odl-mdsal-broker</feature>
+ <feature version="${sdnctl.sli.version}">sdnc-sli</feature>
+ <feature version="${sdnctl.dblib.version}">sdnc-dblib</feature>
+ <bundle>mvn:org.openecomp.sdnc.adaptors/sql-resource-provider/${project.version}</bundle>
+ </feature>
+
+</features>
diff --git a/sql-resource/installer/pom.xml b/sql-resource/installer/pom.xml
new file mode 100755
index 000000000..932047773
--- /dev/null
+++ b/sql-resource/installer/pom.xml
@@ -0,0 +1,138 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>sql-resource</artifactId>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>sql-resource-installer</artifactId>
+ <name>SQL Resource - Karaf Installer</name>
+ <packaging>pom</packaging>
+
+ <properties>
+ <application.name>sdnc-sql-resource</application.name>
+ <features.boot>sdnc-sql-resource</features.boot>
+ <features.repositories>mvn:org.openecomp.sdnc.adaptors/sql-resource-features/${project.version}/xml/features</features.repositories>
+ <include.transitive.dependencies>false</include.transitive.dependencies>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource-features</artifactId>
+ <version>${project.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>maven-repo-zip</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>false</attach>
+ <finalName>stage/${application.name}-${project.version}</finalName>
+ <descriptors>
+ <descriptor>src/assembly/assemble_mvnrepo_zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ <execution>
+ <id>installer-zip</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>true</attach>
+ <finalName>${application.name}-${project.version}-installer</finalName>
+ <descriptors>
+ <descriptor>src/assembly/assemble_installer_zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <phase>prepare-package</phase>
+ <configuration>
+ <transitive>false</transitive>
+ <outputDirectory>${project.build.directory}/assembly/system</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <useRepositoryLayout>true</useRepositoryLayout>
+ <addParentPoms>false</addParentPoms>
+ <copyPom>false</copyPom>
+ <includeGroupIds>org.openecomp.sdnc</includeGroupIds>
+ <excludeArtifactIds>sli-common,sli-provider,dblib-provider</excludeArtifactIds>
+ <scope>provided</scope>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>copy-version</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals><!-- here the phase you need -->
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${basedir}/target/stage</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources/scripts</directory>
+ <includes>
+ <include>install-feature.sh</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/sql-resource/installer/src/assembly/assemble_installer_zip.xml b/sql-resource/installer/src/assembly/assemble_installer_zip.xml
new file mode 100644
index 000000000..e278872a1
--- /dev/null
+++ b/sql-resource/installer/src/assembly/assemble_installer_zip.xml
@@ -0,0 +1,59 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 ONAP 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=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>installer_zip</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <!-- we want "system" and related files right at the root level
+ as this file is suppose to be unzip on top of a karaf
+ distro. -->
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target/stage/</directory>
+ <outputDirectory>${application.name}</outputDirectory>
+ <fileMode>755</fileMode>
+ <includes>
+ <include>*.sh</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/stage/</directory>
+ <outputDirectory>${application.name}</outputDirectory>
+ <fileMode>644</fileMode>
+ <excludes>
+ <exclude>*.sh</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+
+
+
+</assembly>
diff --git a/sql-resource/installer/src/assembly/assemble_mvnrepo_zip.xml b/sql-resource/installer/src/assembly/assemble_mvnrepo_zip.xml
new file mode 100644
index 000000000..1edacdb6d
--- /dev/null
+++ b/sql-resource/installer/src/assembly/assemble_mvnrepo_zip.xml
@@ -0,0 +1,49 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 ONAP 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=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>mvnrepo_zip</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <!-- we want "system" and related files right at the root level
+ as this file is suppose to be unzip on top of a karaf
+ distro. -->
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target/assembly/</directory>
+ <outputDirectory>.</outputDirectory>
+ <excludes>
+ </excludes>
+ </fileSet>
+ </fileSets>
+
+
+
+</assembly>
diff --git a/sql-resource/installer/src/main/resources/scripts/install-feature.sh b/sql-resource/installer/src/main/resources/scripts/install-feature.sh
new file mode 100644
index 000000000..9a47d2225
--- /dev/null
+++ b/sql-resource/installer/src/main/resources/scripts/install-feature.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# Copyright (C) 2017 ONAP 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=========================================================
+###
+
+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/sql-resource/pom.xml b/sql-resource/pom.xml
new file mode 100755
index 000000000..a8d8ae696
--- /dev/null
+++ b/sql-resource/pom.xml
@@ -0,0 +1,43 @@
+<?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/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sdnc-adaptors</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource</artifactId>
+
+
+ <name>Sql Resource Adaptor</name>
+ <description>The Sql resource adaptor allows service logic to read/write data from a local database using direct SQL statements</description>
+
+ <version>0.0.1-SNAPSHOT</version>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource-features</artifactId>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <modules>
+ <module>provider</module>
+ <module>features</module>
+ <module>installer</module>
+ </modules>
+</project>
diff --git a/sql-resource/provider/pom.xml b/sql-resource/provider/pom.xml
new file mode 100755
index 000000000..fd773af21
--- /dev/null
+++ b/sql-resource/provider/pom.xml
@@ -0,0 +1,105 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.sdnc.adaptors</groupId>
+ <artifactId>sql-resource</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>sql-resource-provider</artifactId>
+ <packaging>bundle</packaging>
+ <name>Sql Resource Adaptor - Provider</name>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-common</artifactId>
+ <version>${sdnctl.sli.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-provider</artifactId>
+ <version>${sdnctl.sli.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>${equinox.osgi.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-provider</artifactId>
+ <version>${sdnctl.dblib.version}</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+<!-- <plugin>
+ <groupId>com.brocade.developer</groupId>
+ <artifactId>providermodule-plugin</artifactId>
+ <configuration>
+ <packageId>org.openecomp.sdnc</packageId>
+ <appName>sql-resource</appName>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin> -->
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>org.openecomp.sdnc.sli.resource.sql</Bundle-SymbolicName>
+ <Bundle-Activator>org.openecomp.sdnc.sli.resource.sql.SqlResourceActivator</Bundle-Activator>
+ <Export-Package>org.openecomp.sdnc.sli.resource.sql</Export-Package>
+ <Import-Package>*</Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+
+
+ </configuration>
+
+ </plugin>
+
+
+ </plugins>
+ </build>
+</project>
diff --git a/sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResource.java b/sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResource.java
new file mode 100644
index 000000000..9c0007ebe
--- /dev/null
+++ b/sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResource.java
@@ -0,0 +1,516 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP 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=========================================================
+ */
+
+package org.openecomp.sdnc.sli.resource.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.sql.rowset.CachedRowSet;
+
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SqlResource.class);
+
+ private static final String DBLIB_SERVICE = "org.openecomp.sdnc.sli.resource.dblib.DBResourceManager";
+
+ private static String CRYPT_KEY = "";
+
+ public SqlResource() {
+ }
+
+ // For sql-resource, is-available is the same as exists
+ @Override
+ public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+
+ return (exists(resource, key, prefix, ctx));
+
+ }
+
+ @Override
+ public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+
+ DbLibService dblibSvc = getDbLibService();
+ if (dblibSvc == null) {
+ return (QueryStatus.FAILURE);
+ }
+
+ String theStmt = resolveCtxVars(key, ctx);
+
+ try {
+ CachedRowSet results = dblibSvc.getData(theStmt, null, null);
+
+ if (!results.next()) {
+ return (QueryStatus.NOT_FOUND);
+ }
+
+ int numRows = results.getInt(1);
+
+ if (numRows > 0) {
+ return (QueryStatus.SUCCESS);
+ } else {
+ return (QueryStatus.NOT_FOUND);
+ }
+ } catch (Exception e) {
+ LOG.error("Caught SQL exception", e);
+ return (QueryStatus.FAILURE);
+ }
+ }
+
+ // @Override
+ public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
+ String orderBy, SvcLogicContext ctx) throws SvcLogicException {
+
+ DbLibService dblibSvc = getDbLibService();
+
+ if (dblibSvc == null) {
+ return (QueryStatus.FAILURE);
+ }
+
+ String sqlQuery = resolveCtxVars(key, ctx);
+
+ try {
+
+ CachedRowSet results = dblibSvc.getData(sqlQuery, null, null);
+
+ QueryStatus retval = QueryStatus.SUCCESS;
+
+ if (!results.next()) {
+ retval = QueryStatus.NOT_FOUND;
+ LOG.debug("No data found");
+ } else {
+ saveCachedRowSetToCtx(results, ctx, prefix, dblibSvc);
+ }
+ return (retval);
+ } catch (Exception e) {
+ LOG.error("Caught SQL exception", e);
+ return (QueryStatus.FAILURE);
+ }
+ }
+
+ public void saveCachedRowSetToCtx(CachedRowSet results, SvcLogicContext ctx, String prefix, DbLibService dblibSvc)
+ throws SQLException {
+ if (ctx != null) {
+ if ((prefix != null) && prefix.endsWith("[]")) {
+ // Return an array.
+ String pfx = prefix.substring(0, prefix.length() - 2);
+ int idx = 0;
+ do {
+ ResultSetMetaData rsMeta = results.getMetaData();
+ int numCols = rsMeta.getColumnCount();
+
+ for (int i = 0; i < numCols; i++) {
+ String colValue = null;
+ String tableName = rsMeta.getTableName(i + 1);
+ if (rsMeta.getColumnType(i + 1) == java.sql.Types.VARBINARY) {
+ colValue = decryptColumn(tableName, rsMeta.getColumnName(i + 1), results.getBytes(i + 1),
+ dblibSvc);
+ } else {
+ colValue = results.getString(i + 1);
+ }
+ LOG.debug("Setting " + pfx + "[" + idx + "]."
+ + rsMeta.getColumnLabel(i + 1).replaceAll("_", "-") + " = " + colValue);
+ ctx.setAttribute(pfx + "[" + idx + "]." + rsMeta.getColumnLabel(i + 1).replaceAll("_", "-"),
+ colValue);
+ }
+ idx++;
+ } while (results.next());
+ LOG.debug("Setting " + pfx + "_length = " + idx);
+ ctx.setAttribute(pfx + "_length", "" + idx);
+ } else {
+ ResultSetMetaData rsMeta = results.getMetaData();
+ int numCols = rsMeta.getColumnCount();
+
+ for (int i = 0; i < numCols; i++) {
+ String colValue = null;
+ String tableName = rsMeta.getTableName(i + 1);
+ if ("VARBINARY".equalsIgnoreCase(rsMeta.getColumnTypeName(i + 1))) {
+ colValue = decryptColumn(tableName, rsMeta.getColumnName(i + 1), results.getBytes(i + 1),
+ dblibSvc);
+ } else {
+ colValue = results.getString(i + 1);
+ }
+ if (prefix != null) {
+ LOG.debug("Setting " + prefix + "." + rsMeta.getColumnLabel(i + 1).replaceAll("_", "-") + " = "
+ + colValue);
+ ctx.setAttribute(prefix + "." + rsMeta.getColumnLabel(i + 1).replaceAll("_", "-"), colValue);
+ } else {
+ LOG.debug("Setting " + rsMeta.getColumnLabel(i + 1).replaceAll("_", "-") + " = " + colValue);
+ ctx.setAttribute(rsMeta.getColumnLabel(i + 1).replaceAll("_", "-"), colValue);
+ }
+ }
+ }
+ }
+ }
+
+ // reserve is no-op
+ @Override
+ public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+ // release is no-op
+ @Override
+ public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+ private QueryStatus executeSqlWrite(String key, SvcLogicContext ctx) throws SvcLogicException {
+ QueryStatus retval = QueryStatus.SUCCESS;
+
+ DbLibService dblibSvc = getDbLibService();
+
+ if (dblibSvc == null) {
+ return (QueryStatus.FAILURE);
+ }
+
+ String sqlStmt = resolveCtxVars(key, ctx);
+
+ LOG.debug("key = [" + key + "]; sqlStmt = [" + sqlStmt + "]");
+ try {
+
+ if (!dblibSvc.writeData(sqlStmt, null, null)) {
+ retval = QueryStatus.FAILURE;
+ }
+ } catch (Exception e) {
+ LOG.error("Caught SQL exception", e);
+ retval = QueryStatus.FAILURE;
+ }
+
+ return (retval);
+
+ }
+
+ private String resolveCtxVars(String key, SvcLogicContext ctx) {
+ if (key == null) {
+ return (null);
+ }
+
+ if (key.startsWith("'") && key.endsWith("'")) {
+ key = key.substring(1, key.length() - 1);
+ LOG.debug("Stripped outer single quotes - key is now [" + key + "]");
+ }
+
+ String[] keyTerms = key.split("\\s+");
+
+ StringBuffer sqlBuffer = new StringBuffer();
+
+ for (int i = 0; i < keyTerms.length; i++) {
+ sqlBuffer.append(resolveTerm(keyTerms[i], ctx));
+ sqlBuffer.append(" ");
+ }
+
+ return (sqlBuffer.toString());
+ }
+
+ private String resolveTerm(String term, SvcLogicContext ctx) {
+ if (term == null) {
+ return (null);
+ }
+
+ LOG.trace("resolveTerm: term is " + term);
+
+ if (term.startsWith("$") && (ctx != null)) {
+ // Resolve any index variables.
+ term = resolveCtxVariable(term.substring(1), ctx);
+ // Escape single quote
+ if (term != null) {
+ term = term.replaceAll("'", "''");
+ }
+ return ("'" + term + "'");
+ } else {
+ return (term);
+ }
+
+ }
+
+ private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) {
+
+ if (ctxVarName.indexOf('[') == -1) {
+ // Ctx variable contains no arrays
+ if ("CRYPT_KEY".equals(ctxVarName)) {
+ // Handle crypt key as special case. If it's set as a context
+ // variable, use it. Otherwise, use
+ // configured crypt key.
+ String cryptKey = ctx.getAttribute(ctxVarName);
+ if ((cryptKey != null) && (cryptKey.length() > 0)) {
+ return (cryptKey);
+ } else {
+ return (CRYPT_KEY);
+ }
+ }
+ return (ctx.getAttribute(ctxVarName));
+ }
+
+ // Resolve any array references
+ StringBuffer sbuff = new StringBuffer();
+ String[] ctxVarParts = ctxVarName.split("\\[");
+ sbuff.append(ctxVarParts[0]);
+ for (int i = 1; i < ctxVarParts.length; i++) {
+ if (ctxVarParts[i].startsWith("$")) {
+ int endBracketLoc = ctxVarParts[i].indexOf("]");
+ if (endBracketLoc == -1) {
+ // Missing end bracket ... give up parsing
+ LOG.warn("Variable reference " + ctxVarName + " seems to be missing a ']'");
+ return (ctx.getAttribute(ctxVarName));
+ }
+
+ String idxVarName = ctxVarParts[i].substring(1, endBracketLoc);
+ String remainder = ctxVarParts[i].substring(endBracketLoc);
+
+ sbuff.append("[");
+ sbuff.append(ctx.getAttribute(idxVarName));
+ sbuff.append(remainder);
+
+ } else {
+ // Index is not a variable reference
+ sbuff.append("[");
+ sbuff.append(ctxVarParts[i]);
+ }
+ }
+
+ return (ctx.getAttribute(sbuff.toString()));
+ }
+
+ @Override
+ public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms,
+ String prefix, SvcLogicContext ctx) throws SvcLogicException {
+ return (executeSqlWrite(key, ctx));
+ }
+
+ private DbLibService getDbLibService() {
+ // Try to get dblib as an OSGI service
+ DbLibService dblibSvc = null;
+ BundleContext bctx = null;
+ ServiceReference sref = null;
+
+ Bundle bundle = FrameworkUtil.getBundle(SqlResource.class);
+
+ if (bundle != null) {
+ bctx = bundle.getBundleContext();
+ }
+
+ if (bctx != null) {
+ sref = bctx.getServiceReference(DBLIB_SERVICE);
+ }
+
+ if (sref == null) {
+ LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
+ } else {
+ dblibSvc = (DbLibService) bctx.getService(sref);
+ if (dblibSvc == null) {
+ LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
+ }
+ }
+
+ if (dblibSvc == null) {
+ // Must not be running in an OSGI container. See if you can load it
+ // as a
+ // a POJO then.
+ try {
+ dblibSvc = DBResourceManager.create(System.getProperties());
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to create dblib service", e);
+ }
+
+ if (dblibSvc == null) {
+ LOG.warn("Could not create new DBResourceManager");
+ }
+ }
+
+ return (dblibSvc);
+ }
+
+ @Override
+ public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx)
+ throws SvcLogicException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("SqlResource.notify called with resource=" + resource + ", action=" + action);
+ }
+ return QueryStatus.SUCCESS;
+ }
+
+ @Override
+ public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
+ return (executeSqlWrite(key, ctx));
+ }
+
+ public QueryStatus update(String resource, String key, Map<String, String> parms, String prefix,
+ SvcLogicContext ctx) throws SvcLogicException {
+ return (executeSqlWrite(key, ctx));
+ }
+
+ private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) {
+ String strValue = new String(colValue);
+
+ if (StringUtils.isAsciiPrintable(strValue)) {
+
+ // If printable, not encrypted
+ return (strValue);
+ } else {
+ PreparedStatement stmt = null;
+ Connection conn = null;
+ ResultSet results = null;
+ try {
+ // CachedRowSet results =
+ // dblibSvc.getData("SELECT
+ // CAST(AES_DECRYPT('"+strValue+"','"+CRYPT_KEY+"') AS CHAR(50))
+ // FROM DUAL",
+ // null, null);
+ conn = ((DBResourceManager) dblibSvc).getConnection();
+
+ stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL");
+
+ stmt.setBytes(1, colValue);
+ stmt.setString(2, getCryptKey());
+
+ results = stmt.executeQuery();
+
+ if ((results != null) && results.next()) {
+ strValue = results.getString(1);
+ LOG.debug("Decrypted value is " + strValue);
+ } else {
+ LOG.warn("Cannot decrypt " + tableName + "." + colName);
+ }
+ } catch (Exception e) {
+ LOG.error("Caught exception trying to decrypt " + tableName + "." + colName, e);
+ } finally {
+ try {
+ if (results != null) {
+ results.close();
+ results = null;
+ }
+ } catch (Exception exc) {
+
+ }
+
+ try {
+ if (stmt != null) {
+ stmt.close();
+ stmt = null;
+ }
+ } catch (Exception exc) {
+
+ }
+
+ try {
+ if (conn != null) {
+ conn.close();
+ conn = null;
+ }
+ } catch (Exception exc) {
+
+ }
+
+ }
+ }
+ return (strValue);
+ }
+
+ public static String getCryptKey() {
+ return (CRYPT_KEY);
+ }
+
+ public static String setCryptKey(String key) {
+ CRYPT_KEY = key;
+ return (CRYPT_KEY);
+ }
+
+ public String parameterizedQuery(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ DbLibService dblibSvc = getDbLibService();
+ String prefix = parameters.get("prefix");
+ String query = parameters.get("query");
+
+ ArrayList<String> arguments = new ArrayList<String>();
+ for (Entry<String, String> a : parameters.entrySet()) {
+ if (a.getKey().startsWith("param")) {
+ arguments.add(a.getValue());
+ }
+ }
+
+ try {
+ if (dblibSvc == null) {
+ return mapQueryStatus(QueryStatus.FAILURE);
+ }
+ if (query.contains("count") || query.contains("COUNT")) {
+ CachedRowSet results = dblibSvc.getData(query, arguments, null);
+
+ if (!results.next()) {
+ return mapQueryStatus(QueryStatus.FAILURE);
+ }
+
+ int numRows = results.getInt(1);
+ ctx.setAttribute(prefix + ".count", String.valueOf(numRows));
+ if (numRows > 0) {
+ return "true";
+ } else {
+ return "false";
+ }
+ } else if (query.startsWith("select") || query.startsWith("SELECT")) {
+ CachedRowSet results = dblibSvc.getData(query, arguments, null);
+ if (!results.next()) {
+ return mapQueryStatus(QueryStatus.NOT_FOUND);
+ } else {
+ saveCachedRowSetToCtx(results, ctx, prefix, dblibSvc);
+ }
+ } else {
+ if (!dblibSvc.writeData(query, arguments, null)) {
+ return mapQueryStatus(QueryStatus.FAILURE);
+ }
+ }
+ return mapQueryStatus(QueryStatus.SUCCESS);
+ } catch (SQLException e) {
+ LOG.error("Caught SQL exception", e);
+ return mapQueryStatus(QueryStatus.FAILURE);
+ }
+ }
+
+ protected String mapQueryStatus(QueryStatus status) {
+ String str = status.toString();
+ str = str.toLowerCase();
+ str = str.replaceAll("_", "-");
+ return str;
+ }
+}
diff --git a/sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceActivator.java b/sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceActivator.java
new file mode 100644
index 000000000..e1994b2e3
--- /dev/null
+++ b/sql-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceActivator.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP 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=========================================================
+ */
+
+package org.openecomp.sdnc.sli.resource.sql;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SqlResourceActivator implements BundleActivator {
+
+ private static final String SQLRESOURCE_PROP_PATH = "/sql-resource.properties";
+
+ private ServiceRegistration registration = null;
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SqlResourceActivator.class);
+
+ @Override
+ public void start(BundleContext ctx) throws Exception {
+
+ String cfgDir = System.getenv("SDNC_CONFIG_DIR");
+
+ if ((cfgDir == null) || (cfgDir.length() == 0)) {
+ cfgDir = "/opt/sdnc/data/properties";
+ LOG.warn("SDNC_CONFIG_DIR unset - defaulting to "+cfgDir);
+ }
+
+ String cryptKey = "";
+
+ File sqlResourcePropFile = new File(cfgDir+SQLRESOURCE_PROP_PATH);
+ Properties sqlResourceProps = new Properties();
+ if (sqlResourcePropFile.exists()) {
+ try {
+
+ sqlResourceProps.load(new FileInputStream(sqlResourcePropFile));
+
+ cryptKey = sqlResourceProps.getProperty("org.openecomp.sdnc.resource.sql.cryptkey");
+ } catch (Exception e) {
+ LOG.warn(
+ "Could not load properties file " + sqlResourcePropFile.getAbsolutePath(), e);
+ }
+ } else {
+ LOG.warn("Cannot read "+sqlResourcePropFile.getAbsolutePath()+" to find encryption key - using default");
+ }
+
+ SqlResource.setCryptKey(cryptKey);
+
+ // Advertise Sql resource adaptor
+ SvcLogicResource impl = new SqlResource();
+ String regName = impl.getClass().getName();
+
+ if (registration == null)
+ {
+ LOG.debug("Registering SqlResource service "+regName);
+ registration =ctx.registerService(regName, impl, null);
+ }
+
+ }
+
+ @Override
+ public void stop(BundleContext ctx) throws Exception {
+
+ if (registration != null)
+ {
+ registration.unregister();
+ registration = null;
+ }
+ }
+
+}
diff --git a/sql-resource/provider/src/main/resources/svclogic.properties b/sql-resource/provider/src/main/resources/svclogic.properties
new file mode 100644
index 000000000..a7948fc55
--- /dev/null
+++ b/sql-resource/provider/src/main/resources/svclogic.properties
@@ -0,0 +1,34 @@
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# Copyright (C) 2017 ONAP 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.openecomp.sdnc.sli.dbtype=jdbc
+org.openecomp.sdnc.sli.jdbc.hosts=sdnctldb01,sdnctldb02
+org.openecomp.sdnc.sli.jdbc.url=jdbc:mysql://DBHOST:3306/sdnctl
+org.openecomp.sdnc.sli.jdbc.database=sdnctl
+org.openecomp.sdnc.sli.jdbc.user=sdnctl
+org.openecomp.sdnc.sli.jdbc.password=gamma
+org.openecomp.sdnc.sli.jdbc.connection.name=sdnctldb01
+
+org.openecomp.sdnc.sli.jdbc.connection.timeout=50
+org.openecomp.sdnc.sli.jdbc.request.timeout=100
+org.openecomp.sdnc.sli.jdbc.limit.init=10
+org.openecomp.sdnc.sli.jdbc.limit.min=10
+org.openecomp.sdnc.sli.jdbc.limit.max=20
diff --git a/sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java b/sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java
new file mode 100644
index 000000000..5b35f5aa7
--- /dev/null
+++ b/sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java
@@ -0,0 +1,218 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP 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=========================================================
+ */
+
+package org.openecomp.sdnc.sli.resource.sql;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.TestCase;
+
+public class SqlResourceTest extends TestCase {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SqlResourceTest.class);
+
+
+ public void testExists() {
+
+
+ Properties props = new Properties();
+ InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
+ if (propStr == null) {
+ fail("src/test/resources/svclogic.properties missing");
+ }
+
+ try {
+ props.load(propStr);
+ propStr.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Could not initialize properties");
+ }
+
+ // Add properties to global properties
+
+ Enumeration propNames = props.keys();
+
+ while (propNames.hasMoreElements()) {
+ String propName = (String) propNames.nextElement();
+
+ System.setProperty(propName, props.getProperty(propName));
+ }
+
+ SqlResource sqlResource = new SqlResource();
+
+
+
+ InputStream testStr = getClass().getResourceAsStream("/save.tests");
+ BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ try {
+ String testExpr = null;
+
+ int testNum = 0;
+ while ((testExpr = testsReader.readLine()) != null) {
+ testExpr = testExpr.trim();
+
+ if (testExpr.startsWith("#")) {
+ testExpr = testExpr.substring(1).trim();
+ String[] nameValue = testExpr.split("=");
+ String name = nameValue[0].trim();
+ String value = nameValue[1].trim();
+
+ LOG.info("Setting context attribute " + name + " = "
+ + value);
+ ctx.setAttribute(name, value);
+
+ } else {
+
+ testNum++;
+ String sqlStmt = testExpr;
+ QueryStatus status = sqlResource.save("SQL", true, false, sqlStmt, null, "savetest"+testNum, ctx);
+
+ switch (status) {
+ case SUCCESS:
+ LOG.info("Found data for query [" + sqlStmt + "]");
+ break;
+ case NOT_FOUND:
+ LOG.info("Did not data for query [" + sqlStmt + "]");
+ break;
+ default:
+ fail("Failure executing query [" + sqlStmt + "]");
+
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Caught exception running tests");
+ }
+
+
+ testStr = getClass().getResourceAsStream("/query.tests");
+ testsReader = new BufferedReader(new InputStreamReader(testStr));
+
+ try {
+ String testExpr = null;
+
+ int testNum = 0;
+ while ((testExpr = testsReader.readLine()) != null) {
+ testExpr = testExpr.trim();
+ if (testExpr.startsWith("#")) {
+ testExpr = testExpr.substring(1).trim();
+ String[] nameValue = testExpr.split("=");
+ String name = nameValue[0].trim();
+ String value = nameValue[1].trim();
+
+ LOG.info("Setting context attribute " + name + " = "
+ + value);
+ ctx.setAttribute(name, value);
+
+ } else {
+
+ testNum++;
+
+ String sqlStmt = testExpr;
+ QueryStatus status = sqlResource.query("SQL", false, null,
+ sqlStmt, "querytest" + testNum, null, ctx);
+
+ switch (status) {
+ case SUCCESS:
+ LOG.info("Found data for query [" + sqlStmt + "]");
+ break;
+ case NOT_FOUND:
+ LOG.info("Did not data for query [" + sqlStmt + "]");
+ break;
+ default:
+ fail("Failure executing query [" + sqlStmt + "]");
+
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Caught exception running tests");
+ }
+
+
+ testStr = getClass().getResourceAsStream("/delete.tests");
+ testsReader = new BufferedReader(new InputStreamReader(testStr));
+
+ try {
+ String testExpr = null;
+
+ int testNum = 0;
+ while ((testExpr = testsReader.readLine()) != null) {
+ testExpr = testExpr.trim();
+ if (testExpr.startsWith("#")) {
+ testExpr = testExpr.substring(1).trim();
+ String[] nameValue = testExpr.split("=");
+ String name = nameValue[0].trim();
+ String value = nameValue[1].trim();
+
+ LOG.info("Setting context attribute " + name + " = "
+ + value);
+ ctx.setAttribute(name, value);
+
+ } else {
+
+ testNum++;
+
+ String sqlStmt = testExpr;
+ QueryStatus status = sqlResource.delete("SQL", sqlStmt, ctx);
+
+ switch (status) {
+ case SUCCESS:
+ LOG.info("Found data for query [" + sqlStmt + "]");
+ break;
+ case NOT_FOUND:
+ LOG.info("Did not data for query [" + sqlStmt + "]");
+ break;
+ default:
+ fail("Failure executing query [" + sqlStmt + "]");
+
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Caught exception running tests");
+ }
+
+ for (String attrName : ctx.getAttributeKeySet()) {
+ LOG.info("ctx.getAttribute("+attrName+") = "+ctx.getAttribute(attrName));
+ }
+ }
+
+}
diff --git a/sql-resource/provider/src/test/resources/delete.tests b/sql-resource/provider/src/test/resources/delete.tests
new file mode 100755
index 000000000..a60a3bc73
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/delete.tests
@@ -0,0 +1,2 @@
+DROP TABLE SQLRESOURCE_ORDER;
+DROP TABLE SQLRESOURCE_ORDER_ITEM;
diff --git a/sql-resource/provider/src/test/resources/query.tests b/sql-resource/provider/src/test/resources/query.tests
new file mode 100755
index 000000000..ec05c22e3
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/query.tests
@@ -0,0 +1,5 @@
+# max-price = 100
+SELECT * FROM SQLRESOURCE_ORDER where placed_on < now();
+SELECT SQLRESOURCE_ORDER.order_number, clli, service, price FROM SQLRESOURCE_ORDER, SQLRESOURCE_ORDER_ITEM where SQLRESOURCE_ORDER.order_number = SQLRESOURCE_ORDER_ITEM.order_number and price > $max-price ;
+SELECT SQLRESOURCE_ORDER.order_number, clli, service, price FROM SQLRESOURCE_ORDER, SQLRESOURCE_ORDER_ITEM where SQLRESOURCE_ORDER.order_number = SQLRESOURCE_ORDER_ITEM.order_number and price < $max-price ;
+SELECT SQLRESOURCE_ORDER.order_number AS ordernum, clli, service, price FROM SQLRESOURCE_ORDER, SQLRESOURCE_ORDER_ITEM where SQLRESOURCE_ORDER.order_number = SQLRESOURCE_ORDER_ITEM.order_number and price < $max-price ;
diff --git a/sql-resource/provider/src/test/resources/save.tests b/sql-resource/provider/src/test/resources/save.tests
new file mode 100755
index 000000000..e2c42217d
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/save.tests
@@ -0,0 +1,13 @@
+# order-number = 1234
+# zero = 0
+# item[0].clli = MTJNJA14
+# item[0].service = NoD
+# item[0].price = 1000000
+# item[1].clli = MTJNJA14
+# item[1].service = Pizza
+# item[1].price = 10
+CREATE TABLE IF NOT EXISTS SQLRESOURCE_ORDER (order_number VARCHAR(40), placed_on TIMESTAMP);
+CREATE TABLE IF NOT EXISTS SQLRESOURCE_ORDER_ITEM (order_number VARCHAR(40), clli VARCHAR(40), service VARCHAR(40), price INTEGER(4));
+INSERT INTO SQLRESOURCE_ORDER VALUES ( $order-number , now());
+INSERT INTO SQLRESOURCE_ORDER_ITEM VALUES( $order-number , $item[$zero].clli , $item[0].service , $item[0].price );
+INSERT INTO SQLRESOURCE_ORDER_ITEM VALUES( $order-number , $item[1].clli , $item[1].service , $item[1].price );
diff --git a/sql-resource/provider/src/test/resources/simplelogger.properties b/sql-resource/provider/src/test/resources/simplelogger.properties
new file mode 100644
index 000000000..b28e45781
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/simplelogger.properties
@@ -0,0 +1,22 @@
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# Copyright (C) 2017 ONAP 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.slf4j.simpleLogger.defaultLogLevel=debug
diff --git a/sql-resource/provider/src/test/resources/svclogic.properties b/sql-resource/provider/src/test/resources/svclogic.properties
new file mode 100644
index 000000000..16ac91c93
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/svclogic.properties
@@ -0,0 +1,34 @@
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# Copyright (C) 2017 ONAP 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.openecomp.sdnc.sli.dbtype=jdbc
+org.openecomp.sdnc.sli.jdbc.hosts=localhost
+org.openecomp.sdnc.sli.jdbc.url=jdbc:mysql://DBHOST:3306/sdnctl
+org.openecomp.sdnc.sli.jdbc.database=sdnctl
+org.openecomp.sdnc.sli.jdbc.user=sdnctl
+org.openecomp.sdnc.sli.jdbc.password=gamma
+org.openecomp.sdnc.sli.jdbc.connection.name=sdnctldb01
+
+org.openecomp.sdnc.sli.jdbc.connection.timeout=50
+org.openecomp.sdnc.sli.jdbc.request.timeout=100
+org.openecomp.sdnc.sli.jdbc.limit.init=10
+org.openecomp.sdnc.sli.jdbc.limit.min=10
+org.openecomp.sdnc.sli.jdbc.limit.max=20