From 5120b4b92f67166e935008ae1670cc7baa9cd994 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 8 Nov 2023 10:54:06 -0600 Subject: [PATCH 1/9] Issue 219: Change Module and Deployment Descriptors to be consistent with standard FOLIO practices. Relocate the the Descriptors. Rename the Descriptors to be a template and bring in the template processing plugins into the POM file. Change the variable behavior in the Descriptors to be consistent with how standard FOLIO practices use them (`${project.version}` instead of `@project.version@` for example). Added `-XX:MaxRAMPercentage=66.0` for consistency with other projects. Some projects use a value like 85.0. I don't have a realistic clue here on what value to use and I am open to not having this environment variable set at all if a proposal to remove it is given. The Deployment Descriptor used to have only `--server.port=%p`. Other FOLIO projects have both `-Dport=%p` and `-Dhttp.port=%p`. This plays it safe by having all three. A required dependency to `mod-workflow` is added to the Module Descriptor. --- .../DeploymentDescriptor-template.json | 7 ++ .../ModuleDescriptor-template.json | 20 ++++-- pom.xml | 69 ++++++++++++++----- .../descriptors/DeploymentDescriptor.json | 7 -- 4 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 descriptors/DeploymentDescriptor-template.json rename src/main/resources/descriptors/ModuleDescriptor.json => descriptors/ModuleDescriptor-template.json (97%) delete mode 100644 src/main/resources/descriptors/DeploymentDescriptor.json diff --git a/descriptors/DeploymentDescriptor-template.json b/descriptors/DeploymentDescriptor-template.json new file mode 100644 index 00000000..84ec910a --- /dev/null +++ b/descriptors/DeploymentDescriptor-template.json @@ -0,0 +1,7 @@ +{ + "srvcId": "${project.artifactId}-${project.version}", + "nodeId": "localhost", + "descriptor": { + "exec": "java -Dport=%p -jar ../${artifactId}/target/${project.artifactId}-${project.version}.jar -Dspring.config.location=classpath:/ -Dhttp.port=%p --server.port=%p" + } +} diff --git a/src/main/resources/descriptors/ModuleDescriptor.json b/descriptors/ModuleDescriptor-template.json similarity index 97% rename from src/main/resources/descriptors/ModuleDescriptor.json rename to descriptors/ModuleDescriptor-template.json index fd989324..0070d38b 100644 --- a/src/main/resources/descriptors/ModuleDescriptor.json +++ b/descriptors/ModuleDescriptor-template.json @@ -1,5 +1,5 @@ { - "id": "@project.artifactId@-@project.version@", + "id": "${project.artifactId}-${project.version}", "name": "Camnuda BPM Module", "provides": [ { @@ -382,12 +382,22 @@ "visible": false } ], - "requires": [ ], + "requires": [ + { + "id": "mod-workflow", + "version": "1.1" + } + ], "launchDescriptor": { - "dockerImage": "@project.artifactId@:@project.version@", + "dockerImage": "${project.artifactId}:${project.version}", + "dockerPull" : false, "dockerArgs": { "HostConfig": { "PortBindings": { "8081/tcp": [{ "HostPort": "%p" }] } } }, - "dockerPull" : false + "env": [ + { "name": "JAVA_OPTIONS", + "value": "-XX:MaxRAMPercentage=66.0" + } + ] } -} \ No newline at end of file +} diff --git a/pom.xml b/pom.xml index fbcc8e40..c6e02358 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,57 @@ + + org.apache.maven.plugins + maven-resources-plugin + + + filter-descriptor-inputs + generate-resources + + copy-resources + + + ${project.build.directory} + + + ${basedir}/descriptors + *Descriptor*-template.json + true + + + + + + + + + com.coderplus.maven.plugins + copy-rename-maven-plugin + 1.0.1 + + + rename-descriptor-outputs + generate-resources + + rename + + + + + ${project.build.directory}/ModuleDescriptor-template.json + ${project.build.directory}/ModuleDescriptor.json + + + ${project.build.directory}/DeploymentDescriptor-template.json + ${project.build.directory}/DeploymentDescriptor.json + + + + + + + @@ -140,24 +191,6 @@ application.yml - - true - src/main/resources/descriptors - descriptors - - DeploymentDescriptor.json - ModuleDescriptor.json - - - - true - src/main/resources/descriptors - ../descriptors - - DeploymentDescriptor.json - ModuleDescriptor.json - - diff --git a/src/main/resources/descriptors/DeploymentDescriptor.json b/src/main/resources/descriptors/DeploymentDescriptor.json deleted file mode 100644 index 6128a5a9..00000000 --- a/src/main/resources/descriptors/DeploymentDescriptor.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "srvcId": "@project.artifactId@-@project.version@", - "nodeId": "localhost", - "descriptor": { - "exec": "java -jar ../mod-camunda/target/mod-camunda-@project.version@.jar -Dspring.config.location=classpath:/ --server.port=%p" - } -} \ No newline at end of file From 49815fcbf6052621436a16194e84b22a8ad9c367 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 8 Nov 2023 15:33:18 -0600 Subject: [PATCH 2/9] Issue 219: Add requirements for proper backend deployment. The amount of memory needed is currently unknown and so the provided `357913941` is used. The environment variables that are needed have yet to be fully hashed out. Only the specifically required environment variables are added. Others will needed to be added in another commit. see: https://dev.folio.org/guides/module-descriptor/ see: https://dev.folio.org/guides/install-backend-module/ --- descriptors/ModuleDescriptor-template.json | 18 +++++++++++++++--- .../folio/rest/controller/AdminController.java | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/folio/rest/controller/AdminController.java diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 0070d38b..6571390d 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -392,12 +392,24 @@ "dockerImage": "${project.artifactId}:${project.version}", "dockerPull" : false, "dockerArgs": { - "HostConfig": { "PortBindings": { "8081/tcp": [{ "HostPort": "%p" }] } } + "HostConfig": { + "Memory": 357913941, + "PortBindings": { "8081/tcp": [ { "HostPort": "%p" } ] } + } }, "env": [ - { "name": "JAVA_OPTIONS", + { + "name": "JAVA_OPTIONS", "value": "-XX:MaxRAMPercentage=66.0" - } + }, + { "name": "DB_HOST", "value": "postgres" }, + { "name": "DB_PORT", "value": "5432" }, + { "name": "DB_USERNAME", "value": "folio_admin" }, + { "name": "DB_PASSWORD", "value": "folio_admin" }, + { "name": "DB_DATABASE", "value": "okapi_modules" }, + { "name": "DB_QUERYTIMEOUT", "value": "60000" }, + { "name": "DB_CHARSET", "value": "UTF-8" }, + { "name": "DB_MAXPOOLSIZE", "value": "5" } ] } } diff --git a/src/main/java/org/folio/rest/controller/AdminController.java b/src/main/java/org/folio/rest/controller/AdminController.java new file mode 100644 index 00000000..c2c47968 --- /dev/null +++ b/src/main/java/org/folio/rest/controller/AdminController.java @@ -0,0 +1,17 @@ +package org.folio.rest.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/admin") +public class AdminController { + + @GetMapping("/health") + public ResponseEntity health(){ + return ResponseEntity.ok().build(); + } + +} From 134147b1484bfbd69130d058b296311b79a72f49 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 8 Nov 2023 16:05:10 -0600 Subject: [PATCH 3/9] Issue 219: Fix white space issues. --- descriptors/ModuleDescriptor-template.json | 2 +- src/main/java/org/folio/rest/controller/AdminController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 6571390d..63cb5eaa 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -399,7 +399,7 @@ }, "env": [ { - "name": "JAVA_OPTIONS", + "name": "JAVA_OPTIONS", "value": "-XX:MaxRAMPercentage=66.0" }, { "name": "DB_HOST", "value": "postgres" }, diff --git a/src/main/java/org/folio/rest/controller/AdminController.java b/src/main/java/org/folio/rest/controller/AdminController.java index c2c47968..aadfae47 100644 --- a/src/main/java/org/folio/rest/controller/AdminController.java +++ b/src/main/java/org/folio/rest/controller/AdminController.java @@ -11,7 +11,7 @@ public class AdminController { @GetMapping("/health") public ResponseEntity health(){ - return ResponseEntity.ok().build(); + return ResponseEntity.ok().build(); } } From 61796e982b389ecb5331ba2a2feec8cfe756624c Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 9 Nov 2023 09:15:07 -0600 Subject: [PATCH 4/9] Issue 219: Configure descriptor, adding some ENV data and then use them. Update the `application.yml` to utilize these. Update the default memory to 384MB. Enable postgresql by default, disabling H2. --- descriptors/ModuleDescriptor-template.json | 5 +++-- src/main/resources/application.yml | 26 +++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 63cb5eaa..27fc9643 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -393,7 +393,7 @@ "dockerPull" : false, "dockerArgs": { "HostConfig": { - "Memory": 357913941, + "Memory": 402653184, "PortBindings": { "8081/tcp": [ { "HostPort": "%p" } ] } } }, @@ -409,7 +409,8 @@ { "name": "DB_DATABASE", "value": "okapi_modules" }, { "name": "DB_QUERYTIMEOUT", "value": "60000" }, { "name": "DB_CHARSET", "value": "UTF-8" }, - { "name": "DB_MAXPOOLSIZE", "value": "5" } + { "name": "DB_MAXPOOLSIZE", "value": "16" }, + { "name": "OKAPI_URL", "value": "http://10.0.2.15:9130", "description": "The URL to the OKAPI service." } ] } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index be0e4de1..63a12dff 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -26,33 +26,33 @@ spring: returnBodyOnUpdate: true sql: init: - platform: h2 + #platform: h2 + platform: postgres datasource: hikari: leakDetectionThreshold: 1800000 connectionTimeout: 30000 idleTimeout: 600000 maxLifetime: 1800000 - maximumPoolSize: 16 - url: jdbc:h2:./target/mod-camunda;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - driverClassName: org.h2.Driver - # platform: postgres - # driverClassName: org.postgresql.Driver - # url: jdbc:postgresql://localhost:5432/mod_camunda + maximumPoolSize: ${DB_MAXPOOLSIZE:16} + #url: jdbc:h2:./target/mod-camunda;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + #driverClassName: org.h2.Driver + driverClassName: org.postgresql.Driver + url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_DATABASE:mod_camunda} - username: folio_admin - password: folio_admin + username: ${DB_USERNAME:folio_admin} + password: ${DB_PASSWORD:folio_admin} h2: console: - enabled: true + enabled: false path: /h2console settings: web-allow-others: true jpa: - database-platform: org.hibernate.dialect.H2Dialect - # database-platform: org.hibernate.dialect.PostgreSQLDialect + #database-platform: org.hibernate.dialect.H2Dialect + database-platform: org.hibernate.dialect.PostgreSQLDialect properties.hibernate.jdbc.lob.non_contextual_creation: true generate-ddl: false @@ -116,7 +116,7 @@ tenant: - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.decision.engine.sql - classpath:/org/camunda/bpm/engine/db/create/activiti.h2.create.decision.history.sql -okapi.url: http://localhost:9130 +okapi.url: ${OKAPI_URL:http://localhost:9130} error: handling: From 38c1599e92a7ccbcfad231591eb30a4111bf7fd8 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 9 Nov 2023 16:26:08 -0600 Subject: [PATCH 5/9] Issue 219: Remove shade plugin due to inherent problems and bugs. Errors regarding multiple registrations of `AttributeConverter` have surfaced (in mod-workflow). This is a bug between the shade plugin and hibernate as far as I can tell from my online research. I believe that this is sufficient justification to deviate from the Folio practice of using the shade plugin. Strip out the shade plugin entirely and update the `Dockerfile`. --- Dockerfile | 6 +++--- pom.xml | 26 -------------------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index d6c00605..4665b6d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,11 @@ USER folio ENV VERTICLE_FILE mod-camunda.jar -# Set the location of the verticles +# Set the location of the verticles. ENV VERTICLE_HOME /usr/verticles -# Copy your fat jar to the container -COPY target/fat/${VERTICLE_FILE} ${VERTICLE_HOME}/${VERTICLE_FILE} +# Copy your jar to the container. +COPY service/target/workflow-camunda*.jar ${VERTICLE_HOME}/${VERTICLE_FILE} # Expose this port locally in the container. EXPOSE 9000 diff --git a/pom.xml b/pom.xml index c6e02358..f118e542 100644 --- a/pom.xml +++ b/pom.xml @@ -78,32 +78,6 @@ - - org.apache.maven.plugins - maven-shade-plugin - 3.5.1 - - - package - - shade - - - - - - org.folio.inventory.Launcher - true - - - - - ${project.build.directory}/fat/${project.artifactId}.jar - - - - - org.apache.maven.plugins maven-resources-plugin From 9299c2d6b52c28c32ffaa12e57ad5f40d93970d9 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 10 Nov 2023 10:17:47 -0600 Subject: [PATCH 6/9] Issue 219: The default application.yml is missing the spring.datasource.platform. Not having this works fine for h2. Not having this breaks for postgresql. --- src/main/resources/application.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 63a12dff..f8295048 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -37,8 +37,10 @@ spring: maximumPoolSize: ${DB_MAXPOOLSIZE:16} #url: jdbc:h2:./target/mod-camunda;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE #driverClassName: org.h2.Driver + #platform: h2 driverClassName: org.postgresql.Driver url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_DATABASE:mod_camunda} + platform: postgres username: ${DB_USERNAME:folio_admin} password: ${DB_PASSWORD:folio_admin} From 25da75fc5ccafcbe7c64a97eeebea5d029d25503 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 10 Nov 2023 10:39:14 -0600 Subject: [PATCH 7/9] Issue 219: Dockerfile is for camunda and not workflow, use correct name and path. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4665b6d7..d154fce0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ ENV VERTICLE_FILE mod-camunda.jar ENV VERTICLE_HOME /usr/verticles # Copy your jar to the container. -COPY service/target/workflow-camunda*.jar ${VERTICLE_HOME}/${VERTICLE_FILE} +COPY target/mod-camunda*.jar ${VERTICLE_HOME}/${VERTICLE_FILE} # Expose this port locally in the container. EXPOSE 9000 From 0a8919a44cb8fc77d7d68380d3877806038a9593 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 10 Nov 2023 15:21:28 -0600 Subject: [PATCH 8/9] Issue 219: Make Dockerfile expose port consistent with Descriptor, changing 9000 to 8081. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d154fce0..12f2f110 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ ENV VERTICLE_HOME /usr/verticles COPY target/mod-camunda*.jar ${VERTICLE_HOME}/${VERTICLE_FILE} # Expose this port locally in the container. -EXPOSE 9000 +EXPOSE 8081 From 1a65b07c616cc0ea4312a2a6a84c52d4c0f5323d Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 10 Nov 2023 16:35:20 -0600 Subject: [PATCH 9/9] Issue 219: Switch to actuator for /admin/health. --- pom.xml | 5 +++++ .../folio/rest/controller/AdminController.java | 17 ----------------- src/main/resources/application.yml | 12 ++++++++++++ 3 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 src/main/java/org/folio/rest/controller/AdminController.java diff --git a/pom.xml b/pom.xml index f118e542..5b1807b3 100644 --- a/pom.xml +++ b/pom.xml @@ -369,6 +369,11 @@ 22.3.3 + + org.springframework.boot + spring-boot-starter-actuator + + diff --git a/src/main/java/org/folio/rest/controller/AdminController.java b/src/main/java/org/folio/rest/controller/AdminController.java deleted file mode 100644 index aadfae47..00000000 --- a/src/main/java/org/folio/rest/controller/AdminController.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.folio.rest.controller; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/admin") -public class AdminController { - - @GetMapping("/health") - public ResponseEntity health(){ - return ResponseEntity.ok().build(); - } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f8295048..e487cbe1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -127,6 +127,18 @@ error: # comma seperated email addresses emailTo: support@mailinator.com +management: + endpoints: + web: + exposure: + include: health + base-path: /admin + health: + defaults: + enabled: true + readinessstate: + enabled: true + info: build: artifact: "@project.artifactId@"