Skip to content

Instantly share code, notes, and snippets.

@ryantenney
Forked from sheki/HealthCheck.java
Created February 28, 2012 21:55
Show Gist options
  • Save ryantenney/1935505 to your computer and use it in GitHub Desktop.
Save ryantenney/1935505 to your computer and use it in GitHub Desktop.
import com.yammer.metrics.annotation.Timed;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/healthcheck")
public interface HealthCheck
{
@GET
@Path("/console")
@Produces({"text/html"})
Response healthAsHTML();
@GET
@Path("/json")
@Produces({"application/json"})
Response healthAsJSON();
}
import com.flipkart.digital.core.cache.CacheInterceptor;
import com.flipkart.digital.inventory.api.resources.health.CompleteHealth;
import com.yammer.metrics.annotation.Timed;
import flipkart.platform.soa.ComponentHealth;
import flipkart.platform.soa.ComponentUtils;
import flipkart.platform.soa.DeepHealthReporter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.core.Response;
import java.lang.String;
/**
*
*/
@Component
@Scope("request")
public class HealthCheckImpl implements HealthCheck
{
@Autowired
private CacheInterceptor cacheable;
@Timed(name = "healthAsHTML")
public Response healthAsHTML()
{
final Response.ResponseBuilder responseBuilder = Response.ok();
String output = ComponentUtils.healthAsHTML(findOutHealth());
responseBuilder.entity(output);
return responseBuilder.build();
}
@Timed
public Response healthAsJSON()
{
final Response.ResponseBuilder responseBuilder = Response.ok();
String output = ComponentUtils.healthAsJSON(findOutHealth());
responseBuilder.entity(output);
return responseBuilder.build();
}
private ComponentHealth findOutHealth()
{
final CompleteHealth health = new CompleteHealth(cacheable);
final DeepHealthReporter deepHealthReporter = new DeepHealthReporter(health);
return deepHealthReporter.getComponentHealth();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment