Search in sources :

Example 66 with NodeClient

use of org.elasticsearch.client.node.NodeClient in project elasticsearch by elastic.

the class RestDeleteSnapshotAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    DeleteSnapshotRequest deleteSnapshotRequest = deleteSnapshotRequest(request.param("repository"), request.param("snapshot"));
    deleteSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteSnapshotRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().deleteSnapshot(deleteSnapshotRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Requests.deleteSnapshotRequest(org.elasticsearch.client.Requests.deleteSnapshotRequest) Settings(org.elasticsearch.common.settings.Settings) DELETE(org.elasticsearch.rest.RestRequest.Method.DELETE) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) DeleteSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) RestController(org.elasticsearch.rest.RestController) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) DeleteSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)

Example 67 with NodeClient

use of org.elasticsearch.client.node.NodeClient in project elasticsearch by elastic.

the class RestDeleteStoredScriptAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String id = request.param("id");
    String lang = request.param("lang");
    // name ordering issues in the handlers' paths.
    if (id == null) {
        id = lang;
        lang = null;
    }
    if (lang != null) {
        deprecationLogger.deprecated("specifying lang [" + lang + "] as part of the url path is deprecated");
    }
    DeleteStoredScriptRequest deleteStoredScriptRequest = new DeleteStoredScriptRequest(id, lang);
    return channel -> client.admin().cluster().deleteStoredScript(deleteStoredScriptRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) DELETE(org.elasticsearch.rest.RestRequest.Method.DELETE) RestRequest(org.elasticsearch.rest.RestRequest) DeleteStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) DeleteStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)

Example 68 with NodeClient

use of org.elasticsearch.client.node.NodeClient in project elasticsearch by elastic.

the class RestGetRepositoriesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
    GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    settingsFilter.addFilterSettingParams(request);
    return channel -> client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (RepositoryMetaData repositoryMetaData : response.repositories()) {
                RepositoriesMetaData.toXContent(repositoryMetaData, builder, request);
            }
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) Set(java.util.Set) Requests.getRepositoryRequest(org.elasticsearch.client.Requests.getRepositoryRequest) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 69 with NodeClient

use of org.elasticsearch.client.node.NodeClient in project elasticsearch by elastic.

the class RestGetSnapshotsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String repository = request.param("repository");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
    GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(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 RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) Requests.getSnapshotsRequest(org.elasticsearch.client.Requests.getSnapshotsRequest) 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) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) Strings(org.elasticsearch.common.Strings) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)

Example 70 with NodeClient

use of org.elasticsearch.client.node.NodeClient in project elasticsearch by elastic.

the class RestGetStoredScriptAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, NodeClient client) throws IOException {
    String id;
    String lang;
    // name ordering issues in the handlers' paths.
    if (request.param("id") == null) {
        id = request.param("lang");
        ;
        lang = null;
    } else {
        id = request.param("id");
        lang = request.param("lang");
    }
    if (lang != null) {
        deprecationLogger.deprecated("specifying lang [" + lang + "] as part of the url path is deprecated");
    }
    GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id, lang);
    return channel -> client.admin().cluster().getStoredScript(getRequest, new RestBuilderListener<GetStoredScriptResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetStoredScriptResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            builder.field(_ID_PARSE_FIELD.getPreferredName(), id);
            if (lang != null) {
                builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), lang);
            }
            StoredScriptSource source = response.getSource();
            boolean found = source != null;
            builder.field(FOUND_PARSE_FIELD.getPreferredName(), found);
            if (found) {
                if (lang == null) {
                    builder.startObject(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName());
                    builder.field(StoredScriptSource.LANG_PARSE_FIELD.getPreferredName(), source.getLang());
                    builder.field(StoredScriptSource.CODE_PARSE_FIELD.getPreferredName(), source.getCode());
                    if (source.getOptions().isEmpty() == false) {
                        builder.field(StoredScriptSource.OPTIONS_PARSE_FIELD.getPreferredName(), source.getOptions());
                    }
                    builder.endObject();
                } else {
                    builder.field(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName(), source.getCode());
                }
            }
            builder.endObject();
            return new BytesRestResponse(found ? RestStatus.OK : RestStatus.NOT_FOUND, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GetStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) GetStoredScriptResponse(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse) StoredScriptSource(org.elasticsearch.script.StoredScriptSource) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) ParseField(org.elasticsearch.common.ParseField) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) GetStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) StoredScriptSource(org.elasticsearch.script.StoredScriptSource) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException) GetStoredScriptResponse(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse)

Aggregations

NodeClient (org.elasticsearch.client.node.NodeClient)125 Settings (org.elasticsearch.common.settings.Settings)115 RestRequest (org.elasticsearch.rest.RestRequest)108 RestController (org.elasticsearch.rest.RestController)107 IOException (java.io.IOException)103 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)36 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)35 POST (org.elasticsearch.rest.RestRequest.Method.POST)34 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)30 RestBuilderListener (org.elasticsearch.rest.action.RestBuilderListener)27 Set (java.util.Set)24 Table (org.elasticsearch.common.Table)24 OK (org.elasticsearch.rest.RestStatus.OK)23 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)23 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)20 Collections (java.util.Collections)18