Skip to content

Commit

Permalink
RHPAM-2261] - DB2 fails with externaldb template (#300)
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 29, 2019
1 parent 722c723 commit dcb463e
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 24 deletions.
77 changes: 77 additions & 0 deletions jboss-kie-kieserver/added/launch/jboss-kie-cli-datasource-patch.sh
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# Note that, this is a temporary script until https://issues.jboss.org/browse/CLOUD-2903
# TODO: remove it once the fix for the issue above is available. Follow up task https://issues.jboss.org/browse/KIECLOUD-311
#
# It's purpose is to add two xa-pool properties for XA datasources which are not exposed
# by environment variables on EAP datasource configuration script.
#
# This script will accept only two envs:
#
# ${DATASOURCE_PREFIX}_IS_SAME_RM_OVERRIDE
# /subsystem=datasources/xa-data-source=test-TEST:write-attribute(name=same-rm-override, value=true)
# Should result on <is-same-rm-override>true</is-same-rm-override>
# ${DATASOURCE_PREFIX}_NO_TX_SEPARATE_POOLS
# /subsystem=datasources/xa-data-source=test-TEST:write-attribute(name=no-tx-separate-pool,value=true)
# Should result on <no-tx-separate-pools>true</no-tx-separate-pools>
#
source "${JBOSS_HOME}/bin/launch/launch-common.sh"
source "${JBOSS_HOME}/bin/launch/logging.sh"

function configure() {
override_xa_datasource
}

function override_xa_datasource() {
local patch_needed="FALSE"

for dsPrefix in $(echo $DATASOURCES | sed "s/,/ /g"); do
nonxa=$(find_env "${dsPrefix}_NONXA")

if [ "${nonxa^^}" == "FALSE" ]; then

is_same_rm_override=$(find_env "${dsPrefix}_IS_SAME_RM_OVERRIDE")
no_tx_separate_pools=$(find_env "${dsPrefix}_NO_TX_SEPARATE_POOLS")

# not set by default, needs to allow to set true or false.
if [ "${is_same_rm_override^^}" == "TRUE" ]; then
local value="true"
if [ "${is_same_rm_override^^}" == "FALSE" ]; then
value="false"
fi
patch_needed="TRUE"
echo "/subsystem=datasources/xa-data-source=${dsPrefix,,}-${dsPrefix^^}:write-attribute(name=same-rm-override, value=${value})" >> /tmp/datasource-patch.cli
fi
# no need to set false value since its default value is false.
if [ "${no_tx_separate_pools^^}" == "TRUE" ]; then
patch_needed="TRUE"
echo "/subsystem=datasources/xa-data-source=${dsPrefix,,}-${dsPrefix^^}:write-attribute(name=no-tx-separate-pool, value=true)" >> /tmp/datasource-patch.cli
fi
fi
done

if [ "${patch_needed^^}" == "TRUE" ]; then
# last, add shutdown instruction to stop eap admin mode
echo "shutdown" >> /tmp/datasource-patch.cli

log_info "Starting EAP on admin-only mode to apply post datasource configuration."
$JBOSS_HOME/bin/standalone.sh --admin-only --server-config="standalone-openshift.xml" &
JBOSS_PID=$(echo $!)

# wait eap finish to start on admin mode
start=$(date +%s)
end=$((start + 120))
until $JBOSS_HOME/bin/jboss-cli.sh --command="connect" || [ $(date +%s) -ge "$end" ]; do
sleep 5
done

log_info "Executing the following cli commands: "
log_info "`cat /tmp/datasource-patch.cli`"

$JBOSS_HOME/bin/jboss-cli.sh --connect --file=/tmp/datasource-patch.cli
if [ $? -ne 0 ]; then
kill -15 $JBOSS_PID
fi
log_info "The file /tmp/datasource-patch.cli will be kept for further review."
fi
}

63 changes: 54 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,14 +157,18 @@ 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")
fi

# EJB timer needs to be XA.
EJB_TIMER_NONXA="false"
# If set, applies the same value to EJB_TIMER datasource
# To apply only for EJB_TIMER datasource set the envs using the EJB_TIMER prefix.
EJB_TIMER_IS_SAME_RM_OVERRIDE=$(find_env "${prefix}_IS_SAME_RM_OVERRIDE" "${EJB_TIMER_IS_SAME_RM_OVERRIDE}")
EJB_TIMER_NO_TX_SEPARATE_POOLS=$(find_env "${prefix}_NO_TX_SEPARATE_POOLS" "${EJB_TIMER_NO_TX_SEPARATE_POOLS}")

EJB_TIMER_MAX_POOL_SIZE=${EJB_TIMER_MAX_POOL_SIZE:-"10"}
EJB_TIMER_MIN_POOL_SIZE=${EJB_TIMER_MIN_POOL_SIZE:-"10"}
Expand Down Expand Up @@ -255,6 +260,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 +275,32 @@ 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
if [[ "$(eval echo \$${prefix}_DRIVER)" = *"db2"* ]]; then
eval ${prefix}_XA_CONNECTION_PROPERTY_DatabaseName="${xa_database:-${database}}"
eval ${prefix}_XA_CONNECTION_PROPERTY_ServerName=${host}
eval ${prefix}_XA_CONNECTION_PROPERTY_PortNumber=${port}

else
eval ${prefix}_XA_CONNECTION_PROPERTY_URL="${jdbcUrl}"
fi
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 +333,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
2 changes: 2 additions & 0 deletions jboss-kie-kieserver/added/openshift-launch.sh
Expand Up @@ -35,6 +35,8 @@ CONFIGURE_SCRIPTS=(
$JBOSS_HOME/bin/launch/jboss-kie-kieserver.sh
$JBOSS_HOME/bin/launch/jboss-kie-kieserver-jms.sh
$JBOSS_HOME/bin/launch/jboss-kie-wildfly-config-files-formatter.sh
# TODO remove once https://issues.jboss.org/browse/CLOUD-2903 is done, follow up task https://issues.jboss.org/browse/KIECLOUD-311
$JBOSS_HOME/bin/launch/jboss-kie-cli-datasource-patch.sh
/opt/run-java/proxy-options
)

Expand Down
94 changes: 91 additions & 3 deletions jboss-kie-kieserver/tests/bats/jboss-kie-kieserver.bats
Expand Up @@ -39,7 +39,7 @@ teardown() {
[ "${RHPAM_XA_CONNECTION_PROPERTY_URL}" = "${RHPAM_URL}" ]
}

@test "verify if EJB_TIMER is correctly configured with xa-data-sources when driver is mariadb" {
@test "verify if EJB_TIMER is correctly configured with data-sources when driver is mariadb" {
local expected_timer_service="EJB_TIMER"
local expected_datasources="EJB_TIMER,RHPAM"
export DATASOURCES="RHPAM"
Expand All @@ -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 All @@ -65,7 +66,7 @@ teardown() {
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_Url}" = "jdbc:mariadb://myapp-host:3306/rhpam-mariadb?pinGlobalTxToPhysicalConnection=true\&amp;enabledSslProtocolSuites=TLSv1.2" ]
}

@test "verify if EJB_TIMER is correctly configured with xa-data-sources when driver is mysql" {
@test "verify if EJB_TIMER is correctly configured with data-sources when driver is mysql" {
local expected_timer_service="EJB_TIMER"
local expected_datasources="EJB_TIMER,RHPAM"
export DATASOURCES="RHPAM"
Expand All @@ -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 All @@ -123,7 +126,7 @@ teardown() {
[ "${EJB_TIMER_XA_CONNECTION_PROPERTY_URL}" = "jdbc:mysql://myapp-host:3306/rhpam-mysql?pinGlobalTxToPhysicalConnection=true\&amp;enabledTLSProtocols=TLSv1.2" ]
}

@test "verify if EJB_TIMER is correctly configured with xa-data-sources when driver is postgresql" {
@test "verify if EJB_TIMER is correctly configured with data-sources when driver is postgresql" {
local expected_timer_service="EJB_TIMER"
local expected_datasources="EJB_TIMER,RHPAM"
export DATASOURCES="RHPAM"
Expand All @@ -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,89 @@ 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 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 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 "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="java:/jboss/datasources/rhpam"
export RHPAM_JTA="true"
export RHPAM_NONXA="false"
configure_EJB_Timer_datasource >&2
echo "RHPAM_URL url is ${RHPAM_URL} " >&2
echo "RHPAM_XA_CONNECTION_PROPERTY_URL is ${RHPAM_XA_CONNECTION_PROPERTY_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}" = "" ]
[ "${RHPAM_XA_CONNECTION_PROPERTY_URL}" = "" ]
[ "${RHPAM_XA_CONNECTION_PROPERTY_ServerName}" = "${RHPAM_SERVICE_HOST}" ]
[ "${RHPAM_XA_CONNECTION_PROPERTY_DatabaseName}" = "${RHPAM_DATABASE}" ]
[ "${RHPAM_XA_CONNECTION_PROPERTY_PortNumber}" = "${RHPAM_SERVICE_PORT}" ]

[ "${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 "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 dcb463e

Please sign in to comment.