Skip to content

Commit

Permalink
RHPAM-2261] - DB2 fails with externaldb template
Browse files Browse the repository at this point in the history
Signed-off-by: Filippe Spolti <fspolti@redhat.com>
  • Loading branch information
spolti committed Aug 12, 2019
1 parent e31ae60 commit 3ebd8c8
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 20 deletions.
52 changes: 43 additions & 9 deletions jboss-kie-kieserver/added/launch/jboss-kie-kieserver.sh
Expand Up @@ -98,15 +98,16 @@ function configure_EJB_Timer_datasource {
# EJBTimer datasource
local dsPrefix="${DATASOURCES%,*}"
DATASOURCES="EJB_TIMER,${DATASOURCES}"
set_url $dsPrefix
set_timer_env $dsPrefix
TIMER_SERVICE_DATA_STORE="EJB_TIMER"

# default value for ${prefix)_NONXA should be true
if [ -z "$(eval echo \$${dsPrefix}_NONXA)" ]; then
eval ${dsPrefix}_NONXA="true"
fi

set_url $dsPrefix
set_timer_env $dsPrefix
TIMER_SERVICE_DATA_STORE="EJB_TIMER"

# set 4 as default value for ${prefix)_XA_CONNECTION_PROPERTY_DRIVER_TYPE
if [[ "$(eval echo \$${dsPrefix}_DRIVER)" = *"db2"* ]]; then
local driverType=$(find_env "${dsPrefix}_DRIVER_TYPE" "4")
Expand Down Expand Up @@ -156,7 +157,7 @@ function declare_timer_common_variables {
}

function set_timer_defaults {
if [ "x${EJB_TIMER_JNDI}" != "x" ]; then
if [ "x${EJB_TIMER_JNDI}" != "x" ]; then
EJB_TIMER_JNDI="${EJB_TIMER_JNDI}_EJBTimer"
else
EJB_TIMER_JNDI=$(find_env "${prefix}_JNDI" "java:jboss/datasources/ejb_timer")
Expand Down Expand Up @@ -255,6 +256,11 @@ function declare_xa_variables {
local url=$(find_env "${prefix}_URL")
url=$(find_env "${prefix}_XA_CONNECTION_PROPERTY_URL" "${url}")
if [ "x${url}" == "x" ]; then
local serviceHost=$(find_env "${service}_SERVICE_HOST")
local host=$(find_env "${prefix}_SERVICE_HOST" "${serviceHost}")
local servicePort=$(find_env "${service}_SERVICE_PORT")
local port=$(find_env "${prefix}_SERVICE_PORT" "${servicePort}")
local database=$(find_env "${prefix}_DATABASE")
database=$(find_env "${prefix}_DATABASE")
xa_database=$(find_env "${prefix}_XA_CONNECTION_PROPERTY_DatabaseName")
EJB_TIMER_XA_CONNECTION_PROPERTY_DatabaseName=${xa_database:-${database}}
Expand All @@ -265,13 +271,25 @@ function declare_xa_variables {
get_svc_var "PORT" "PortNumber" $prefix $service
fi

# keep compatibility with *SERVICE_* envs, set connection-url for non ejb timer ds
local jdbcUrl="jdbc:${EJB_TIMER_DRIVER}://${host}:${port}/${database}"
case $EJB_TIMER_DRIVER in
microsoft|mssql|sqlserver)
jdbcUrl=jdbc:sqlserver://${host}:${port};databaseName=${database};
;;
*)
;;
esac

local nonxa=$(find_env ${prefix}_NONXA)
if [ "${nonxa^^}" = "TRUE" ]; then
eval export ${prefix}_URL="${jdbcUrl}"
else
eval ${prefix}_XA_CONNECTION_PROPERTY_URL="${jdbcUrl}"
fi

#postgresql/mariadb/mysql with custom drivers are not correctly configured if no PREFIX_URL is set
if [[ $EJB_TIMER_DRIVER = *"postgresql"* ]] || [[ $EJB_TIMER_DRIVER = *"mysql"* ]] || [[ $EJB_TIMER_DRIVER = *"mariadb"* ]]; then
local serviceHost=$(find_env "${service}_SERVICE_HOST")
local host=$(find_env "${prefix}_SERVICE_HOST" "${serviceHost}")
local servicePort=$(find_env "${service}_SERVICE_PORT")
local port=$(find_env "${prefix}_SERVICE_PORT" "${servicePort}")
local database=$(find_env "${prefix}_DATABASE")
local dbType="postgresql"
local enabledTLSParameterName="enabledSslProtocolSuites"
if [[ $EJB_TIMER_DRIVER = *"mysql"* ]]; then
Expand Down Expand Up @@ -304,6 +322,22 @@ function declare_xa_variables {

fix_ejbtimer_xa_url
fi

elif [ "x${url}" != "x" ]; then
# RHPAM-2261 - db2 does not accept URL/Url XA property
if [[ $EJB_TIMER_DRIVER = *"db2"* ]]; then
local unprefixedUrl=${url#jdbc:db2://}
local serverName=${unprefixedUrl%:*}
local dataBaseName=${unprefixedUrl#*/}
local portNumber=$(echo ${unprefixedUrl%/*} | awk -F: '{print $2}')

EJB_TIMER_XA_CONNECTION_PROPERTY_DatabaseName=${dataBaseName}
EJB_TIMER_XA_CONNECTION_PROPERTY_ServerName=${serverName}
EJB_TIMER_XA_CONNECTION_PROPERTY_PortNumber=${portNumber}

eval unset EJB_TIMER_XA_CONNECTION_PROPERTY_URL
eval unset EJB_TIMER_XA_CONNECTION_PROPERTY_Url
fi
fi
}

Expand Down
55 changes: 55 additions & 0 deletions jboss-kie-kieserver/tests/bats/jboss-kie-kieserver.bats
Expand Up @@ -53,6 +53,7 @@ teardown() {
export RHPAM_JTA="true"
configure_EJB_Timer_datasource >&2
echo "EJBTimer url is ${EJB_TIMER_XA_CONNECTION_PROPERTY_Url} " >&2
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
[ "${RHPAM_URL}" = "jdbc:mariadb://myapp-host:3306/rhpam-mariadb?enabledSslProtocolSuites=TLSv1.2" ]
Expand Down Expand Up @@ -80,6 +81,7 @@ teardown() {
configure_EJB_Timer_datasource >&2
echo "EJBTimer url is ${EJB_TIMER_XA_CONNECTION_PROPERTY_URL} " >&2
echo "RHPAM url is ${RHPAM_URL} " >&2
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
[ "${RHPAM_URL}" = "jdbc:mysql://myapp-host:3306/rhpam-mysql?enabledTLSProtocols=TLSv1.2" ]
Expand Down Expand Up @@ -110,6 +112,7 @@ teardown() {
configure_EJB_Timer_datasource >&2
echo "EJBTimer url is ${EJB_TIMER_XA_CONNECTION_PROPERTY_URL} " >&2
echo "RHPAM url is ${RHPAM_URL} " >&2
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
[ "${RHPAM_URL}" = "jdbc:mysql://myapp-host:3306/rhpam-mysql?enabledTLSProtocols=TLSv1.2" ]
Expand Down Expand Up @@ -137,6 +140,7 @@ teardown() {
export RHPAM_JTA="true"
configure_EJB_Timer_datasource >&2
echo "EJBTimer url is ${EJB_TIMER_XA_CONNECTION_PROPERTY_Url} " >&2
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
[ "${RHPAM_URL}" = "jdbc:${RHPAM_DRIVER}://${RHPAM_SERVICE_HOST}:${RHPAM_SERVICE_PORT}/${RHPAM_DATABASE}" ]
Expand Down Expand Up @@ -198,6 +202,7 @@ teardown() {
configure_EJB_Timer_datasource >&2
echo -en "EJB_TIMER env are: \n $(env | grep -i ejb_timer | sort -u) \n" >&2
log_info "EJB_TIMER_XA_CONNECTION_PROPERTY_URL is ${EJB_TIMER_XA_CONNECTION_PROPERTY_URL}"
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
# we do not expect that this var is set anymore, since we're using URL property directly
Expand All @@ -210,6 +215,56 @@ teardown() {
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_URL}" = "jdbc:${RHPAM_DRIVER}://${RHPAM_XA_CONNECTION_PROPERTY_ServerName}:${RHPAM_XA_CONNECTION_PROPERTY_Port}/${RHPAM_XA_CONNECTION_PROPERTY_DatabaseName}?pinGlobalTxToPhysicalConnection=true\&amp;enabledTLSProtocols=TLSv1.2" ]
}

@test "verify if EJB_TIMER is correctly configured with xa-data-sources when driver is db2 using SERVICE envs" {
local expected_timer_service="EJB_TIMER"
local expected_datasources="EJB_TIMER,RHPAM"
export DATASOURCES="RHPAM"
export RHPAM_DRIVER="db2"
export RHPAM_DATABASE="rhpam-db2"
export RHPAM_USERNAME="rhpam-user"
export RHPAM_PASSWORD="rhpam-pwd"
export RHPAM_SERVICE_HOST="myapp-host"
export RHPAM_SERVICE_PORT="50000"
export RHPAM_JNDI="jboss:/datasources/rhpam"
export RHPAM_JTA="true"
configure_EJB_Timer_datasource >&2
echo "RHPAM_URL url is ${RHPAM_URL} " >&2
echo "jdbc:${RHPAM_DRIVER}://${RHPAM_SERVICE_HOST}:${RHPAM_SERVICE_PORT}/${RHPAM_DATABASE}" >&2
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
[ "${RHPAM_URL}" = "jdbc:${RHPAM_DRIVER}://${RHPAM_SERVICE_HOST}:${RHPAM_SERVICE_PORT}/${RHPAM_DATABASE}" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_ServerName}" = "${RHPAM_SERVICE_HOST}" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_DatabaseName}" = "${RHPAM_DATABASE}" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_PortNumber}" = "${RHPAM_SERVICE_PORT}" ]
# the URL property must not be set
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_URL}" = "" ]
}

@test "verify if EJB_TIMER is correctly configured with xa-data-sources when driver is db2 using URL" {
local expected_timer_service="EJB_TIMER"
local expected_datasources="EJB_TIMER,RHPAM"
export DATASOURCES="RHPAM"
export RHPAM_DRIVER="db2"
export RHPAM_URL="jdbc:db2://myapp-host:50000/rhpam-db2"
export RHPAM_USERNAME="rhpam-user"
export RHPAM_PASSWORD="rhpam-pwd"
export RHPAM_JNDI="jboss:/datasources/rhpam"
export RHPAM_JTA="true"
configure_EJB_Timer_datasource >&2
echo "RHPAM_URL url is ${RHPAM_URL} " >&2
[ "${TIMER_SERVICE_DATA_STORE^^}" = "${expected_timer_service}" ]
[ "${DATASOURCES}" = "${expected_datasources}" ]
[ "${EJB_TIMER_DRIVER}" = "${RHPAM_DRIVER}" ]
[ "${RHPAM_URL}" = "jdbc:${RHPAM_DRIVER}://myapp-host:50000/rhpam-db2" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_ServerName}" = "myapp-host" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_DatabaseName}" = "rhpam-db2" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_PortNumber}" = "50000" ]
# the URL property must not be set
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_URL}" = "" ]
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_Url}" = "" ]
}

@test "check if kie server location is set according to the route" {
local expected="http://${HOSTNAME}:80/services/rest/server"
KIE_SERVER_ROUTE_NAME="my-route-name"
Expand Down

0 comments on commit 3ebd8c8

Please sign in to comment.