Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Dropwizard Oor Bundle [![Travis build status](https://travis-ci.org/phaneesh/dropwizard-oor.svg?branch=master)](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
Expand All @@ -22,7 +23,7 @@ This makes it easier perform rolling deployments & maintenance of dropwizard app
<dependency>
<groupId>io.dropwizard.oor</groupId>
<artifactId>dropwizard-oor</artifactId>
<version>2.0.24-1</version>
<version>2.0.24-2</version>
</dependency>
```

Expand All @@ -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;
}


});
}
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.raven.dropwizard</groupId>
<artifactId>dropwizard-oor</artifactId>
<version>2.0.24-1</version>
<version>2.0.24-2</version>
<packaging>jar</packaging>

<name>dropwizard-oor</name>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/dropwizard/oor/OorBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
37 changes: 37 additions & 0 deletions src/main/java/io/dropwizard/oor/resources/HealthCheckResource.java
Original file line number Diff line number Diff line change
@@ -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());
}

}