Search in sources :

Example 46 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestRepositoriesAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(RestRequest request, NodeClient client) {
    GetRepositoriesRequest getRepositoriesRequest = new GetRepositoriesRequest();
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getRepositories(getRepositoriesRequest, new RestResponseListener<GetRepositoriesResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetRepositoriesResponse getRepositoriesResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getRepositoriesResponse), channel);
        }
    });
}
Also used : RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) RestResponse(org.elasticsearch.rest.RestResponse) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 47 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestSegmentsAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {

                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
Also used : IndicesSegmentResponse(org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) GET(org.elasticsearch.rest.RestRequest.Method.GET) IndicesSegmentsRequest(org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest) RestResponse(org.elasticsearch.rest.RestResponse) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) Segment(org.elasticsearch.index.engine.Segment) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments) Map(java.util.Map) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) Table(org.elasticsearch.common.Table) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) IndicesSegmentResponse(org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse) IndicesSegmentsRequest(org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments)

Example 48 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestSnapshotAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest().repository(request.param("repository")).snapshots(new String[] { GetSnapshotsRequest.ALL_SNAPSHOTS });
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
        }
    });
}
Also used : DateTimeFormat(org.joda.time.format.DateTimeFormat) GET(org.elasticsearch.rest.RestRequest.Method.GET) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) TimeUnit(java.util.concurrent.TimeUnit) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) SnapshotState(org.elasticsearch.snapshots.SnapshotState) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestResponse(org.elasticsearch.rest.RestResponse)

Example 49 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestRecoveryAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
    recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
    recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));
    return channel -> client.admin().indices().recoveries(recoveryRequest, new RestBuilderListener<RecoveryResponse>(channel) {

        @Override
        public RestResponse buildResponse(RecoveryResponse response, XContentBuilder builder) throws Exception {
            response.detailed(recoveryRequest.detailed());
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RecoveryRequest(org.elasticsearch.action.admin.indices.recovery.RecoveryRequest) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) RecoveryRequest(org.elasticsearch.action.admin.indices.recovery.RecoveryRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse)

Example 50 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class TestResponseHeaderRestAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    if ("password".equals(request.header("Secret"))) {
        RestResponse response = new BytesRestResponse(RestStatus.OK, "Access granted");
        response.addHeader("Secret", "granted");
        return channel -> channel.sendResponse(response);
    } else {
        RestResponse response = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Access denied");
        response.addHeader("Secret", "required");
        return channel -> channel.sendResponse(response);
    }
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) RestResponse(org.elasticsearch.rest.RestResponse) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse)

Aggregations

RestResponse (org.elasticsearch.rest.RestResponse)51 NodeClient (org.elasticsearch.client.node.NodeClient)48 Settings (org.elasticsearch.common.settings.Settings)48 RestController (org.elasticsearch.rest.RestController)48 RestRequest (org.elasticsearch.rest.RestRequest)48 GET (org.elasticsearch.rest.RestRequest.Method.GET)40 Strings (org.elasticsearch.common.Strings)33 IOException (java.io.IOException)31 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)31 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)30 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)27 RestBuilderListener (org.elasticsearch.rest.action.RestBuilderListener)25 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)23 OK (org.elasticsearch.rest.RestStatus.OK)20 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)20 Table (org.elasticsearch.common.Table)17 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)12 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)12 RestActions.buildBroadcastShardsHeader (org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader)11 RestStatus (org.elasticsearch.rest.RestStatus)10