This is an automated email from the ASF dual-hosted git repository.
dgriffon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new 43bebe7de UNOMI-863: set up OSGi DS to allow config update in the
HeathCheck service. (#708)
43bebe7de is described below
commit 43bebe7def6b9873563ee9a8f5b89d79be6d7133
Author: David Griffon <[email protected]>
AuthorDate: Thu Nov 7 10:35:34 2024 +0100
UNOMI-863: set up OSGi DS to allow config update in the HeathCheck service.
(#708)
---
.github/workflows/unomi-ci-build-tests.yml | 1 +
.../unomi/healthcheck/HealthCheckConfig.java | 4 +++
.../unomi/healthcheck/HealthCheckService.java | 33 ++++++++++++----------
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/.github/workflows/unomi-ci-build-tests.yml
b/.github/workflows/unomi-ci-build-tests.yml
index 37d040c2d..d6cb887c6 100644
--- a/.github/workflows/unomi-ci-build-tests.yml
+++ b/.github/workflows/unomi-ci-build-tests.yml
@@ -13,6 +13,7 @@ jobs:
unit-tests:
name: Execute unit tests
runs-on: ubuntu-latest
+ timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
diff --git
a/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckConfig.java
b/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckConfig.java
index a36501fda..e86018dc3 100644
---
a/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckConfig.java
+++
b/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckConfig.java
@@ -65,6 +65,10 @@ public class HealthCheckConfig {
return this.config.get(configKey);
}
+ public int getSize() {
+ return this.config.size();
+ }
+
public boolean isEnabled() {
return enabled;
}
diff --git
a/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
b/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
index 54a288063..9da585e14 100644
---
a/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
+++
b/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
@@ -49,31 +49,28 @@ public class HealthCheckService {
@Reference
protected HttpService httpService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY, updated =
"updated")
private HealthCheckConfig config;
public HealthCheckService() {
LOGGER.info("Building healthcheck service...");
}
- public void setConfig(HealthCheckConfig config) {
- this.config = config;
- }
-
@Activate
public void activate() throws ServletException, NamespaceException {
- if (config.isEnabled()) {
- LOGGER.info("Activating healthcheck service...");
- executor = Executors.newSingleThreadExecutor();
- httpService.registerServlet("/health/check", new
HealthCheckServlet(this), null,
- new HealthCheckHttpContext(config.get(CONFIG_AUTH_REALM)));
- this.registered = true;
- } else {
- LOGGER.info("Healthcheck service is disabled");
+ LOGGER.info("Activating healthcheck service...");
+ executor = Executors.newSingleThreadExecutor();
+ if (!registered) {
+ setConfig(config);
}
}
- public void updated() throws ServletException, NamespaceException {
+ @Reference(service = HealthCheckConfig.class, policy =
ReferencePolicy.DYNAMIC, updated = "setConfig")
+ private void setConfig(HealthCheckConfig config) throws ServletException,
NamespaceException {
+ this.config = config;
+ if (httpService == null ) {
+ LOGGER.info("Healthcheck config with {} entrie(s) did not update
the service as not fully started yet.", config.getSize());
+ return;
+ }
if (config.isEnabled()) {
LOGGER.info("Updating healthcheck service...");
if (registered) {
@@ -84,10 +81,16 @@ public class HealthCheckService {
new HealthCheckHttpContext(config.get(CONFIG_AUTH_REALM)));
registered = true;
} else {
+ httpService.unregister("/health/check");
+ registered = false;
LOGGER.info("Healthcheck service is disabled");
}
}
+ private void unsetConfig(HealthCheckConfig config) {
+ this.config = null;
+ }
+
@Deactivate
public void deactivate() {
LOGGER.info("Deactivating healthcheck service...");
@@ -112,7 +115,7 @@ public class HealthCheckService {
}
public List<HealthCheckResponse> check() throws RejectedExecutionException
{
- if (config.isEnabled()) {
+ if (config !=null && config.isEnabled()) {
LOGGER.debug("Health check called");
if (busy) {
throw new RejectedExecutionException("Health check already in
progress");