From 3c43a53c065282a8e4b3e35e793cc6498534344d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 16 Oct 2024 16:59:39 +0200 Subject: [PATCH 01/43] - Included the health check at https://{geoporta_endpoint}/health via `microprofile-health-api` (see https://microprofile.io/specifications/microprofile-health/) --- geoportal-service/CHANGELOG.md | 4 ++++ .../gcube/extra-resources/WEB-INF/gcube-app.xml | 2 ++ geoportal-service/pom.xml | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/geoportal-service/CHANGELOG.md b/geoportal-service/CHANGELOG.md index 3ac8b7c..3694189 100644 --- a/geoportal-service/CHANGELOG.md +++ b/geoportal-service/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for org.gcube.application.geoportal-service +## [v1.2.2-SNAPSHOT] - 2024-10-16 + +- Included the health check at https://{geoporta_endpoint}/health via `microprofile-health-api` (see https://microprofile.io/specifications/microprofile-health/) + ## [v1.2.1] - 2024-10-02 - Included the file size to reduce/optimize the time to upload files to the storage hub [#28150] diff --git a/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml b/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml index 907178e..132eedd 100644 --- a/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml +++ b/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml @@ -7,5 +7,7 @@ ${project.description} /srv/docs/* /srv/api-docs/* + /srv/health + /srv/health/* diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index fc18c4b..e521417 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.gcube.application geoportal-service - 1.2.1 + 1.2.2-SNAPSHOT Geoportal Service war @@ -155,6 +155,11 @@ javax.xml.ws jaxws-api test --> + + org.eclipse.microprofile.health + microprofile-health-api + 4.0 + From 984c3edf3174e1e7f97c021b1412baece708e7d0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 16 Oct 2024 17:02:03 +0200 Subject: [PATCH 02/43] - added GeoportalHealthCheck --- .../service/rest/GeoportalHealthCheck.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealthCheck.java 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/rest/GeoportalHealthCheck.java new file mode 100644 index 0000000..c8a5aed --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealthCheck.java @@ -0,0 +1,95 @@ +package org.gcube.application.geoportal.service.rest; + +import java.util.Optional; + +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 javax.ws.rs.core.Response; + +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.HealthCheckResponse.Status; +import org.eclipse.microprofile.health.HealthCheckResponseBuilder; +import org.eclipse.microprofile.health.Liveness; +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 com.mongodb.client.MongoIterable; + +@Path("/health") +public class GeoportalHealthCheck implements HealthCheck { + + @GET + @Path("") + @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) + public Response check() { + + HealthCheckResponse hcr = call(); + return Response.ok().entity(hcr).build(); + } + + @Liveness + @Override + public HealthCheckResponse call() { + + return new HealthCheckResponse("geooportal-service", Status.UP, Optional.empty()); + } + + @GET + @Path("/mongo") + @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) + public Response checkDatabase(@QueryParam("context") String 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(); + } + + private HealthCheckResponse checkMongo(String context) { + HealthCheckResponseBuilder buildHCRBuilder = HealthCheckResponse.named("mongo"); + Mongo mongo = null; + try { + ScopeProvider.instance.set(context); + mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); + buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); + buildHCRBuilder = buildHCRBuilder.up(); + MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) + .listCollectionNames(); + int i = 1; + for (String coll : collections) { + buildHCRBuilder.withData("collection " + i, coll); + i++; + } + return buildHCRBuilder.build(); + } catch (Exception e) { + buildHCRBuilder.down(); + if (mongo != null) { + MongoConnection connection = null; + try { + connection = mongo.getConnection(); + buildHCRBuilder = appendMongoInfo(buildHCRBuilder, connection); + } catch (Exception e1) { + buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); + } + + } + return buildHCRBuilder.build(); + } finally { + ScopeProvider.instance.reset(); + } + } + + private HealthCheckResponseBuilder appendMongoInfo(HealthCheckResponseBuilder buildHCRBuilder, + MongoConnection connection) { + buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); + buildHCRBuilder.withData("db_name ", connection.getDatabase()); + return buildHCRBuilder; + } + +} From 52d456a9b3b553908e1d3b7dc0fc087b47142d7d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 16 Oct 2024 17:13:41 +0200 Subject: [PATCH 03/43] updated --- .../application/geoportal/service/GeoPortalService.java | 2 ++ .../geoportal/service/rest/GeoportalHealthCheck.java | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index 7d9466e..2cf04bd 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -21,6 +21,7 @@ import org.gcube.application.geoportal.service.engine.providers.ucd.ProfileMap; import org.gcube.application.geoportal.service.engine.providers.ucd.SingleISResourceUCDProvider; import org.gcube.application.geoportal.service.engine.providers.ucd.UCDManager; import org.gcube.application.geoportal.service.model.internal.db.Mongo; +import org.gcube.application.geoportal.service.rest.GeoportalHealthCheck; import org.gcube.application.geoportal.service.rest.Plugins; import org.gcube.application.geoportal.service.rest.ProfiledDocuments; import org.gcube.application.geoportal.service.rest.UseCaseDescriptors; @@ -53,6 +54,7 @@ public class GeoPortalService extends ResourceConfig{ registerClasses(ProfiledDocuments.class); registerClasses(UseCaseDescriptors.class); registerClasses(Plugins.class); + registerClasses(GeoportalHealthCheck.class); //registerClasses(DocsGenerator.class); log.info("Setting implementations .. "); 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/rest/GeoportalHealthCheck.java index c8a5aed..3c8c5f2 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/rest/GeoportalHealthCheck.java @@ -21,14 +21,17 @@ import org.gcube.common.scope.api.ScopeProvider; import com.mongodb.client.MongoIterable; +import lombok.extern.slf4j.Slf4j; + @Path("/health") +@Slf4j public class GeoportalHealthCheck implements HealthCheck { @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(); } @@ -44,7 +47,7 @@ public class GeoportalHealthCheck implements HealthCheck { @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(); From fc8b5512498a42075ac714cd16e7fc90b464d97d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 16 Oct 2024 17:54:29 +0200 Subject: [PATCH 04/43] added and used `HealthCheckResponseGeoportalProvider` --- .../service/rest/GeoportalHealthCheck.java | 23 ++-- .../HealthCheckResponseGeoportalProvider.java | 114 ++++++++++++++++++ 2 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java 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/rest/GeoportalHealthCheck.java index 3c8c5f2..2f4e404 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/rest/GeoportalHealthCheck.java @@ -12,11 +12,11 @@ import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; import org.eclipse.microprofile.health.HealthCheckResponse.Status; -import org.eclipse.microprofile.health.HealthCheckResponseBuilder; import org.eclipse.microprofile.health.Liveness; 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.application.geoportal.service.rest.check.HealthCheckResponseGeoportalProvider; import org.gcube.common.scope.api.ScopeProvider; import com.mongodb.client.MongoIterable; @@ -55,40 +55,41 @@ public class GeoportalHealthCheck implements HealthCheck { } private HealthCheckResponse checkMongo(String context) { - HealthCheckResponseBuilder buildHCRBuilder = HealthCheckResponse.named("mongo"); + HealthCheckResponseGeoportalProvider buildHCRProvider = new HealthCheckResponseGeoportalProvider(); + buildHCRProvider.setName("mongo"); Mongo mongo = null; try { ScopeProvider.instance.set(context); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); - buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); - buildHCRBuilder = buildHCRBuilder.up(); + buildHCRProvider = appendMongoInfo(buildHCRProvider, mongo.getConnection()); + buildHCRProvider.setStatus(Status.UP); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); int i = 1; for (String coll : collections) { - buildHCRBuilder.withData("collection " + i, coll); + buildHCRProvider.withData("collection " + i, coll); i++; } - return buildHCRBuilder.build(); + return buildHCRProvider.buildHealthCheckResponse(); } catch (Exception e) { - buildHCRBuilder.down(); + buildHCRProvider.setStatus(Status.DOWN); if (mongo != null) { MongoConnection connection = null; try { connection = mongo.getConnection(); - buildHCRBuilder = appendMongoInfo(buildHCRBuilder, connection); + buildHCRProvider = appendMongoInfo(buildHCRProvider, connection); } catch (Exception e1) { - buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); + buildHCRProvider.withData("hosts ", connection.getHosts() + ""); } } - return buildHCRBuilder.build(); + return buildHCRProvider.buildHealthCheckResponse(); } finally { ScopeProvider.instance.reset(); } } - private HealthCheckResponseBuilder appendMongoInfo(HealthCheckResponseBuilder buildHCRBuilder, + private HealthCheckResponseGeoportalProvider appendMongoInfo(HealthCheckResponseGeoportalProvider buildHCRBuilder, MongoConnection connection) { buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); buildHCRBuilder.withData("db_name ", connection.getDatabase()); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java new file mode 100644 index 0000000..e85b981 --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java @@ -0,0 +1,114 @@ +package org.gcube.application.geoportal.service.rest.check; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.HealthCheckResponse.Status; + +/** + * The Class HealthCheckResponseGeoportalProvider. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 16, 2024 + */ +public class HealthCheckResponseGeoportalProvider { + + private String name; + private Status status; + private Optional> data; + private Map myMap; + + /** + * Instantiates a new health check response geoportal provider. + */ + public HealthCheckResponseGeoportalProvider() { + + } + + /** + * Instantiates a new health check response geoportal provider. + * + * @param name the name + * @param status the status + * @param data the data + */ + public HealthCheckResponseGeoportalProvider(String name, Status status, Optional> data) { + this.name = name; + this.status = status; + this.data = data; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the status. + * + * @return the status + */ + public Status getStatus() { + return status; + } + + /** + * Gets the data. + * + * @return the data + */ + public Optional> getData() { + return data; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Sets the status. + * + * @param status the new status + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * With data. + * + * @param key the key + * @param value the value + */ + public void withData(String key, String value) { + if (myMap == null) { + myMap = new HashMap<>(); + } + + myMap.put(key, value); + } + + /** + * Builds the health check response. + * + * @return the health check response + */ + public HealthCheckResponse buildHealthCheckResponse() { + if (myMap != null) + data = Optional.of(myMap); + return new HealthCheckResponse(name, status, data); + } + +} From b6e9fcddaec888b9f8b46ec2a342d789ea303808 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 11:18:03 +0200 Subject: [PATCH 05/43] added some logs --- .../geoportal/service/rest/GeoportalHealthCheck.java | 2 ++ .../rest/check/HealthCheckResponseGeoportalProvider.java | 6 ++++++ 2 files changed, 8 insertions(+) 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/rest/GeoportalHealthCheck.java index 2f4e404..5343a76 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/rest/GeoportalHealthCheck.java @@ -65,8 +65,10 @@ public class GeoportalHealthCheck implements HealthCheck { buildHCRProvider.setStatus(Status.UP); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); + log.info("listCollectionNames is null: {}", collections == null); int i = 1; for (String coll : collections) { + log.info("adding collection: {}", coll); buildHCRProvider.withData("collection " + i, coll); i++; } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java index e85b981..7ec1ac5 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java @@ -7,6 +7,8 @@ import java.util.Optional; import org.eclipse.microprofile.health.HealthCheckResponse; import org.eclipse.microprofile.health.HealthCheckResponse.Status; +import lombok.extern.slf4j.Slf4j; + /** * The Class HealthCheckResponseGeoportalProvider. * @@ -14,6 +16,7 @@ import org.eclipse.microprofile.health.HealthCheckResponse.Status; * * Oct 16, 2024 */ +@Slf4j public class HealthCheckResponseGeoportalProvider { private String name; @@ -108,6 +111,9 @@ public class HealthCheckResponseGeoportalProvider { public HealthCheckResponse buildHealthCheckResponse() { if (myMap != null) data = Optional.of(myMap); + + log.info("data are: "+data); + return new HealthCheckResponse(name, status, data); } From a41854bec3c34c0f583362b7b0fca2886af3ad51 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 11:47:59 +0200 Subject: [PATCH 06/43] using microprofile-health-api v2.2 --- geoportal-service/pom.xml | 2 +- .../service/rest/GeoportalHealthCheck.java | 8 +-- .../HealthCheckResponseGeoportalProvider.java | 53 +++++-------------- 3 files changed, 19 insertions(+), 44 deletions(-) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index e521417..94a9dd0 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -158,7 +158,7 @@ org.eclipse.microprofile.health microprofile-health-api - 4.0 + 2.2 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/rest/GeoportalHealthCheck.java index 5343a76..9530ebc 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/rest/GeoportalHealthCheck.java @@ -11,7 +11,7 @@ import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.HealthCheckResponse.Status; +import org.eclipse.microprofile.health.HealthCheckResponse.State; import org.eclipse.microprofile.health.Liveness; import org.gcube.application.cms.implementations.ImplementationProvider; import org.gcube.application.geoportal.common.model.configuration.MongoConnection; @@ -40,7 +40,7 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { - return new HealthCheckResponse("geooportal-service", Status.UP, Optional.empty()); + return new HealthCheckResponse("geooportal-service", State.UP, Optional.empty()); } @GET @@ -62,7 +62,7 @@ public class GeoportalHealthCheck implements HealthCheck { ScopeProvider.instance.set(context); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRProvider = appendMongoInfo(buildHCRProvider, mongo.getConnection()); - buildHCRProvider.setStatus(Status.UP); + buildHCRProvider.setState(State.UP); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); @@ -74,7 +74,7 @@ public class GeoportalHealthCheck implements HealthCheck { } return buildHCRProvider.buildHealthCheckResponse(); } catch (Exception e) { - buildHCRProvider.setStatus(Status.DOWN); + buildHCRProvider.setState(State.DOWN); if (mongo != null) { MongoConnection connection = null; try { diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java index 7ec1ac5..a744dad 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.Optional; import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.HealthCheckResponse.Status; +import org.eclipse.microprofile.health.HealthCheckResponse.State; import lombok.extern.slf4j.Slf4j; @@ -20,9 +20,9 @@ import lombok.extern.slf4j.Slf4j; public class HealthCheckResponseGeoportalProvider { private String name; - private Status status; private Optional> data; private Map myMap; + private State state; /** * Instantiates a new health check response geoportal provider. @@ -38,55 +38,30 @@ public class HealthCheckResponseGeoportalProvider { * @param status the status * @param data the data */ - public HealthCheckResponseGeoportalProvider(String name, Status status, Optional> data) { + public HealthCheckResponseGeoportalProvider(String name, State state, Optional> data) { this.name = name; - this.status = status; + this.state = state; this.data = data; } - /** - * Gets the name. - * - * @return the name - */ public String getName() { return name; } - /** - * Gets the status. - * - * @return the status - */ - public Status getStatus() { - return status; - } - - /** - * Gets the data. - * - * @return the data - */ public Optional> getData() { return data; } - /** - * Sets the name. - * - * @param name the new name - */ + public State getState() { + return state; + } + public void setName(String name) { this.name = name; } - /** - * Sets the status. - * - * @param status the new status - */ - public void setStatus(Status status) { - this.status = status; + public void setState(State state) { + this.state = state; } /** @@ -111,10 +86,10 @@ public class HealthCheckResponseGeoportalProvider { public HealthCheckResponse buildHealthCheckResponse() { if (myMap != null) data = Optional.of(myMap); - - log.info("data are: "+data); - - return new HealthCheckResponse(name, status, data); + + log.info("data are: " + data); + + return new HealthCheckResponse(name, state, data); } } From d96e22aab730fa18cc21f3b0a90387f59b36cf98 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 11:59:09 +0200 Subject: [PATCH 07/43] Using `smallrye-health` as implementation of `microprofile-health-api` --- geoportal-service/pom.xml | 12 +++++++--- .../service/rest/GeoportalHealthCheck.java | 22 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 94a9dd0..cb19603 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -155,10 +155,16 @@ javax.xml.ws jaxws-api test --> + + + + + + - org.eclipse.microprofile.health - microprofile-health-api - 2.2 + io.smallrye + smallrye-health + 2.2.6 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/rest/GeoportalHealthCheck.java index 9530ebc..14eb106 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/rest/GeoportalHealthCheck.java @@ -1,7 +1,5 @@ package org.gcube.application.geoportal.service.rest; -import java.util.Optional; - import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -11,12 +9,11 @@ import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.HealthCheckResponse.State; +import org.eclipse.microprofile.health.HealthCheckResponseBuilder; import org.eclipse.microprofile.health.Liveness; 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.application.geoportal.service.rest.check.HealthCheckResponseGeoportalProvider; import org.gcube.common.scope.api.ScopeProvider; import com.mongodb.client.MongoIterable; @@ -27,6 +24,8 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class GeoportalHealthCheck implements HealthCheck { + private static final String SERVICE_NAME = "geooportal-service"; + @GET @Path("") @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @@ -40,7 +39,7 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { - return new HealthCheckResponse("geooportal-service", State.UP, Optional.empty()); + return HealthCheckResponse.named(SERVICE_NAME).state(true).build(); } @GET @@ -55,14 +54,13 @@ public class GeoportalHealthCheck implements HealthCheck { } private HealthCheckResponse checkMongo(String context) { - HealthCheckResponseGeoportalProvider buildHCRProvider = new HealthCheckResponseGeoportalProvider(); - buildHCRProvider.setName("mongo"); + HealthCheckResponseBuilder buildHCRProvider = HealthCheckResponse.named("mongo"); Mongo mongo = null; try { ScopeProvider.instance.set(context); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRProvider = appendMongoInfo(buildHCRProvider, mongo.getConnection()); - buildHCRProvider.setState(State.UP); + buildHCRProvider.state(true); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); @@ -72,9 +70,9 @@ public class GeoportalHealthCheck implements HealthCheck { buildHCRProvider.withData("collection " + i, coll); i++; } - return buildHCRProvider.buildHealthCheckResponse(); + return buildHCRProvider.build(); } catch (Exception e) { - buildHCRProvider.setState(State.DOWN); + buildHCRProvider.state(false); if (mongo != null) { MongoConnection connection = null; try { @@ -85,13 +83,13 @@ public class GeoportalHealthCheck implements HealthCheck { } } - return buildHCRProvider.buildHealthCheckResponse(); + return buildHCRProvider.build(); } finally { ScopeProvider.instance.reset(); } } - private HealthCheckResponseGeoportalProvider appendMongoInfo(HealthCheckResponseGeoportalProvider buildHCRBuilder, + private HealthCheckResponseBuilder appendMongoInfo(HealthCheckResponseBuilder buildHCRBuilder, MongoConnection connection) { buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); buildHCRBuilder.withData("db_name ", connection.getDatabase()); From 957b26ad259e7d897f8ffcf7864ee4b06509b9b9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 12:24:18 +0200 Subject: [PATCH 08/43] added @RequestScoped --- geoportal-service/pom.xml | 15 ++++++++++----- .../service/rest/GeoportalHealthCheck.java | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index cb19603..3c97e63 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -155,17 +155,22 @@ javax.xml.ws jaxws-api test --> - - - - - + + + + + io.smallrye smallrye-health 2.2.6 + + io.smallrye + smallrye-health-extension-api + 2.2.6 + 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/rest/GeoportalHealthCheck.java index 14eb106..caa8bd8 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/rest/GeoportalHealthCheck.java @@ -11,15 +11,19 @@ import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; import org.eclipse.microprofile.health.HealthCheckResponseBuilder; import org.eclipse.microprofile.health.Liveness; +import org.eclipse.microprofile.health.Readiness; 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 +@Readiness @Path("/health") @Slf4j public class GeoportalHealthCheck implements HealthCheck { From 7041889700ed064c6b22c29df450a906b1d7b2be Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 12:36:33 +0200 Subject: [PATCH 09/43] updated smallrye-health at 2.2.6 --- geoportal-service/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 3c97e63..b5945f5 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -166,11 +166,6 @@ smallrye-health 2.2.6 - - io.smallrye - smallrye-health-extension-api - 2.2.6 - From 0426eef8f58d1f19418b38a68e0dee0cd06e72b8 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 14:13:06 +0200 Subject: [PATCH 10/43] removed -SNAPSHOT from 'plugin-framework-version' (fixing https://support.d4science.org/issues/28033#note-3) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dcadae..34e7fe0 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 2.5.1 [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) - 1.0.6-SNAPSHOT + 1.0.6 [2.0.0, 3.0.0-SNAPSHOT) From b00d80ab9a4aad1db4290fdde358c1aac37af187 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 14:17:02 +0200 Subject: [PATCH 11/43] updated --- .../gcube/application/geoportal/service/GeoPortalService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index 2cf04bd..f4a0387 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -21,10 +21,10 @@ import org.gcube.application.geoportal.service.engine.providers.ucd.ProfileMap; import org.gcube.application.geoportal.service.engine.providers.ucd.SingleISResourceUCDProvider; import org.gcube.application.geoportal.service.engine.providers.ucd.UCDManager; import org.gcube.application.geoportal.service.model.internal.db.Mongo; -import org.gcube.application.geoportal.service.rest.GeoportalHealthCheck; import org.gcube.application.geoportal.service.rest.Plugins; import org.gcube.application.geoportal.service.rest.ProfiledDocuments; import org.gcube.application.geoportal.service.rest.UseCaseDescriptors; +import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; import org.glassfish.jersey.server.ResourceConfig; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; From 4ac33c1f5c6a1e6aa728e4456a5ab25e5f41efec Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 15:10:28 +0200 Subject: [PATCH 12/43] added inject --- geoportal-service/pom.xml | 6 +++ .../service/health/GeoportalHealthCheck.java | 41 +++++++++++++++++ .../MongoHealthCheck.java} | 44 +++++------------- .../service/rest/GeoportalHealth.java | 46 +++++++++++++++++++ 4 files changed, 105 insertions(+), 32 deletions(-) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/GeoportalHealthCheck.java rename geoportal-service/src/main/java/org/gcube/application/geoportal/service/{rest/GeoportalHealthCheck.java => health/MongoHealthCheck.java} (67%) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java 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(); + } + +} From 2dc1e7c8aa572ec29eb093734d5757b9ee508f21 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 15:22:29 +0200 Subject: [PATCH 13/43] added GeoportalHealthResource --- .../geoportal/service/GeoPortalService.java | 4 ++-- .../service/health/GeoportalHealthCheck.java | 14 +++++--------- .../service/health/MongoHealthCheck.java | 18 +++++++++--------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index f4a0387..faa09e3 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -21,10 +21,10 @@ import org.gcube.application.geoportal.service.engine.providers.ucd.ProfileMap; import org.gcube.application.geoportal.service.engine.providers.ucd.SingleISResourceUCDProvider; import org.gcube.application.geoportal.service.engine.providers.ucd.UCDManager; import org.gcube.application.geoportal.service.model.internal.db.Mongo; +import org.gcube.application.geoportal.service.rest.GeoportalHealth; import org.gcube.application.geoportal.service.rest.Plugins; import org.gcube.application.geoportal.service.rest.ProfiledDocuments; import org.gcube.application.geoportal.service.rest.UseCaseDescriptors; -import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; import org.glassfish.jersey.server.ResourceConfig; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; @@ -54,7 +54,7 @@ public class GeoPortalService extends ResourceConfig{ registerClasses(ProfiledDocuments.class); registerClasses(UseCaseDescriptors.class); registerClasses(Plugins.class); - registerClasses(GeoportalHealthCheck.class); + registerClasses(GeoportalHealth.class); //registerClasses(DocsGenerator.class); log.info("Setting implementations .. "); 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 index 41877c7..5d0ff7b 100644 --- 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 @@ -22,20 +22,16 @@ 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(); // } @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); - return HealthCheckResponse.named(SERVICE_NAME).state(true).build(); + return HealthCheckResponse.named(SERVICE_NAME).state(true).withData("status", "healthy").build(); } - } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java index 09d3e70..e73b086 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java @@ -38,36 +38,36 @@ public class MongoHealthCheck implements HealthCheck { } private HealthCheckResponse checkMongo(String context) { - HealthCheckResponseBuilder buildHCRProvider = HealthCheckResponse.named(SERVICE_NAME); + HealthCheckResponseBuilder buildHCRBuilder = HealthCheckResponse.named(SERVICE_NAME); Mongo mongo = null; try { ScopeProvider.instance.set(context); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); - buildHCRProvider = appendMongoInfo(buildHCRProvider, mongo.getConnection()); - buildHCRProvider.state(true); + buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); + buildHCRBuilder.state(true); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); int i = 1; for (String coll : collections) { log.info("adding collection: {}", coll); - buildHCRProvider.withData("collection " + i, coll); + buildHCRBuilder.withData("collection " + i, coll); i++; } - return buildHCRProvider.build(); + return buildHCRBuilder.build(); } catch (Exception e) { - buildHCRProvider.state(false); + buildHCRBuilder.state(false); if (mongo != null) { MongoConnection connection = null; try { connection = mongo.getConnection(); - buildHCRProvider = appendMongoInfo(buildHCRProvider, connection); + buildHCRBuilder = appendMongoInfo(buildHCRBuilder, connection); } catch (Exception e1) { - buildHCRProvider.withData("hosts ", connection.getHosts() + ""); + buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); } } - return buildHCRProvider.build(); + return buildHCRBuilder.build(); } finally { ScopeProvider.instance.reset(); } From aace2f9c3f72e495d6643265c6fc454d2bc48212 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 15:49:16 +0200 Subject: [PATCH 14/43] removed @Inject --- .../service/health/GeoportalHealthCheck.java | 11 ----------- .../geoportal/service/health/MongoHealthCheck.java | 5 +---- .../geoportal/service/rest/GeoportalHealth.java | 11 ++--------- 3 files changed, 3 insertions(+), 24 deletions(-) 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 index 5d0ff7b..ae8f94f 100644 --- 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 @@ -1,11 +1,6 @@ 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; @@ -22,12 +17,6 @@ public class GeoportalHealthCheck implements HealthCheck { private static final String SERVICE_NAME = "geooportal-service"; -// @Override -// public HealthCheckResponse call() { -// log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); -// return HealthCheckResponse.named(SERVICE_NAME).state(true).build(); -// } - @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java index e73b086..ca7b1b4 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java @@ -1,8 +1,6 @@ package org.gcube.application.geoportal.service.health; import javax.enterprise.context.ApplicationScoped; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -32,9 +30,8 @@ public class MongoHealthCheck implements HealthCheck { return checkMongo(context); } - public MongoHealthCheck context(String context) { + public MongoHealthCheck(String context) { this.context = context; - return this; } private HealthCheckResponse checkMongo(String 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 index fed36bd..549b030 100644 --- 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 @@ -1,6 +1,5 @@ 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; @@ -17,18 +16,12 @@ import lombok.extern.slf4j.Slf4j; @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(); + return new GeoportalHealthCheck().call(); } @GET @@ -40,7 +33,7 @@ public class GeoportalHealth { return HealthCheckResponse.named("databaseCheck") .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); - return mongoHC.context(context).call(); + return new MongoHealthCheck(context).call(); } } From 4152d6f17fb70f67db338c7d90fc3c3031196fbd Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 17 Oct 2024 16:59:13 +0200 Subject: [PATCH 15/43] updated pom of the cms-suite --- geoportal-service/pom.xml | 8 +------- .../service/rest/GeoportalHealth.java | 4 ++-- .../health/GeoportalHealthCheck.java | 8 +++----- .../{ => rest}/health/MongoHealthCheck.java | 9 +++------ pom.xml | 18 +++++++++--------- 5 files changed, 18 insertions(+), 29 deletions(-) rename geoportal-service/src/main/java/org/gcube/application/geoportal/service/{ => rest}/health/GeoportalHealthCheck.java (69%) rename geoportal-service/src/main/java/org/gcube/application/geoportal/service/{ => rest}/health/MongoHealthCheck.java (92%) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 2f04bc1..fe25a84 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -164,13 +164,7 @@ io.smallrye smallrye-health - 2.2.6 - - - - javax.enterprise - cdi-api - 2.0 + 2.1.0 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 index 549b030..c04fdc6 100644 --- 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 @@ -7,8 +7,8 @@ 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 org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; +import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck; import lombok.extern.slf4j.Slf4j; 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/rest/health/GeoportalHealthCheck.java similarity index 69% rename from geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/GeoportalHealthCheck.java rename to geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index ae8f94f..7cd1ff5 100644 --- 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/rest/health/GeoportalHealthCheck.java @@ -1,6 +1,4 @@ -package org.gcube.application.geoportal.service.health; - -import javax.enterprise.context.ApplicationScoped; +package org.gcube.application.geoportal.service.rest.health; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -9,7 +7,7 @@ import org.eclipse.microprofile.health.Readiness; import lombok.extern.slf4j.Slf4j; -@ApplicationScoped + @Readiness @Liveness @Slf4j @@ -20,7 +18,7 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); - return HealthCheckResponse.named(SERVICE_NAME).state(true).withData("status", "healthy").build(); + return HealthCheckResponse.named(SERVICE_NAME).status(true).withData("status", "healthy").build(); } } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java similarity index 92% rename from geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java rename to geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index ca7b1b4..d1be35a 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -1,6 +1,4 @@ -package org.gcube.application.geoportal.service.health; - -import javax.enterprise.context.ApplicationScoped; +package org.gcube.application.geoportal.service.rest.health; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -16,7 +14,6 @@ import com.mongodb.client.MongoIterable; import lombok.extern.slf4j.Slf4j; -@ApplicationScoped @Readiness @Liveness @Slf4j @@ -41,7 +38,7 @@ public class MongoHealthCheck implements HealthCheck { ScopeProvider.instance.set(context); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); - buildHCRBuilder.state(true); + buildHCRBuilder.status(true); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); @@ -53,7 +50,7 @@ public class MongoHealthCheck implements HealthCheck { } return buildHCRBuilder.build(); } catch (Exception e) { - buildHCRBuilder.state(false); + buildHCRBuilder.status(false); if (mongo != null) { MongoConnection connection = null; try { diff --git a/pom.xml b/pom.xml index 34e7fe0..df38443 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,10 @@ https://code-repo.d4science.org/gCubeSystem - 2.5.1 [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) - 1.0.6 - [2.0.0, 3.0.0-SNAPSHOT) + ${gcube-smartgears-bom-version-p} + ${plugin-framework-version-p} + ${authorization-utils-range-p} @@ -39,9 +39,9 @@ - 2.5.1 - 1.0.6 - [2.0.0, 3.0.0-SNAPSHOT) + 2.5.1 + 1.0.6 + [2.0.0, 3.0.0-SNAPSHOT) @@ -53,9 +53,9 @@ - 2.5.1-SNAPSHOT - 1.0.6-SNAPSHOT - [2.0.0, 3.0.0-SNAPSHOT) + 2.5.1-SNAPSHOT + 1.0.6-SNAPSHOT + [2.0.0, 3.0.0-SNAPSHOT) From 773b6d572006406a8cba7ae7f336d8db42497c60 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 10:53:58 +0200 Subject: [PATCH 16/43] updated state --- .../geoportal/service/rest/health/GeoportalHealthCheck.java | 2 +- .../geoportal/service/rest/health/MongoHealthCheck.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index 7cd1ff5..b8c38ce 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -18,7 +18,7 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); - return HealthCheckResponse.named(SERVICE_NAME).status(true).withData("status", "healthy").build(); + return HealthCheckResponse.named(SERVICE_NAME).state(true).withData("status", "healthy").build(); } } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index d1be35a..4e88e51 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -38,7 +38,7 @@ public class MongoHealthCheck implements HealthCheck { ScopeProvider.instance.set(context); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); - buildHCRBuilder.status(true); + buildHCRBuilder.state(true); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); @@ -50,7 +50,7 @@ public class MongoHealthCheck implements HealthCheck { } return buildHCRBuilder.build(); } catch (Exception e) { - buildHCRBuilder.status(false); + buildHCRBuilder.state(false); if (mongo != null) { MongoConnection connection = null; try { From 28508eef33d3cd4353e6fb681051eb2e8be6639b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 11:29:05 +0200 Subject: [PATCH 17/43] updated pom --- CHANGELOG.md | 2 +- pom.xml | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 847a49b..c6f418f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for org.gcube.spatial.data.gcube-sdi-suite -## [v1.0.6] +## [v1.0.6-SNAPSHOT] - Integrated an EventManager centrally [#26321] - sdi-plugins: add the logic to apply a regex to the value that must be added to index [#26322] diff --git a/pom.xml b/pom.xml index df38443..afe3c07 100644 --- a/pom.xml +++ b/pom.xml @@ -10,25 +10,11 @@ org.gcube.application.cms gcube-cms-suite pom - 1.0.6 + 1.0.6-SNAPSHOT Gcube CMS Suite gCube CMS Suite is a set of components designed to manage complex space-temporal Documents defined by metadata Profiles. - - UTF-8 - 8.0-M4 - 3.0.1 - distro - https://code-repo.d4science.org/gCubeSystem - - - [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) - ${gcube-smartgears-bom-version-p} - ${plugin-framework-version-p} - ${authorization-utils-range-p} - - @@ -48,6 +34,7 @@ geoportal-snapshot-profile + true !Release @@ -60,6 +47,20 @@ + + UTF-8 + 8.0-M4 + 3.0.1 + distro + https://code-repo.d4science.org/gCubeSystem + + + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + ${gcube-smartgears-bom-version-p} + ${plugin-framework-version-p} + ${authorization-utils-range-p} + + From 536c96e09ff18c1c6b13af3ea95d29cfd1b7e420 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 14:21:09 +0200 Subject: [PATCH 18/43] merged with `master` branch --- catalogue-binding-plugin/pom.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/catalogue-binding-plugin/pom.xml b/catalogue-binding-plugin/pom.xml index 6760516..836b8c3 100644 --- a/catalogue-binding-plugin/pom.xml +++ b/catalogue-binding-plugin/pom.xml @@ -52,13 +52,13 @@ org.gcube.portlets.user uri-resolver-manager - [1.0.0,2.0.0-SNAPSHOT) + [1.8.0-SNAPSHOT,2.0.0-SNAPSHOT) org.gcube.data-catalogue gcat-client - [2.0.0,3.0.0-SNAPSHOT) + [2.4.0,3.0.0-SNAPSHOT) @@ -73,11 +73,11 @@ json 20090211 - + org.gcube.application geoportal-client - [1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT) + [1.2.2-SNAPSHOT, 2.0.0-SNAPSHOT) javax.servlet @@ -91,16 +91,10 @@ test - - org.slf4j - slf4j-api - provided - - org.gcube.application geoportal-data-mapper - [1.0.0, 2.0.0-SNAPSHOT) + [1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT) @@ -122,6 +116,12 @@ test + + org.slf4j + slf4j-api + provided + + From 903a48923a445d60f585c0cab67cbd506304af89 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 14:51:43 +0200 Subject: [PATCH 19/43] updaed dependency at helidon-microprofile-health v2.2.2 --- geoportal-service/pom.xml | 16 +++- .../HealthCheckResponseGeoportalProvider.java | 95 ------------------- 2 files changed, 11 insertions(+), 100 deletions(-) delete mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index fe25a84..915e16b 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -161,12 +161,18 @@ - - io.smallrye - smallrye-health - 2.1.0 - + + + + + + + + io.helidon.microprofile.health + helidon-microprofile-health + 2.2.2 + diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java deleted file mode 100644 index a744dad..0000000 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/check/HealthCheckResponseGeoportalProvider.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.gcube.application.geoportal.service.rest.check; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.HealthCheckResponse.State; - -import lombok.extern.slf4j.Slf4j; - -/** - * The Class HealthCheckResponseGeoportalProvider. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Oct 16, 2024 - */ -@Slf4j -public class HealthCheckResponseGeoportalProvider { - - private String name; - private Optional> data; - private Map myMap; - private State state; - - /** - * Instantiates a new health check response geoportal provider. - */ - public HealthCheckResponseGeoportalProvider() { - - } - - /** - * Instantiates a new health check response geoportal provider. - * - * @param name the name - * @param status the status - * @param data the data - */ - public HealthCheckResponseGeoportalProvider(String name, State state, Optional> data) { - this.name = name; - this.state = state; - this.data = data; - } - - public String getName() { - return name; - } - - public Optional> getData() { - return data; - } - - public State getState() { - return state; - } - - public void setName(String name) { - this.name = name; - } - - public void setState(State state) { - this.state = state; - } - - /** - * With data. - * - * @param key the key - * @param value the value - */ - public void withData(String key, String value) { - if (myMap == null) { - myMap = new HashMap<>(); - } - - myMap.put(key, value); - } - - /** - * Builds the health check response. - * - * @return the health check response - */ - public HealthCheckResponse buildHealthCheckResponse() { - if (myMap != null) - data = Optional.of(myMap); - - log.info("data are: " + data); - - return new HealthCheckResponse(name, state, data); - } - -} From d3a63635c9718eefac5518c5899510bea134f184 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 14:55:17 +0200 Subject: [PATCH 20/43] reverted the pom --- pom.xml | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index afe3c07..5e8e136 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,20 @@ gCube CMS Suite is a set of components designed to manage complex space-temporal Documents defined by metadata Profiles. + + UTF-8 + 8.0-M4 + 3.0.1 + distro + https://code-repo.d4science.org/gCubeSystem + + + 2.5.1 + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + 1.0.6 + [2.0.0, 3.0.0-SNAPSHOT) + + @@ -25,42 +39,27 @@ - 2.5.1 - 1.0.6 - [2.0.0, 3.0.0-SNAPSHOT) + 2.5.1 + 1.0.6 + [2.0.0, 3.0.0-SNAPSHOT) geoportal-snapshot-profile - true !Release - 2.5.1-SNAPSHOT - 1.0.6-SNAPSHOT - [2.0.0, 3.0.0-SNAPSHOT) + 2.5.1-SNAPSHOT + 1.0.6-SNAPSHOT + [2.0.0, 3.0.0-SNAPSHOT) - - UTF-8 - 8.0-M4 - 3.0.1 - distro - https://code-repo.d4science.org/gCubeSystem - - - [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) - ${gcube-smartgears-bom-version-p} - ${plugin-framework-version-p} - ${authorization-utils-range-p} - - From c2f65dd2342fd65690beb56e3449b78a1091b218 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 15:05:19 +0200 Subject: [PATCH 21/43] added smallrye-health v2.2.3 --- geoportal-service/pom.xml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index 915e16b..f195cdf 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -161,18 +161,12 @@ - - - - - - - - io.helidon.microprofile.health - helidon-microprofile-health - 2.2.2 + io.smallrye + smallrye-health + 2.2.3 + From ca5c9eec77b943237f2e4afdde9c1b467564a855 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 15:14:02 +0200 Subject: [PATCH 22/43] added log --- .../geoportal/service/rest/health/GeoportalHealthCheck.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index b8c38ce..a7c3463 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -18,7 +18,9 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); - return HealthCheckResponse.named(SERVICE_NAME).state(true).withData("status", "healthy").build(); + HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).withData("serviceStatus", "healthy").build(); + log.info("Generated HealthCheckResponse: " + response); + return response; } } From 6e608191df191077f653f38c3856819bb7b5267f Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 15:20:54 +0200 Subject: [PATCH 23/43] added other logs --- .../geoportal/service/rest/health/GeoportalHealthCheck.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index a7c3463..d08f6da 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -19,7 +19,8 @@ public class GeoportalHealthCheck implements HealthCheck { public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).withData("serviceStatus", "healthy").build(); - log.info("Generated HealthCheckResponse: " + response); + log.info("Generated HealthCheckResponse: " + response.toString()); + log.info("Generated HealthCheckResponse map: " + response.getData()!=null?response.getData().toString():""); return response; } From af16e3b20046965e588619275965faf982d1fd98 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 15:36:16 +0200 Subject: [PATCH 24/43] added custom serializer --- .../service/rest/GeoportalHealth.java | 19 ++++++++++++++++--- .../rest/health/GeoportalHealthCheck.java | 2 -- 2 files changed, 16 insertions(+), 5 deletions(-) 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 index c04fdc6..11cf4ca 100644 --- 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 @@ -5,11 +5,15 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheckResponse; import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + import lombok.extern.slf4j.Slf4j; @Path("/health") @@ -18,10 +22,13 @@ public class GeoportalHealth { @GET @Path("") - @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) - public HealthCheckResponse serviceCheck() { + @Produces({ MediaType.APPLICATION_JSON }) + public String serviceCheck() throws JsonProcessingException { log.info("serviceCheck called"); - return new GeoportalHealthCheck().call(); + HealthCheckResponse response = new GeoportalHealthCheck().call(); + String json = healthCheckSerializer(response); + log.info("serviceCheck response is {}", json); + return json; } @GET @@ -36,4 +43,10 @@ public class GeoportalHealth { return new MongoHealthCheck(context).call(); } + private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + // Serializes HealthCheckResponse in JSON + return mapper.writeValueAsString(response); + } + } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index d08f6da..466d2fe 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -19,8 +19,6 @@ public class GeoportalHealthCheck implements HealthCheck { public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).withData("serviceStatus", "healthy").build(); - log.info("Generated HealthCheckResponse: " + response.toString()); - log.info("Generated HealthCheckResponse map: " + response.getData()!=null?response.getData().toString():""); return response; } From e7d6a2d70715326dfba1e95902553673387da5be Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 16:35:22 +0200 Subject: [PATCH 25/43] added custom HealthCheckResponseSerializer --- .../service/rest/GeoportalHealth.java | 37 ++++++++++++----- .../rest/health/GeoportalHealthCheck.java | 4 +- .../health/HealthCheckResponseSerializer.java | 40 +++++++++++++++++++ .../service/health/HealthCheckSerializer.java | 32 +++++++++++++++ 4 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/HealthCheckResponseSerializer.java create mode 100644 geoportal-service/src/test/java/org/gcube/application/geoportal/service/health/HealthCheckSerializer.java 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 index 11cf4ca..b95ff0e 100644 --- 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 @@ -9,10 +9,12 @@ import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheckResponse; import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; +import org.gcube.application.geoportal.service.rest.health.HealthCheckResponseSerializer; import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import lombok.extern.slf4j.Slf4j; @@ -20,32 +22,47 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class GeoportalHealth { + private ObjectMapper mapper = new ObjectMapper(); + + public GeoportalHealth() { + SimpleModule module = new SimpleModule(); + module.addSerializer(HealthCheckResponse.class, new HealthCheckResponseSerializer()); + mapper.registerModule(module); + } + @GET @Path("") @Produces({ MediaType.APPLICATION_JSON }) - public String serviceCheck() throws JsonProcessingException { - log.info("serviceCheck called"); + public Response serviceCheck() throws JsonProcessingException { + log.debug("serviceCheck called"); HealthCheckResponse response = new GeoportalHealthCheck().call(); String json = healthCheckSerializer(response); log.info("serviceCheck response is {}", json); - return json; + return Response.ok().entity(json).build(); } @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") + public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { + log.debug("databaseCheck called in the context {}", context); + if (context == null) { + HealthCheckResponse response = HealthCheckResponse.named("databaseCheck") .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); + String json = healthCheckSerializer(response); + log.info("databaseCheck error response is {}", json); + // Bad request + return Response.status(400).entity(json).build(); + } - return new MongoHealthCheck(context).call(); + HealthCheckResponse response = new MongoHealthCheck(context).call(); + String json = healthCheckSerializer(response); + log.info("databaseCheck response is {}", json); + return Response.ok().entity(json).build(); } private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); - // Serializes HealthCheckResponse in JSON + // Serializes HealthCheckResponse in JSON with custom HealthCheckResponseSerializer return mapper.writeValueAsString(response); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index 466d2fe..834dccb 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -7,7 +7,6 @@ import org.eclipse.microprofile.health.Readiness; import lombok.extern.slf4j.Slf4j; - @Readiness @Liveness @Slf4j @@ -18,7 +17,8 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); - HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).withData("serviceStatus", "healthy").build(); + HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true) + .withData("serviceStatus", "healthy").build(); return response; } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/HealthCheckResponseSerializer.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/HealthCheckResponseSerializer.java new file mode 100644 index 0000000..fbb4972 --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/HealthCheckResponseSerializer.java @@ -0,0 +1,40 @@ +package org.gcube.application.geoportal.service.rest.health; + +import java.io.IOException; +import java.util.Map; + +import org.eclipse.microprofile.health.HealthCheckResponse; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HealthCheckResponseSerializer extends JsonSerializer { + + @Override + public void serialize(HealthCheckResponse response, JsonGenerator gen, SerializerProvider serializers) + throws IOException { + gen.writeStartObject(); + if (response.getName() != null) + gen.writeStringField("name", response.getName()); + if (response.getState() != null) + gen.writeStringField("state", response.getState().toString()); + + response.getData().ifPresent(data -> { + try { + gen.writeObjectFieldStart("data"); + for (Map.Entry entry : data.entrySet()) { + gen.writeObjectField(entry.getKey(), entry.getValue()); + } + gen.writeEndObject(); + } catch (IOException e) { + log.warn("Error on serializing the data field", e); + } + }); + + gen.writeEndObject(); + } +} \ No newline at end of file diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/health/HealthCheckSerializer.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/health/HealthCheckSerializer.java new file mode 100644 index 0000000..44a1101 --- /dev/null +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/health/HealthCheckSerializer.java @@ -0,0 +1,32 @@ +package org.gcube.application.geoportal.service.health; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.gcube.application.geoportal.service.rest.health.HealthCheckResponseSerializer; + +public class HealthCheckSerializer { + + public static void main(String[] args) throws Exception { + HealthCheckResponse response = HealthCheckResponse.named("geooportal-service") + .state(true) + .withData("status", "healthy") + .build(); + + // Configura ObjectMapper con il serializer personalizzato + ObjectMapper mapper = new ObjectMapper(); + SimpleModule module = new SimpleModule(); + module.addSerializer(HealthCheckResponse.class, new HealthCheckResponseSerializer()); + mapper.registerModule(module); + + // Serializza l'oggetto HealthCheckResponse in JSON + String json = mapper.writeValueAsString(response); + + // Stampa il JSON serializzato + System.out.println(json); + } + + + +} \ No newline at end of file From 8cea8b9aea9ef01f1c460eaadfda4248bcf357e6 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 16:50:07 +0200 Subject: [PATCH 26/43] updated --- .../geoportal/service/rest/health/GeoportalHealthCheck.java | 3 +-- .../geoportal/service/rest/health/MongoHealthCheck.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index 834dccb..09ca5fb 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -17,8 +17,7 @@ public class GeoportalHealthCheck implements HealthCheck { @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); - HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true) - .withData("serviceStatus", "healthy").build(); + HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).build(); return response; } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index 4e88e51..9771096 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -45,7 +45,7 @@ public class MongoHealthCheck implements HealthCheck { int i = 1; for (String coll : collections) { log.info("adding collection: {}", coll); - buildHCRBuilder.withData("collection " + i, coll); + buildHCRBuilder.withData("collection_" + i, coll); i++; } return buildHCRBuilder.build(); @@ -57,7 +57,7 @@ public class MongoHealthCheck implements HealthCheck { connection = mongo.getConnection(); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, connection); } catch (Exception e1) { - buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); + buildHCRBuilder.withData("hosts", connection.getHosts() + ""); } } @@ -69,7 +69,7 @@ public class MongoHealthCheck implements HealthCheck { private HealthCheckResponseBuilder appendMongoInfo(HealthCheckResponseBuilder buildHCRBuilder, MongoConnection connection) { - buildHCRBuilder.withData("hosts ", connection.getHosts() + ""); + buildHCRBuilder.withData("hosts", connection.getHosts() + ""); buildHCRBuilder.withData("db_name ", connection.getDatabase()); return buildHCRBuilder; } From 9e3549e4100d1e012b84358d95b6adad16c61041 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 16:56:04 +0200 Subject: [PATCH 27/43] fixed produces to MediaType.APPLICATION_JSON --- .../service/rest/GeoportalHealth.java | 5 +- .../geoportal/service/rest/GuardedMethod.java | 71 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) 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 index b95ff0e..d66013b 100644 --- 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 @@ -43,7 +43,7 @@ public class GeoportalHealth { @GET @Path("/mongo") - @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { log.debug("databaseCheck called in the context {}", context); if (context == null) { @@ -62,7 +62,8 @@ public class GeoportalHealth { } private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { - // Serializes HealthCheckResponse in JSON with custom HealthCheckResponseSerializer + // Serializes HealthCheckResponse in JSON with custom + // HealthCheckResponseSerializer return mapper.writeValueAsString(response); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java index 49bb9ce..bffc3ca 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java @@ -19,18 +19,15 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class GuardedMethod { - private static List preoperations=new ArrayList<>(); + private static List preoperations = new ArrayList<>(); - public static void addPreoperation(Runnable preoperation){ + public static void addPreoperation(Runnable preoperation) { preoperations.add(preoperation); } + private T result = null; - - - private T result=null; - - public GuardedMethod execute() throws WebApplicationException{ + public GuardedMethod execute() throws WebApplicationException { try { if (!preoperations.isEmpty()) { log.trace("Running preops (size : {} )", preoperations.size()); @@ -40,41 +37,41 @@ public abstract class GuardedMethod { log.trace("Executing actual method.."); result = run(); return this; - }catch (InvalidUserRoleException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Invalid Step ID ", e,Status.FORBIDDEN); - }catch (UnrecognizedStepException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Invalid Step ID ", e,Status.BAD_REQUEST); - }catch (ConfigurationException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Environment is not properly configured", e,Status.EXPECTATION_FAILED); - }catch (InsufficientPrivileges e){ - log.error("Returning exception ",e); - throw new WebApplicationException("User has insufficient privileges for requested action", e,Status.FORBIDDEN); - }catch(WebApplicationException e) { + } catch (InvalidUserRoleException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Invalid Step ID ", e, Status.FORBIDDEN); + } catch (UnrecognizedStepException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Invalid Step ID ", e, Status.BAD_REQUEST); + } catch (ConfigurationException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Environment is not properly configured", e, Status.EXPECTATION_FAILED); + } catch (InsufficientPrivileges e) { + log.error("Returning exception ", e); + throw new WebApplicationException("User has insufficient privileges for requested action", e, + Status.FORBIDDEN); + } catch (WebApplicationException e) { log.error("Throwing Web Application Exception ", e); throw e; - }catch(ProjectNotFoundException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Project not found", e,Status.NOT_FOUND); - }catch(ProjectLockedException e){ - log.error("Returning exception ",e); - throw new WebApplicationException("Project is currently locked", e,Status.PRECONDITION_FAILED); - }catch(InvalidLockException e){ - log.error("Lock exception ",e); - throw new WebApplicationException("Conflicts found in locks", e,Status.CONFLICT); - }catch(Throwable t) { - log.error("Unexpected error ",t); - throw new WebApplicationException("Unexpected internal error", t,Status.INTERNAL_SERVER_ERROR); + } catch (ProjectNotFoundException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Project not found", e, Status.NOT_FOUND); + } catch (ProjectLockedException e) { + log.error("Returning exception ", e); + throw new WebApplicationException("Project is currently locked", e, Status.PRECONDITION_FAILED); + } catch (InvalidLockException e) { + log.error("Lock exception ", e); + throw new WebApplicationException("Conflicts found in locks", e, Status.CONFLICT); + } catch (Throwable t) { + log.error("Unexpected error ", t); + throw new WebApplicationException("Unexpected internal error", t, Status.INTERNAL_SERVER_ERROR); } - + } - + public T getResult() { return result; } - - - protected abstract T run() throws Exception,WebApplicationException; + + protected abstract T run() throws Exception, WebApplicationException; } From a991055fd64a2b489f7302f362cb7f2eabc2f76b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 16:56:22 +0200 Subject: [PATCH 28/43] formatted --- .../geoportal/service/GeoPortalService.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index faa09e3..7d7e531 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -33,29 +33,28 @@ import lombok.extern.slf4j.Slf4j; @ApplicationPath(InterfaceConstants.APPLICATION_PATH) @Slf4j -public class GeoPortalService extends ResourceConfig{ +public class GeoPortalService extends ResourceConfig { - public Map,Class> customImplementations(){ + public Map, Class> customImplementations() { return Collections.EMPTY_MAP; } - + public GeoPortalService() { super(); - //Register interrfaces + // Register interfaces log.info("Initializing serialization"); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(Serialization.mapper); register(provider); - registerClasses(RequestFilter.class); registerClasses(ProfiledDocuments.class); registerClasses(UseCaseDescriptors.class); registerClasses(Plugins.class); registerClasses(GeoportalHealth.class); - //registerClasses(DocsGenerator.class); + // registerClasses(DocsGenerator.class); log.info("Setting implementations .. "); @@ -64,25 +63,19 @@ public class GeoPortalService extends ResourceConfig{ ImplementationProvider.get().setEngine(new StorageClientProvider(), StorageUtils.class); ImplementationProvider.get().setEngine(new SingleISResourceUCDProvider(), ProfileMap.class); ImplementationProvider.get().setEngine(new PluginManager(), PluginManager.PluginMap.class); - ImplementationProvider.get().setEngine(new UCDManager(),UCDManagerI.class); + ImplementationProvider.get().setEngine(new UCDManager(), UCDManagerI.class); ImplementationProvider.get().setEngine(new ConfigurationCache(), ConfigurationCache.ConfigurationMap.class); - - for(Map.Entry, Class> entry : customImplementations().entrySet()){ - log.warn("LOADING CUSTOM ENGINE : {} serving {}",entry.getKey(),entry.getValue()); + for (Map.Entry, Class> entry : customImplementations().entrySet()) { + log.warn("LOADING CUSTOM ENGINE : {} serving {}", entry.getKey(), entry.getValue()); ImplementationProvider.get().setEngine(entry.getKey(), entry.getValue()); } log.debug("ENGINES ARE : "); - ImplementationProvider.get().getManagerList().forEach( - (aClass, s) -> log.debug("{} serving {} ",aClass,s)); + ImplementationProvider.get().getManagerList().forEach((aClass, s) -> log.debug("{} serving {} ", aClass, s)); ImplementationProvider.get().initEngines(); - } - - - } From fb6857a984f60c60dba64dc54aecfa7a8c519895 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 17:24:38 +0200 Subject: [PATCH 29/43] added /health into servlet mapping --- .../extra-resources/WEB-INF/gcube-app.xml | 1 - .../geoportal/service/GeoPortalService.java | 2 +- .../src/main/webapp/WEB-INF/web.xml | 23 ++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml b/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml index 132eedd..41d1018 100644 --- a/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml +++ b/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml @@ -8,6 +8,5 @@ /srv/docs/* /srv/api-docs/* /srv/health - /srv/health/* diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index 7d7e531..0a4bcb2 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -53,7 +53,7 @@ public class GeoPortalService extends ResourceConfig { registerClasses(ProfiledDocuments.class); registerClasses(UseCaseDescriptors.class); registerClasses(Plugins.class); - registerClasses(GeoportalHealth.class); + //registerClasses(GeoportalHealth.class); // registerClasses(DocsGenerator.class); log.info("Setting implementations .. "); diff --git a/geoportal-service/src/main/webapp/WEB-INF/web.xml b/geoportal-service/src/main/webapp/WEB-INF/web.xml index b387ccd..5c7e88d 100644 --- a/geoportal-service/src/main/webapp/WEB-INF/web.xml +++ b/geoportal-service/src/main/webapp/WEB-INF/web.xml @@ -1,11 +1,13 @@ - org.gcube.application.geoportal.service.GeoPortalService + org.gcube.application.geoportal.service.GeoPortalService + org.glassfish.jersey.servlet.ServletContainer javax.ws.rs.Application - org.gcube.application.geoportal.service.GeoPortalService + org.gcube.application.geoportal.service.GeoPortalService + jersey.config.server.provider.classnames @@ -20,16 +22,21 @@ - default - /docs/* - + default + /docs/* + - default - /api-docs/* + default + /api-docs/* + + + default + /health - org.gcube.application.geoportal.service.GeoPortalService + org.gcube.application.geoportal.service.GeoPortalService + /srv/* \ No newline at end of file From 44335052c30161acdbd95d8e1fa4080babcfbce0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 18 Oct 2024 17:37:45 +0200 Subject: [PATCH 30/43] added GeoPortalServiceHealth under /api/health --- .../service/GeoPortalServiceHealth.java | 17 +++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java new file mode 100644 index 0000000..71b187b --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java @@ -0,0 +1,17 @@ +package org.gcube.application.geoportal.service; + +import javax.ws.rs.ApplicationPath; + +import org.gcube.application.geoportal.service.rest.GeoportalHealth; +import org.glassfish.jersey.server.ResourceConfig; + +@ApplicationPath("/api") +public class GeoPortalServiceHealth extends ResourceConfig { + + public GeoPortalServiceHealth() { + + registerClasses(GeoportalHealth.class); + + } + +} diff --git a/geoportal-service/src/main/webapp/WEB-INF/web.xml b/geoportal-service/src/main/webapp/WEB-INF/web.xml index 5c7e88d..078da9f 100644 --- a/geoportal-service/src/main/webapp/WEB-INF/web.xml +++ b/geoportal-service/src/main/webapp/WEB-INF/web.xml @@ -31,7 +31,7 @@ default - /health + /api/health From c5b325344b63932644739de287fadf6e8206a6a1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 21 Oct 2024 10:43:38 +0200 Subject: [PATCH 31/43] Updated gcube-app configuration --- .../geoportal/service/GeoPortalService.java | 2 +- .../service/GeoPortalServiceHealth.java | 34 +++++++++---------- .../src/main/webapp/WEB-INF/gcube-app.xml | 12 +++++++ .../src/main/webapp/WEB-INF/web.xml | 6 +--- 4 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index 0a4bcb2..7d7e531 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -53,7 +53,7 @@ public class GeoPortalService extends ResourceConfig { registerClasses(ProfiledDocuments.class); registerClasses(UseCaseDescriptors.class); registerClasses(Plugins.class); - //registerClasses(GeoportalHealth.class); + registerClasses(GeoportalHealth.class); // registerClasses(DocsGenerator.class); log.info("Setting implementations .. "); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java index 71b187b..09ea94c 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java @@ -1,17 +1,17 @@ -package org.gcube.application.geoportal.service; - -import javax.ws.rs.ApplicationPath; - -import org.gcube.application.geoportal.service.rest.GeoportalHealth; -import org.glassfish.jersey.server.ResourceConfig; - -@ApplicationPath("/api") -public class GeoPortalServiceHealth extends ResourceConfig { - - public GeoPortalServiceHealth() { - - registerClasses(GeoportalHealth.class); - - } - -} +//package org.gcube.application.geoportal.service; +// +//import javax.ws.rs.ApplicationPath; +// +//import org.gcube.application.geoportal.service.rest.GeoportalHealth; +//import org.glassfish.jersey.server.ResourceConfig; +// +//@ApplicationPath("/") +//public class GeoPortalServiceHealth extends ResourceConfig { +// +// public GeoPortalServiceHealth() { +// +// registerClasses(GeoportalHealth.class); +// +// } +// +//} diff --git a/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml b/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml new file mode 100644 index 0000000..41ab521 --- /dev/null +++ b/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml @@ -0,0 +1,12 @@ + + + + ${project.artifactId} + ${project.groupId} + ${project.version} + ${project.description} + + + /src/health + + diff --git a/geoportal-service/src/main/webapp/WEB-INF/web.xml b/geoportal-service/src/main/webapp/WEB-INF/web.xml index 078da9f..ef51265 100644 --- a/geoportal-service/src/main/webapp/WEB-INF/web.xml +++ b/geoportal-service/src/main/webapp/WEB-INF/web.xml @@ -29,11 +29,7 @@ default /api-docs/* - - default - /api/health - - + org.gcube.application.geoportal.service.GeoPortalService From 3b208b450e4d923988f7eaccd075d01e5728951a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 21 Oct 2024 13:58:33 +0200 Subject: [PATCH 32/43] added exclude `/srv/health` --- .../gcube/extra-resources/WEB-INF/gcube-app.xml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml b/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml index 41d1018..a417488 100644 --- a/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml +++ b/geoportal-service/gcube/extra-resources/WEB-INF/gcube-app.xml @@ -1,12 +1,13 @@ - ${project.artifactId} - ${project.groupId} - ${project.version} - ${project.description} - /srv/docs/* - /srv/api-docs/* - /srv/health + ${project.artifactId} + ${project.groupId} + ${project.version} + ${project.description} + + + /srv/health + /srv/health/* From a4611b887a1b98493e0d0baf3bfa239a9229fb79 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 21 Oct 2024 15:13:54 +0200 Subject: [PATCH 33/43] added more logs --- .../service/GeoPortalServiceHealth.java | 17 ----------------- .../service/rest/health/MongoHealthCheck.java | 3 +++ .../src/main/webapp/WEB-INF/gcube-app.xml | 12 ------------ 3 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java delete mode 100644 geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java deleted file mode 100644 index 09ea94c..0000000 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalServiceHealth.java +++ /dev/null @@ -1,17 +0,0 @@ -//package org.gcube.application.geoportal.service; -// -//import javax.ws.rs.ApplicationPath; -// -//import org.gcube.application.geoportal.service.rest.GeoportalHealth; -//import org.glassfish.jersey.server.ResourceConfig; -// -//@ApplicationPath("/") -//public class GeoPortalServiceHealth extends ResourceConfig { -// -// public GeoPortalServiceHealth() { -// -// registerClasses(GeoportalHealth.class); -// -// } -// -//} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index 9771096..1144696 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -32,6 +32,7 @@ public class MongoHealthCheck implements HealthCheck { } private HealthCheckResponse checkMongo(String context) { + log.debug("checkMongo in the context: {}", context); HealthCheckResponseBuilder buildHCRBuilder = HealthCheckResponse.named(SERVICE_NAME); Mongo mongo = null; try { @@ -39,6 +40,7 @@ public class MongoHealthCheck implements HealthCheck { mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); buildHCRBuilder.state(true); + log.info("checkMongo is OK in the context: {}", context); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); @@ -50,6 +52,7 @@ public class MongoHealthCheck implements HealthCheck { } return buildHCRBuilder.build(); } catch (Exception e) { + log.info("checkMongo is KO in the context: {}", context); buildHCRBuilder.state(false); if (mongo != null) { MongoConnection connection = null; diff --git a/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml b/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml deleted file mode 100644 index 41ab521..0000000 --- a/geoportal-service/src/main/webapp/WEB-INF/gcube-app.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - ${project.artifactId} - ${project.groupId} - ${project.version} - ${project.description} - - - /src/health - - From a341824dc624f8f86b434f0940b1946c5667c1c0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 22 Oct 2024 16:38:40 +0200 Subject: [PATCH 34/43] added log of exception on failing --- .../geoportal/service/rest/GeoportalHealth.java | 10 ++++++++-- .../service/rest/health/MongoHealthCheck.java | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) 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 index d66013b..d09c1c6 100644 --- 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 @@ -6,8 +6,10 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.HealthCheckResponse.State; import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; import org.gcube.application.geoportal.service.rest.health.HealthCheckResponseSerializer; import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck; @@ -47,7 +49,7 @@ public class GeoportalHealth { public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { log.debug("databaseCheck called in the context {}", context); if (context == null) { - HealthCheckResponse response = HealthCheckResponse.named("databaseCheck") + HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); String json = healthCheckSerializer(response); log.info("databaseCheck error response is {}", json); @@ -56,9 +58,13 @@ public class GeoportalHealth { } HealthCheckResponse response = new MongoHealthCheck(context).call(); + ResponseBuilder responseBuilder = Response.ok(); + if (response.getState().equals(State.DOWN)) { + responseBuilder = responseBuilder.status(503); + } String json = healthCheckSerializer(response); log.info("databaseCheck response is {}", json); - return Response.ok().entity(json).build(); + return responseBuilder.entity(json).build(); } private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index 1144696..53a00bb 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j; public class MongoHealthCheck implements HealthCheck { private String context; - private static final String SERVICE_NAME = "mongo"; + public static final String SERVICE_NAME = "mongo"; @Override public HealthCheckResponse call() { @@ -40,7 +40,6 @@ public class MongoHealthCheck implements HealthCheck { mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); buildHCRBuilder.state(true); - log.info("checkMongo is OK in the context: {}", context); MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) .listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); @@ -50,9 +49,11 @@ public class MongoHealthCheck implements HealthCheck { buildHCRBuilder.withData("collection_" + i, coll); i++; } + log.info("checkMongo is OK in the context: {}", context); return buildHCRBuilder.build(); } catch (Exception e) { - log.info("checkMongo is KO in the context: {}", context); + log.error("Error on checkMongo: ", e); + log.warn("checkMongo is KO in the context: {}", context); buildHCRBuilder.state(false); if (mongo != null) { MongoConnection connection = null; From ba3cb8eddc1dbd2e175ff426c5ceb5fd8de10b39 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 22 Oct 2024 17:09:13 +0200 Subject: [PATCH 35/43] Minor fix into UserUtils to check if the `user` is `null`. --- cms-plugin-framework/CHANGELOG.md | 3 +- cms-plugin-framework/pom.xml | 2 +- .../cms/implementations/utils/UserUtils.java | 41 ++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cms-plugin-framework/CHANGELOG.md b/cms-plugin-framework/CHANGELOG.md index f936503..e6c491a 100644 --- a/cms-plugin-framework/CHANGELOG.md +++ b/cms-plugin-framework/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog for org.gcube.application.cms-plugin-framework -## [v1.0.6] - 2024-10-01 +## [v1.0.6-SNAPSHOT] - 2024-10-01 - Included the file size to reduce/optimize the time to upload files to the storage hub [#28150] +- Checked if the user is `null` in the `UserUtils` class [#28301] ## [v1.0.5] - 2024-07-03 diff --git a/cms-plugin-framework/pom.xml b/cms-plugin-framework/pom.xml index 95a99d4..791e98b 100644 --- a/cms-plugin-framework/pom.xml +++ b/cms-plugin-framework/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cms-plugin-framework - 1.0.6 + 1.0.6-SNAPSHOT org.gcube.application.cms diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/utils/UserUtils.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/utils/UserUtils.java index 86806ff..a168533 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/utils/UserUtils.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/utils/UserUtils.java @@ -21,28 +21,31 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class UserUtils { - public static List DEFAULT_ROLES=new ArrayList<>(); + public static List DEFAULT_ROLES = new ArrayList<>(); public static AuthenticatedUser getCurrent() throws SecurityException { log.debug("Loading caller info.."); SecretManager cm = SecretManagerProvider.instance.get(); String context = cm.getContext(); - if(context==null) throw new SecurityException("Cannot determine context"); + if (context == null) + throw new SecurityException("Cannot determine context"); + Set roles = new HashSet<>(); org.gcube.common.authorization.utils.user.User user = cm.getUser(); - log.info("Identified caller {} in context {}",user.getUsername(),context); - Set roles=new HashSet<>(); - roles.addAll(user.getRoles()); + if (user == null) { + log.warn("No user found in the session work, context is {}", context); + } else { + log.info("Identified caller {} in context {}", user.getUsername(), context); + roles.addAll(user.getRoles()); + } + AuthenticatedUser toReturn = new AuthenticatedUser(user, roles, AccessTokenProvider.instance.get(), + SecurityTokenProvider.instance.get(), context); - AuthenticatedUser toReturn = - new AuthenticatedUser(user,roles, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context); - - log.info("Current User is {} ",toReturn); + log.info("Current User is {} ", toReturn); return toReturn; } - @AllArgsConstructor @Getter public static class AuthenticatedUser { @@ -63,10 +66,10 @@ public class UserUtils { builder.append("User [user="); builder.append(user); builder.append(", uma_token="); - builder.append(uma_token==null?uma_token:"***"); + builder.append(uma_token == null ? uma_token : "***"); builder.append(", gcube_token="); - builder.append(gcube_token==null?gcube_token:"***"); + builder.append(gcube_token == null ? gcube_token : "***"); builder.append(", roles="); builder.append(roles); @@ -77,14 +80,14 @@ public class UserUtils { return builder.toString(); } - public AccountingInfo asInfo(){ - AccountingInfo info=new AccountingInfo(); + public AccountingInfo asInfo() { + AccountingInfo info = new AccountingInfo(); User user = new User(); - try{ + try { user.setUsername(this.getUser().getUsername()); user.setRoles(roles); - }catch(Exception e){ - log.warn("Unable to determine user id, using FAKE",e); + } catch (Exception e) { + log.warn("Unable to determine user id, using FAKE", e); user.setUsername("FAKE"); user.setRoles(new HashSet<>()); user.getRoles().addAll(DEFAULT_ROLES); @@ -92,9 +95,9 @@ public class UserUtils { info.setUser(user); info.setInstant(LocalDateTime.now()); - Context c=new Context(); + Context c = new Context(); c.setId(this.context); - c.setName(context.contains("/")?context.substring(context.lastIndexOf("/")):context); + c.setName(context.contains("/") ? context.substring(context.lastIndexOf("/")) : context); info.setContext(c); return info; } From ed7d1e36daffbb09848f996899cb11ddc78dc5bb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 22 Oct 2024 17:32:54 +0200 Subject: [PATCH 36/43] commented the javadoc --- geoportal-service/CHANGELOG.md | 2 +- .../service/rest/GeoportalHealth.java | 35 +++++++++++- .../rest/health/GeoportalHealthCheck.java | 13 +++++ .../service/rest/health/MongoHealthCheck.java | 54 +++++++++++++++---- 4 files changed, 92 insertions(+), 12 deletions(-) diff --git a/geoportal-service/CHANGELOG.md b/geoportal-service/CHANGELOG.md index 3694189..2c89dc4 100644 --- a/geoportal-service/CHANGELOG.md +++ b/geoportal-service/CHANGELOG.md @@ -2,7 +2,7 @@ ## [v1.2.2-SNAPSHOT] - 2024-10-16 -- Included the health check at https://{geoporta_endpoint}/health via `microprofile-health-api` (see https://microprofile.io/specifications/microprofile-health/) +- Included the health check at https://{geoporta_endpoint}/health via `smallrye-health` (that implements the https://microprofile.io/specifications/microprofile-health/) [#28301] ## [v1.2.1] - 2024-10-02 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 index d09c1c6..8e9c451 100644 --- 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 @@ -20,18 +20,34 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import lombok.extern.slf4j.Slf4j; +/** + * The Class GeoportalHealth. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 22, 2024 + */ @Path("/health") @Slf4j public class GeoportalHealth { private ObjectMapper mapper = new ObjectMapper(); + /** + * Instantiates a new geoportal health. + */ public GeoportalHealth() { SimpleModule module = new SimpleModule(); module.addSerializer(HealthCheckResponse.class, new HealthCheckResponseSerializer()); mapper.registerModule(module); } + /** + * Service check. + * + * @return the response compliant to `microprofile-health` specification. 200 if is OK. Otherwise it fails. + * @throws JsonProcessingException the json processing exception + */ @GET @Path("") @Produces({ MediaType.APPLICATION_JSON }) @@ -43,10 +59,18 @@ public class GeoportalHealth { return Response.ok().entity(json).build(); } + /** + * Database check. + * + * @param context the gcube context + * @param include_collections if the check has to include the mongo collections in the response + * @return the response compliant to `microprofile-health` specification + * @throws JsonProcessingException the json processing exception + */ @GET @Path("/mongo") @Produces({ MediaType.APPLICATION_JSON }) - public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { + public Response databaseCheck(@QueryParam("context") String context, @QueryParam("include_collections") Boolean includeCollections) throws JsonProcessingException { log.debug("databaseCheck called in the context {}", context); if (context == null) { HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) @@ -57,7 +81,7 @@ public class GeoportalHealth { return Response.status(400).entity(json).build(); } - HealthCheckResponse response = new MongoHealthCheck(context).call(); + HealthCheckResponse response = new MongoHealthCheck(context, includeCollections).call(); ResponseBuilder responseBuilder = Response.ok(); if (response.getState().equals(State.DOWN)) { responseBuilder = responseBuilder.status(503); @@ -67,6 +91,13 @@ public class GeoportalHealth { return responseBuilder.entity(json).build(); } + /** + * Health check serializer. + * + * @param response the response + * @return the string + * @throws JsonProcessingException the json processing exception + */ private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { // Serializes HealthCheckResponse in JSON with custom // HealthCheckResponseSerializer diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index 09ca5fb..7257afe 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -7,6 +7,14 @@ import org.eclipse.microprofile.health.Readiness; import lombok.extern.slf4j.Slf4j; + +/** + * The Class GeoportalHealthCheck. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 22, 2024 + */ @Readiness @Liveness @Slf4j @@ -14,6 +22,11 @@ public class GeoportalHealthCheck implements HealthCheck { private static final String SERVICE_NAME = "geooportal-service"; + /** + * Call. + * + * @return the health check response + */ @Override public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index 53a00bb..4cf7b13 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -14,23 +14,50 @@ import com.mongodb.client.MongoIterable; import lombok.extern.slf4j.Slf4j; + +/** + * The Class MongoHealthCheck. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 22, 2024 + */ @Readiness @Liveness @Slf4j public class MongoHealthCheck implements HealthCheck { private String context; + private Boolean includeCollections; public static final String SERVICE_NAME = "mongo"; + /** + * Call. + * + * @return the health check response + */ @Override public HealthCheckResponse call() { return checkMongo(context); } - public MongoHealthCheck(String context) { + /** + * Instantiates a new mongo health check. + * + * @param context the context + * @param includeCollections the include collections + */ + public MongoHealthCheck(String context, Boolean includeCollections) { this.context = context; + this.includeCollections = includeCollections; } + /** + * Check mongo. + * + * @param context the context + * @return the health check response + */ private HealthCheckResponse checkMongo(String context) { log.debug("checkMongo in the context: {}", context); HealthCheckResponseBuilder buildHCRBuilder = HealthCheckResponse.named(SERVICE_NAME); @@ -40,14 +67,16 @@ public class MongoHealthCheck implements HealthCheck { mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); buildHCRBuilder.state(true); - MongoIterable collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) - .listCollectionNames(); - log.info("listCollectionNames is null: {}", collections == null); - int i = 1; - for (String coll : collections) { - log.info("adding collection: {}", coll); - buildHCRBuilder.withData("collection_" + i, coll); - i++; + if (includeCollections) { + MongoIterable collections = mongo.getTheClient() + .getDatabase(mongo.getConnection().getDatabase()).listCollectionNames(); + log.info("listCollectionNames is null: {}", collections == null); + int i = 1; + for (String coll : collections) { + log.debug("adding collection: {}", coll); + buildHCRBuilder.withData("collection_" + i, coll); + i++; + } } log.info("checkMongo is OK in the context: {}", context); return buildHCRBuilder.build(); @@ -71,6 +100,13 @@ public class MongoHealthCheck implements HealthCheck { } } + /** + * Append mongo info. + * + * @param buildHCRBuilder the build HCR builder + * @param connection the connection + * @return the health check response builder + */ private HealthCheckResponseBuilder appendMongoInfo(HealthCheckResponseBuilder buildHCRBuilder, MongoConnection connection) { buildHCRBuilder.withData("hosts", connection.getHosts() + ""); From faffb4248312af723c6881d5a915f073e816f32d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 23 Oct 2024 15:41:04 +0200 Subject: [PATCH 37/43] added `database` health_check --- .../geoportal/service/ServiceConstants.java | 22 +-- .../engine/providers/MongoClientProvider.java | 2 +- .../service/rest/GeoportalHealth.java | 49 +++++- .../rest/health/DatabaseHealthCheck.java | 155 ++++++++++++++++++ sdi-plugins/CHANGELOG.md | 2 +- sdi-plugins/pom.xml | 2 +- .../cms/sdi/plugins/SDIAbstractPlugin.java | 10 +- .../cms/sdi/plugins/SDIIndexerPlugin.java | 4 + 8 files changed, 223 insertions(+), 23 deletions(-) create mode 100644 geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/ServiceConstants.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/ServiceConstants.java index 8b46015..3c7ada0 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/ServiceConstants.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/ServiceConstants.java @@ -1,15 +1,17 @@ package org.gcube.application.geoportal.service; - public class ServiceConstants { - public static final String SE_GNA_DB_FLAG="GNA_DB"; - public static final String SE_GNA_DB_CATEGORY="Database"; - - public static final String MONGO_SE_PLATFORM="mongodb"; - public static final String MONGO_SE_GNA_FLAG="internal-db"; - - - - + // SE DB flagName + public static final String SE_GNA_DB_FLAGNAME = "GNA_DB"; + // SE DB flagValue + public static final String SE_GNA_DB_FLAGVALUE = "Concessioni"; + // SE DB category + public static final String SE_GNA_DB_CATEGORY = "Database"; + // SE DB platform + public static final String SE_GNA_DB_PLATFORM = "postgis"; + + public static final String MONGO_SE_PLATFORM = "mongodb"; + public static final String MONGO_SE_GNA_FLAG = "internal-db"; + } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/MongoClientProvider.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/MongoClientProvider.java index bc368e7..64fcbb4 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/MongoClientProvider.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/MongoClientProvider.java @@ -29,7 +29,7 @@ public class MongoClientProvider extends AbstractScopedMap { getProvidedObjectByClass(ISInterface.class), ServiceConstants.SE_GNA_DB_CATEGORY, ServiceConstants.MONGO_SE_PLATFORM, - ServiceConstants.SE_GNA_DB_FLAG, + ServiceConstants.SE_GNA_DB_FLAGNAME, ServiceConstants.MONGO_SE_GNA_FLAG); log.debug("Connecting to "+conn); 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 index 8e9c451..23df7c7 100644 --- 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 @@ -10,6 +10,7 @@ import javax.ws.rs.core.Response.ResponseBuilder; import org.eclipse.microprofile.health.HealthCheckResponse; import org.eclipse.microprofile.health.HealthCheckResponse.State; +import org.gcube.application.geoportal.service.rest.health.DatabaseHealthCheck; import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; import org.gcube.application.geoportal.service.rest.health.HealthCheckResponseSerializer; import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck; @@ -25,7 +26,7 @@ import lombok.extern.slf4j.Slf4j; * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Oct 22, 2024 + * Oct 22, 2024 */ @Path("/health") @Slf4j @@ -45,7 +46,8 @@ public class GeoportalHealth { /** * Service check. * - * @return the response compliant to `microprofile-health` specification. 200 if is OK. Otherwise it fails. + * @return the response compliant to `microprofile-health` specification. 200 if + * is OK. Otherwise it fails. * @throws JsonProcessingException the json processing exception */ @GET @@ -60,17 +62,50 @@ public class GeoportalHealth { } /** - * Database check. + * Mongo check. * - * @param context the gcube context - * @param include_collections if the check has to include the mongo collections in the response + * @param context the gcube context + * @param include_collections if the check has to include the mongo collections + * in the response * @return the response compliant to `microprofile-health` specification * @throws JsonProcessingException the json processing exception */ @GET @Path("/mongo") @Produces({ MediaType.APPLICATION_JSON }) - public Response databaseCheck(@QueryParam("context") String context, @QueryParam("include_collections") Boolean includeCollections) throws JsonProcessingException { + public Response mongoCheck(@QueryParam("context") String context, + @QueryParam("include_collections") Boolean includeCollections) throws JsonProcessingException { + log.debug("mongoCheck called in the context {}", context); + if (context == null) { + HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) + .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); + String json = healthCheckSerializer(response); + log.info("mongoCheck error response is {}", json); + // Bad request + return Response.status(400).entity(json).build(); + } + + HealthCheckResponse response = new MongoHealthCheck(context, includeCollections).call(); + ResponseBuilder responseBuilder = Response.ok(); + if (response.getState().equals(State.DOWN)) { + responseBuilder = responseBuilder.status(503); + } + String json = healthCheckSerializer(response); + log.info("mongoCheck response is {}", json); + return responseBuilder.entity(json).build(); + } + + /** + * Database check. + * + * @param context the gcube context + * @return the response compliant to `microprofile-health` specification + * @throws JsonProcessingException the json processing exception + */ + @GET + @Path("/database") + @Produces({ MediaType.APPLICATION_JSON }) + public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { log.debug("databaseCheck called in the context {}", context); if (context == null) { HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) @@ -81,7 +116,7 @@ public class GeoportalHealth { return Response.status(400).entity(json).build(); } - HealthCheckResponse response = new MongoHealthCheck(context, includeCollections).call(); + HealthCheckResponse response = new DatabaseHealthCheck(context).call(); ResponseBuilder responseBuilder = Response.ok(); if (response.getState().equals(State.DOWN)) { responseBuilder = responseBuilder.status(503); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java new file mode 100644 index 0000000..c5a47fe --- /dev/null +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java @@ -0,0 +1,155 @@ +package org.gcube.application.geoportal.service.rest.health; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.HealthCheckResponseBuilder; +import org.eclipse.microprofile.health.Liveness; +import org.eclipse.microprofile.health.Readiness; +import org.gcube.application.cms.implementations.ISInterface; +import org.gcube.application.cms.implementations.ImplementationProvider; +import org.gcube.application.geoportal.common.model.rest.ConfigurationException; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; +import org.gcube.application.geoportal.service.ServiceConstants; +import org.gcube.common.scope.api.ScopeProvider; + +import lombok.extern.slf4j.Slf4j; + +/** + * The Class DatabaseHealthCheck. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 23, 2024 + */ +@Readiness +@Liveness +@Slf4j +public class DatabaseHealthCheck implements HealthCheck { + + private String context; + public static final String SERVICE_NAME = "database"; + + private static final int CONNECTION_TIMEOUT = 30; + + /** + * Call. + * + * @return the health check response + */ + @Override + public HealthCheckResponse call() { + return checkDatabase(context); + } + + /** + * Instantiates a new database health check. + * + * @param context the context + */ + public DatabaseHealthCheck(String context) { + this.context = context; + } + + /** + * Check database. + * + * @param context the context + * @return the health check response + */ + private HealthCheckResponse checkDatabase(String context) { + log.debug("checkMongo in the context: {}", context); + HealthCheckResponseBuilder buildHCRBuilder = HealthCheckResponse.named(SERVICE_NAME); + + ScopeProvider.instance.set(context); + + try { + + DatabaseConnection databaseConnection = null; + ISInterface isInterface = ImplementationProvider.get().getProvidedObjectByClass(ISInterface.class); + + try { + if (isInterface == null) + throw new Exception(ISInterface.class.getSimpleName() + " configuration is null for " + + DatabaseConnection.class.getSimpleName()); + + databaseConnection = isInterface.queryForDatabase(ServiceConstants.SE_GNA_DB_CATEGORY, + ServiceConstants.SE_GNA_DB_PLATFORM, ServiceConstants.SE_GNA_DB_FLAGNAME, + ServiceConstants.SE_GNA_DB_FLAGVALUE); + + if (databaseConnection == null) + throw new Exception(DatabaseConnection.class.getSimpleName() + " configuration is null"); + } catch (Exception e) { + log.error("Error on checking DB configuration: ", e); + buildHCRBuilder.state(false); + return buildHCRBuilder.build(); + } + + boolean connectionStatus = checkDatabaseConnection(databaseConnection); + buildHCRBuilder = appendDBInfo(buildHCRBuilder, databaseConnection); + buildHCRBuilder.state(connectionStatus); + log.info("checkDatabase is OK in the context: {}. State is {}", context, connectionStatus); + return buildHCRBuilder.build(); + + } catch (Exception e) { + log.error("Error on checkDatabase: ", e); + log.warn("checkDatabase is KO in the context: {}", context); + buildHCRBuilder.state(false); + return buildHCRBuilder.build(); + } finally { + ScopeProvider.instance.reset(); + } + } + + /** + * Append DB info. + * + * @param buildHCRBuilder the build HCR builder + * @param connection the connection + * @return the health check response builder + */ + private HealthCheckResponseBuilder appendDBInfo(HealthCheckResponseBuilder buildHCRBuilder, + DatabaseConnection connection) { + buildHCRBuilder.withData("host", connection.getUrl() + ""); + buildHCRBuilder.withData("user ", connection.getUser()); + buildHCRBuilder.withData("pwd ", "****"); + return buildHCRBuilder; + } + + /** + * Check database connection. + * + * @param connectionParameters the connection parameters + * @return true, if successful + */ + private boolean checkDatabaseConnection(DatabaseConnection connectionParameters) { + + try { + + if (connectionParameters == null) + throw new ConfigurationException("connectionParameters is null"); + + // Getting connection + Connection connection = DriverManager.getConnection(connectionParameters.getUrl(), + connectionParameters.getUser(), connectionParameters.getPwd()); + // Check if the connection is valid (timeout 30 seconds) + if (connection != null && connection.isValid(CONNECTION_TIMEOUT)) { + log.debug("Connection to DB " + connectionParameters.getUrl() + " is OK!"); + return true; + } else { + log.debug("Connection to DB " + connectionParameters.getUrl() + " is KO!"); + return false; + } + } catch (SQLException e) { + log.warn("Error on connecting to DB: " + connectionParameters, e); + return false; + } catch (ConfigurationException e1) { + log.warn("Error on reading connection configuration: " + connectionParameters, e1); + return false; + } + } + +} diff --git a/sdi-plugins/CHANGELOG.md b/sdi-plugins/CHANGELOG.md index 0fb028b..27bdb59 100644 --- a/sdi-plugins/CHANGELOG.md +++ b/sdi-plugins/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog for org.gcube.application.cms.sdi-plugins -## [v1.1.4] +## [v1.1.4-SNAPSHOT] - Improved logs - Added fallback on /geoserver/rest path [#28150#note-8] diff --git a/sdi-plugins/pom.xml b/sdi-plugins/pom.xml index 71ec477..8811cf9 100644 --- a/sdi-plugins/pom.xml +++ b/sdi-plugins/pom.xml @@ -5,7 +5,7 @@ 4.0.0 sdi-plugins - 1.1.4 + 1.1.4-SNAPSHOT gCube CMS - SDI Plugins diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java index 2a3aa34..90aa669 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIAbstractPlugin.java @@ -23,7 +23,11 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class SDIAbstractPlugin extends AbstractPlugin implements InitializablePlugin { - protected static AbstractScopedMap sdiCache; + public static final String POSTGIS_CREDENTIALS = "POSTGIS-CREDENTIALS"; + + public static final String SDI_CACHE = "SDI-CACHE"; + + protected static AbstractScopedMap sdiCache; protected static AbstractScopedMap postgisCache; @@ -31,7 +35,7 @@ public abstract class SDIAbstractPlugin extends AbstractPlugin implements Initia private static void initCache(){ if(sdiCache==null) { log.info("Creating internal caches.. "); - sdiCache = new AbstractScopedMap("SDI-CACHE") { + sdiCache = new AbstractScopedMap(SDI_CACHE) { @Override protected SDIManagerWrapper retrieveObject(String context) throws ConfigurationException { try { @@ -44,7 +48,7 @@ public abstract class SDIAbstractPlugin extends AbstractPlugin implements Initia sdiCache.setTTL(Duration.of(10, ChronoUnit.MINUTES)); } if(postgisCache==null) { - postgisCache = new AbstractScopedMap("POSTGIS-CREDENTIALS") { + postgisCache = new AbstractScopedMap(POSTGIS_CREDENTIALS) { @Override protected DatabaseConnection retrieveObject(String context) throws ConfigurationException { try { diff --git a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java index 4a41e74..4a67e59 100644 --- a/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java +++ b/sdi-plugins/src/main/java/org/gcube/application/cms/sdi/plugins/SDIIndexerPlugin.java @@ -463,6 +463,10 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin DatabaseConnection connectionParameters = null; try { connectionParameters = postgisCache.getObject(); + + if(connectionParameters==null) + throw new ConfigurationException("connectionParameters is null"); + // Getting connection Connection connection = DriverManager.getConnection(connectionParameters.getUrl(), connectionParameters.getUser(), connectionParameters.getPwd()); From 4d0df2de07e356425c3103c898c6fb6d2c1f101c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 23 Oct 2024 15:57:33 +0200 Subject: [PATCH 38/43] Updated Database health_check --- .../geoportal/service/rest/GeoportalHealth.java | 2 +- .../service/rest/health/DatabaseHealthCheck.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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 index 23df7c7..47a53de 100644 --- 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 @@ -108,7 +108,7 @@ public class GeoportalHealth { public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { log.debug("databaseCheck called in the context {}", context); if (context == null) { - HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) + HealthCheckResponse response = HealthCheckResponse.named(DatabaseHealthCheck.SERVICE_NAME) .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); String json = healthCheckSerializer(response); log.info("databaseCheck error response is {}", json); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java index c5a47fe..343de34 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/DatabaseHealthCheck.java @@ -114,7 +114,13 @@ public class DatabaseHealthCheck implements HealthCheck { private HealthCheckResponseBuilder appendDBInfo(HealthCheckResponseBuilder buildHCRBuilder, DatabaseConnection connection) { buildHCRBuilder.withData("host", connection.getUrl() + ""); - buildHCRBuilder.withData("user ", connection.getUser()); + + // anonymize the DB username + String userNotClear = "***"; + if (connection.getUser() != null && connection.getUser().length() > 3) { + userNotClear = connection.getUser().substring(0, 3) + userNotClear; + } + buildHCRBuilder.withData("user ", userNotClear); buildHCRBuilder.withData("pwd ", "****"); return buildHCRBuilder; } From a970284fb7ce73e952bc8a9010c2a2aa80302fb9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 23 Oct 2024 17:37:54 +0200 Subject: [PATCH 39/43] fixed `includeCollections` parameter --- .../geoportal/service/rest/health/MongoHealthCheck.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java index 4cf7b13..be7cf23 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/MongoHealthCheck.java @@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j; public class MongoHealthCheck implements HealthCheck { private String context; - private Boolean includeCollections; + private Boolean includeCollections = false; public static final String SERVICE_NAME = "mongo"; /** @@ -67,7 +67,7 @@ public class MongoHealthCheck implements HealthCheck { mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); buildHCRBuilder = appendMongoInfo(buildHCRBuilder, mongo.getConnection()); buildHCRBuilder.state(true); - if (includeCollections) { + if (includeCollections!=null && includeCollections) { MongoIterable collections = mongo.getTheClient() .getDatabase(mongo.getConnection().getDatabase()).listCollectionNames(); log.info("listCollectionNames is null: {}", collections == null); From daf99809e64e2b23bacd638eda8b390f84730d15 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 23 Oct 2024 17:56:00 +0200 Subject: [PATCH 40/43] added default value ('false`) to `includeCollections` parameter --- .../application/geoportal/service/rest/GeoportalHealth.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 index 47a53de..6df4bb4 100644 --- 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 @@ -1,5 +1,6 @@ package org.gcube.application.geoportal.service.rest; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -74,8 +75,9 @@ public class GeoportalHealth { @Path("/mongo") @Produces({ MediaType.APPLICATION_JSON }) public Response mongoCheck(@QueryParam("context") String context, - @QueryParam("include_collections") Boolean includeCollections) throws JsonProcessingException { - log.debug("mongoCheck called in the context {}", context); + @DefaultValue("false") @QueryParam("include_collections") Boolean includeCollections) + throws JsonProcessingException { + log.debug("mongoCheck called in the context {}, includeCollections {}", context, includeCollections); if (context == null) { HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); From 48098c9aec8d31bbce05358110f56ea09bd781ef Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 24 Oct 2024 10:48:31 +0200 Subject: [PATCH 41/43] Excluding GeoportalHealth by api-doc --- geoportal-service/enunciate.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/geoportal-service/enunciate.xml b/geoportal-service/enunciate.xml index 3c3f8bb..3bf4cf7 100644 --- a/geoportal-service/enunciate.xml +++ b/geoportal-service/enunciate.xml @@ -3,13 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd"> - + + From e19323c0b098106797338c9fe7ca9b399efa6eed Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 24 Oct 2024 11:12:01 +0200 Subject: [PATCH 42/43] to build -SNAPSHOT version --- notifications-plugins/CHANGELOG.md | 2 +- notifications-plugins/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/notifications-plugins/CHANGELOG.md b/notifications-plugins/CHANGELOG.md index d1ac0d6..5209f50 100644 --- a/notifications-plugins/CHANGELOG.md +++ b/notifications-plugins/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog for org.gcube.application.cms.notifications-plugins -## [v1.0.5] - 2024-07-03 +## [v1.0.5-SNAPSHOT] - 2024-07-03 - Implemented the notification-plugin [#26453] - Updated lower range of social-service-client to `2.1.0-SNAPSHOT` diff --git a/notifications-plugins/pom.xml b/notifications-plugins/pom.xml index bf3f9bc..5dadb66 100644 --- a/notifications-plugins/pom.xml +++ b/notifications-plugins/pom.xml @@ -5,7 +5,7 @@ 4.0.0 notifications-plugins - 1.0.5 + 1.0.5-SNAPSHOT gCube CMS - Notifications Plugins From 64aaed5d2780dbf0687ea7099623c4c09b94e35f Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 28 Oct 2024 15:47:10 +0100 Subject: [PATCH 43/43] removed -SNAPSHOT --- CHANGELOG.md | 2 +- cms-plugin-framework/CHANGELOG.md | 2 +- cms-plugin-framework/pom.xml | 2 +- geoportal-service/CHANGELOG.md | 2 +- geoportal-service/pom.xml | 2 +- notifications-plugins/CHANGELOG.md | 2 +- notifications-plugins/pom.xml | 2 +- pom.xml | 2 +- sdi-plugins/CHANGELOG.md | 3 ++- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6f418f..847a49b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for org.gcube.spatial.data.gcube-sdi-suite -## [v1.0.6-SNAPSHOT] +## [v1.0.6] - Integrated an EventManager centrally [#26321] - sdi-plugins: add the logic to apply a regex to the value that must be added to index [#26322] diff --git a/cms-plugin-framework/CHANGELOG.md b/cms-plugin-framework/CHANGELOG.md index e6c491a..b51dd93 100644 --- a/cms-plugin-framework/CHANGELOG.md +++ b/cms-plugin-framework/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog for org.gcube.application.cms-plugin-framework -## [v1.0.6-SNAPSHOT] - 2024-10-01 +## [v1.0.6] - 2024-10-01 - Included the file size to reduce/optimize the time to upload files to the storage hub [#28150] - Checked if the user is `null` in the `UserUtils` class [#28301] diff --git a/cms-plugin-framework/pom.xml b/cms-plugin-framework/pom.xml index 791e98b..95a99d4 100644 --- a/cms-plugin-framework/pom.xml +++ b/cms-plugin-framework/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cms-plugin-framework - 1.0.6-SNAPSHOT + 1.0.6 org.gcube.application.cms diff --git a/geoportal-service/CHANGELOG.md b/geoportal-service/CHANGELOG.md index 2c89dc4..fe472bd 100644 --- a/geoportal-service/CHANGELOG.md +++ b/geoportal-service/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog for org.gcube.application.geoportal-service -## [v1.2.2-SNAPSHOT] - 2024-10-16 +## [v1.2.2] - 2024-10-16 - Included the health check at https://{geoporta_endpoint}/health via `smallrye-health` (that implements the https://microprofile.io/specifications/microprofile-health/) [#28301] diff --git a/geoportal-service/pom.xml b/geoportal-service/pom.xml index f195cdf..987298b 100644 --- a/geoportal-service/pom.xml +++ b/geoportal-service/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.gcube.application geoportal-service - 1.2.2-SNAPSHOT + 1.2.2 Geoportal Service war diff --git a/notifications-plugins/CHANGELOG.md b/notifications-plugins/CHANGELOG.md index 5209f50..d1ac0d6 100644 --- a/notifications-plugins/CHANGELOG.md +++ b/notifications-plugins/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog for org.gcube.application.cms.notifications-plugins -## [v1.0.5-SNAPSHOT] - 2024-07-03 +## [v1.0.5] - 2024-07-03 - Implemented the notification-plugin [#26453] - Updated lower range of social-service-client to `2.1.0-SNAPSHOT` diff --git a/notifications-plugins/pom.xml b/notifications-plugins/pom.xml index 5dadb66..bf3f9bc 100644 --- a/notifications-plugins/pom.xml +++ b/notifications-plugins/pom.xml @@ -5,7 +5,7 @@ 4.0.0 notifications-plugins - 1.0.5-SNAPSHOT + 1.0.5 gCube CMS - Notifications Plugins diff --git a/pom.xml b/pom.xml index 5e8e136..34e7fe0 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.application.cms gcube-cms-suite pom - 1.0.6-SNAPSHOT + 1.0.6 Gcube CMS Suite gCube CMS Suite is a set of components designed to manage complex space-temporal Documents defined by metadata Profiles. diff --git a/sdi-plugins/CHANGELOG.md b/sdi-plugins/CHANGELOG.md index 27bdb59..2abd5f0 100644 --- a/sdi-plugins/CHANGELOG.md +++ b/sdi-plugins/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog for org.gcube.application.cms.sdi-plugins -## [v1.1.4-SNAPSHOT] +## [v1.1.4] - Improved logs - Added fallback on /geoserver/rest path [#28150#note-8] +- Improved some business logics ## [v1.1.3] - Added apply regex business logic [#26322]