Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.18.x] [CLOUD-3649] generating driver configuration according to DRIVERS environment variable #233

Open
wants to merge 1 commit into
base: 0.18.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1054,4 +1054,98 @@ function inject_job_repository() {
echo "${cli}" >> "${DEFAULT_JOB_REPOSITORY_FILE}"
fi

}
}

function clearDriverEnv() {
local prefix=$1

unset ${prefix}_DRIVER_MODULE
unset ${prefix}_DRIVER_NAME
unset ${prefix}_DRIVER_CLASS
unset ${prefix}_XA_DATASOURCE_CLASS
}

function clearDriversEnv() {
if [ -n "$DRIVERS" ]; then
for driver_prefix in $(echo $DRIVERS | sed "s/,/ /g"); do
clearDriverEnv $driver_prefix
done
unset DRIVERS
fi
}

function inject_drivers() {
# Add extensions from envs
if [ -n "$DRIVERS" ]; then
for driver_prefix in $(echo $DRIVERS | sed "s/,/ /g"); do
inject_driver $driver_prefix
done
fi
}

function inject_driver() {
local prefix=$1

local driver_module
local driver_name
local driver_class
local datasource_class

driver_module=$(find_env "${prefix}_DRIVER_MODULE")
if [ -z "$driver_module" ]; then
log_warning "Warning - ${prefix}_DRIVER_MODULE is missing from driver configuration. Driver will not be configured"
return
fi

driver_name=$(find_env "${prefix}_DRIVER_NAME")
if [ -z "$driver_name" ]; then
log_warning "Warning - ${prefix}_DRIVER_NAME is missing from driver configuration. Driver will not be configured"
return
fi

driver_class=$(find_env "${prefix}_DRIVER_CLASS")
datasource_class=$(find_env "${prefix}_XA_DATASOURCE_CLASS")
if [ -z "$driver_class" ] && [ -z "$datasource_class" ]; then
log_warning "Warning - ${prefix}_DRIVER_NAME and ${prefix}_XA_DATASOURCE_CLASS is missing from driver configuration. At least one is required. Driver will not be configured"
return
fi

local configMode
getConfigurationMode "<!-- ##DRIVERS## -->" "configMode"

if [ "${configMode}" = "xml" ]; then
driver="<driver name=\"$driver_name\" module=\"$driver_module\">"
if [ -n "$datasource_class" ]; then
driver="${driver}
<xa-datasource-class>${datasource_class}</xa-datasource-class>"
fi
if [ -n "$driver_class" ]; then
driver="${driver}
<driver-class>${driver_class}</driver-class>"
fi
driver="${driver}</driver>"
elif [ "${configMode}" = "cli" ]; then
driver="
if (outcome == success) of /subsystem=datasources/jdbc-driver=${driver_name}:read-resource
echo Cannot add the driver with name '${driver_name}'. There is a driver with the same name already configured. >> \${error_file}
exit
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@istudens , what would happen if a user used the s2i mechanism to install drivers (install.sh, configure-drivers, ...) and set the DRIVERS env variables (explicit export or --build-env). When the server would then start, the env variables would be present in the image and the server would fail to start. Did you try that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfdenise nope, I haven't tested combination with custom install.sh and configure-drivers out of it, I will do it

else
/subsystem=datasources/jdbc-driver=${driver_name}:add(driver-name=\"${driver_name}\", driver-module-name=\"${driver_module}\""
if [ -n "$datasource_class" ]; then
driver="${driver}, driver-xa-datasource-class-name=\"${datasource_class}\""
fi
if [ -n "$driver_class" ]; then
driver="${driver}, driver-class-name=\"${driver_class}\""
fi
driver="${driver})
end-if"
fi

if [ -n "$driver" ]; then
if [ "${configMode}" = "xml" ]; then
sed -i "s|<!-- ##DRIVERS## -->|${driver}\n<!-- ##DRIVERS## -->|" $CONFIG_FILE
elif [ "${configMode}" = "cli" ]; then
echo "${driver}" >> ${CLI_SCRIPT_FILE}
fi
fi
}
Expand Up @@ -21,17 +21,20 @@ function preConfigure() {

function prepareEnv() {
initTempFiles
clearDriversEnv
clearDatasourcesEnv
clearTxDatasourceEnv
}

function configure() {
initTempFiles
inject_drivers
inject_datasources
}

function configureEnv() {
initTempFiles
inject_drivers
inject_external_datasources

# TODO - I don't think this is being used any more? The real action seems to be in tx-datasource.sh
Expand Down Expand Up @@ -93,4 +96,4 @@ function generate_datasource() {
local url="${14}"

generate_datasource_common "${1}" "${2}" "${3}" "${4}" "${5}" "${6}" "${7}" "${8}" "${9}" "${10}" "${11}" "${12}" "${13}" "${14}"
}
}