Search in sources :

Example 41 with RestRequest

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

the class RestRestoreSnapshotAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RestoreSnapshotRequest restoreSnapshotRequest = restoreSnapshotRequest(request.param("repository"), request.param("snapshot"));
    restoreSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", restoreSnapshotRequest.masterNodeTimeout()));
    restoreSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
    request.applyContentParser(p -> restoreSnapshotRequest.source(p.mapOrdered()));
    return channel -> client.admin().cluster().restoreSnapshot(restoreSnapshotRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Requests.restoreSnapshotRequest(org.elasticsearch.client.Requests.restoreSnapshotRequest) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)

Example 42 with RestRequest

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

the class RestSnapshotsStatusAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String repository = request.param("repository", "_all");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
    if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
        snapshots = Strings.EMPTY_ARRAY;
    }
    SnapshotsStatusRequest snapshotsStatusRequest = snapshotsStatusRequest(repository).snapshots(snapshots);
    snapshotsStatusRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", snapshotsStatusRequest.ignoreUnavailable()));
    snapshotsStatusRequest.masterNodeTimeout(request.paramAsTime("master_timeout", snapshotsStatusRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().snapshotsStatus(snapshotsStatusRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) SnapshotsStatusRequest(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) Requests.snapshotsStatusRequest(org.elasticsearch.client.Requests.snapshotsStatusRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) SnapshotsStatusRequest(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)

Example 43 with RestRequest

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

the class RestVerifyRepositoryAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    VerifyRepositoryRequest verifyRepositoryRequest = verifyRepositoryRequest(request.param("repository"));
    verifyRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", verifyRepositoryRequest.masterNodeTimeout()));
    verifyRepositoryRequest.timeout(request.paramAsTime("timeout", verifyRepositoryRequest.timeout()));
    return channel -> client.admin().cluster().verifyRepository(verifyRepositoryRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) VerifyRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest) Settings(org.elasticsearch.common.settings.Settings) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests.verifyRepositoryRequest(org.elasticsearch.client.Requests.verifyRepositoryRequest) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) VerifyRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)

Example 44 with RestRequest

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

the class RestCloseIndexAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
    closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout()));
    closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
    closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
    return channel -> client.admin().indices().close(closeIndexRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest)

Example 45 with RestRequest

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

the class RestTable method buildXContentBuilder.

public static RestResponse buildXContentBuilder(Table table, RestChannel channel) throws Exception {
    RestRequest request = channel.request();
    XContentBuilder builder = channel.newBuilder();
    List<DisplayHeader> displayHeaders = buildDisplayHeaders(table, request);
    builder.startArray();
    List<Integer> rowOrder = getRowOrder(table, request);
    for (Integer row : rowOrder) {
        builder.startObject();
        for (DisplayHeader header : displayHeaders) {
            builder.field(header.display, renderValue(request, table.getAsMap().get(header.name).get(row).value));
        }
        builder.endObject();
    }
    builder.endArray();
    return new BytesRestResponse(RestStatus.OK, builder);
}
Also used : RestRequest(org.elasticsearch.rest.RestRequest) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

RestRequest (org.elasticsearch.rest.RestRequest)133 Settings (org.elasticsearch.common.settings.Settings)110 RestController (org.elasticsearch.rest.RestController)110 NodeClient (org.elasticsearch.client.node.NodeClient)108 IOException (java.io.IOException)91 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)88 Strings (org.elasticsearch.common.Strings)61 GET (org.elasticsearch.rest.RestRequest.Method.GET)57 RestResponse (org.elasticsearch.rest.RestResponse)50 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)41 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)41 POST (org.elasticsearch.rest.RestRequest.Method.POST)34 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)30 RestBuilderListener (org.elasticsearch.rest.action.RestBuilderListener)27 OK (org.elasticsearch.rest.RestStatus.OK)23 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)23 FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)21 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)20 Table (org.elasticsearch.common.Table)19 HashMap (java.util.HashMap)17