@Override public void handleRequest(final RestRequest request, final RestChannel channel) { ClusterStateRequest clusterStateRequest = new ClusterStateRequest(); clusterStateRequest.listenerThreaded(false); clusterStateRequest.masterNodeTimeout(TimeValue.timeValueMillis(0)); clusterStateRequest.local(true); clusterStateRequest.filterAll().filterBlocks(false); client .admin() .cluster() .state( clusterStateRequest, new ActionListener<ClusterStateResponse>() { @Override public void onResponse(ClusterStateResponse response) { RestStatus status = RestStatus.OK; if (response.getState().blocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE)) { status = RestStatus.SERVICE_UNAVAILABLE; } if (request.method() == RestRequest.Method.HEAD) { channel.sendResponse(new StringRestResponse(status)); return; } try { XContentBuilder builder = RestXContentBuilder.restContentBuilder(request).prettyPrint(); builder.startObject(); builder.field("ok", true); builder.field("status", status.getStatus()); if (settings.get("name") != null) { builder.field("name", settings.get("name")); } builder .startObject("version") .field("number", version.number()) .field("build_hash", Build.CURRENT.hash()) .field("build_timestamp", Build.CURRENT.timestamp()) .field("build_snapshot", version.snapshot) // We use the lucene version from lucene constants since // this includes bugfix release version as well and is already in // the right format. We can also be sure that the format is maitained // since this is also recorded in lucene segments and has BW compat .field("lucene_version", Constants.LUCENE_MAIN_VERSION) .endObject(); builder.field("tagline", "You Know, for Search"); builder.endObject(); channel.sendResponse(new XContentRestResponse(request, status, builder)); } catch (Throwable e) { onFailure(e); } } @Override public void onFailure(Throwable e) { try { if (request.method() == HEAD) { channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e))); } else { channel.sendResponse(new XContentThrowableRestResponse(request, e)); } } catch (Exception e1) { logger.warn("Failed to send response", e); } } }); }