Example usage for org.apache.lucene.util Constants LUCENE_MAIN_VERSION

List of usage examples for org.apache.lucene.util Constants LUCENE_MAIN_VERSION

Introduction

In this page you can find the example usage for org.apache.lucene.util Constants LUCENE_MAIN_VERSION.

Prototype

String LUCENE_MAIN_VERSION

To view the source code for org.apache.lucene.util Constants LUCENE_MAIN_VERSION.

Click Source Link

Document

This is the internal Lucene version, including bugfix versions, recorded into each segment.

Usage

From source file:org.elasticsearch.rest.action.main.RestMainAction.java

License:Apache License

@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);/*from ww  w  .  j  av a 2  s .  c  o  m*/
    clusterStateRequest.clear().blocks(true);
    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);

                // Default to pretty printing, but allow ?pretty=false to disable
                if (!request.hasParam("pretty")) {
                    builder.prettyPrint().lfAtEnd();
                }

                builder.startObject();
                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);
            }
        }
    });
}