diff --git a/.gitignore b/.gitignore index c89da4648..f113d0974 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,5 @@ hs_err_pid* /dependences/ /build/ *.properties - # skip folder dependencies !dependencies/*.jar diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index 5afa053f1..5036bb095 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -1,4 +1,4 @@ -arguments=--init-script /home/yamel/.config/Code/User/globalStorage/redhat.java/1.24.0/config_linux/org.eclipse.osgi/55/0/.cp/gradle/init/init.gradle --init-script /home/yamel/.config/Code/User/globalStorage/redhat.java/1.24.0/config_linux/org.eclipse.osgi/55/0/.cp/gradle/protobuf/init.gradle +arguments= auto.sync=false build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.4.2)) diff --git a/README.es.md b/README.es.md index 8362a7747..b8d939ecd 100644 --- a/README.es.md +++ b/README.es.md @@ -99,9 +99,13 @@ Para utilizar esta imagen Docker debe tener su motor Docker versión mayor o igu * `DB_NAME`: Nombre de la base de datos que Adempiere-Backend utilizará para conectarse con la base de datos. Por defecto: `adempiere`. * `DB_USER`: Usuario de base de datos que Adempiere-Backend utilizará para conectarse con la base de datos. Por defecto: `adempiere`. * `DB_PASSWORD`: Contraseña de la base de datos que Adempiere-Backend utilizará para conectarse con la base de datos. Por defecto: `adempiere`. - * `JWT_SECRET_KEY`: Clave secreta, para el hash de encriptado del JSON Web Token, el valor por defecto es `4C74928D8BA93C0708D28773A6FD273F63482CF8B3FC0AD11355A8E9CD583AD5` esta debe ser cambiada obligatoriamente por seguridad. Ver https://www.grc.com/passwords.htm. - * `JWT_EXPIRATION_TIME`: Tiempo de expiración en milisegundos, vida util del JSON Web Token desde que se genera, el valor por defecto es `86400000` milisegundos, es decir 24 horas. - * `ADEMPIERE_APPS_TYPE`: Tipo de aplicación para la conexión de gestión de bases de datos. Por defecto: `wildfly`. + * `IDLE_TIMEOUT`: Establece el tiempo máximo que una conexión puede permanecer sin uso antes de cerrarse para liberar recursos. Por defecto: `300`. + * `MINIMUM_IDLE`: Establece la cantidad mínima de conexiones que deben mantenerse abiertas y listas para usar, incluso si no se están utilizando actualmente. Esto ayuda a mejorar el rendimiento al reducir el tiempo que lleva obtener una conexión. Por defecto: `1`. + * `MAXIMUM_POOL_SIZE`: Establece la cantidad máxima de conexiones que pueden estar abiertas al mismo tiempo. Esto ayuda a evitar que el grupo crezca demasiado y utilice demasiada memoria. Por defecto: `10`. + * `CONNECTION_TIMEOUT`: Establece el tiempo máximo que HikariCP esperará para obtener una conexión del grupo antes de darse por vencido y generar un error. Por defecto: `5000`. + * `MAXIMUM_LIFETIME`: Establece la cantidad máxima de tiempo que una conexión puede permanecer abierta en el pool antes de que se cierre automáticamente. Esto ayuda a mantener el pool limpio y evita problemas. Por defecto: `6000`. + * `KEEPALIVE_TIME`: Establece una consulta de prueba que HikariCP ejecutará en las conexiones para asegurarse de que aún funcionan correctamente. Por defecto: `360000`. + * `CONNECTION_TEST_QUERY`: Establece la frecuencia con la que HikariCP comprobará si una conexión sigue funcionando correctamente. Esto ayuda a evitar problemas con conexiones que podrían quedar inactivas. Por defecto: `SELECT 1` * `SERVER_PORT`: Puerto para acceder a Adempiere-Backend desde fuera del contenedor. Por defecto: `50059`. * `SERVER_LOG_LEVEL`: Nivel de Bitácora. Por defecto: `WARNING`. * `TZ`: (Time Zone) Indica la zona horaria a establecer en el contenedor basado en nginx, el valor por defecto es `America/Caracas` (UTC -4:00). @@ -117,9 +121,14 @@ gradle assemble gradle build ``` -Construir imagen docker +Construir imagen (alpine) ```shell -docker build -t solopcloud/adempiere-backend:dev -f ./build-docker/development.Dockerfile . +docker build -t solopcloud/adempiere-backend:alpine-dev -f ./docker/alpine.Dockerfile . +``` + +Construir imagen (multi-arch) +```shell +docker build -t solopcloud/adempiere-backend:dev -f ./docker/focal.Dockerfile . ``` ### Descargar imagen docker: diff --git a/README.md b/README.md index 3660b6ad3..684c299d9 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,13 @@ To use this Docker image you must have your Docker engine version greater than o * `DB_NAME`: Database name that Adempiere-Backend will use to connect with the database. Default: `adempiere`. * `DB_USER`: Database user that Adempiere-Backend will use to connect with the database. Default: `adempiere`. * `DB_PASSWORD`: Database password that Adempiere-Backend will use to connect with the database. Default: `adempiere`. - * `JWT_SECRET_KEY`: Secret key, for the encryption hash of the JSON Web Token, the default value is `4C74928D8BA93C0708D28773A6FD273F63482CF8B3FC0AD11355A8E9CD583AD5` this must be changed for security reasons. See https://www.grc.com/passwords.htm. - * `JWT_EXPIRATION_TIME`: Expiration time in milliseconds, lifetime of the JSON Web Token since it is generated, the default value is `86400000` milliseconds, that is 24 hours. - * `ADEMPIERE_APPS_TYPE`: Application Type for Database Management Connection. Default: `wildfly`. + * `IDLE_TIMEOUT`: It sets the maximum time a connection can sit around without being used before it gets closed to free up resources. Default: `300`. + * `MINIMUM_IDLE`: It sets the minimum number of connections that should be kept open and ready to use, even if they're not currently being used. This helps improve performance by reducing the time it takes to get a connection. Default: `1`. + * `MAXIMUM_POOL_SIZE`: It sets the maximum number of connections that can be open at the same time. This helps prevent the pool from getting too big and using up too much memory. Default: `10`. + * `CONNECTION_TIMEOUT`: it sets the maximum time HikariCP will wait to get a connection from the pool before giving up and throwing an error. Default: `5000`. + * `MAXIMUM_LIFETIME`: It sets the maximum amount of time a connection can stay open in the pool before it's automatically closed. This helps keep the pool clean and prevents problems. Default: `6000`. + * `KEEPALIVE_TIME`: It sets a test query that HikariCP will run on connections to make sure they're still working properly. Default: `360000`. + * `CONNECTION_TEST_QUERY`: It sets how often HikariCP will check if a connection is still working properly. This helps prevent problems with connections that might become inactive. Default: `SELECT 1` * `SERVER_PORT`: Port to access Adempiere-Backend from outside of the container. Default: `50059`. * `SERVER_LOG_LEVEL`: Log Level. Default: `WARNING`. * `TZ`: (Time Zone) Indicates the time zone to set in the nginx-based container, the default value is `America/Caracas` (UTC -4:00). @@ -117,9 +121,14 @@ gradle assemble gradle build ``` -Build docker image +Build docker image (alpine) ```shell -docker build -t solopcloud/adempiere-backend:dev -f ./build-docker/development.Dockerfile . +docker build -t solopcloud/adempiere-backend:alpine-dev -f ./docker/alpine.Dockerfile . +``` + +Build docker image (multi-arch) +```shell +docker build -t solopcloud/adempiere-backend:dev -f ./docker/focal.Dockerfile . ``` ### Download docker image: diff --git a/build.gradle b/build.gradle index bc22b9564..46d53f58d 100644 --- a/build.gradle +++ b/build.gradle @@ -71,7 +71,7 @@ dependencies { compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // ADempiere Core + Patches + Features - implementation "com.solop:adempiere.solop_libs:3.9.4.001-1.0.9" + implementation "com.solop:adempiere.solop_libs:3.9.4.001-1.1.2" } configurations.all { diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile index 246ed3840..1333d6d86 100644 --- a/docker/alpine.Dockerfile +++ b/docker/alpine.Dockerfile @@ -7,15 +7,19 @@ LABEL maintainer="ySenih@erpya.com; EdwinBetanc0urt@outlook.com;" \ ENV \ SERVER_PORT="50059" \ SERVER_LOG_LEVEL="WARNING" \ - JWT_SECRET_KEY="2C51599F5B1248F945B93E05EFC43B3A15D8EB0707C0F02FD97028786C40976F" \ - JWT_EXPIRATION_TIME=86400000 \ DB_HOST="localhost" \ DB_PORT="5432" \ DB_NAME="adempiere" \ DB_USER="adempiere" \ DB_PASSWORD="adempiere" \ DB_TYPE="PostgreSQL" \ - ADEMPIERE_APPS_TYPE="wildfly" \ + IDLE_TIMEOUT="300" \ + MINIMUM_IDLE="1" \ + MAXIMUM_POOL_SIZE="10" \ + CONNECTION_TIMEOUT="5000" \ + MAXIMUM_LIFETIME="6000" \ + KEEPALIVE_TIME="360000" \ + CONNECTION_TEST_QUERY="\"SELECT 1\"" \ SYSTEM_LOGO_URL="" \ TZ="America/Caracas" diff --git a/docker/env.yaml b/docker/env.yaml index 5e8960907..5fd0c2ae8 100644 --- a/docker/env.yaml +++ b/docker/env.yaml @@ -2,9 +2,6 @@ server: port: 50059 host: localhost log_level: WARNING - jwt_secret_key: fill_secret_key - # Default 24 hours - jwt_expiration_time: fill_expiration_time database: host: localhost port: 5432 @@ -12,3 +9,10 @@ database: user: adempiere_user_value password: adempiere_pass_value type: PostgreSQL + idle_timeout: fill_idle_timeout + minimum_idle: fill_minimum_idle + maximum_pool_size: fill_maximum_pool_size + connection_timeout: fill_connection_timeout + maximum_lifetime: fill_maximum_lifetime + keepalive_time: fill_keepalive_time + connection_test_query: fill_connection_test_query \ No newline at end of file diff --git a/docker/focal.Dockerfile b/docker/focal.Dockerfile index d26257e99..53a6df9d9 100644 --- a/docker/focal.Dockerfile +++ b/docker/focal.Dockerfile @@ -7,15 +7,19 @@ LABEL maintainer="ySenih@erpya.com; EdwinBetanc0urt@outlook.com;" \ ENV \ SERVER_PORT="50059" \ SERVER_LOG_LEVEL="WARNING" \ - JWT_SECRET_KEY="2C51599F5B1248F945B93E05EFC43B3A15D8EB0707C0F02FD97028786C40976F" \ - JWT_EXPIRATION_TIME=86400000 \ DB_HOST="localhost" \ DB_PORT="5432" \ DB_NAME="adempiere" \ DB_USER="adempiere" \ DB_PASSWORD="adempiere" \ DB_TYPE="PostgreSQL" \ - ADEMPIERE_APPS_TYPE="wildfly" \ + IDLE_TIMEOUT="300" \ + MINIMUM_IDLE="1" \ + MAXIMUM_POOL_SIZE="10" \ + CONNECTION_TIMEOUT="5000" \ + MAXIMUM_LIFETIME="6000" \ + KEEPALIVE_TIME="360000" \ + CONNECTION_TEST_QUERY="\"SELECT 1\"" \ SYSTEM_LOGO_URL="" \ TZ="America/Caracas" diff --git a/docker/start.sh b/docker/start.sh index a8af0c500..c86cbe78e 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -4,8 +4,6 @@ # Set server values sed -i "s|50059|$SERVER_PORT|g" env.yaml sed -i "s|WARNING|$SERVER_LOG_LEVEL|g" env.yaml -sed -i "s|fill_secret_key|$JWT_SECRET_KEY|g" env.yaml -sed -i "s|fill_expiration_time|$JWT_EXPIRATION_TIME|g" env.yaml export DEFAULT_JAVA_OPTIONS='"-Xms64M" "-Xmx1512M"' @@ -16,7 +14,13 @@ sed -i "s|adempiere_token_value|$SERVER_PRIVATE_KEY|g" env.yaml sed -i "s|adempiere_database_value|$DB_NAME|g" env.yaml sed -i "s|adempiere_user_value|$DB_USER|g" env.yaml sed -i "s|adempiere_pass_value|$DB_PASSWORD|g" env.yaml -sed -i "s|PostgreSQL|$DB_TYPE|g" env.yaml +sed -i "s|fill_idle_timeout|$IDLE_TIMEOUT|g" env.yaml +sed -i "s|fill_minimum_idle|$MINIMUM_IDLE|g" env.yaml +sed -i "s|fill_maximum_pool_size|$MAXIMUM_POOL_SIZE|g" env.yaml +sed -i "s|fill_connection_timeout|$CONNECTION_TIMEOUT|g" env.yaml +sed -i "s|fill_maximum_lifetime|$MAXIMUM_LIFETIME|g" env.yaml +sed -i "s|fill_keepalive_time|$KEEPALIVE_TIME|g" env.yaml +sed -i "s|fill_connection_test_query|$CONNECTION_TEST_QUERY|g" env.yaml sed -i "s|$DEFAULT_JAVA_OPTIONS|$GRPC_JAVA_OPTIONS|g" bin/adempiere-all-in-one-server # Run app diff --git a/docker/start_grpc_proxy.sh b/docker/start_grpc_proxy.sh index a690268fa..b7cfc533d 100644 --- a/docker/start_grpc_proxy.sh +++ b/docker/start_grpc_proxy.sh @@ -3,42 +3,15 @@ PROD_FILE=/etc/envoy/envoy.yaml - # copy `envoy_template.yaml` file to `envoy.yaml` cp -rf /etc/envoy/envoy_template.yaml $PROD_FILE - # Set server values sed -i "s|5555|$SERVER_PORT|g" $PROD_FILE - -# # create array to iterate -# SERVICES_LIST=$(echo $SERVICES_ENABLED | tr "; " "\n") - -# SERVICES_LIST_TO_SET="" -# for SERVICE_ITEM in $SERVICES_LIST -# do -# # Service to lower case -# SERVICE_LOWER_CASE=$(echo $SERVICE_ITEM | tr '[:upper:]' '[:lower:]') - -# NEW_LINE="\n" -# PREFIX=" - " -# if [ -z "$SERVICES_LIST_TO_SET" ] -# then -# NEW_LINE="" -# PREFIX="- " -# fi - -# # Add to the list of services -# SERVICES_LIST_TO_SET="${SERVICES_LIST_TO_SET}${NEW_LINE}${PREFIX}${SERVICE_LOWER_CASE}" -# done - -# sed -i "s|- services_enabled|$SERVICES_LIST_TO_SET|g" $PROD_FILE - # Backend gRPC sed -i "s|backend_host|$BACKEND_HOST|g" $PROD_FILE sed -i "s|backend_port|$BACKEND_PORT|g" $PROD_FILE - # Run app /usr/local/bin/envoy -c /etc/envoy/envoy.yaml diff --git a/resources/standalone.yaml b/resources/standalone.yaml index 2e130538b..dacb53bc2 100644 --- a/resources/standalone.yaml +++ b/resources/standalone.yaml @@ -1,13 +1,10 @@ server: port: 50059 log_level: WARNING - jwt_secret_key: 2C51599F5B1248F945B93E05EFC43B3A15D8EB0707C0F02FD97028786C40976F - # Default 24 hours - jwt_expiration_time: 86400000 database: host: localhost port: 5432 - name: adempiere + name: "adempiere" user: adempiere password: adempiere type: PostgreSQL diff --git a/src/main/java/org/spin/base/setup/Database.java b/src/main/java/org/spin/base/setup/Database.java index 6c39b090d..d032657bb 100644 --- a/src/main/java/org/spin/base/setup/Database.java +++ b/src/main/java/org/spin/base/setup/Database.java @@ -32,6 +32,20 @@ public class Database { private String name; /** Database type */ private String type; + /** IDLE Timeout */ + private long idle_timeout; + /** Minimum IDLE */ + private int minimum_idle; + /** Maximum Pool Size */ + private int maximum_pool_size; + /** Connection Timeout */ + private long connection_timeout; + /** Maximum Lifetime */ + private long maximum_lifetime; + /** Keepalive Time */ + private long keepalive_time; + /** Connection Test Query */ + private String connection_test_query; /** * Default constructor @@ -100,6 +114,34 @@ public final String getType() { return type; } + public long getIdle_timeout() { + return idle_timeout; + } + + public int getMinimum_idle() { + return minimum_idle; + } + + public int getMaximum_pool_size() { + return maximum_pool_size; + } + + public long getConnection_timeout() { + return connection_timeout; + } + + public long getMaximum_lifetime() { + return maximum_lifetime; + } + + public long getKeepalive_time() { + return keepalive_time; + } + + public String getConnection_test_query() { + return connection_test_query; + } + @Override public String toString() { return "Database [host=" + host + ", port=" + port + ", user=" + user + ", password=******, name=" diff --git a/src/main/java/org/spin/base/setup/SetupLoader.java b/src/main/java/org/spin/base/setup/SetupLoader.java index 414f35e02..2cfb8ccca 100644 --- a/src/main/java/org/spin/base/setup/SetupLoader.java +++ b/src/main/java/org/spin/base/setup/SetupLoader.java @@ -26,6 +26,7 @@ import org.compiere.util.DB; import org.compiere.util.Ini; import org.compiere.util.Util; +import org.spin.server.config.BackendDatabaseConfig; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -121,14 +122,27 @@ public void validateLoad() throws Exception { // Set default init Ini.setProperty(Ini.P_CONNECTION, connection.toStringLong()); Ini.setClient(true); -// Ini.setProperty(Ini.P_ADEMPIERE_APPS_TYPE, "wildfly"); + // Set Database default parameters + // Close inactive connections after 5 minutes 300 + BackendDatabaseConfig.setIdleTimeout(dataBase.getIdle_timeout()); + // Minimum connection opening 1 + BackendDatabaseConfig.setMinimumIdle(dataBase.getMinimum_idle()); + // 10 + BackendDatabaseConfig.setMaximumPoolSize(dataBase.getMaximum_pool_size() + 1); + // New connection waiting time 5 seconds 5000 + BackendDatabaseConfig.setConnectionTimeout(dataBase.getConnection_timeout()); + // Close connections after 10 minutes + BackendDatabaseConfig.setMaxLifetime(dataBase.getMaximum_lifetime()); + // Validate connection each 6 minutes 360000 + BackendDatabaseConfig.setKeepaliveTime(dataBase.getKeepalive_time()); + // Test connection just make a ping to validate database "SELECT 1" + BackendDatabaseConfig.setConnectionTestQuery(dataBase.getConnection_test_query()); Level logLevel = Level.parse(setup.getServer().getLog_level().toUpperCase()); Ini.setProperty(Ini.P_TRACEFILE, logLevel.getName()); CLogMgt.setLevel(logLevel); DB.setDBTarget(connection); } - /** * @return * @see org.spin.base.setup.SetupWrapper#getDatabase()