summaryrefslogtreecommitdiffstats
path: root/dblib
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2018-02-01 16:57:00 -0500
committerDan Timoney <dtimoney@att.com>2018-02-09 17:08:35 -0500
commit131cb46f6109a6099a445cb8e1b12ff5b68ae6de (patch)
tree783f96f27c1bc9292fdd836c488c4dd8a86aeb2d /dblib
parente36be89362fe80a7cd3da69a886c6c1f1c99a65c (diff)
Upgrade sli/core to Nitrogen
Use Apache derby for dblib SingleFeatureTest Change-Id: I6b41f7ede1a98b33824fceea9100e75c1ce8dda4 Issue-ID: CCSDK-175 Signed-off-by: Dan Timoney <dtimoney@att.com> 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 <richard.tabedzki@att.com> Use Apache derby for dblib test Use Apache derby for dblib SingleFeatureTest Change-Id: Ie497557f162e203fa5c5c82c17ddc55ba0c11b38 Issue-ID: CCSDK-175 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'dblib')
-rw-r--r--dblib/features/ccsdk-dblib/pom.xml96
-rw-r--r--dblib/features/ccsdk-dblib/src/main/feature/feature.xml14
-rw-r--r--dblib/features/features-dblib/pom.xml29
-rwxr-xr-xdblib/features/pom.xml143
-rwxr-xr-xdblib/features/src/main/resources/features.xml18
-rwxr-xr-xdblib/installer/pom.xml268
-rwxr-xr-xdblib/pom.xml87
-rwxr-xr-xdblib/provider/pom.xml90
-rwxr-xr-xdblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java1008
-rwxr-xr-xdblib/provider/src/main/resources/dblib.properties7
10 files changed, 862 insertions, 898 deletions
diff --git a/dblib/features/ccsdk-dblib/pom.xml b/dblib/features/ccsdk-dblib/pom.xml
new file mode 100644
index 000000000..8cf1c93f3
--- /dev/null
+++ b/dblib/features/ccsdk-dblib/pom.xml
@@ -0,0 +1,96 @@
+<?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.onap.ccsdk.parent</groupId>
+ <artifactId>single-feature-parent</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>ccsdk-dblib</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <packaging>feature</packaging>
+
+ <name>ccsdk-sli-core :: dblib :: ${project.artifactId}</name>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>mdsal-model-artifacts</artifactId>
+ <version>0.11.1</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>mdsal-artifacts</artifactId>
+ <version>1.6.1</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>odl-mdsal-broker</artifactId>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>dblib-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>${mariadb.connector.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jdbc</artifactId>
+ <version>${tomcat-jdbc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>utils-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>${equinox.osgi.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.11.1.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <excludedArtifactIds>
+ <excludedArtifactId>slf4j-api</excludedArtifactId>
+ <excludedArtifactId>tomcat-jdbc</excludedArtifactId>
+ <excludedArtifactId>tomcat-juli</excludedArtifactId>
+ </excludedArtifactIds>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/dblib/features/ccsdk-dblib/src/main/feature/feature.xml b/dblib/features/ccsdk-dblib/src/main/feature/feature.xml
new file mode 100644
index 000000000..514ce8de4
--- /dev/null
+++ b/dblib/features/ccsdk-dblib/src/main/feature/feature.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="ccsdk-dblib">
+ <repository>mvn:org.opendaylight.controller/odl-mdsal-broker/1.6.1/xml/features</repository>
+ <feature name="ccsdk-dblib" description="ccsdk-sli-core :: dblib :: ccsdk-dblib" version="${project.version}">
+ <details>Root POM to be used in place of odlparent for CCSDK based projects</details>
+ <feature version="1.6.1" prerequisite="false" dependency="false">odl-mdsal-broker</feature>
+ <feature prerequisite="true" dependency="false">wrap</feature>
+ <bundle>mvn:org.onap.ccsdk.sli.core/dblib-provider/${project.version}</bundle>
+ <bundle>mvn:org.mariadb.jdbc/mariadb-java-client/2.1.1</bundle>
+ <bundle>wrap:mvn:org.apache.tomcat/tomcat-jdbc/8.5.14/$DynamicImport-Package=org.mariadb.*,org.apache.derby.*&amp;overwrite=merge</bundle>
+ <bundle>wrap:mvn:org.apache.tomcat/tomcat-juli/8.5.14/$DynamicImport-Package=org.mariadb.*,org.apache.derby.*&amp;overwrite=merge</bundle>
+ <bundle>mvn:org.onap.ccsdk.sli.core/utils-provider/${project.version}</bundle>
+ </feature>
+</features>
diff --git a/dblib/features/features-dblib/pom.xml b/dblib/features/features-dblib/pom.xml
new file mode 100644
index 000000000..b7c2150dd
--- /dev/null
+++ b/dblib/features/features-dblib/pom.xml
@@ -0,0 +1,29 @@
+<?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.onap.ccsdk.parent</groupId>
+ <artifactId>feature-repo-parent</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>features-dblib</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <packaging>feature</packaging>
+
+ <name>ccsdk-sli-core :: dblib :: ${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ccsdk-dblib</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
+
+ </dependencies>
+</project>
diff --git a/dblib/features/pom.xml b/dblib/features/pom.xml
index e9cb6dd0b..18f087397 100755
--- a/dblib/features/pom.xml
+++ b/dblib/features/pom.xml
@@ -1,138 +1,23 @@
<?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>dblib</artifactId>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <version>0.2.0-SNAPSHOT</version>
+ <groupId>org.onap.ccsdk.parent</groupId>
+ <artifactId>odlparent-lite</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <relativePath/>
</parent>
- <artifactId>dblib-features</artifactId>
- <name>DBLIB Adaptor - Features</name>
-
- <packaging>jar</packaging>
-
- <dependencies>
-
-
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>${commons.lang.version}</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>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-jdbc</artifactId>
- <version>${tomcat-jdbc.version}</version>
- </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>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-feature-aggregator</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
- <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>
+ <name>ccsdk-sli-core :: dblib :: ${project.artifactId}</name>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.16</version>
- <configuration>
- <systemPropertyVariables>
- <karaf.distro.groupId>org.opendaylight.odlparent</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>
+ <modules>
+ <module>features-dblib</module>
+ <module>ccsdk-dblib</module>
+ </modules>
</project>
diff --git a/dblib/features/src/main/resources/features.xml b/dblib/features/src/main/resources/features.xml
deleted file mode 100755
index aa31db751..000000000
--- a/dblib/features/src/main/resources/features.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<features name="sdnc-dblib-${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-dblib' description="sdnc-dblib" version='${project.version}'>
- <!-- Most applications will have a dependency on the ODL MD-SAL Broker -->
- <feature version="${odl.mdsal.version}">odl-mdsal-broker</feature>
- <bundle>wrap:mvn:org.apache.tomcat/tomcat-jdbc/${tomcat-jdbc.version}/$DynamicImport-Package=org.mariadb.*&amp;overwrite=merge</bundle>
- <bundle>mvn:org.onap.ccsdk.sli.core/dblib-provider/${project.version}</bundle>
- <bundle>mvn:org.mariadb.jdbc/mariadb-java-client/${mariadb.connector.version}</bundle>
- </feature>
-
-</features>
diff --git a/dblib/installer/pom.xml b/dblib/installer/pom.xml
index bff158011..8d6147b72 100755
--- a/dblib/installer/pom.xml
+++ b/dblib/installer/pom.xml
@@ -1,143 +1,149 @@
<?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>dblib</artifactId>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <version>0.2.0-SNAPSHOT</version>
- </parent>
- <artifactId>dblib-installer</artifactId>
- <name>DBLIB Adaptor - Karaf Installer</name>
- <packaging>pom</packaging>
+<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>
- <properties>
- <application.name>sdnc-dblib</application.name>
- <features.boot>sdnc-dblib</features.boot>
- <features.repositories>mvn:org.onap.ccsdk.sli.core/dblib-features/${project.version}/xml/features</features.repositories>
- <include.transitive.dependencies>false</include.transitive.dependencies>
- </properties>
+ <parent>
+ <groupId>org.onap.ccsdk.parent</groupId>
+ <artifactId>odlparent-lite</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <relativePath />
+ </parent>
- <dependencies>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-installer</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-features</artifactId>
- <version>${project.version}</version>
- <classifier>features</classifier>
- <type>xml</type>
- <exclusions>
- <exclusion>
- <groupId>*</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
+ <name>ccsdk-sli-core :: dblib :: ${project.artifactId}</name>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <properties>
+ <application.name>ccsdk-dblib</application.name>
+ <features.boot>${application.name}</features.boot>
+ <features.repositories>mvn:org.onap.ccsdk.sli.core/${features.boot}/${project.version}/xml/features</features.repositories>
+ <include.transitive.dependencies>false</include.transitive.dependencies>
+ </properties>
+ <dependencies>
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-jdbc</artifactId>
- <version>${tomcat-jdbc.version}</version>
- </dependency>
- </dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>${application.name}</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <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.onap.ccsdk.sli,org.apache.tomcat</includeGroupIds>
- <excludeArtifactIds>sli-common,sli-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>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jdbc</artifactId>
+ <version>${tomcat-jdbc.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <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.onap.ccsdk.sli,org.apache.tomcat</includeGroupIds>
+ <excludeArtifactIds>sli-common,sli-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/dblib/pom.xml b/dblib/pom.xml
index e7743d81c..58f40ff69 100755
--- a/dblib/pom.xml
+++ b/dblib/pom.xml
@@ -1,77 +1,26 @@
<?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.onap.ccsdk.sli.core</groupId>
- <artifactId>ccsdk-sli-core</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+<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.onap.ccsdk.parent</groupId>
+ <artifactId>odlparent-lite</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <relativePath/>
</parent>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>dblib</artifactId>
+ <version>0.2.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
- <modelVersion>4.0.0</modelVersion>
- <packaging>pom</packaging>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib</artifactId>
-
-
- <name>DBLIB Adaptor</name>
- <description>The DBLIB adaptor allows service logic to access persistent data in a local sql database</description>
-
- <version>0.2.0-SNAPSHOT</version>
-
- <build>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>${maven.compile.plugin.version}</version>
- <configuration>
- <source>${java.version.source}</source>
- <target>${java.version.target}</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.10</version>
-
- <executions>
- <execution>
- <id>aggregate</id>
- <goals>
- <goal>aggregate</goal>
- </goals>
- <phase>site</phase>
-
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1.1</version>
- <executions>
- <execution>
- <id>bundle-sources</id>
- <phase>package</phase>
- <goals>
- <!-- produce source artifact for main project sources -->
- <goal>jar-no-fork</goal>
-
- <!-- produce source artifact for project test sources -->
- <goal>test-jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
-
- </pluginManagement>
- </build>
- <organization>
- <name>AT&amp;T</name>
+ <name>ccsdk-sli-core :: dblib</name>
+ <description>The DBLIB adaptor allows service logic to access persistent data in a local sql database</description>
+ <organization>
+ <name>ONAP</name>
</organization>
- <modules>
+
+ <modules>
<module>provider</module>
<module>features</module>
<module>installer</module>
diff --git a/dblib/provider/pom.xml b/dblib/provider/pom.xml
index 3bdd7e67b..e6fd1bcb1 100755
--- a/dblib/provider/pom.xml
+++ b/dblib/provider/pom.xml
@@ -1,19 +1,27 @@
<?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">
+<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.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <groupId>org.onap.ccsdk.parent</groupId>
+ <artifactId>binding-parent</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <relativePath />
</parent>
+
+ <groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>dblib-provider</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <version>0.2.1-SNAPSHOT</version>
<packaging>bundle</packaging>
- <name>DBLIB Adaptor - Provider</name>
+
+ <name>ccsdk-sli-core :: dblib :: ${project.artifactId}</name>
<url>http://maven.apache.org</url>
+
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -21,12 +29,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>ch.vorburger.mariaDB4j</groupId>
- <artifactId>mariaDB4j</artifactId>
- <version>2.2.3</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>ch.vorburger.mariaDB4j</groupId>
+ <artifactId>mariaDB4j</artifactId>
+ <version>2.2.3</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>equinoxSDK381</groupId>
<artifactId>org.eclipse.osgi</artifactId>
@@ -48,53 +56,31 @@
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mariadb.jdbc</groupId>
- <artifactId>mariadb-java-client</artifactId>
- <version>${mariadb.connector.version}</version>
- </dependency>
<dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-jdbc</artifactId>
- <version>${tomcat-jdbc.version}</version>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>${mariadb.connector.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jdbc</artifactId>
+ <version>${tomcat-jdbc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>utils-provider</artifactId>
<version>${project.version}</version>
</dependency>
- <!-- Testing related dependencies -->
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
+ <!-- Testing related dependencies -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${bundle.plugin.version}</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>org.onap.ccsdk.sli.core.dblib</Bundle-SymbolicName>
- <Export-Package>org.onap.ccsdk.sli.core.dblib;version=${project.version}</Export-Package>
- <Import-Package>*,org.mariadb.jdbc</Import-Package>
- <Embed-Transitive>true</Embed-Transitive>
- </instructions>
- </configuration>
-
- </plugin>
-
-
- </plugins>
- </build>
</project>
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
index d2331786e..8dac33611 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
@@ -56,500 +56,516 @@ import org.slf4j.LoggerFactory;
public abstract class CachedDataSource implements DataSource, SQLExecutionMonitorObserver {
- private static final Logger LOGGER = LoggerFactory.getLogger(CachedDataSource.class);
-
- private static final String SQL_FAILURE = "SQL FAILURE. time(ms): ";
- private static final String FAILED_TO_EXECUTE = "> Failed to execute: ";
- private static final String WITH_ARGUMENTS = " with arguments: ";
- private static final String WITH_NO_ARGUMENTS = " with no arguments. ";
- private static final String SQL_DATA_SOURCE = "SQL DataSource <";
-
-
- protected long connReqTimeout = 30L;
- protected long dataReqTimeout = 100L;
-
- private final SQLExecutionMonitor monitor;
- protected DataSource ds = null;
- protected String connectionName = null;
- protected boolean initialized = false;
-
- private long interval = 1000;
- private long initialDelay = 5000;
- private long expectedCompletionTime = 50L;
- private boolean canTakeOffLine = true;
- private long unprocessedFailoverThreshold = 3L;
-
- private long nextErrorReportTime = 0L;
-
- private String globalHostName = null;
-
-
- public CachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException {
- configure(jdbcElem);
- monitor = new SQLExecutionMonitor(this);
- }
-
- protected abstract void configure(BaseDBConfiguration jdbcElem) throws DBConfigException;
-
- /* (non-Javadoc)
- * @see javax.sql.DataSource#getConnection()
- */
- @Override
- public Connection getConnection() throws SQLException {
- return ds.getConnection();
- }
-
- public CachedRowSet getData(String statement, List<Object> arguments)
- throws SQLException {
- TestObject testObject = monitor.registerRequest();
-
- try (Connection connection = this.getConnection()) {
- if (connection == null) {
- throw new SQLException("Connection invalid");
- }
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Obtained connection <{}>: {}", connectionName, connection);
- }
- return executePreparedStatement(connection, statement, arguments, true);
- } finally {
- monitor.deregisterRequest(testObject);
- }
- }
-
- public boolean writeData(String statement, List<Object> arguments)
- throws SQLException {
- TestObject testObject = monitor.registerRequest();
-
- try (Connection connection = this.getConnection()) {
- if (connection == null) {
- throw new SQLException("Connection invalid");
- }
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Obtained connection <{}>: {}", connectionName, connection);
- }
- return executeUpdatePreparedStatement(connection, statement, arguments, true);
- } finally {
- monitor.deregisterRequest(testObject);
- }
- }
-
- CachedRowSet executePreparedStatement(Connection conn, String statement,
- List<Object> arguments, boolean close) throws SQLException {
- long time = System.currentTimeMillis();
-
- CachedRowSet data = null;
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("SQL Statement: {}", statement);
- if (arguments != null && !arguments.isEmpty()) {
- LOGGER.debug("Argunments: {}", arguments);
- }
- }
-
- ResultSet rs = null;
- try (PreparedStatement ps = conn.prepareStatement(statement)) {
- data = RowSetProvider.newFactory().createCachedRowSet();
- if (arguments != null) {
- for (int i = 0, max = arguments.size(); i < max; i++) {
- ps.setObject(i + 1, arguments.get(i));
- }
- }
- rs = ps.executeQuery();
- data.populate(rs);
- // Point the rowset Cursor to the start
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("SQL SUCCESS. rows returned: {}, time(ms): {}", data.size(), (System.currentTimeMillis()
- - time));
- }
- } catch (SQLException exc) {
- handleSqlExceptionForExecuteStatement(conn, statement, arguments, exc, time);
- } finally {
- handleFinallyBlockForExecutePreparedStatement(rs, conn, close);
- }
-
- return data;
- }
-
- private void handleSqlExceptionForExecuteStatement(Connection conn, String statement,
- List<Object> arguments, SQLException exc, long time) throws SQLException {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(SQL_FAILURE + (System.currentTimeMillis() - time));
- }
- try {
- conn.rollback();
- } catch (Exception thr) {
- LOGGER.error(thr.getLocalizedMessage(), thr);
- }
- if (arguments != null && !arguments.isEmpty()) {
- LOGGER.error(String.format("<%s%s%s%s%s", connectionName, FAILED_TO_EXECUTE, statement, WITH_ARGUMENTS,
- arguments), exc);
- } else {
- LOGGER.error(String.format("<%s%s%s%s", connectionName, FAILED_TO_EXECUTE, statement, WITH_NO_ARGUMENTS),
- exc);
- }
- throw exc;
- }
-
- private void handleFinallyBlockForExecutePreparedStatement(ResultSet rs, Connection conn, boolean close) {
- try {
- if (rs != null) {
- rs.close();
- }
- } catch (Exception exc) {
- LOGGER.error(exc.getLocalizedMessage(), exc);
- }
- try {
- if (conn != null && close) {
- conn.close();
- }
- } catch (Exception exc) {
- LOGGER.error(exc.getLocalizedMessage(), exc);
- }
- }
-
- boolean executeUpdatePreparedStatement(Connection conn, String statement, List<Object> arguments,
- boolean close) throws SQLException {
- long time = System.currentTimeMillis();
-
- CachedRowSet data;
-
- try (PreparedStatement ps = conn.prepareStatement(statement)) {
- data = RowSetProvider.newFactory().createCachedRowSet();
- if (arguments != null) {
- prepareStatementForExecuteUpdate(arguments, ps);
- }
- ps.executeUpdate();
- // Point the rowset Cursor to the start
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("SQL SUCCESS. rows returned: {}, time(ms): {}", data.size(), (System.currentTimeMillis()
- - time));
- }
- ps.close();
- } catch (SQLException exc) {
- handleSqlExceptionForExecuteStatement(conn, statement, arguments, exc, time);
- } finally {
- try {
- if (close) {
- conn.close();
- }
- } catch (Exception exc) {
- LOGGER.error(exc.getLocalizedMessage(), exc);
- }
- }
-
- return true;
- }
-
- private void prepareStatementForExecuteUpdate(List<Object> arguments, PreparedStatement ps)
- throws SQLException {
- for (int i = 0, max = arguments.size(); i < max; i++) {
- Object value = arguments.get(i);
- if (value instanceof Blob) {
- ps.setBlob(i + 1, (Blob) value);
- } else if (value instanceof Timestamp) {
- ps.setTimestamp(i + 1, (Timestamp) value);
- } else if (value instanceof Integer) {
- ps.setInt(i + 1, (Integer) value);
- } else if (value instanceof Long) {
- ps.setLong(i + 1, (Long) value);
- } else if (value instanceof Date) {
- ps.setDate(i + 1, (Date) value);
- } else {
- ps.setObject(i + 1, value);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
- */
- @Override
- public Connection getConnection(String username, String password)
- throws SQLException {
- return ds.getConnection(username, password);
- }
-
- /* (non-Javadoc)
- * @see javax.sql.DataSource#getLogWriter()
- */
- @Override
- public PrintWriter getLogWriter() throws SQLException {
- return ds.getLogWriter();
- }
-
- /* (non-Javadoc)
- * @see javax.sql.DataSource#getLoginTimeout()
- */
- @Override
- public int getLoginTimeout() throws SQLException {
- return ds.getLoginTimeout();
- }
-
- /* (non-Javadoc)
- * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
- */
- @Override
- public void setLogWriter(PrintWriter out) throws SQLException {
- ds.setLogWriter(out);
- }
-
- /* (non-Javadoc)
- * @see javax.sql.DataSource#setLoginTimeout(int)
- */
- @Override
- public void setLoginTimeout(int seconds) throws SQLException {
- ds.setLoginTimeout(seconds);
- }
-
-
- @Override
- public final String getDbConnectionName() {
- return connectionName;
- }
-
- protected final void setDbConnectionName(String name) {
- this.connectionName = name;
- }
-
- public void cleanUp() {
- if (ds != null && ds instanceof Closeable) {
- try {
- ((Closeable) ds).close();
- } catch (IOException e) {
- LOGGER.warn(e.getMessage());
- }
- }
- ds = null;
- monitor.deleteObservers();
- monitor.cleanup();
- }
-
- public boolean isInitialized() {
- return initialized;
- }
-
- protected boolean testConnection() {
- return testConnection(false);
- }
-
- protected boolean testConnection(boolean errorLevel) {
- ResultSet rs = null;
- try (Connection conn = this.getConnection(); Statement stmt = conn.createStatement()) {
- Boolean readOnly;
- String hostname;
- rs = stmt.executeQuery(
- "SELECT @@global.read_only, @@global.hostname"); //("SELECT 1 FROM DUAL"); //"select BANNER from SYS.V_$VERSION"
- while (rs.next()) {
- readOnly = rs.getBoolean(1);
- hostname = rs.getString(2);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- SQL_DATA_SOURCE + getDbConnectionName() + "> connected to " + hostname + ", read-only is "
- + readOnly + ", tested successfully ");
- }
- }
- } catch (Exception exc) {
- if (errorLevel) {
- LOGGER.error(
- SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage());
- } else {
- LOGGER.info(
- SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage());
- }
- return false;
- } finally {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException e) {
- LOGGER.error(e.getLocalizedMessage(), e);
- }
- }
- }
- return true;
- }
-
- @Override
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return false;
- }
-
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return null;
- }
-
- @SuppressWarnings("deprecation")
- public void setConnectionCachingEnabled(boolean state) {
-// if(ds != null && ds instanceof OracleDataSource)
-// try {
-// ((OracleDataSource)ds).setConnectionCachingEnabled(true);
-// } catch (SQLException exc) {
-// LOGGER.warn("", exc);
-// }
- }
-
- public void addObserver(Observer observer) {
- monitor.addObserver(observer);
- }
-
- public void deleteObserver(Observer observer) {
- monitor.deleteObserver(observer);
- }
-
- @Override
- public long getInterval() {
- return interval;
- }
-
- @Override
- public long getInitialDelay() {
- return initialDelay;
- }
-
- @Override
- public void setInterval(long value) {
- interval = value;
- }
-
- @Override
- public void setInitialDelay(long value) {
- initialDelay = value;
- }
-
- @Override
- public long getExpectedCompletionTime() {
- return expectedCompletionTime;
- }
-
- @Override
- public void setExpectedCompletionTime(long value) {
- expectedCompletionTime = value;
- }
-
- @Override
- public long getUnprocessedFailoverThreshold() {
- return unprocessedFailoverThreshold;
- }
-
- @Override
- public void setUnprocessedFailoverThreshold(long value) {
- this.unprocessedFailoverThreshold = value;
- }
-
- public boolean canTakeOffLine() {
- return canTakeOffLine;
- }
-
- public void blockImmediateOffLine() {
- canTakeOffLine = false;
- final Thread offLineTimer = new Thread(() -> {
- try {
- Thread.sleep(30000L);
- } catch (Exception exc) {
- LOGGER.error(exc.getLocalizedMessage(), exc);
- } finally {
- canTakeOffLine = true;
- }
- });
- offLineTimer.setDaemon(true);
- offLineTimer.start();
- }
-
- /**
- * @return the monitor
- */
- final SQLExecutionMonitor getMonitor() {
- return monitor;
- }
-
- protected boolean isSlave() throws PoolExhaustedException {
- CachedRowSet rs;
- boolean isSlave;
- String hostname = "UNDETERMINED";
- try {
- boolean localSlave = true;
- rs = this.getData("SELECT @@global.read_only, @@global.hostname", new ArrayList<>());
- while (rs.next()) {
- localSlave = rs.getBoolean(1);
- hostname = rs.getString(2);
- }
- isSlave = localSlave;
- } catch (PoolExhaustedException peexc) {
- throw peexc;
- } catch (Exception e) {
- LOGGER.error("", e);
- isSlave = true;
- }
- if (isSlave) {
- LOGGER.debug("SQL SLAVE : {} on server {}", connectionName, hostname);
- } else {
- LOGGER.debug("SQL MASTER : {} on server {}", connectionName, hostname);
- }
- return isSlave;
- }
-
- public boolean isFabric() {
- return false;
- }
-
- protected boolean lockTable(Connection conn, String tableName) {
- boolean retValue = false;
- String query = "LOCK TABLES " + tableName + " WRITE";
- try (Statement preStmt = conn.createStatement(); Statement lock = conn.prepareStatement(query);
- ResultSet rs = preStmt.executeQuery("GETDATE()")) {
- if (tableName != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Executing 'LOCK TABLES " + tableName + " WRITE' on connection " + conn.toString());
- if ("SVC_LOGIC".equals(tableName)) {
- Exception e = new Exception();
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- LOGGER.debug(sw.toString());
- }
- }
- lock.execute(query);
- retValue = true;
- }
- } catch (Exception exc) {
- LOGGER.error("", exc);
- retValue = false;
- }
- return retValue;
- }
-
- protected boolean unlockTable(Connection conn) {
- boolean retValue;
- try (Statement lock = conn.createStatement()) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Executing 'UNLOCK TABLES' on connection {}", conn);
- }
- retValue = lock.execute("UNLOCK TABLES");
- } catch (Exception exc) {
- LOGGER.error("", exc);
- retValue = false;
- }
- return retValue;
- }
-
- public void getPoolInfo(boolean allocation) {
-
- }
-
- public long getNextErrorReportTime() {
- return nextErrorReportTime;
- }
-
- public void setNextErrorReportTime(long nextTime) {
- this.nextErrorReportTime = nextTime;
- }
-
- public void setGlobalHostName(String hostname) {
- this.globalHostName = hostname;
- }
-
- public String getGlobalHostName() {
- return globalHostName;
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(CachedDataSource.class);
+
+ private static final String SQL_FAILURE = "SQL FAILURE. time(ms): ";
+ private static final String FAILED_TO_EXECUTE = "> Failed to execute: ";
+ private static final String WITH_ARGUMENTS = " with arguments: ";
+ private static final String WITH_NO_ARGUMENTS = " with no arguments. ";
+ private static final String SQL_DATA_SOURCE = "SQL DataSource <";
+
+ protected long connReqTimeout = 30L;
+ protected long dataReqTimeout = 100L;
+
+ private final SQLExecutionMonitor monitor;
+ protected DataSource ds = null;
+ protected String connectionName = null;
+ protected boolean initialized = false;
+
+ private long interval = 1000;
+ private long initialDelay = 5000;
+ private long expectedCompletionTime = 50L;
+ private boolean canTakeOffLine = true;
+ private long unprocessedFailoverThreshold = 3L;
+
+ private long nextErrorReportTime = 0L;
+
+ private String globalHostName = null;
+
+ private boolean isDerby = false;
+
+ public CachedDataSource(BaseDBConfiguration jdbcElem) throws DBConfigException {
+ configure(jdbcElem);
+
+ if ("org.apache.derby.jdbc.EmbeddedDriver".equals(jdbcElem.getDriverName())) {
+ isDerby = true;
+ }
+ monitor = new SQLExecutionMonitor(this);
+ }
+
+ protected abstract void configure(BaseDBConfiguration jdbcElem) throws DBConfigException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.sql.DataSource#getConnection()
+ */
+ @Override
+ public Connection getConnection() throws SQLException {
+ return ds.getConnection();
+ }
+
+ public CachedRowSet getData(String statement, List<Object> arguments) throws SQLException {
+ TestObject testObject = monitor.registerRequest();
+
+ try (Connection connection = this.getConnection()) {
+ if (connection == null) {
+ throw new SQLException("Connection invalid");
+ }
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Obtained connection <{}>: {}", connectionName, connection);
+ }
+ return executePreparedStatement(connection, statement, arguments, true);
+ } finally {
+ monitor.deregisterRequest(testObject);
+ }
+ }
+
+ public boolean writeData(String statement, List<Object> arguments) throws SQLException {
+ TestObject testObject = monitor.registerRequest();
+
+ try (Connection connection = this.getConnection()) {
+ if (connection == null) {
+ throw new SQLException("Connection invalid");
+ }
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Obtained connection <{}>: {}", connectionName, connection);
+ }
+ return executeUpdatePreparedStatement(connection, statement, arguments, true);
+ } finally {
+ monitor.deregisterRequest(testObject);
+ }
+ }
+
+ CachedRowSet executePreparedStatement(Connection conn, String statement, List<Object> arguments, boolean close)
+ throws SQLException {
+ long time = System.currentTimeMillis();
+
+ CachedRowSet data = null;
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SQL Statement: {}", statement);
+ if (arguments != null && !arguments.isEmpty()) {
+ LOGGER.debug("Argunments: {}", arguments);
+ }
+ }
+
+ ResultSet rs = null;
+ try (PreparedStatement ps = conn.prepareStatement(statement)) {
+ data = RowSetProvider.newFactory().createCachedRowSet();
+ if (arguments != null) {
+ for (int i = 0, max = arguments.size(); i < max; i++) {
+ ps.setObject(i + 1, arguments.get(i));
+ }
+ }
+ rs = ps.executeQuery();
+ data.populate(rs);
+ // Point the rowset Cursor to the start
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SQL SUCCESS. rows returned: {}, time(ms): {}", data.size(),
+ (System.currentTimeMillis() - time));
+ }
+ } catch (SQLException exc) {
+ handleSqlExceptionForExecuteStatement(conn, statement, arguments, exc, time);
+ } finally {
+ handleFinallyBlockForExecutePreparedStatement(rs, conn, close);
+ }
+
+ return data;
+ }
+
+ private void handleSqlExceptionForExecuteStatement(Connection conn, String statement, List<Object> arguments,
+ SQLException exc, long time) throws SQLException {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(SQL_FAILURE + (System.currentTimeMillis() - time));
+ }
+ try {
+ conn.rollback();
+ } catch (Exception thr) {
+ LOGGER.error(thr.getLocalizedMessage(), thr);
+ }
+ if (arguments != null && !arguments.isEmpty()) {
+ LOGGER.error(String.format("<%s%s%s%s%s", connectionName, FAILED_TO_EXECUTE, statement, WITH_ARGUMENTS,
+ arguments), exc);
+ } else {
+ LOGGER.error(String.format("<%s%s%s%s", connectionName, FAILED_TO_EXECUTE, statement, WITH_NO_ARGUMENTS),
+ exc);
+ }
+ throw exc;
+ }
+
+ private void handleFinallyBlockForExecutePreparedStatement(ResultSet rs, Connection conn, boolean close) {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (Exception exc) {
+ LOGGER.error(exc.getLocalizedMessage(), exc);
+ }
+ try {
+ if (conn != null && close) {
+ conn.close();
+ }
+ } catch (Exception exc) {
+ LOGGER.error(exc.getLocalizedMessage(), exc);
+ }
+ }
+
+ boolean executeUpdatePreparedStatement(Connection conn, String statement, List<Object> arguments, boolean close)
+ throws SQLException {
+ long time = System.currentTimeMillis();
+
+ CachedRowSet data;
+
+ try (PreparedStatement ps = conn.prepareStatement(statement)) {
+ data = RowSetProvider.newFactory().createCachedRowSet();
+ if (arguments != null) {
+ prepareStatementForExecuteUpdate(arguments, ps);
+ }
+ ps.executeUpdate();
+ // Point the rowset Cursor to the start
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("SQL SUCCESS. rows returned: {}, time(ms): {}", data.size(),
+ (System.currentTimeMillis() - time));
+ }
+ ps.close();
+ } catch (SQLException exc) {
+ handleSqlExceptionForExecuteStatement(conn, statement, arguments, exc, time);
+ } finally {
+ try {
+ if (close) {
+ conn.close();
+ }
+ } catch (Exception exc) {
+ LOGGER.error(exc.getLocalizedMessage(), exc);
+ }
+ }
+
+ return true;
+ }
+
+ private void prepareStatementForExecuteUpdate(List<Object> arguments, PreparedStatement ps) throws SQLException {
+ for (int i = 0, max = arguments.size(); i < max; i++) {
+ Object value = arguments.get(i);
+ if (value instanceof Blob) {
+ ps.setBlob(i + 1, (Blob) value);
+ } else if (value instanceof Timestamp) {
+ ps.setTimestamp(i + 1, (Timestamp) value);
+ } else if (value instanceof Integer) {
+ ps.setInt(i + 1, (Integer) value);
+ } else if (value instanceof Long) {
+ ps.setLong(i + 1, (Long) value);
+ } else if (value instanceof Date) {
+ ps.setDate(i + 1, (Date) value);
+ } else {
+ ps.setObject(i + 1, value);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
+ */
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException {
+ return ds.getConnection(username, password);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.sql.DataSource#getLogWriter()
+ */
+ @Override
+ public PrintWriter getLogWriter() throws SQLException {
+ return ds.getLogWriter();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.sql.DataSource#getLoginTimeout()
+ */
+ @Override
+ public int getLoginTimeout() throws SQLException {
+ return ds.getLoginTimeout();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
+ */
+ @Override
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ ds.setLogWriter(out);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.sql.DataSource#setLoginTimeout(int)
+ */
+ @Override
+ public void setLoginTimeout(int seconds) throws SQLException {
+ ds.setLoginTimeout(seconds);
+ }
+
+ @Override
+ public final String getDbConnectionName() {
+ return connectionName;
+ }
+
+ protected final void setDbConnectionName(String name) {
+ this.connectionName = name;
+ }
+
+ public void cleanUp() {
+ if (ds != null && ds instanceof Closeable) {
+ try {
+ ((Closeable) ds).close();
+ } catch (IOException e) {
+ LOGGER.warn(e.getMessage());
+ }
+ }
+ ds = null;
+ monitor.deleteObservers();
+ monitor.cleanup();
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ protected boolean testConnection() {
+ return testConnection(false);
+ }
+
+ protected boolean testConnection(boolean errorLevel) {
+ ResultSet rs = null;
+ try (Connection conn = this.getConnection(); Statement stmt = conn.createStatement()) {
+ Boolean readOnly;
+ String hostname;
+ rs = stmt.executeQuery("SELECT @@global.read_only, @@global.hostname"); // ("SELECT 1 FROM DUAL"); //"select
+ // BANNER from SYS.V_$VERSION"
+ while (rs.next()) {
+ readOnly = rs.getBoolean(1);
+ hostname = rs.getString(2);
+
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(SQL_DATA_SOURCE + getDbConnectionName() + "> connected to " + hostname
+ + ", read-only is " + readOnly + ", tested successfully ");
+ }
+ }
+ } catch (Exception exc) {
+ if (errorLevel) {
+ LOGGER.error(
+ SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage());
+ } else {
+ LOGGER.info(
+ SQL_DATA_SOURCE + this.getDbConnectionName() + "> test failed. Cause : " + exc.getMessage());
+ }
+ return false;
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getLocalizedMessage(), e);
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setConnectionCachingEnabled(boolean state) {
+ // if(ds != null && ds instanceof OracleDataSource)
+ // try {
+ // ((OracleDataSource)ds).setConnectionCachingEnabled(true);
+ // } catch (SQLException exc) {
+ // LOGGER.warn("", exc);
+ // }
+ }
+
+ public void addObserver(Observer observer) {
+ monitor.addObserver(observer);
+ }
+
+ public void deleteObserver(Observer observer) {
+ monitor.deleteObserver(observer);
+ }
+
+ @Override
+ public long getInterval() {
+ return interval;
+ }
+
+ @Override
+ public long getInitialDelay() {
+ return initialDelay;
+ }
+
+ @Override
+ public void setInterval(long value) {
+ interval = value;
+ }
+
+ @Override
+ public void setInitialDelay(long value) {
+ initialDelay = value;
+ }
+
+ @Override
+ public long getExpectedCompletionTime() {
+ return expectedCompletionTime;
+ }
+
+ @Override
+ public void setExpectedCompletionTime(long value) {
+ expectedCompletionTime = value;
+ }
+
+ @Override
+ public long getUnprocessedFailoverThreshold() {
+ return unprocessedFailoverThreshold;
+ }
+
+ @Override
+ public void setUnprocessedFailoverThreshold(long value) {
+ this.unprocessedFailoverThreshold = value;
+ }
+
+ public boolean canTakeOffLine() {
+ return canTakeOffLine;
+ }
+
+ public void blockImmediateOffLine() {
+ canTakeOffLine = false;
+ final Thread offLineTimer = new Thread(() -> {
+ try {
+ Thread.sleep(30000L);
+ } catch (Exception exc) {
+ LOGGER.error(exc.getLocalizedMessage(), exc);
+ } finally {
+ canTakeOffLine = true;
+ }
+ });
+ offLineTimer.setDaemon(true);
+ offLineTimer.start();
+ }
+
+ /**
+ * @return the monitor
+ */
+ final SQLExecutionMonitor getMonitor() {
+ return monitor;
+ }
+
+ protected boolean isSlave() throws PoolExhaustedException {
+
+ // If using Apache derby, just return false
+ if (isDerby) {
+ return false;
+ }
+ CachedRowSet rs;
+ boolean isSlave;
+ String hostname = "UNDETERMINED";
+ try {
+ boolean localSlave = true;
+ rs = this.getData("SELECT @@global.read_only, @@global.hostname", new ArrayList<>());
+ while (rs.next()) {
+ localSlave = rs.getBoolean(1);
+ hostname = rs.getString(2);
+ }
+ isSlave = localSlave;
+ } catch (PoolExhaustedException peexc) {
+ throw peexc;
+ } catch (Exception e) {
+ LOGGER.error("", e);
+ isSlave = true;
+ }
+ if (isSlave) {
+ LOGGER.debug("SQL SLAVE : {} on server {}", connectionName, hostname);
+ } else {
+ LOGGER.debug("SQL MASTER : {} on server {}", connectionName, hostname);
+ }
+ return isSlave;
+ }
+
+ public boolean isFabric() {
+ return false;
+ }
+
+ protected boolean lockTable(Connection conn, String tableName) {
+ boolean retValue = false;
+ String query = "LOCK TABLES " + tableName + " WRITE";
+ try (Statement preStmt = conn.createStatement();
+ Statement lock = conn.prepareStatement(query);
+ ResultSet rs = preStmt.executeQuery("GETDATE()")) {
+ if (tableName != null) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Executing 'LOCK TABLES " + tableName + " WRITE' on connection " + conn.toString());
+ if ("SVC_LOGIC".equals(tableName)) {
+ Exception e = new Exception();
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ e.printStackTrace(pw);
+ LOGGER.debug(sw.toString());
+ }
+ }
+ lock.execute(query);
+ retValue = true;
+ }
+ } catch (Exception exc) {
+ LOGGER.error("", exc);
+ retValue = false;
+ }
+ return retValue;
+ }
+
+ protected boolean unlockTable(Connection conn) {
+ boolean retValue;
+ try (Statement lock = conn.createStatement()) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Executing 'UNLOCK TABLES' on connection {}", conn);
+ }
+ retValue = lock.execute("UNLOCK TABLES");
+ } catch (Exception exc) {
+ LOGGER.error("", exc);
+ retValue = false;
+ }
+ return retValue;
+ }
+
+ public void getPoolInfo(boolean allocation) {
+
+ }
+
+ public long getNextErrorReportTime() {
+ return nextErrorReportTime;
+ }
+
+ public void setNextErrorReportTime(long nextTime) {
+ this.nextErrorReportTime = nextTime;
+ }
+
+ public void setGlobalHostName(String hostname) {
+ this.globalHostName = hostname;
+ }
+
+ public String getGlobalHostName() {
+ return globalHostName;
+ }
}
diff --git a/dblib/provider/src/main/resources/dblib.properties b/dblib/provider/src/main/resources/dblib.properties
index 3e62308fc..e0399cc31 100755
--- a/dblib/provider/src/main/resources/dblib.properties
+++ b/dblib/provider/src/main/resources/dblib.properties
@@ -1,9 +1,10 @@
org.onap.ccsdk.sli.dbtype=jdbc
org.onap.ccsdk.sli.jdbc.hosts=sdnctldb01,sdnctldb02
-org.onap.ccsdk.sli.jdbc.url=jdbc:mysql://DBHOST:3306/sdnctl
+org.onap.ccsdk.sli.jdbc.url=jdbc:derby:memory:sdnctl;create=true
+org.onap.ccsdk.sli.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
org.onap.ccsdk.sli.jdbc.database=sdnctl
-org.onap.ccsdk.sli.jdbc.user={user for sdnctl}
-org.onap.ccsdk.sli.jdbc.password={password for sdnctl}
+org.onap.ccsdk.sli.jdbc.user=test
+org.onap.ccsdk.sli.jdbc.password=test
org.onap.ccsdk.sli.jdbc.connection.name=sdnctldb01
org.onap.ccsdk.sli.jdbc.connection.timeout=50