using microprofile-health-api v2.2

This commit is contained in:
Francesco Mangiacrapa 2024-10-17 11:47:59 +02:00
parent b6e9fcddae
commit a41854bec3
3 changed files with 19 additions and 44 deletions

View File

@ -158,7 +158,7 @@
<dependency>
<groupId>org.eclipse.microprofile.health</groupId>
<artifactId>microprofile-health-api</artifactId>
<version>4.0</version>
<version>2.2</version>
</dependency>
<!-- Plugins related tests -->

View File

@ -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<String> 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 {

View File

@ -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<Map<String, Object>> data;
private Map<String, Object> 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<Map<String, Object>> data) {
public HealthCheckResponseGeoportalProvider(String name, State state, Optional<Map<String, Object>> 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<Map<String, Object>> 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;
}
/**
@ -114,7 +89,7 @@ public class HealthCheckResponseGeoportalProvider {
log.info("data are: " + data);
return new HealthCheckResponse(name, status, data);
return new HealthCheckResponse(name, state, data);
}
}