From 98c41e74635f7ce9babc1f87e07d035e83a334bc Mon Sep 17 00:00:00 2001 From: lucio Date: Fri, 27 Jan 2023 17:01:22 +0100 Subject: [PATCH] moved health part to a separate library --- pom.xml | 49 ++------------ .../extensions/resource/HealthResource.java | 2 +- .../gcube/smartgears/health/HealthCheck.java | 9 --- .../health/KeyCloakHealthCheck.java | 8 ++- .../smartgears/health/ReadinessChecker.java | 12 ---- .../org/gcube/smartgears/health/Status.java | 6 -- .../health/response/HealthCheckResponse.java | 30 --------- .../response/HealthCheckResponseBuilder.java | 65 ------------------- .../health/response/HealthResponse.java | 18 ----- .../response/HealthResponseBuilder.java | 13 ---- 10 files changed, 12 insertions(+), 200 deletions(-) delete mode 100644 src/main/java/org/gcube/smartgears/health/HealthCheck.java delete mode 100644 src/main/java/org/gcube/smartgears/health/ReadinessChecker.java delete mode 100644 src/main/java/org/gcube/smartgears/health/Status.java delete mode 100644 src/main/java/org/gcube/smartgears/health/response/HealthCheckResponse.java delete mode 100644 src/main/java/org/gcube/smartgears/health/response/HealthCheckResponseBuilder.java delete mode 100644 src/main/java/org/gcube/smartgears/health/response/HealthResponse.java delete mode 100644 src/main/java/org/gcube/smartgears/health/response/HealthResponseBuilder.java diff --git a/pom.xml b/pom.xml index 37a5489..d929d94 100644 --- a/pom.xml +++ b/pom.xml @@ -8,13 +8,10 @@ 1.1.0 - org.gcube.core common-smartgears 4.0.0-SNAPSHOT - SmartGears - @@ -26,7 +23,6 @@ - distro 8.0.42 @@ -35,21 +31,22 @@ 1.8 1.8 - scm:git:https://code-repo.d4science.org/gCubeSystem/common-smartgears.git - scm:git:https://code-repo.d4science.org/gCubeSystem/common-smartgears.git + scm:git:httpstps://code-repo.d4science.org/gCubeSystem/common-smartgears.git https://code-repo.d4science.org/gCubeSystem/common-smartgears - - org.reflections reflections 0.9.10 - + + org.gcube.common + health-api + 1.0.0-SNAPSHOT + org.gcube.common @@ -68,40 +65,33 @@ org.gcube.common common-security - org.gcube.data.publishing document-store-lib - org.gcube.accounting accounting-lib - org.slf4j slf4j-api - org.ini4j ini4j 0.5.4 - org.gcube.core common-validator [1.0.0,2.0.0-SNAPSHOT) - org.gcube.core common-events [1.0.0,2.0.0-SNAPSHOT) - org.gcube.common.security gcube-secrets @@ -110,37 +100,30 @@ javax.ws.rs javax.ws.rs-api - javax.servlet javax.servlet-api 4.0.1 provided - javax.xml.bind jaxb-api - io.micrometer micrometer-core 1.9.0 - io.micrometer micrometer-registry-prometheus 1.9.0 - - - org.jboss.shrinkwrap.resolver shrinkwrap-resolver-depchain @@ -148,7 +131,6 @@ pom test - org.apache.tomcat @@ -156,66 +138,54 @@ ${tomcat.version} provided - org.apache.tomcat.embed tomcat-embed-core ${tomcat.version} test - org.glassfish.jersey.core jersey-client test - - org.apache.tomcat.embed tomcat-embed-core ${tomcat.version} test - org.apache.tomcat.embed tomcat-embed-logging-log4j ${tomcat.version} test - org.apache.tomcat.embed tomcat-embed-jasper ${tomcat.version} test - junit junit 4.10 test - ch.qos.logback logback-classic runtime - org.mockito mockito-core 1.9.0 test - - - @@ -236,7 +206,6 @@ - org.apache.maven.plugins maven-surefire-plugin @@ -249,8 +218,6 @@ - - org.apache.maven.plugins @@ -259,7 +226,6 @@ false probe - WEB-INF/classes/org/gcube/smartgears/probe/**/* false @@ -273,8 +239,6 @@ - - org.apache.maven.plugins maven-surefire-plugin @@ -311,7 +275,6 @@ - diff --git a/src/main/java/org/gcube/smartgears/extensions/resource/HealthResource.java b/src/main/java/org/gcube/smartgears/extensions/resource/HealthResource.java index d3d5394..2f0b997 100644 --- a/src/main/java/org/gcube/smartgears/extensions/resource/HealthResource.java +++ b/src/main/java/org/gcube/smartgears/extensions/resource/HealthResource.java @@ -9,9 +9,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.gcube.common.health.api.response.HealthResponse; import org.gcube.smartgears.extensions.ApiResource; import org.gcube.smartgears.extensions.ApiSignature; -import org.gcube.smartgears.health.response.HealthResponse; public class HealthResource extends ApiResource { diff --git a/src/main/java/org/gcube/smartgears/health/HealthCheck.java b/src/main/java/org/gcube/smartgears/health/HealthCheck.java deleted file mode 100644 index b3f992b..0000000 --- a/src/main/java/org/gcube/smartgears/health/HealthCheck.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.gcube.smartgears.health; - -import org.gcube.smartgears.health.response.HealthCheckResponse; - -public interface HealthCheck { - - HealthCheckResponse check(); - -} diff --git a/src/main/java/org/gcube/smartgears/health/KeyCloakHealthCheck.java b/src/main/java/org/gcube/smartgears/health/KeyCloakHealthCheck.java index 15fd0aa..1a78f73 100644 --- a/src/main/java/org/gcube/smartgears/health/KeyCloakHealthCheck.java +++ b/src/main/java/org/gcube/smartgears/health/KeyCloakHealthCheck.java @@ -2,20 +2,22 @@ package org.gcube.smartgears.health; import java.util.Set; -import org.gcube.smartgears.health.response.HealthCheckResponse; +import org.gcube.common.health.api.HealthCheck; +import org.gcube.common.health.api.ReadinessChecker; +import org.gcube.common.health.api.response.HealthCheckResponse; import org.gcube.smartgears.provider.ProviderFactory; @ReadinessChecker public class KeyCloakHealthCheck implements HealthCheck{ - private static final String CHECK_NAME = "authorizationCheck" ; + private static final String CHECK_NAME = "authorization-check" ; @Override public HealthCheckResponse check() { try { Set contexts = ProviderFactory.provider().containerContext().authorizationProvider().getContexts(); if (contexts.isEmpty()) - return HealthCheckResponse.builder(CHECK_NAME).down().withMessage("no contexts are defined for this server").build(); + return HealthCheckResponse.builder(CHECK_NAME).down().withMessage("no contexts are defined for the client id provided").build(); return HealthCheckResponse.builder(CHECK_NAME).up().build(); }catch (Exception e) { return HealthCheckResponse.builder(CHECK_NAME).down().withMessage(e.getMessage()).build(); diff --git a/src/main/java/org/gcube/smartgears/health/ReadinessChecker.java b/src/main/java/org/gcube/smartgears/health/ReadinessChecker.java deleted file mode 100644 index 6483255..0000000 --- a/src/main/java/org/gcube/smartgears/health/ReadinessChecker.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.gcube.smartgears.health; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface ReadinessChecker { - -} diff --git a/src/main/java/org/gcube/smartgears/health/Status.java b/src/main/java/org/gcube/smartgears/health/Status.java deleted file mode 100644 index 1ecaef1..0000000 --- a/src/main/java/org/gcube/smartgears/health/Status.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.gcube.smartgears.health; - -public enum Status { - - UP, DOWN, NOT_CALCULATED -} diff --git a/src/main/java/org/gcube/smartgears/health/response/HealthCheckResponse.java b/src/main/java/org/gcube/smartgears/health/response/HealthCheckResponse.java deleted file mode 100644 index 33bcdf7..0000000 --- a/src/main/java/org/gcube/smartgears/health/response/HealthCheckResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.gcube.smartgears.health.response; - -import org.gcube.com.fasterxml.jackson.annotation.JsonInclude; -import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include; -import org.gcube.common.validator.annotations.NotEmpty; -import org.gcube.common.validator.annotations.NotNull; -import org.gcube.smartgears.health.Status; - -@JsonInclude(Include.NON_NULL) -public class HealthCheckResponse { - - public static HealthCheckResponseBuilder builder(String checkName) { - return new HealthCheckResponseBuilder(checkName); - } - - protected HealthCheckResponse() {} - - //enum ErrorType {UNRECOVERABLE, RECOVERABLE} - - @NotNull - protected Status status; - - @NotNull @NotEmpty - protected String name; - - //protected ErrorType errorType; - - protected String errorMessage; - -} diff --git a/src/main/java/org/gcube/smartgears/health/response/HealthCheckResponseBuilder.java b/src/main/java/org/gcube/smartgears/health/response/HealthCheckResponseBuilder.java deleted file mode 100644 index 266e0a2..0000000 --- a/src/main/java/org/gcube/smartgears/health/response/HealthCheckResponseBuilder.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.gcube.smartgears.health.response; - -import java.util.ArrayList; -import java.util.List; - -import org.gcube.common.validator.ValidationError; -import org.gcube.common.validator.Validator; -import org.gcube.common.validator.ValidatorFactory; -import org.gcube.smartgears.health.Status; - -public class HealthCheckResponseBuilder { - - private HealthCheckResponse healthCheckResponse = new HealthCheckResponse(); - - protected HealthCheckResponseBuilder(String name) { - healthCheckResponse.name = name; - } - - public BuildPart up() { - healthCheckResponse.status = Status.UP; - return new BuildPart(); - } - - public ErrorPart down() { - healthCheckResponse.status = Status.DOWN; - return new ErrorPart(); - } - - private void validateResponse() { - - List msgs = new ArrayList(); - - Validator validator = ValidatorFactory.validator(); - - for (ValidationError error : validator.validate(healthCheckResponse)) - msgs.add(error.toString()); - - if (!msgs.isEmpty()) - throw new IllegalStateException("invalid configuration: "+msgs); - - } - - public class ErrorPart{ - - private ErrorPart() {} - - public BuildPart withMessage(String message) { - healthCheckResponse.errorMessage = message; - return new BuildPart(); - } - - } - - public class BuildPart{ - - private BuildPart() {}; - - public HealthCheckResponse build() { - validateResponse(); - return healthCheckResponse; - } - - } - -} diff --git a/src/main/java/org/gcube/smartgears/health/response/HealthResponse.java b/src/main/java/org/gcube/smartgears/health/response/HealthResponse.java deleted file mode 100644 index 8321d1f..0000000 --- a/src/main/java/org/gcube/smartgears/health/response/HealthResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.gcube.smartgears.health.response; - -import java.util.List; - -import org.gcube.smartgears.health.HealthCheck; -import org.gcube.smartgears.health.Status; - -public class HealthResponse { - - Status status; - - List checks; - - void register(HealthCheck check){ - checks.add(check); - } - -} diff --git a/src/main/java/org/gcube/smartgears/health/response/HealthResponseBuilder.java b/src/main/java/org/gcube/smartgears/health/response/HealthResponseBuilder.java deleted file mode 100644 index 4077c85..0000000 --- a/src/main/java/org/gcube/smartgears/health/response/HealthResponseBuilder.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.gcube.smartgears.health.response; - -public class HealthResponseBuilder { - - private HealthResponse healthResponse; - - public HealthResponse build() { - return healthResponse; - } - - - -}