From c65bda32f59601f1ea2384f64536fe4ab23c5796 Mon Sep 17 00:00:00 2001 From: mazano Date: Sat, 17 Feb 2024 08:51:48 +0200 Subject: [PATCH] Hazelcast caching with jdbc (#623) * fix hazelcast --- .../hazelcast_cluster/cluster.properties | 12 + build_data/hazelcast_cluster/hazelcast.xml | 43 +++ build_data/hazelcast_cluster/web.xml | 262 ++++++++++++++++++ scripts/entrypoint.sh | 6 +- scripts/functions.sh | 71 +++-- 5 files changed, 374 insertions(+), 20 deletions(-) create mode 100644 build_data/hazelcast_cluster/cluster.properties create mode 100644 build_data/hazelcast_cluster/hazelcast.xml create mode 100644 build_data/hazelcast_cluster/web.xml diff --git a/build_data/hazelcast_cluster/cluster.properties b/build_data/hazelcast_cluster/cluster.properties new file mode 100644 index 00000000..86f20e57 --- /dev/null +++ b/build_data/hazelcast_cluster/cluster.properties @@ -0,0 +1,12 @@ +enabled = true +sync_method = event +sync_delay = 5 +session_sharing = true +session_sticky = false +acktimeout = 2000 +#Disabling the hazelcast shutdown hook +shutdown_hook_enable = false +#Setting the hazelcast logging type to log4j +logging_type = "log4j" +logger.com-hazelcast.name = com.hazelcast +logger.com-hazelcast.level = INFO \ No newline at end of file diff --git a/build_data/hazelcast_cluster/hazelcast.xml b/build_data/hazelcast_cluster/hazelcast.xml new file mode 100644 index 00000000..4cd810c1 --- /dev/null +++ b/build_data/hazelcast_cluster/hazelcast.xml @@ -0,0 +1,43 @@ + + + + geoserver-cluster + ${INSTANCE_STRING} + + + + log4j2 + + + + + 5701 + + + 224.2.2.3 + 54327 + + + 127.0.0.1 + + + my-access-key + my-secret-key + us-east-1 + + + + diff --git a/build_data/hazelcast_cluster/web.xml b/build_data/hazelcast_cluster/web.xml new file mode 100644 index 00000000..fcf9ef4b --- /dev/null +++ b/build_data/hazelcast_cluster/web.xml @@ -0,0 +1,262 @@ + + + + GeoServer + + + serviceStrategy + + PARTIAL-BUFFER2 + + + + + enableVersioning + true + + + + + + + PARTIAL_BUFFER_STRATEGY_SIZE + 50 + + + + + + + + + contextConfigLocation + classpath*:/applicationContext.xml classpath*:/applicationSecurityContext.xml + + + + + hazelcast + org.geoserver.cluster.hazelcast.web.HzSessionShareFilter + + + + SessionDebugger + org.geoserver.filters.SessionDebugFilter + + + + filterChainProxy + org.springframework.web.filter.DelegatingFilterProxy + + + + + + Set Character Encoding + org.vfny.geoserver.filters.SetCharacterEncodingFilter + + encoding + UTF-8 + + + + + GZIP Compression Filter + org.geoserver.filters.GZIPFilter + + + compressed-types + text/.*,.*xml.*,application/json,application/x-javascript + + + + + Request Logging Filter + org.geoserver.filters.LoggingFilter + + + enabled + false + + + + log-request-bodies + false + + + + + Advanced Dispatch Filter + org.geoserver.platform.AdvancedDispatchFilter + + + + + Spring Delegating Filter + org.geoserver.filters.SpringDelegatingFilter + + + + + Thread locals cleanup filter + org.geoserver.filters.ThreadLocalsCleanupFilter + + + + + hazelcast + /* + + + + SessionDebugger + /* + + + + GZIP Compression Filter + /* + + + + Request Logging Filter + /* + + + + + filterChainProxy + /* + + + + Set Character Encoding + /* + + + + Advanced Dispatch Filter + /* + + + + Spring Delegating Filter + /* + + + + Thread locals cleanup filter + /* + + + + + org.geoserver.cluster.hazelcast.web.HzSessionShareListener + + + + + org.geoserver.GeoserverInitStartupListener + + + + + org.geoserver.logging.LoggingStartupContextListener + + + + + org.geoserver.platform.GeoServerContextLoaderListener + + + + + org.geoserver.platform.GeoServerHttpSessionListenerProxy + + + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + + + + + dispatcher + /* + + + + xsl + text/xml + + + sld + text/xml + + + + index.html + + + diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index f5ed472e..625f2136 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -117,9 +117,13 @@ if [[ ${RUN_AS_ROOT} =~ [Ff][Aa][Ll][Ss][Ee] ]];then chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOSERVER_DATA_DIR}"/jdbcconfig fi - if [[ -d "${GEOSERVER_DATA_DIR}"/jdbcconfig ]];then + if [[ -d "${GEOSERVER_DATA_DIR}"/jdbcstore ]];then chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOSERVER_DATA_DIR}"/jdbcstore fi + # hazel cluster + if [[ -d "${GEOSERVER_DATA_DIR}"/cluster ]];then + chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOSERVER_DATA_DIR}"/cluster + fi fi diff --git a/scripts/functions.sh b/scripts/functions.sh index c0cb8426..62eda5f8 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -578,15 +578,20 @@ function setup_jdbc_db_config() { PGPASSWORD="${POSTGRES_PASS}" export PGPASSWORD postgres_ready_status "${HOST}" "${POSTGRES_PORT}" "${POSTGRES_USER}" "$POSTGRES_DB" - if [[ -d "${GEOSERVER_DATA_DIR}"/jdbcconfig ]];then - rm -r "${GEOSERVER_DATA_DIR}"/jdbcconfig - else - create_dir "${GEOSERVER_DATA_DIR}"/jdbcconfig - fi - cp -r /build_data/jdbcconfig/scripts/ "${GEOSERVER_DATA_DIR}"/jdbcconfig + create_dir "${GEOSERVER_DATA_DIR}"/jdbcconfig + cp -r /build_data/jdbcconfig/scripts "${GEOSERVER_DATA_DIR}"/jdbcconfig/ postgres_ssl_setup export SSL_PARAMETERS=${PARAMS} - envsubst < /build_data/jdbcconfig/jdbcconfig.properties > "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties + if [[ -f "${EXTRA_CONFIG_DIR}"/jdbcconfig.properties ]]; then + envsubst < "${EXTRA_CONFIG_DIR}"/jdbcconfig.properties > "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties + else + envsubst < /build_data/jdbcconfig/jdbcconfig.properties > "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties + fi + check_jdbc_config_table=$(psql -d "$POSTGRES_DB" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -h "$HOST" -tAc "SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'object_property')") + if [[ ${check_jdbc_config_table} = "t" ]]; then + sed -i 's/initdb=true/initdb=false/g' "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties + sed -i 's/import=true/import=false/g' "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties + fi else echo "skipping jdbc config and will use default settings" fi @@ -600,24 +605,52 @@ function setup_jdbc_db_store() { export PGPASSWORD postgres_ready_status "${HOST}" "${POSTGRES_PORT}" "${POSTGRES_USER}" "$POSTGRES_DB" if [[ ${DB_BACKEND} =~ [Pp][Oo][Ss][Tt][Gg][Rr][Ee][Ss] ]]; then - if [[ -d "${GEOSERVER_DATA_DIR}"/jdbcstore ]];then - rm -r "${GEOSERVER_DATA_DIR}"/jdbcstore + create_dir "${GEOSERVER_DATA_DIR}"/jdbcstore + create_dir "${GEOSERVER_DATA_DIR}"/jdbcconfig + cp -r /build_data/jdbcstore/scripts "${GEOSERVER_DATA_DIR}"/jdbcstore/ + cp -r /build_data/jdbcconfig/scripts "${GEOSERVER_DATA_DIR}"/jdbcconfig/ + postgres_ssl_setup + export SSL_PARAMETERS=${PARAMS} + if [[ -f "${EXTRA_CONFIG_DIR}"/jdbcconfig.properties ]]; then + envsubst < "${EXTRA_CONFIG_DIR}"/jdbcconfig.properties > "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties else - create_dir "${GEOSERVER_DATA_DIR}"/jdbcstore + envsubst < /build_data/jdbcconfig/jdbcconfig.properties > "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties fi - if [[ -d "${GEOSERVER_DATA_DIR}"/jdbcconfig ]];then - rm -r "${GEOSERVER_DATA_DIR}"/jdbcconfig + if [[ -f "${EXTRA_CONFIG_DIR}"/jdbcstore.properties ]]; then + envsubst < "${EXTRA_CONFIG_DIR}"/jdbcstore.properties > "${GEOSERVER_DATA_DIR}"/jdbcstore/jdbcstore.propertiesproperties else - create_dir "${GEOSERVER_DATA_DIR}"/jdbcconfig + envsubst < /build_data/jdbcstore/jdbcstore.properties > "${GEOSERVER_DATA_DIR}"/jdbcstore/jdbcstore.propertiesproperties + fi + + check_jdbc_store_table=$(psql -d "$POSTGRES_DB" -p "${POSTGRES_PORT}" -U "${POSTGRES_USER}" -h "${HOST}" -tAc "SELECT EXISTS(SELECT 1 from information_schema.tables where table_name = 'resources')") + if [[ ${check_jdbc_store_table} = "t" ]]; then + sed -i 's/initdb=true/initdb=false/g' "${GEOSERVER_DATA_DIR}"/jdbcstore/jdbcstore.properties + sed -i 's/import=true/import=false/g' "${GEOSERVER_DATA_DIR}"/jdbcstore/jdbcstore.properties + fi + check_jdbc_config_table=$(psql -d "$POSTGRES_DB" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -h "$HOST" -tAc "SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'object_property')") + if [[ ${check_jdbc_config_table} = "t" ]]; then + sed -i 's/initdb=true/initdb=false/g' "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties + sed -i 's/import=true/import=false/g' "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties fi - cp -r /build_data/jdbcstore/scripts/ "${GEOSERVER_DATA_DIR}"/jdbcstore - cp -r /build_data/jdbcconfig/scripts/ "${GEOSERVER_DATA_DIR}"/jdbcconfig - postgres_ssl_setup - export SSL_PARAMETERS=${PARAMS} - envsubst < /build_data/jdbcconfig/jdbcconfig.properties > "${GEOSERVER_DATA_DIR}"/jdbcconfig/jdbcconfig.properties - envsubst < /build_data/jdbcstore/jdbcstore.properties > "${GEOSERVER_DATA_DIR}"/jdbcstore/jdbcstore.properties else echo "skipping jdbc store config and will use default settings" fi fi +} + +function setup_hz_cluster() { + # TODO Add http://og.cens.am:8081/opengeo-docs/sysadmin/clustering/setup.html#session-sharing + if [[ ${ext} == 'hz-cluster-plugin' ]];then + create_dir "${GEOSERVER_DATA_DIR}"/cluster + if [[ -f "${EXTRA_CONFIG_DIR}"/hazelcast_cluster.properties ]]; then + envsubst < "${EXTRA_CONFIG_DIR}"/hazelcast_cluster.properties > "${GEOSERVER_DATA_DIR}"/cluster/cluster.properties + else + envsubst < /build_data/hazelcast_cluster/cluster.properties > "${GEOSERVER_DATA_DIR}"/cluster/cluster.properties + fi + if [[ -f "${EXTRA_CONFIG_DIR}"/hazelcast.xml ]]; then + envsubst < "${EXTRA_CONFIG_DIR}"/hazelcast.xml > "${GEOSERVER_DATA_DIR}"/cluster/hazelcast.xml + else + envsubst < /build_data/hazelcast_cluster/hazelcast.xml > "${GEOSERVER_DATA_DIR}"/cluster/hazelcast.xml + fi + fi } \ No newline at end of file