Skip to content

Commit

Permalink
Enable DB2 connectivity in AppServer images (#4060)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardovh committed Nov 28, 2022
1 parent 0d57fbb commit d4b02b2
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 15 deletions.
2 changes: 1 addition & 1 deletion copyrightExcludeFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ TransformerHandlerImpl.java
secrets/
secrets\
.lift.toml
setup.sh
setup.sh
4 changes: 3 additions & 1 deletion core/src/main/resources/SqlTranslationPatterns.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ add_months.target.PostgreSQL =$1::date + ($2 || ' month')::interval

# Oracle source used a.o. in testscenarios: BatchFileTransformerPipe, (Big)ClobAndBlob
dual.source.Oracle=\s*FROM DUAL
dual.source.DB2 =\s*FROM SYSIBM.SYSDUMMY1
dual.sourse.DB2 =\s*FROM SYSIBM.SYSDUMMY1
dual.target.Oracle=\ FROM DUAL
dual.target.DB2 =\ FROM SYSIBM.SYSDUMMY1
dual.target.H2 =
dual.target.MS_SQL=
dual.target.PostgreSQL=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class URLDataSourceFactory extends JndiDataSourceFactory {
private static final Object[][] TEST_DATASOURCES = {
// ProductName, Url, user, password, testPeekDoesntFindRecordsAlreadyLocked
{ "H2", "jdbc:h2:mem:test;LOCK_TIMEOUT=1000", null, null, false, "org.h2.jdbcx.JdbcDataSource" },
{ "DB2", "jdbc:db2://localhost:50000/testiaf", "db2inst1", "syspw", false, "com.ibm.db2.jcc.DB2XADataSource" },
{ "DB2", "jdbc:db2://localhost:50000/testiaf", "testiaf_user", "testiaf_user00", false, "com.ibm.db2.jcc.DB2XADataSource" },
{ "Oracle", "jdbc:oracle:thin:@localhost:1521:ORCLCDB", "testiaf_user", "testiaf_user00", false, "oracle.jdbc.xa.client.OracleXADataSource" },
{ "MS_SQL", "jdbc:sqlserver://localhost:1433;database=testiaf;lockTimeout=10000", "testiaf_user", "testiaf_user00", false, "com.microsoft.sqlserver.jdbc.SQLServerXADataSource" },
{ "MySQL", "jdbc:mysql://localhost:3307/testiaf?sslMode=DISABLED&disableMariaDbDriver=1&pinGlobalTxToPhysicalConnection=true&serverTimezone=Europe/Amsterdam", "testiaf_user", "testiaf_user00", true, "com.mysql.cj.jdbc.MysqlXADataSource" },
Expand Down
5 changes: 5 additions & 0 deletions docker/appserver/JBoss/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<artifactId>postgresql</artifactId>
<version>${postgresql.driver.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2.driver.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions docker/appserver/JBoss/src/configuration/standalone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@
<credential-reference store="CS" alias="testiaf_user"/>
</security>
</xa-datasource>
<xa-datasource jndi-name="java:/jdbc/ibis4test-db2-xa" pool-name="ibis4test-db2">
<driver>db2</driver>
<xa-datasource-property name="databaseName">testiaf</xa-datasource-property>
<xa-datasource-property name="serverName">host.docker.internal</xa-datasource-property>
<xa-datasource-property name="portNumber">50000</xa-datasource-property>
<xa-datasource-property name="driverType">4</xa-datasource-property>
<security>
<user-name>testiaf_user</user-name>
<credential-reference store="CS" alias="testiaf_user"/>
</security>
</xa-datasource>
<!-- End of Framework datasources -->
<drivers>
<driver name="h2" module="com.h2database.h2">
Expand All @@ -267,6 +278,9 @@
<driver name="postgresql" module="module.frank-framework">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
<driver name="db2" module="module.frank-framework">
<xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>
</driver>
<!-- End of Framework drivers -->
</drivers>
</datasources>
Expand Down
5 changes: 5 additions & 0 deletions docker/appserver/Tomcat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<artifactId>postgresql</artifactId>
<version>${postgresql.driver.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2.driver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions docker/appserver/WebSphere/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<artifactId>postgresql</artifactId>
<version>${postgresql.driver.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2.driver.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def createDatasource(datasourceName, providerName, authAlias, properties):
createProvider('H2 JDBC Driver (XA)', 'org.h2.jdbcx.JdbcDataSource', 'classpath=/work/drivers/h2.jar,xa=true')
createProvider('MySQL JDBC Driver', 'com.mysql.cj.jdbc.MysqlXADataSource', 'classpath=/work/drivers/mysql-connector-j.jar')
createProvider('PostgreSQL JDBC Driver', 'org.postgresql.xa.PGXADataSource', 'classpath=/work/drivers/postgresql.jar')
createProvider('DB2 JDBC Driver', 'com.ibm.db2.jcc.DB2XADataSource', 'classpath=/work/drivers/jcc.jar')

createDatasource('ibis4test-h2', 'H2 JDBC Driver (XA)', [], [
[['name', 'URL'],['value', 'jdbc:h2:file:/work/ibis4test;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE']]
Expand Down Expand Up @@ -78,3 +79,11 @@ def createDatasource(datasourceName, providerName, authAlias, properties):
createDatasource('ibis4test-postgres-xa', 'PostgreSQL JDBC Driver', authAliasName, [
[['name', 'URL'], ['value', 'jdbc:postgresql://host.docker.internal:5432/testiaf']]
])

createDatasource('ibis4test-db2-xa', 'DB2 JDBC Driver', authAliasName, [
[['name', 'serverName'], ['value', 'host.docker.internal']],
[['name', 'portNumber'], ['value', '50000']],
[['name', 'databaseName'], ['value', 'testiaf']],
[['name', 'driverType'], ['value', '4']]
])

5 changes: 5 additions & 0 deletions docker/appserver/WildFly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<artifactId>postgresql</artifactId>
<version>${postgresql.driver.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2.driver.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions docker/appserver/WildFly/src/configuration/standalone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@
<user-name>testiaf_user</user-name>
<credential-reference store="CS" alias="testiaf_user"/>
</security>
</xa-datasource>
<xa-datasource jndi-name="java:/jdbc/ibis4test-db2-xa" pool-name="ibis4test-db2">
<driver>db2</driver>
<xa-datasource-property name="databaseName">testiaf</xa-datasource-property>
<xa-datasource-property name="serverName">host.docker.internal</xa-datasource-property>
<xa-datasource-property name="portNumber">50000</xa-datasource-property>
<xa-datasource-property name="driverType">4</xa-datasource-property>
<security>
<user-name>testiaf_user</user-name>
<credential-reference store="CS" alias="testiaf_user"/>
</security>
</xa-datasource>
<!-- End of Framework datasources -->
<drivers>
Expand All @@ -241,6 +252,9 @@
<driver name="postgresql" module="module.frank-framework">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
<driver name="db2" module="module.frank-framework">
<xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>
</driver>
<!-- End of Framework drivers -->
</drivers>
</datasources>
Expand Down
3 changes: 2 additions & 1 deletion docker/dbms/DB2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ibmcom/db2

COPY init_user.* /var/custom/
RUN chmod a+x /var/custom/*

HEALTHCHECK --start-period=240s CMD /opt/ibm/db2/V11.5/bin/db2 CONNECT TO TESTIAF
File renamed without changes.
10 changes: 8 additions & 2 deletions docker/dbms/DB2/init_user.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
useradd -s /bin/bash -d /home/testiaf_user -m -p testiaf_user00 testiaf_user
#!/bin/bash
# Create user, not setting password yet as useradd requires encrypted password
useradd -s /bin/bash -d /home/testiaf_user -m testiaf_user
# Use chpasswd to store the password, chpasswd encrypts it
echo testiaf_user:testiaf_user00 | chpasswd

db2 grant dataaccess on testiaf to user testiaf_user
# Set DB permissions
/opt/ibm/db2/V11.5/bin/db2 CONNECT TO testiaf user db2inst1 using syspw
/opt/ibm/db2/V11.5/bin/db2 GRANT DBADM,CREATETAB,BINDADD,CONNECT,CREATE_NOT_FENCED_ROUTINE,IMPLICIT_SCHEMA,LOAD,CREATE_EXTERNAL_ROUTINE,QUIESCE_CONNECT,SECADM ON DATABASE TO USER testiaf_user
4 changes: 0 additions & 4 deletions docker/dbms/DB2/init_user.sql

This file was deleted.

2 changes: 1 addition & 1 deletion docker/dbms/DB2/rebuild.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker stop iaf-test-db-db2
docker container rm iaf-test-db-db2

docker build .
docker build -t iaf-test-db-db2 .

%~dp0start.bat
2 changes: 1 addition & 1 deletion docker/dbms/DB2/start.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run -itd --name iaf-test-db-db2 --env-file env_list.sh --privileged=true -p 50000:50000 --restart unless-stopped ibmcom/db2
docker run -itd --name iaf-test-db-db2 --env-file env_list.txt --privileged=true -p 50000:50000 --restart unless-stopped iaf-test-db-db2
19 changes: 16 additions & 3 deletions test/src/main/webapp/META-INF/context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
user="${testiaf_user/username:-testiaf_user}"
password="${testiaf_user/password:-testiaf_user00}"
/>


<!-- Postgres XA does not work without BTM/Narayana, gives ClassCastException casting the XA datasource to Java datasource, so add non-XA for those cases -->
<Resource name="jdbc/ibis4test-postgres" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
Expand All @@ -121,12 +122,24 @@
maxWaitMillis="5000"
/>

<Resource name="jdbc/ibis4test-db2-xa" auth="Container"
factory="org.apache.naming.factory.BeanFactory"
type="com.ibm.db2.jcc.DB2XADataSource"
serverName="host.docker.internal"
portNumber="50000"
databaseName="testiaf"
driverType="4"
user="${testiaf_user/username:-testiaf_user}"
password="${testiaf_user/password:-testiaf_user00}"
/>

<!-- DB2 XA does not work without BTM/Narayana, gives ClassCastException casting the XA datasource to Java datasource, so add non-XA for those cases -->
<Resource name="jdbc/ibis4test-db2" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://host.docker.internal:50000/testiaf"
username="db2inst1"
password="syspw"
username="${testiaf_user/username:-testiaf_user}"
password="${testiaf_user/password:-testiaf_user00}"
/>

<Resource
Expand Down

0 comments on commit d4b02b2

Please sign in to comment.