moved health part to a separate library
This commit is contained in:
parent
3407ce025c
commit
98c41e7463
49
pom.xml
49
pom.xml
|
@ -8,13 +8,10 @@
|
|||
<version>1.1.0</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
|
||||
<name>SmartGears</name>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -26,7 +23,6 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<tomcat.version>8.0.42</tomcat.version>
|
||||
|
@ -35,21 +31,22 @@
|
|||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-smartgears.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/common-smartgears.git</developerConnection>
|
||||
<developerConnection>scm:git:httpstps://code-repo.d4science.org/gCubeSystem/common-smartgears.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/common-smartgears</url>
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>health-api</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- gCube Jackson -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
|
@ -68,40 +65,33 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ini4j</groupId>
|
||||
<artifactId>ini4j</artifactId>
|
||||
<version>0.5.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-validator</artifactId>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-events</artifactId>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.security</groupId>
|
||||
<artifactId>gcube-secrets</artifactId>
|
||||
|
@ -110,37 +100,30 @@
|
|||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Added to support Java 11 JDK -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
<!-- END Added to support Java 11 JDK -->
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-core -->
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<version>1.9.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
<version>1.9.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- ***************** test ******************* -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.shrinkwrap.resolver</groupId>
|
||||
<artifactId>shrinkwrap-resolver-depchain</artifactId>
|
||||
|
@ -148,7 +131,6 @@
|
|||
<type>pom</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
|
@ -156,66 +138,54 @@
|
|||
<version>${tomcat.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-logging-log4j</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
<!-- excludes probe package from jar -->
|
||||
<plugin>
|
||||
|
@ -236,7 +206,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
@ -249,8 +218,6 @@
|
|||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- include probe in attached war -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -259,7 +226,6 @@
|
|||
<configuration>
|
||||
<primaryArtifact>false</primaryArtifact>
|
||||
<classifier>probe</classifier>
|
||||
|
||||
<packagingIncludes>WEB-INF/classes/org/gcube/smartgears/probe/**/*</packagingIncludes>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
|
@ -273,8 +239,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
@ -311,7 +275,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package org.gcube.smartgears.health;
|
||||
|
||||
import org.gcube.smartgears.health.response.HealthCheckResponse;
|
||||
|
||||
public interface HealthCheck {
|
||||
|
||||
HealthCheckResponse check();
|
||||
|
||||
}
|
|
@ -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<String> 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();
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package org.gcube.smartgears.health;
|
||||
|
||||
public enum Status {
|
||||
|
||||
UP, DOWN, NOT_CALCULATED
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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<String> msgs = new ArrayList<String>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<HealthCheck> checks;
|
||||
|
||||
void register(HealthCheck check){
|
||||
checks.add(check);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.gcube.smartgears.health.response;
|
||||
|
||||
public class HealthResponseBuilder {
|
||||
|
||||
private HealthResponse healthResponse;
|
||||
|
||||
public HealthResponse build() {
|
||||
return healthResponse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue