diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml
index b5945f5..2f04bc1 100644
--- a/geoportal-service/pom.xml
+++ b/geoportal-service/pom.xml
@@ -167,6 +167,12 @@
2.2.6
+
+ javax.enterprise
+ cdi-api
+ 2.0
+
+
diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/GeoportalHealthCheck.java
new file mode 100644
index 0000000..41877c7
--- /dev/null
+++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/GeoportalHealthCheck.java
@@ -0,0 +1,41 @@
+package org.gcube.application.geoportal.service.health;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.eclipse.microprofile.health.HealthCheck;
+import org.eclipse.microprofile.health.HealthCheckResponse;
+import org.eclipse.microprofile.health.Liveness;
+import org.eclipse.microprofile.health.Readiness;
+
+import lombok.extern.slf4j.Slf4j;
+
+@ApplicationScoped
+@Readiness
+@Liveness
+@Slf4j
+public class GeoportalHealthCheck implements HealthCheck {
+
+ private static final String SERVICE_NAME = "geooportal-service";
+
+// @GET
+// @Path("")
+// @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
+// public Response check() {
+// log.info("Check called");
+// HealthCheckResponse hcr = call();
+// return Response.ok().entity(hcr).build();
+// }
+
+ @Override
+ public HealthCheckResponse call() {
+ log.info(GeoportalHealthCheck.class.getSimpleName() + " call");
+ return HealthCheckResponse.named(SERVICE_NAME).state(true).build();
+ }
+
+
+}
diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java
similarity index 67%
rename from geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealthCheck.java
rename to geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java
index caa8bd8..09d3e70 100644
--- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealthCheck.java
+++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java
@@ -1,10 +1,7 @@
-package org.gcube.application.geoportal.service.rest;
+package org.gcube.application.geoportal.service.health;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
+import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.health.HealthCheck;
@@ -16,49 +13,32 @@ import org.gcube.application.cms.implementations.ImplementationProvider;
import org.gcube.application.geoportal.common.model.configuration.MongoConnection;
import org.gcube.application.geoportal.service.model.internal.db.Mongo;
import org.gcube.common.scope.api.ScopeProvider;
-import org.glassfish.jersey.process.internal.RequestScoped;
import com.mongodb.client.MongoIterable;
import lombok.extern.slf4j.Slf4j;
-@RequestScoped
+@ApplicationScoped
@Readiness
-@Path("/health")
+@Liveness
@Slf4j
-public class GeoportalHealthCheck implements HealthCheck {
+public class MongoHealthCheck implements HealthCheck {
- private static final String SERVICE_NAME = "geooportal-service";
+ private String context;
+ private static final String SERVICE_NAME = "mongo";
- @GET
- @Path("")
- @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
- public Response check() {
- log.info("Check called");
- HealthCheckResponse hcr = call();
- return Response.ok().entity(hcr).build();
- }
-
- @Liveness
@Override
public HealthCheckResponse call() {
-
- return HealthCheckResponse.named(SERVICE_NAME).state(true).build();
+ return checkMongo(context);
}
- @GET
- @Path("/mongo")
- @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
- public Response checkDatabase(@QueryParam("context") String context) {
- log.info("checkDatabase called in the context {}", context);
- if (context == null)
- return Response.status(400).entity("'context' paramater (e.g. '/gcube/devsec/devVRE' is required").build();
-
- return Response.ok().entity(checkMongo(context)).build();
+ public MongoHealthCheck context(String context) {
+ this.context = context;
+ return this;
}
private HealthCheckResponse checkMongo(String context) {
- HealthCheckResponseBuilder buildHCRProvider = HealthCheckResponse.named("mongo");
+ HealthCheckResponseBuilder buildHCRProvider = HealthCheckResponse.named(SERVICE_NAME);
Mongo mongo = null;
try {
ScopeProvider.instance.set(context);
diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java
new file mode 100644
index 0000000..fed36bd
--- /dev/null
+++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java
@@ -0,0 +1,46 @@
+package org.gcube.application.geoportal.service.rest;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.microprofile.health.HealthCheckResponse;
+import org.gcube.application.geoportal.service.health.GeoportalHealthCheck;
+import org.gcube.application.geoportal.service.health.MongoHealthCheck;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Path("/health")
+@Slf4j
+public class GeoportalHealth {
+
+ @Inject
+ GeoportalHealthCheck geoportalHC;
+
+ @Inject
+ MongoHealthCheck mongoHC;
+
+ @GET
+ @Path("")
+ @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
+ public HealthCheckResponse serviceCheck() {
+ log.info("serviceCheck called");
+ return geoportalHC.call();
+ }
+
+ @GET
+ @Path("/mongo")
+ @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
+ public HealthCheckResponse databaseCheck(@QueryParam("context") String context) {
+ log.info("databaseCheck called in the context {}", context);
+ if (context == null)
+ return HealthCheckResponse.named("databaseCheck")
+ .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build();
+
+ return mongoHC.context(context).call();
+ }
+
+}