diff --git a/README.md b/README.md
index 52af4a1..d4c1aab 100755
--- a/README.md
+++ b/README.md
@@ -1,7 +1,8 @@
# Dropwizard Oor Bundle [](https://travis-ci.org/phaneesh/dropwizard-oor)
This bundle adds a healthcheck which can used to take the application out of rotation from
-a loadbalancer which uses /healthcheck endpoint for healthchecks
+a loadbalancer which uses /healthcheck endpoint for healthchecks.
+Also gives capability to expose admin port /healthcheck on application port for lb's which poll on application port.
This bundle compiles only on Java 11.
## Usage
@@ -22,7 +23,7 @@ This makes it easier perform rolling deployments & maintenance of dropwizard app
io.dropwizard.oor
dropwizard-oor
- 2.0.24-1
+ 2.0.24-2
```
@@ -34,10 +35,18 @@ This makes it easier perform rolling deployments & maintenance of dropwizard app
public void initialize(final Bootstrap...) {
bootstrap.addBundle(new OorBundle() {
+ @Override
public boolean withOor() {
return false;
}
+ //Use this only if you require healthcheck on application port
+ @Override
+ public boolean exposeApplicationPortHealthCheck() {
+ return true;
+ }
+
+
});
}
```
diff --git a/pom.xml b/pom.xml
index 66adbf4..1ea5377 100755
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.raven.dropwizard
dropwizard-oor
- 2.0.24-1
+ 2.0.24-2
jar
dropwizard-oor
diff --git a/src/main/java/io/dropwizard/oor/OorBundle.java b/src/main/java/io/dropwizard/oor/OorBundle.java
index 54673ca..b1dc81d 100755
--- a/src/main/java/io/dropwizard/oor/OorBundle.java
+++ b/src/main/java/io/dropwizard/oor/OorBundle.java
@@ -18,6 +18,7 @@
import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.oor.healtcheck.OorHealthCheck;
+import io.dropwizard.oor.resources.HealthCheckResource;
import io.dropwizard.oor.tasks.BirTask;
import io.dropwizard.oor.tasks.OorTask;
import io.dropwizard.setup.Bootstrap;
@@ -42,5 +43,13 @@ public void run(T configuration, Environment environment) throws Exception {
environment.healthChecks().register("oor", new OorHealthCheck(withOor()));
environment.admin().addTask(new OorTask());
environment.admin().addTask(new BirTask());
+ if (exposeApplicationPortHealthCheck()) {
+ environment.jersey().register(new HealthCheckResource(environment.healthChecks()));
+ }
+ }
+
+ protected boolean exposeApplicationPortHealthCheck() {
+ //Client to over-ride if healthCheck resource required at application port
+ return false;
}
}
diff --git a/src/main/java/io/dropwizard/oor/resources/HealthCheckResource.java b/src/main/java/io/dropwizard/oor/resources/HealthCheckResource.java
new file mode 100644
index 0000000..485cdc7
--- /dev/null
+++ b/src/main/java/io/dropwizard/oor/resources/HealthCheckResource.java
@@ -0,0 +1,37 @@
+package io.dropwizard.oor.resources;
+
+import com.codahale.metrics.health.HealthCheckRegistry;
+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 lombok.val;
+
+@Produces(MediaType.APPLICATION_JSON)
+@Path("/healthcheck/status")
+public class HealthCheckResource {
+
+ private HealthCheckRegistry registry;
+
+ public HealthCheckResource(HealthCheckRegistry registry) {
+ this.registry = registry;
+ }
+
+ @GET
+ public Response getHealthcheckStatus() {
+ val healthCheck = registry.runHealthChecks().entrySet();
+ return healthCheck.stream()
+ .filter(entry -> !entry.getValue().isHealthy())
+ .findFirst()
+ .map(result ->
+ Response.serverError()
+ .entity(healthCheck)
+ .build()
+ )
+ .orElse(Response.ok()
+ .entity(healthCheck)
+ .build());
+ }
+
+}
\ No newline at end of file