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> <dependency>
<groupId>org.eclipse.microprofile.health</groupId> <groupId>org.eclipse.microprofile.health</groupId>
<artifactId>microprofile-health-api</artifactId> <artifactId>microprofile-health-api</artifactId>
<version>4.0</version> <version>2.2</version>
</dependency> </dependency>
<!-- Plugins related tests --> <!-- 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.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse; 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.eclipse.microprofile.health.Liveness;
import org.gcube.application.cms.implementations.ImplementationProvider; import org.gcube.application.cms.implementations.ImplementationProvider;
import org.gcube.application.geoportal.common.model.configuration.MongoConnection; import org.gcube.application.geoportal.common.model.configuration.MongoConnection;
@ -40,7 +40,7 @@ public class GeoportalHealthCheck implements HealthCheck {
@Override @Override
public HealthCheckResponse call() { public HealthCheckResponse call() {
return new HealthCheckResponse("geooportal-service", Status.UP, Optional.empty()); return new HealthCheckResponse("geooportal-service", State.UP, Optional.empty());
} }
@GET @GET
@ -62,7 +62,7 @@ public class GeoportalHealthCheck implements HealthCheck {
ScopeProvider.instance.set(context); ScopeProvider.instance.set(context);
mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class); mongo = ImplementationProvider.get().getProvidedObjectByClass(Mongo.class);
buildHCRProvider = appendMongoInfo(buildHCRProvider, mongo.getConnection()); buildHCRProvider = appendMongoInfo(buildHCRProvider, mongo.getConnection());
buildHCRProvider.setStatus(Status.UP); buildHCRProvider.setState(State.UP);
MongoIterable<String> collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase()) MongoIterable<String> collections = mongo.getTheClient().getDatabase(mongo.getConnection().getDatabase())
.listCollectionNames(); .listCollectionNames();
log.info("listCollectionNames is null: {}", collections == null); log.info("listCollectionNames is null: {}", collections == null);
@ -74,7 +74,7 @@ public class GeoportalHealthCheck implements HealthCheck {
} }
return buildHCRProvider.buildHealthCheckResponse(); return buildHCRProvider.buildHealthCheckResponse();
} catch (Exception e) { } catch (Exception e) {
buildHCRProvider.setStatus(Status.DOWN); buildHCRProvider.setState(State.DOWN);
if (mongo != null) { if (mongo != null) {
MongoConnection connection = null; MongoConnection connection = null;
try { try {

View File

@ -5,7 +5,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.eclipse.microprofile.health.HealthCheckResponse; 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; import lombok.extern.slf4j.Slf4j;
@ -20,9 +20,9 @@ import lombok.extern.slf4j.Slf4j;
public class HealthCheckResponseGeoportalProvider { public class HealthCheckResponseGeoportalProvider {
private String name; private String name;
private Status status;
private Optional<Map<String, Object>> data; private Optional<Map<String, Object>> data;
private Map<String, Object> myMap; private Map<String, Object> myMap;
private State state;
/** /**
* Instantiates a new health check response geoportal provider. * Instantiates a new health check response geoportal provider.
@ -38,55 +38,30 @@ public class HealthCheckResponseGeoportalProvider {
* @param status the status * @param status the status
* @param data the data * @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.name = name;
this.status = status; this.state = state;
this.data = data; this.data = data;
} }
/**
* Gets the name.
*
* @return the name
*/
public String getName() { public String getName() {
return name; 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() { public Optional<Map<String, Object>> getData() {
return data; return data;
} }
/** public State getState() {
* Sets the name. return state;
* }
* @param name the new name
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** public void setState(State state) {
* Sets the status. this.state = state;
*
* @param status the new status
*/
public void setStatus(Status status) {
this.status = status;
} }
/** /**
@ -114,7 +89,7 @@ public class HealthCheckResponseGeoportalProvider {
log.info("data are: " + data); log.info("data are: " + data);
return new HealthCheckResponse(name, status, data); return new HealthCheckResponse(name, state, data);
} }
} }