Skip to content

Commit

Permalink
tr(setup): update error message on unsupported vendors (#3180)
Browse files Browse the repository at this point in the history
* tr(setup): update error message on unsupported vendors
* fix(setup): also check bdm db vendor
  • Loading branch information
akantcheff authored Oct 2, 2024
1 parent 2320bdc commit ed949c8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# Bonita database properties
#########################################

# Valid values are: h2, postgres in Community edition, and also sqlserver, oracle, mysql in Subscription editions
# Valid values for Community edition: h2, postgres
# Valid values for Enterprise editions: h2, postgres, sqlserver, oracle, mysql
db.vendor=h2
# when using h2, no server or port setting is needed since connexion is made using file protocol mode using relative directory:
db.server.name=SERVER_NAME
Expand All @@ -24,7 +25,8 @@ db.password=
###################################
# Business Data database properties
###################################
# Valid values are: h2, postgres in Community edition, and also sqlserver, oracle, mysql in Subscription editions
# Valid values for Community edition: h2, postgres
# Valid values for Enterprise editions: h2, postgres, sqlserver, oracle, mysql
bdm.db.vendor=h2
bdm.db.server.name=SERVER_NAME
bdm.db.server.port=SERVER_PORT
Expand Down
43 changes: 36 additions & 7 deletions platform/platform-setup/src/main/standalone/setup.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
setlocal EnableDelayedExpansion

:: Let's position into folder containing this script:
:: Let's position into the folder containing this script:
set CURRENTDIR="%cd%"
set BASEDIR=%~dp0
cd %BASEDIR%
Expand All @@ -17,20 +17,49 @@ set LIB_FOLDER=%BASEDIR%\lib

FOR /F "tokens=1,* delims== eol=#" %%A IN (database.properties) DO (set %%A=%%B)
set BONITA_DATABASE=%db.vendor%
set BONITA_BDM_DATABASE=%bdm.db.vendor%

IF NOT "%BONITA_DATABASE%" == "h2" IF NOT "%BONITA_DATABASE%" == "postgres" (
echo Cannot determine database vendor valid values are [h2, postgres].
echo Please configure file %BASEDIR%database.properties properly.
call :checkVendorSupported %BONITA_DATABASE%
if ERRORLEVEL 1 (
exit /b 1
)
call :checkVendorSupported %BONITA_BDM_DATABASE%
if ERRORLEVEL 1 (
exit /b 1
)

"%JAVA_CMD%" -cp "%BASEDIR%;%CFG_FOLDER%;%INITIAL_CFG_FOLDER%;%LIB_FOLDER%\*" -Dsysprop.bonita.db.vendor=%BONITA_DATABASE% org.bonitasoft.platform.setup.PlatformSetupApplication %*
"%JAVA_CMD%" -cp "%BASEDIR%;%CFG_FOLDER%;%INITIAL_CFG_FOLDER%;%LIB_FOLDER%\*" ^
-Dsysprop.bonita.db.vendor=%BONITA_DATABASE% ^
-Dsysprop.bonita.bdm.db.vendor=%BONITA_BDM_DATABASE% ^
org.bonitasoft.platform.setup.PlatformSetupApplication %*

if errorlevel 1 (
if ERRORLEVEL 1 (
exit /b 1
)

:: restore previous folder:
cd %CURRENTDIR%

exit /b 0
:: exit script with success
exit /b 0


REM Function that exits with an error message if the vendor is not supported
REM - first argument is the database vendor value to check
:checkVendorSupported
set DB_VENDOR=%1
set IS_SUPPORTED=false
for %%d in (h2 postgres) do (
if "%%d" == "!DB_VENDOR!" (
set IS_SUPPORTED=true
goto :breakLoop
)
)
:breakLoop
if "!IS_SUPPORTED!" == "false" (
echo ERROR: Unsupported database vendor ^(valid values are h2, postgres^).
echo For access to additional databases ^(oracle, mysql, sqlserver^), please consider upgrading to the Enterprise Edition.
echo Please update file %BASEDIR%database.properties to set a valid value.
exit /b 1
)
exit /b 0
37 changes: 30 additions & 7 deletions platform/platform-setup/src/main/standalone/setup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
#!/bin/sh
set -e

BASEDIR=$(cd $(dirname $(dirname "$0")/..) && pwd -P)
# Function that exits with an error message if the vendor is not supported
# - first argument is the database vendor value to check
check_vendor_supported() {
db_vendor=$1
is_supported=false
# supported databases:
set -- h2 postgres
for db in "$@"; do
if [ "$db" = "$db_vendor" ]; then
is_supported=true
break
fi
done
if [ "$is_supported" = false ]; then
echo "ERROR: Unsupported database vendor (valid values are h2, postgres)."
echo "For access to additional databases (oracle, mysql, sqlserver), please consider upgrading to the Enterprise Edition."
echo "Please update file ${BASEDIR}/database.properties to set a valid value."
exit 1
fi
}

# Let's position into the folder containing this script:
BASEDIR=$(cd "$(dirname "$(dirname "$0")/..")" && pwd -P)
cd "${BASEDIR}"

# JAVA_CMD is exported by start-bonita.sh, so that same Java command is used:
Expand All @@ -15,14 +37,15 @@ for lib in lib/*.jar; do
done

BONITA_DATABASE=$(grep '^db.vendor=' database.properties | sed -e 's/db.vendor=//g')
check_vendor_supported "$BONITA_DATABASE"

if [ "$BONITA_DATABASE" != "h2" ] && [ "$BONITA_DATABASE" != "postgres" ]; then
echo "Cannot determine database vendor (valid values are h2, postgres)."
echo "Please configure file ${BASEDIR}/database.properties properly."
exit 1
fi
BONITA_BDM_DATABASE=$(grep '^bdm.db.vendor=' database.properties | sed -e 's/bdm.db.vendor=//g')
check_vendor_supported "$BONITA_BDM_DATABASE"

"${JAVA_EXE}" -cp "${BASEDIR}:${CFG_FOLDER}:${INITIAL_CFG_FOLDER}${LIBS_CP}" ${JVM_OPTS} -Dsysprop.bonita.db.vendor=${BONITA_DATABASE} org.bonitasoft.platform.setup.PlatformSetupApplication "$@"
"${JAVA_EXE}" -cp "${BASEDIR}:${CFG_FOLDER}:${INITIAL_CFG_FOLDER}${LIBS_CP}" "${JVM_OPTS}" \
-Dsysprop.bonita.db.vendor="${BONITA_DATABASE}" \
-Dsysprop.bonita.bdm.db.vendor="${BONITA_BDM_DATABASE}" \
org.bonitasoft.platform.setup.PlatformSetupApplication "$@"
COD_RET=$?
if [ ${COD_RET} -ne 0 ]; then
cd - 1>/dev/null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# Bonita database properties
#########################################

# Valid values are: h2, postgres in Community edition, and also sqlserver, oracle, mysql in Subscription editions
# Valid values for Community edition: h2, postgres
# Valid values for Enterprise editions: h2, postgres, sqlserver, oracle, mysql
db.vendor=h2
# when using h2, no server or port setting is needed since connexion is made using file protocol mode using relative directory:
db.server.name=SERVER_NAME
Expand All @@ -29,7 +30,8 @@ db.password=
###################################
# Business Data database properties
###################################
# Valid values are: h2, postgres in Community edition, and also sqlserver, oracle, mysql in Subscription editions
# Valid values for Community edition: h2, postgres
# Valid values for Enterprise editions: h2, postgres, sqlserver, oracle, mysql
bdm.db.vendor=h2
bdm.db.server.name=SERVER_NAME
bdm.db.server.port=SERVER_PORT
Expand Down

0 comments on commit ed949c8

Please sign in to comment.