Skip to content
Permalink
Browse files
[GERONIMO-6781] MP 3-RC3 impl
  • Loading branch information
rmannibucau committed Sep 11, 2020
1 parent 41f8f23 commit c7d39a8ee374ad7943ec8abd27b646fa4db72c5a
Showing 5 changed files with 42 additions and 50 deletions.
@@ -51,17 +51,22 @@ public HealthCheckResponseBuilder withData(final String key, final boolean value

@Override
public HealthCheckResponseBuilder up() {
response.setState(HealthCheckResponse.State.UP);
response.setState(HealthCheckResponse.Status.UP);
return this;
}

@Override
public HealthCheckResponseBuilder down() {
response.setState(HealthCheckResponse.State.DOWN);
response.setState(HealthCheckResponse.Status.DOWN);
return this;
}

@Override
public HealthCheckResponseBuilder status(final boolean up) {
return state(up);
}

// @Override - dropped from the spec
public HealthCheckResponseBuilder state(final boolean up) {
if (up) {
up();
@@ -16,31 +16,24 @@
*/
package org.apache.geronimo.microprofile.common.impl;

import java.util.Map;
import java.util.Optional;
import org.eclipse.microprofile.health.HealthCheckResponse;

import javax.json.bind.annotation.JsonbProperty;
import javax.json.bind.annotation.JsonbTransient;

import org.eclipse.microprofile.health.HealthCheckResponse;
import java.util.Map;
import java.util.Optional;

public class HealthCheckResponseImpl extends HealthCheckResponse {
private String name;
private State state;
private Status state;
private Map<String, Object> data;

@Override
public String getName() {
return name;
}

@Override
@JsonbTransient
public State getState() {
return state;
}

public State getStatus() {
public Status getStatus() {
return state;
}

@@ -59,7 +52,7 @@ public void setName(final String name) {
this.name = name;
}

public void setState(final State state) {
public void setState(final Status state) {
this.state = state;
}

@@ -16,22 +16,21 @@
*/
package org.apache.geronimo.microprofile.common.jaxrs;

import static java.util.stream.Collectors.toList;

import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;

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 java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import static java.util.stream.Collectors.toList;

@Path("health")
// @ApplicationScoped
@@ -77,26 +76,26 @@ private Response toResponse(final Function<HealthChecksRegistry, Collection<Heal
.stream()
.map(HealthCheck::call)
.collect(toList());
final HealthCheckResponse.State globalState = checks.stream()
.reduce(HealthCheckResponse.State.UP, (a, b) -> combine(a, b.getState()), this::combine);
return Response.status(globalState == HealthCheckResponse.State.DOWN ? Response.Status.SERVICE_UNAVAILABLE : Response.Status.OK).entity(new AggregatedResponse(globalState, checks)).build();
final HealthCheckResponse.Status globalState = checks.stream()
.reduce(HealthCheckResponse.Status.UP, (a, b) -> combine(a, b.getStatus()), this::combine);
return Response.status(globalState == HealthCheckResponse.Status.DOWN ? Response.Status.SERVICE_UNAVAILABLE : Response.Status.OK).entity(new AggregatedResponse(globalState, checks)).build();
}

private HealthCheckResponse.State combine(final HealthCheckResponse.State a, final HealthCheckResponse.State b) {
return a == HealthCheckResponse.State.DOWN || b == HealthCheckResponse.State.DOWN ? HealthCheckResponse.State.DOWN : a;
private HealthCheckResponse.Status combine(final HealthCheckResponse.Status a, final HealthCheckResponse.Status b) {
return a == HealthCheckResponse.Status.DOWN || b == HealthCheckResponse.Status.DOWN ? HealthCheckResponse.Status.DOWN : a;
}

public static class AggregatedResponse {
private HealthCheckResponse.State status;
private HealthCheckResponse.Status status;
private Collection<HealthCheckResponse> checks;

private AggregatedResponse(final HealthCheckResponse.State state,
private AggregatedResponse(final HealthCheckResponse.Status state,
final Collection<HealthCheckResponse> checks) {
this.status = state;
this.checks = checks;
}

public HealthCheckResponse.State getStatus() {
public HealthCheckResponse.Status getStatus() {
return status;
}

@@ -16,14 +16,10 @@
*/
package org.apache.geronimo.microprofile.impl.health.cdi;

import static java.util.stream.Collectors.toList;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
@@ -34,11 +30,14 @@
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessBean;
import javax.enterprise.util.AnnotationLiteral;
import org.apache.geronimo.microprofile.common.registry.HealthChecksRegistry;
import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

public class GeronimoHealthExtension implements Extension, HealthChecksRegistry {
private final Collection<Bean<?>> beans = new ArrayList<>();
@@ -62,10 +61,6 @@ void findChecks(@Observes final ProcessBean<?> bean) {
if (!bean.getBean().getTypes().contains(HealthCheck.class)) {
return;
}
// deprecated - use @Liveness or @Readiness
if (bean.getAnnotated().isAnnotationPresent(Health.class)) {
beans.add(bean.getBean());
}
if (bean.getBean().getQualifiers().contains(LivenessLiteral.INSTANCE)) {
livenessBeans.add(bean.getBean());
}
@@ -42,7 +42,7 @@
</scm>

<properties>
<spec.version>2.1</spec.version>
<spec.version>3.0-RC3</spec.version>
</properties>

<modules>

0 comments on commit c7d39a8

Please sign in to comment.