REST api: made it possible to copy the REST headers from REST requests to the corresponding TransportRequest(s)
Introduced the use of the FilterClient in all of the REST actions, which delegates all of the operations to the internal Client, but makes sure that the headers are properly copied if needed from REST requests to TransportRequest(s) when it comes to executing them. Added new abstract handleRequest method to BaseRestHandler with additional Client argument and made private the client instance member (was protected before) to force the use of the client received as argument. The list of headers to be copied over is by default empty but can be extended via plugins. Closes #6513
This commit is contained in:
parent
8f8b2d7979
commit
12fd6ce98c
|
@ -19,19 +19,135 @@
|
|||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.elasticsearch.action.*;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.client.FilterClient;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base handler for REST requests
|
||||
*/
|
||||
public abstract class BaseRestHandler extends AbstractComponent implements RestHandler {
|
||||
|
||||
protected final Client client;
|
||||
// non volatile since the assumption is that useful headers are registered on startup
|
||||
private static String[] usefulHeaders = new String[0];
|
||||
|
||||
/**
|
||||
* Controls which REST headers get copied over from a {@link org.elasticsearch.rest.RestRequest} to
|
||||
* its corresponding {@link org.elasticsearch.transport.TransportRequest}(s).
|
||||
*
|
||||
* By default no headers get copied but it is possible to extend this behaviour via plugins by calling this method.
|
||||
*/
|
||||
public static synchronized void addUsefulHeaders(String... headers) {
|
||||
String[] copy = new String[usefulHeaders.length + headers.length];
|
||||
System.arraycopy(usefulHeaders, 0, copy, 0 , usefulHeaders.length);
|
||||
System.arraycopy(headers, 0, copy, usefulHeaders.length, headers.length);
|
||||
usefulHeaders = copy;
|
||||
}
|
||||
|
||||
static String[] usefulHeaders() {
|
||||
String[] copy = new String[usefulHeaders.length];
|
||||
System.arraycopy(usefulHeaders, 0, copy, 0 , usefulHeaders.length);
|
||||
return copy;
|
||||
}
|
||||
|
||||
private final Client client;
|
||||
|
||||
protected BaseRestHandler(Settings settings, Client client) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void handleRequest(RestRequest request, RestChannel channel) throws Exception {
|
||||
handleRequest(request, channel, usefulHeaders.length == 0 ? client : new HeadersCopyClient(client, request, usefulHeaders));
|
||||
}
|
||||
|
||||
protected abstract void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception;
|
||||
|
||||
static final class HeadersCopyClient extends FilterClient {
|
||||
|
||||
private final RestRequest restRequest;
|
||||
private final String[] usefulHeaders;
|
||||
private final IndicesAdmin indicesAdmin;
|
||||
private final ClusterAdmin clusterAdmin;
|
||||
|
||||
HeadersCopyClient(Client in, RestRequest restRequest, String[] usefulHeaders) {
|
||||
super(in);
|
||||
this.restRequest = restRequest;
|
||||
this.usefulHeaders = usefulHeaders;
|
||||
this.indicesAdmin = new IndicesAdmin(in.admin().indices());
|
||||
this.clusterAdmin = new ClusterAdmin(in.admin().cluster());
|
||||
}
|
||||
|
||||
private void copyHeaders(ActionRequest request) {
|
||||
for (String usefulHeader : usefulHeaders) {
|
||||
String headerValue = restRequest.header(usefulHeader);
|
||||
if (headerValue != null) {
|
||||
request.putHeader(usefulHeader, headerValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, Client> action, Request request) {
|
||||
copyHeaders(request);
|
||||
return super.execute(action, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> void execute(Action<Request, Response, RequestBuilder, Client> action, Request request, ActionListener<Response> listener) {
|
||||
copyHeaders(request);
|
||||
super.execute(action, request, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterAdminClient cluster() {
|
||||
return clusterAdmin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicesAdminClient indices() {
|
||||
return indicesAdmin;
|
||||
}
|
||||
|
||||
private final class ClusterAdmin extends FilterClient.ClusterAdmin {
|
||||
private ClusterAdmin(ClusterAdminClient in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, ClusterAdminClient>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, ClusterAdminClient> action, Request request) {
|
||||
copyHeaders(request);
|
||||
return super.execute(action, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, ClusterAdminClient>> void execute(Action<Request, Response, RequestBuilder, ClusterAdminClient> action, Request request, ActionListener<Response> listener) {
|
||||
copyHeaders(request);
|
||||
super.execute(action, request, listener);
|
||||
}
|
||||
}
|
||||
|
||||
private final class IndicesAdmin extends FilterClient.IndicesAdmin {
|
||||
private IndicesAdmin(IndicesAdminClient in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, IndicesAdminClient>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, IndicesAdminClient> action, Request request) {
|
||||
copyHeaders(request);
|
||||
return super.execute(action, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, IndicesAdminClient>> void execute(Action<Request, Response, RequestBuilder, IndicesAdminClient> action, Request request, ActionListener<Response> listener) {
|
||||
copyHeaders(request);
|
||||
super.execute(action, request, listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.rest;
|
||||
|
||||
/**
|
||||
*
|
||||
* Handler for REST requests
|
||||
*/
|
||||
public interface RestHandler {
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
|
||||
clusterHealthRequest.listenerThreaded(false);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class RestNodesHotThreadsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
|
||||
NodesHotThreadsRequest nodesHotThreadsRequest = new NodesHotThreadsRequest(nodesIds);
|
||||
nodesHotThreadsRequest.threads(request.paramAsInt("threads", nodesHotThreadsRequest.threads()));
|
||||
|
|
|
@ -59,7 +59,7 @@ public class RestNodesInfoAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] nodeIds;
|
||||
Set<String> metrics;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public class RestNodesRestartAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
|
||||
NodesRestartRequest nodesRestartRequest = new NodesRestartRequest(nodesIds);
|
||||
nodesRestartRequest.listenerThreaded(false);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RestNodesShutdownAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
|
||||
NodesShutdownRequest nodesShutdownRequest = new NodesShutdownRequest(nodesIds);
|
||||
nodesShutdownRequest.listenerThreaded(false);
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RestNodesStatsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
|
||||
Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all"));
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RestDeleteRepositoryAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteRepositoryRequest deleteRepositoryRequest = deleteRepositoryRequest(request.param("repository"));
|
||||
deleteRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteRepositoryRequest.masterNodeTimeout()));
|
||||
deleteRepositoryRequest.listenerThreaded(false);
|
||||
|
|
|
@ -31,8 +31,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.client.Requests.getRepositoryRequest;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
@ -50,7 +48,7 @@ public class RestGetRepositoriesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
|
||||
GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
|
||||
getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RestPutRepositoryAction extends BaseRestHandler {
|
|||
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PutRepositoryRequest putRepositoryRequest = putRepositoryRequest(request.param("repository"));
|
||||
putRepositoryRequest.listenerThreaded(false);
|
||||
putRepositoryRequest.source(request.content().toUtf8());
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestClusterRerouteAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
final ClusterRerouteRequest clusterRerouteRequest = Requests.clusterRerouteRequest();
|
||||
clusterRerouteRequest.listenerThreaded(false);
|
||||
clusterRerouteRequest.dryRun(request.paramAsBoolean("dry_run", clusterRerouteRequest.dryRun()));
|
||||
|
|
|
@ -29,8 +29,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RestClusterGetSettingsAction extends BaseRestHandler {
|
||||
|
@ -42,7 +40,7 @@ public class RestClusterGetSettingsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
|
||||
.listenerThreaded(false)
|
||||
.routingTable(false)
|
||||
|
|
|
@ -44,7 +44,7 @@ public class RestClusterUpdateSettingsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
final ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = Requests.clusterUpdateSettingsRequest();
|
||||
clusterUpdateSettingsRequest.listenerThreaded(false);
|
||||
clusterUpdateSettingsRequest.timeout(request.paramAsTime("timeout", clusterUpdateSettingsRequest.timeout()));
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RestClusterSearchShardsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final ClusterSearchShardsRequest clusterSearchShardsRequest = Requests.clusterSearchShardsRequest(indices);
|
||||
clusterSearchShardsRequest.local(request.paramAsBoolean("local", clusterSearchShardsRequest.local()));
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RestCreateSnapshotAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
CreateSnapshotRequest createSnapshotRequest = createSnapshotRequest(request.param("repository"), request.param("snapshot"));
|
||||
createSnapshotRequest.listenerThreaded(false);
|
||||
createSnapshotRequest.source(request.content().toUtf8());
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RestDeleteSnapshotAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteSnapshotRequest deleteSnapshotRequest = deleteSnapshotRequest(request.param("repository"), request.param("snapshot"));
|
||||
deleteSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteSnapshotRequest.masterNodeTimeout()));
|
||||
client.admin().cluster().deleteSnapshot(deleteSnapshotRequest, new AcknowledgedRestListener<DeleteSnapshotResponse>(channel));
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RestGetSnapshotsAction extends BaseRestHandler {
|
|||
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String repository = request.param("repository");
|
||||
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
|
||||
if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RestRestoreSnapshotAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
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));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestSnapshotsStatusAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String repository = request.param("repository", "_all");
|
||||
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
|
||||
if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.elasticsearch.common.xcontent.XContentBuilderString;
|
|||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
|
@ -55,7 +54,7 @@ public class RestClusterStateAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
|
||||
clusterStateRequest.listenerThreaded(false);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
|
|
@ -44,7 +44,7 @@ public class RestClusterStatsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ClusterStatsRequest clusterStatsRequest = new ClusterStatsRequest().nodesIds(request.paramAsStringArray("nodeId", null));
|
||||
clusterStatsRequest.listenerThreaded(false);
|
||||
client.admin().cluster().clusterStats(clusterStatsRequest, new RestToXContentListener<ClusterStatsResponse>(channel));
|
||||
|
|
|
@ -41,7 +41,7 @@ public class RestPendingClusterTasksAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
|
||||
pendingClusterTasksRequest.masterNodeTimeout(request.paramAsTime("master_timeout", pendingClusterTasksRequest.masterNodeTimeout()));
|
||||
pendingClusterTasksRequest.local(request.paramAsBoolean("local", pendingClusterTasksRequest.local()));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestIndicesAliasesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
indicesAliasesRequest.listenerThreaded(false);
|
||||
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
|
||||
|
|
|
@ -41,7 +41,7 @@ public class RestIndexDeleteAliasesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
|
|
|
@ -54,7 +54,7 @@ public class RestGetAliasesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name");
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases);
|
||||
|
|
|
@ -54,7 +54,7 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RestAliasesExistAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] aliases = request.paramAsStringArray("name", Strings.EMPTY_ARRAY);
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class RestIndexPutAliasAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
String alias = request.param("name");
|
||||
Map<String, Object> filter = null;
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String text = request.param("text");
|
||||
if (text == null && request.hasContent()) {
|
||||
text = request.content().toUtf8();
|
||||
|
|
|
@ -54,7 +54,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
clearIndicesCacheRequest.listenerThreaded(false);
|
||||
clearIndicesCacheRequest.indicesOptions(IndicesOptions.fromRequest(request, clearIndicesCacheRequest.indicesOptions()));
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RestCloseIndexAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
closeIndexRequest.listenerThreaded(false);
|
||||
closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout()));
|
||||
|
|
|
@ -44,7 +44,7 @@ public class RestCreateIndexAction extends BaseRestHandler {
|
|||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
|
||||
createIndexRequest.listenerThreaded(false);
|
||||
if (request.hasContent()) {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RestDeleteIndexAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
deleteIndexRequest.listenerThreaded(false);
|
||||
deleteIndexRequest.timeout(request.paramAsTime("timeout", deleteIndexRequest.timeout()));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RestIndicesExistsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
indicesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions()));
|
||||
indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local()));
|
||||
|
|
|
@ -44,7 +44,7 @@ public class RestTypesExistsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
TypesExistsRequest typesExistsRequest = new TypesExistsRequest(
|
||||
Strings.splitStringByCommaToArray(request.param("index")), Strings.splitStringByCommaToArray(request.param("type"))
|
||||
);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RestFlushAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
FlushRequest flushRequest = new FlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
flushRequest.listenerThreaded(false);
|
||||
flushRequest.indicesOptions(IndicesOptions.fromRequest(request, flushRequest.indicesOptions()));
|
||||
|
|
|
@ -50,7 +50,7 @@ public class RestDeleteMappingAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteMappingRequest deleteMappingRequest = deleteMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
deleteMappingRequest.listenerThreaded(false);
|
||||
deleteMappingRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||
|
|
|
@ -56,7 +56,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
|
||||
final String[] fields = Strings.splitStringByCommaToArray(request.param("fields"));
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RestGetMappingAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
|
||||
GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
|
||||
|
|
|
@ -65,7 +65,7 @@ public class RestPutMappingAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
putMappingRequest.listenerThreaded(false);
|
||||
putMappingRequest.type(request.param("type"));
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RestOpenIndexAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
OpenIndexRequest openIndexRequest = new OpenIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
openIndexRequest.listenerThreaded(false);
|
||||
openIndexRequest.timeout(request.paramAsTime("timeout", openIndexRequest.timeout()));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RestOptimizeAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
OptimizeRequest optimizeRequest = new OptimizeRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
optimizeRequest.listenerThreaded(false);
|
||||
optimizeRequest.indicesOptions(IndicesOptions.fromRequest(request, optimizeRequest.indicesOptions()));
|
||||
|
|
|
@ -46,7 +46,7 @@ public class RestRecoveryAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
|
||||
final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RestRefreshAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
refreshRequest.listenerThreaded(false);
|
||||
refreshRequest.force(request.paramAsBoolean("force", refreshRequest.force()));
|
||||
|
|
|
@ -46,7 +46,7 @@ public class RestIndicesSegmentsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
indicesSegmentsRequest.listenerThreaded(false);
|
||||
indicesSegmentsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesSegmentsRequest.indicesOptions()));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");
|
||||
GetSettingsRequest getSettingsRequest = new GetSettingsRequest()
|
||||
.indices(Strings.splitStringByCommaToArray(request.param("index")))
|
||||
|
@ -79,8 +79,6 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
static class Fields {
|
||||
|
||||
static final XContentBuilderString SETTINGS = new XContentBuilderString("settings");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RestUpdateSettingsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
UpdateSettingsRequest updateSettingsRequest = updateSettingsRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
updateSettingsRequest.listenerThreaded(false);
|
||||
updateSettingsRequest.timeout(request.paramAsTime("timeout", updateSettingsRequest.timeout()));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RestIndicesStatsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
|
||||
indicesStatsRequest.listenerThreaded(false);
|
||||
indicesStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesStatsRequest.indicesOptions()));
|
||||
|
|
|
@ -38,7 +38,7 @@ public class RestDeleteIndexTemplateAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteIndexTemplateRequest deleteIndexTemplateRequest = new DeleteIndexTemplateRequest(request.param("name"));
|
||||
deleteIndexTemplateRequest.listenerThreaded(false);
|
||||
deleteIndexTemplateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexTemplateRequest.masterNodeTimeout()));
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RestGetIndexTemplateAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
|
||||
|
||||
GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class RestHeadIndexTemplateAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(request.param("name"));
|
||||
getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
|
||||
client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestResponseListener<GetIndexTemplatesResponse>(channel) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class RestPutIndexTemplateAction extends BaseRestHandler {
|
|||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));
|
||||
putRequest.listenerThreaded(false);
|
||||
putRequest.template(request.param("template", putRequest.template()));
|
||||
|
|
|
@ -55,7 +55,7 @@ public class RestValidateQueryAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
validateQueryRequest.listenerThreaded(false);
|
||||
validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions()));
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RestDeleteWarmerAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteWarmerRequest deleteWarmerRequest = new DeleteWarmerRequest(Strings.splitStringByCommaToArray(request.param("name")))
|
||||
.indices(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
deleteWarmerRequest.listenerThreaded(false);
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RestGetWarmerAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final String[] types = Strings.splitStringByCommaToArray(request.param("type"));
|
||||
final String[] names = request.paramAsStringArray("name", Strings.EMPTY_ARRAY);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class RestPutWarmerAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name"));
|
||||
putWarmerRequest.listenerThreaded(false);
|
||||
SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")))
|
||||
|
|
|
@ -70,16 +70,16 @@ public class RestBenchAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
switch (request.method()) {
|
||||
case POST:
|
||||
handleAbortRequest(request, channel);
|
||||
handleAbortRequest(request, channel, client);
|
||||
break;
|
||||
case PUT:
|
||||
handleSubmitRequest(request, channel);
|
||||
handleSubmitRequest(request, channel, client);
|
||||
break;
|
||||
case GET:
|
||||
handleStatusRequest(request, channel);
|
||||
handleStatusRequest(request, channel, client);
|
||||
break;
|
||||
default:
|
||||
// Politely ignore methods we don't support
|
||||
|
@ -90,7 +90,7 @@ public class RestBenchAction extends BaseRestHandler {
|
|||
/**
|
||||
* Reports on the status of all actively running benchmarks
|
||||
*/
|
||||
private void handleStatusRequest(final RestRequest request, final RestChannel channel) {
|
||||
private void handleStatusRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
|
||||
BenchmarkStatusRequest benchmarkStatusRequest = new BenchmarkStatusRequest();
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class RestBenchAction extends BaseRestHandler {
|
|||
/**
|
||||
* Aborts an actively running benchmark
|
||||
*/
|
||||
private void handleAbortRequest(final RestRequest request, final RestChannel channel) {
|
||||
private void handleAbortRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] benchmarkNames = Strings.splitStringByCommaToArray(request.param("name"));
|
||||
AbortBenchmarkRequest abortBenchmarkRequest = new AbortBenchmarkRequest(benchmarkNames);
|
||||
|
||||
|
@ -119,7 +119,7 @@ public class RestBenchAction extends BaseRestHandler {
|
|||
/**
|
||||
* Submits a benchmark for execution
|
||||
*/
|
||||
private void handleSubmitRequest(final RestRequest request, final RestChannel channel) {
|
||||
private void handleSubmitRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
String[] types = Strings.splitStringByCommaToArray(request.param("type"));
|
||||
|
|
|
@ -69,7 +69,7 @@ public class RestBulkAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
BulkRequest bulkRequest = Requests.bulkRequest();
|
||||
bulkRequest.listenerThreaded(false);
|
||||
String defaultIndex = request.param("index");
|
||||
|
|
|
@ -37,14 +37,14 @@ public abstract class AbstractCatAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
}
|
||||
|
||||
abstract void doRequest(final RestRequest request, final RestChannel channel);
|
||||
abstract void doRequest(final RestRequest request, final RestChannel channel, final Client client);
|
||||
|
||||
abstract void documentation(StringBuilder sb);
|
||||
|
||||
abstract Table getTableWithHeader(final RestRequest request);
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
boolean helpWanted = request.paramAsBoolean("help", false);
|
||||
if (helpWanted) {
|
||||
Table table = getTableWithHeader(request);
|
||||
|
@ -63,7 +63,7 @@ public abstract class AbstractCatAction extends BaseRestHandler {
|
|||
out.close();
|
||||
channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes(), true));
|
||||
} else {
|
||||
doRequest(request, channel);
|
||||
doRequest(request, channel, client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RestAliasAction extends AbstractCatAction {
|
|||
|
||||
|
||||
@Override
|
||||
void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ?
|
||||
new GetAliasesRequest(request.param("alias")) :
|
||||
new GetAliasesRequest();
|
||||
|
|
|
@ -59,7 +59,7 @@ public class RestAllocationAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().routingTable(true);
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
@ -48,7 +47,7 @@ public class RestCatAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
channel.sendResponse(new BytesRestResponse(RestStatus.OK, HELP));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RestCountAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
CountRequest countRequest = new CountRequest(indices);
|
||||
String source = request.param("source");
|
||||
|
|
|
@ -56,7 +56,7 @@ public class RestFielddataAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
|
||||
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
|
||||
nodesStatsRequest.clear();
|
||||
|
|
|
@ -53,7 +53,7 @@ public class RestHealthAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest();
|
||||
|
||||
client.admin().cluster().health(clusterHealthRequest, new RestResponseListener<ClusterHealthResponse>(channel) {
|
||||
|
|
|
@ -62,7 +62,7 @@ public class RestIndicesAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().indices(indices).metaData(true);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class RestMasterAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().nodes(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
|
|
@ -61,7 +61,7 @@ public class RestNodesAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().nodes(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestPendingClusterTasksAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
|
||||
pendingClusterTasksRequest.masterNodeTimeout(request.paramAsTime("master_timeout", pendingClusterTasksRequest.masterNodeTimeout()));
|
||||
pendingClusterTasksRequest.local(request.paramAsBoolean("local", pendingClusterTasksRequest.local()));
|
||||
|
|
|
@ -55,7 +55,7 @@ public class RestPluginsAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().nodes(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
|
|
@ -64,7 +64,7 @@ public class RestRecoveryAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
|
||||
recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.rest.action.cat;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.action.admin.indices.segments.*;
|
||||
|
@ -35,7 +34,6 @@ import org.elasticsearch.rest.action.support.RestActionListener;
|
|||
import org.elasticsearch.rest.action.support.RestResponseListener;
|
||||
import org.elasticsearch.rest.action.support.RestTable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -51,7 +49,7 @@ public class RestSegmentsAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
|
|
|
@ -56,7 +56,7 @@ public class RestShardsAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
|
|
@ -120,7 +120,7 @@ public class RestThreadPoolAction extends AbstractCatAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.clear().nodes(true);
|
||||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
|
||||
|
|
|
@ -54,7 +54,7 @@ public class RestCountAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
|
||||
countRequest.listenerThreaded(false);
|
||||
|
|
|
@ -49,7 +49,7 @@ public class RestDeleteAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
|
||||
deleteRequest.listenerThreaded(false);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
deleteByQueryRequest.listenerThreaded(false);
|
||||
if (request.hasContent()) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RestExplainAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final ExplainRequest explainRequest = new ExplainRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
explainRequest.parent(request.param("parent"));
|
||||
explainRequest.routing(request.param("routing"));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RestGetAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
getRequest.listenerThreaded(false);
|
||||
getRequest.operationThreaded(true);
|
||||
|
|
|
@ -49,7 +49,7 @@ public class RestGetSourceAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
getRequest.listenerThreaded(false);
|
||||
getRequest.operationThreaded(true);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RestHeadAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
getRequest.listenerThreaded(false);
|
||||
getRequest.operationThreaded(true);
|
||||
|
|
|
@ -19,25 +19,19 @@
|
|||
|
||||
package org.elasticsearch.rest.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.get.MultiGetRequest;
|
||||
import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestToXContentListener;
|
||||
import org.elasticsearch.search.fetch.source.FetchSourceContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestStatus.BAD_REQUEST;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestMultiGetAction extends BaseRestHandler {
|
||||
|
||||
|
@ -57,7 +51,7 @@ public class RestMultiGetAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
multiGetRequest.listenerThreaded(false);
|
||||
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
|
||||
|
|
|
@ -50,20 +50,25 @@ public class RestIndexAction extends BaseRestHandler {
|
|||
controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation
|
||||
controller.registerHandler(PUT, "/{index}/{type}/{id}", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/{id}", this);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/{id}/_create", new CreateHandler());
|
||||
controller.registerHandler(POST, "/{index}/{type}/{id}/_create", new CreateHandler());
|
||||
CreateHandler createHandler = new CreateHandler(settings, client);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/{id}/_create", createHandler);
|
||||
controller.registerHandler(POST, "/{index}/{type}/{id}/_create", createHandler);
|
||||
}
|
||||
|
||||
final class CreateHandler implements RestHandler {
|
||||
final class CreateHandler extends BaseRestHandler {
|
||||
protected CreateHandler(Settings settings, final Client client) {
|
||||
super(settings, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RestRequest request, RestChannel channel) {
|
||||
public void handleRequest(RestRequest request, RestChannel channel, final Client client) {
|
||||
request.params().put("op_type", "create");
|
||||
RestIndexAction.this.handleRequest(request, channel);
|
||||
RestIndexAction.this.handleRequest(request, channel, client);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
indexRequest.listenerThreaded(false);
|
||||
indexRequest.operationThreaded(true);
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.rest.action.main;
|
|||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.elasticsearch.Build;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
|
@ -52,7 +51,7 @@ public class RestMainAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.listenerThreaded(false);
|
||||
clusterStateRequest.masterNodeTimeout(TimeValue.timeValueMillis(0));
|
||||
|
|
|
@ -19,25 +19,20 @@
|
|||
|
||||
package org.elasticsearch.rest.action.mlt;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.mlt.MoreLikeThisRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestToXContentListener;
|
||||
import org.elasticsearch.search.Scroll;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.client.Requests.moreLikeThisRequest;
|
||||
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -52,7 +47,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
MoreLikeThisRequest mltRequest = moreLikeThisRequest(request.param("index")).type(request.param("type")).id(request.param("id"));
|
||||
mltRequest.routing(request.param("routing"));
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.elasticsearch.rest.action.percolate;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.percolate.MultiPercolateRequest;
|
||||
import org.elasticsearch.action.percolate.MultiPercolateResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
|
@ -26,16 +25,12 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestToXContentListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -59,7 +54,7 @@ public class RestMultiPercolateAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest restRequest, final RestChannel restChannel) throws Exception {
|
||||
public void handleRequest(final RestRequest restRequest, final RestChannel restChannel, final Client client) throws Exception {
|
||||
MultiPercolateRequest multiPercolateRequest = new MultiPercolateRequest();
|
||||
multiPercolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, multiPercolateRequest.indicesOptions()));
|
||||
multiPercolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("index")));
|
||||
|
|
|
@ -45,20 +45,20 @@ public class RestPercolateAction extends BaseRestHandler {
|
|||
controller.registerHandler(GET, "/{index}/{type}/_percolate", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_percolate", this);
|
||||
|
||||
RestPercolateExistingDocHandler existingDocHandler = new RestPercolateExistingDocHandler();
|
||||
RestPercolateExistingDocHandler existingDocHandler = new RestPercolateExistingDocHandler(settings, client);
|
||||
controller.registerHandler(GET, "/{index}/{type}/{id}/_percolate", existingDocHandler);
|
||||
controller.registerHandler(POST, "/{index}/{type}/{id}/_percolate", existingDocHandler);
|
||||
|
||||
RestCountPercolateDocHandler countHandler = new RestCountPercolateDocHandler();
|
||||
RestCountPercolateDocHandler countHandler = new RestCountPercolateDocHandler(settings, client);
|
||||
controller.registerHandler(GET, "/{index}/{type}/_percolate/count", countHandler);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_percolate/count", countHandler);
|
||||
|
||||
RestCountPercolateExistingDocHandler countExistingDocHandler = new RestCountPercolateExistingDocHandler();
|
||||
RestCountPercolateExistingDocHandler countExistingDocHandler = new RestCountPercolateExistingDocHandler(settings, client);
|
||||
controller.registerHandler(GET, "/{index}/{type}/{id}/_percolate/count", countExistingDocHandler);
|
||||
controller.registerHandler(POST, "/{index}/{type}/{id}/_percolate/count", countExistingDocHandler);
|
||||
}
|
||||
|
||||
void parseDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel) {
|
||||
void parseDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel, final Client client) {
|
||||
percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("index")));
|
||||
percolateRequest.documentType(restRequest.param("type"));
|
||||
percolateRequest.routing(restRequest.param("routing"));
|
||||
|
@ -66,10 +66,10 @@ public class RestPercolateAction extends BaseRestHandler {
|
|||
percolateRequest.source(RestActions.getRestContent(restRequest), restRequest.contentUnsafe());
|
||||
|
||||
percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
|
||||
executePercolate(percolateRequest, restRequest, restChannel);
|
||||
executePercolate(percolateRequest, restChannel, client);
|
||||
}
|
||||
|
||||
void parseExistingDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel) {
|
||||
void parseExistingDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel, final Client client) {
|
||||
String index = restRequest.param("index");
|
||||
String type = restRequest.param("type");
|
||||
percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("percolate_index", index)));
|
||||
|
@ -90,51 +90,59 @@ public class RestPercolateAction extends BaseRestHandler {
|
|||
percolateRequest.source(restRequest.content(), restRequest.contentUnsafe());
|
||||
|
||||
percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
|
||||
executePercolate(percolateRequest, restRequest, restChannel);
|
||||
executePercolate(percolateRequest, restChannel, client);
|
||||
}
|
||||
|
||||
void executePercolate(final PercolateRequest percolateRequest, final RestRequest restRequest, final RestChannel restChannel) {
|
||||
void executePercolate(final PercolateRequest percolateRequest, final RestChannel restChannel, final Client client) {
|
||||
// we just send a response, no need to fork
|
||||
percolateRequest.listenerThreaded(false);
|
||||
client.percolate(percolateRequest, new RestToXContentListener<PercolateResponse>(restChannel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel) {
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel, final Client client) {
|
||||
PercolateRequest percolateRequest = new PercolateRequest();
|
||||
parseDocPercolate(percolateRequest, restRequest, restChannel);
|
||||
parseDocPercolate(percolateRequest, restRequest, restChannel, client);
|
||||
}
|
||||
|
||||
final class RestCountPercolateDocHandler implements RestHandler {
|
||||
final class RestCountPercolateDocHandler extends BaseRestHandler {
|
||||
|
||||
private RestCountPercolateDocHandler(Settings settings, final Client client) {
|
||||
super(settings, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel) {
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel, final Client client) {
|
||||
PercolateRequest percolateRequest = new PercolateRequest();
|
||||
percolateRequest.onlyCount(true);
|
||||
parseDocPercolate(percolateRequest, restRequest, restChannel);
|
||||
parseDocPercolate(percolateRequest, restRequest, restChannel, client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final class RestPercolateExistingDocHandler implements RestHandler {
|
||||
final class RestPercolateExistingDocHandler extends BaseRestHandler {
|
||||
|
||||
protected RestPercolateExistingDocHandler(Settings settings, final Client client) {
|
||||
super(settings, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel) {
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel, final Client client) {
|
||||
PercolateRequest percolateRequest = new PercolateRequest();
|
||||
parseExistingDocPercolate(percolateRequest, restRequest, restChannel);
|
||||
parseExistingDocPercolate(percolateRequest, restRequest, restChannel, client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final class RestCountPercolateExistingDocHandler implements RestHandler {
|
||||
final class RestCountPercolateExistingDocHandler extends BaseRestHandler {
|
||||
|
||||
protected RestCountPercolateExistingDocHandler(Settings settings, final Client client) {
|
||||
super(settings, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel) {
|
||||
public void handleRequest(RestRequest restRequest, RestChannel restChannel, final Client client) {
|
||||
PercolateRequest percolateRequest = new PercolateRequest();
|
||||
percolateRequest.onlyCount(true);
|
||||
parseExistingDocPercolate(percolateRequest, restRequest, restChannel);
|
||||
parseExistingDocPercolate(percolateRequest, restRequest, restChannel, client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class RestClearScrollAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String scrollIds = request.param("scroll_id");
|
||||
if (scrollIds == null) {
|
||||
scrollIds = RestActions.getRestContent(request).toUtf8();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.rest.action.search;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.search.MultiSearchRequest;
|
||||
import org.elasticsearch.action.search.MultiSearchResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
|
@ -27,17 +26,12 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestToXContentListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestStatus.BAD_REQUEST;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -60,7 +54,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
|
||||
multiSearchRequest.listenerThreaded(false);
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.rest.RestChannel;
|
|||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.support.RestStatusToXContentListener;
|
||||
import org.elasticsearch.rest.action.support.RestToXContentListener;
|
||||
import org.elasticsearch.search.Scroll;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.source.FetchSourceContext;
|
||||
|
@ -68,7 +67,7 @@ public class RestSearchAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
SearchRequest searchRequest;
|
||||
searchRequest = RestSearchAction.parseSearchRequest(request);
|
||||
searchRequest.listenerThreaded(false);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.rest.action.search;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchScrollRequest;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -51,7 +52,7 @@ public class RestSearchScrollAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String scrollId = request.param("scroll_id");
|
||||
if (scrollId == null) {
|
||||
scrollId = RestActions.getRestContent(request).toUtf8();
|
||||
|
@ -63,6 +64,6 @@ public class RestSearchScrollAction extends BaseRestHandler {
|
|||
searchScrollRequest.scroll(new Scroll(parseTimeValue(scroll, null)));
|
||||
}
|
||||
|
||||
client.searchScroll(searchScrollRequest, new RestStatusToXContentListener(channel));
|
||||
client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<SearchResponse>(channel));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RestSuggestAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
SuggestRequest suggestRequest = new SuggestRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
suggestRequest.indicesOptions(IndicesOptions.fromRequest(request, suggestRequest.indicesOptions()));
|
||||
suggestRequest.listenerThreaded(false);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.rest.action.termvector;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.termvector.MultiTermVectorsRequest;
|
||||
import org.elasticsearch.action.termvector.MultiTermVectorsResponse;
|
||||
import org.elasticsearch.action.termvector.TermVectorRequest;
|
||||
|
@ -27,14 +26,12 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestToXContentListener;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestMultiTermVectorsAction extends BaseRestHandler {
|
||||
|
||||
|
@ -50,7 +47,7 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest();
|
||||
multiTermVectorsRequest.listenerThreaded(false);
|
||||
TermVectorRequest template = new TermVectorRequest();
|
||||
|
|
|
@ -53,7 +53,7 @@ public class RestTermVectorAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
TermVectorRequest termVectorRequest = new TermVectorRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
XContentParser parser = null;
|
||||
if (request.hasContent()) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RestUpdateAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) throws Exception {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
|
||||
UpdateRequest updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
updateRequest.listenerThreaded(false);
|
||||
updateRequest.routing(request.param("routing"));
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TestResponseHeaderRestAction extends BaseRestHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RestRequest request, RestChannel channel) {
|
||||
public void handleRequest(RestRequest request, RestChannel channel, Client client) {
|
||||
if ("password".equals(request.header("Secret"))) {
|
||||
RestResponse response = new BytesRestResponse(RestStatus.OK, "Access granted");
|
||||
response.addHeader("Secret", "granted");
|
||||
|
|
|
@ -0,0 +1,476 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.*;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest;
|
||||
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.client.*;
|
||||
import org.elasticsearch.client.support.AbstractClient;
|
||||
import org.elasticsearch.client.support.AbstractClusterAdminClient;
|
||||
import org.elasticsearch.client.support.AbstractIndicesAdminClient;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.rest.BaseRestHandler.HeadersCopyClient;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
|
||||
public class HeadersCopyClientTests extends ElasticsearchTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddUsefulHeaders() throws InterruptedException {
|
||||
//take the existing headers into account to make sure this test runs with tests.iters>1 as the list is static
|
||||
final List<String> headers = Lists.newArrayList(BaseRestHandler.usefulHeaders());
|
||||
int iterations = randomIntBetween(1, 5);
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(iterations);
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
int headersCount = randomInt(10);
|
||||
final String[] newHeaders = new String[headersCount];
|
||||
for (int j = 0; j < headersCount; j++) {
|
||||
String usefulHeader = randomRealisticUnicodeOfLengthBetween(1, 30);
|
||||
newHeaders[j] = usefulHeader;
|
||||
headers.add(usefulHeader);
|
||||
}
|
||||
|
||||
executorService.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BaseRestHandler.addUsefulHeaders(newHeaders);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
executorService.shutdown();
|
||||
assertThat(executorService.awaitTermination(1, TimeUnit.SECONDS), equalTo(true));
|
||||
String[] usefulHeaders = BaseRestHandler.usefulHeaders();
|
||||
assertThat(usefulHeaders.length, equalTo(headers.size()));
|
||||
|
||||
Arrays.sort(usefulHeaders);
|
||||
Collections.sort(headers);
|
||||
assertThat(usefulHeaders, equalTo(headers.toArray(new String[headers.size()])));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeadersRequest() {
|
||||
Map<String, String> existingTransportHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> leftRestHeaders = randomHeadersFrom(restHeaders);
|
||||
Set<String> usefulRestHeaders = new HashSet<>(leftRestHeaders.keySet());
|
||||
usefulRestHeaders.addAll(randomHeaders(randomIntBetween(0, 10), "useful-").keySet());
|
||||
|
||||
HashMap<String, String> expectedHeaders = new HashMap<>();
|
||||
expectedHeaders.putAll(existingTransportHeaders);
|
||||
expectedHeaders.putAll(leftRestHeaders);
|
||||
|
||||
Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders), usefulRestHeaders);
|
||||
|
||||
SearchRequest searchRequest = Requests.searchRequest();
|
||||
putHeaders(searchRequest, existingTransportHeaders);
|
||||
assertHeaders(searchRequest, existingTransportHeaders);
|
||||
client.search(searchRequest);
|
||||
assertHeaders(searchRequest, expectedHeaders);
|
||||
|
||||
GetRequest getRequest = Requests.getRequest("index");
|
||||
putHeaders(getRequest, existingTransportHeaders);
|
||||
assertHeaders(getRequest, existingTransportHeaders);
|
||||
client.get(getRequest);
|
||||
assertHeaders(getRequest, expectedHeaders);
|
||||
|
||||
IndexRequest indexRequest = Requests.indexRequest();
|
||||
putHeaders(indexRequest, existingTransportHeaders);
|
||||
assertHeaders(indexRequest, existingTransportHeaders);
|
||||
client.index(indexRequest);
|
||||
assertHeaders(indexRequest, expectedHeaders);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeadersClusterAdminRequest() {
|
||||
Map<String, String> existingTransportHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> leftRestHeaders = randomHeadersFrom(restHeaders);
|
||||
Set<String> usefulRestHeaders = new HashSet<>(leftRestHeaders.keySet());
|
||||
usefulRestHeaders.addAll(randomHeaders(randomIntBetween(0, 10), "useful-").keySet());
|
||||
|
||||
HashMap<String, String> expectedHeaders = new HashMap<>();
|
||||
expectedHeaders.putAll(existingTransportHeaders);
|
||||
expectedHeaders.putAll(leftRestHeaders);
|
||||
|
||||
Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders), usefulRestHeaders);
|
||||
|
||||
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
|
||||
putHeaders(clusterHealthRequest, existingTransportHeaders);
|
||||
assertHeaders(clusterHealthRequest, existingTransportHeaders);
|
||||
client.admin().cluster().health(clusterHealthRequest);
|
||||
assertHeaders(clusterHealthRequest, expectedHeaders);
|
||||
|
||||
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
|
||||
putHeaders(clusterStateRequest, existingTransportHeaders);
|
||||
assertHeaders(clusterStateRequest, existingTransportHeaders);
|
||||
client.admin().cluster().state(clusterStateRequest);
|
||||
assertHeaders(clusterStateRequest, expectedHeaders);
|
||||
|
||||
ClusterStatsRequest clusterStatsRequest = Requests.clusterStatsRequest();
|
||||
putHeaders(clusterStatsRequest, existingTransportHeaders);
|
||||
assertHeaders(clusterStatsRequest, existingTransportHeaders);
|
||||
client.admin().cluster().clusterStats(clusterStatsRequest);
|
||||
assertHeaders(clusterStatsRequest, expectedHeaders);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeadersIndicesAdminRequest() {
|
||||
Map<String, String> existingTransportHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> leftRestHeaders = randomHeadersFrom(restHeaders);
|
||||
Set<String> usefulRestHeaders = new HashSet<>(leftRestHeaders.keySet());
|
||||
usefulRestHeaders.addAll(randomHeaders(randomIntBetween(0, 10), "useful-").keySet());
|
||||
|
||||
HashMap<String, String> expectedHeaders = new HashMap<>();
|
||||
expectedHeaders.putAll(existingTransportHeaders);
|
||||
expectedHeaders.putAll(leftRestHeaders);
|
||||
|
||||
Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders), usefulRestHeaders);
|
||||
|
||||
CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test");
|
||||
putHeaders(createIndexRequest, existingTransportHeaders);
|
||||
assertHeaders(createIndexRequest, existingTransportHeaders);
|
||||
client.admin().indices().create(createIndexRequest);
|
||||
assertHeaders(createIndexRequest, expectedHeaders);
|
||||
|
||||
CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test");
|
||||
putHeaders(closeIndexRequest, existingTransportHeaders);
|
||||
assertHeaders(closeIndexRequest, existingTransportHeaders);
|
||||
client.admin().indices().close(closeIndexRequest);
|
||||
assertHeaders(closeIndexRequest, expectedHeaders);
|
||||
|
||||
FlushRequest flushRequest = Requests.flushRequest();
|
||||
putHeaders(flushRequest, existingTransportHeaders);
|
||||
assertHeaders(flushRequest, existingTransportHeaders);
|
||||
client.admin().indices().flush(flushRequest);
|
||||
assertHeaders(flushRequest, expectedHeaders);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeadersRequestBuilder() {
|
||||
Map<String, String> existingTransportHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> leftRestHeaders = randomHeadersFrom(restHeaders);
|
||||
Set<String> usefulRestHeaders = new HashSet<>(leftRestHeaders.keySet());
|
||||
usefulRestHeaders.addAll(randomHeaders(randomIntBetween(0, 10), "useful-").keySet());
|
||||
|
||||
HashMap<String, String> expectedHeaders = new HashMap<>();
|
||||
expectedHeaders.putAll(existingTransportHeaders);
|
||||
expectedHeaders.putAll(leftRestHeaders);
|
||||
|
||||
Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders), usefulRestHeaders);
|
||||
|
||||
ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] {
|
||||
client.prepareIndex("index", "type"),
|
||||
client.prepareGet("index", "type", "id"),
|
||||
client.prepareBulk(),
|
||||
client.prepareDelete(),
|
||||
client.prepareIndex(),
|
||||
client.prepareClearScroll(),
|
||||
client.prepareMultiGet(),
|
||||
client.prepareBenchStatus()
|
||||
};
|
||||
|
||||
for (ActionRequestBuilder requestBuilder : requestBuilders) {
|
||||
putHeaders(requestBuilder.request(), existingTransportHeaders);
|
||||
assertHeaders(requestBuilder.request(), existingTransportHeaders);
|
||||
requestBuilder.get();
|
||||
assertHeaders(requestBuilder.request(), expectedHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeadersClusterAdminRequestBuilder() {
|
||||
Map<String, String> existingTransportHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> leftRestHeaders = randomHeadersFrom(restHeaders);
|
||||
Set<String> usefulRestHeaders = new HashSet<>(leftRestHeaders.keySet());
|
||||
usefulRestHeaders.addAll(randomHeaders(randomIntBetween(0, 10), "useful-").keySet());
|
||||
|
||||
HashMap<String, String> expectedHeaders = new HashMap<>();
|
||||
expectedHeaders.putAll(existingTransportHeaders);
|
||||
expectedHeaders.putAll(leftRestHeaders);
|
||||
|
||||
Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders), usefulRestHeaders);
|
||||
|
||||
ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] {
|
||||
client.admin().cluster().prepareNodesInfo(),
|
||||
client.admin().cluster().prepareClusterStats(),
|
||||
client.admin().cluster().prepareState(),
|
||||
client.admin().cluster().prepareCreateSnapshot("repo", "name"),
|
||||
client.admin().cluster().prepareHealth(),
|
||||
client.admin().cluster().prepareReroute()
|
||||
};
|
||||
|
||||
for (ActionRequestBuilder requestBuilder : requestBuilders) {
|
||||
putHeaders(requestBuilder.request(), existingTransportHeaders);
|
||||
assertHeaders(requestBuilder.request(), existingTransportHeaders);
|
||||
requestBuilder.get();
|
||||
assertHeaders(requestBuilder.request(), expectedHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeadersIndicesAdminRequestBuilder() {
|
||||
Map<String, String> existingTransportHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
|
||||
Map<String, String> leftRestHeaders = randomHeadersFrom(restHeaders);
|
||||
Set<String> usefulRestHeaders = new HashSet<>(leftRestHeaders.keySet());
|
||||
usefulRestHeaders.addAll(randomHeaders(randomIntBetween(0, 10), "useful-").keySet());
|
||||
|
||||
HashMap<String, String> expectedHeaders = new HashMap<>();
|
||||
expectedHeaders.putAll(existingTransportHeaders);
|
||||
expectedHeaders.putAll(leftRestHeaders);
|
||||
|
||||
Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders), usefulRestHeaders);
|
||||
|
||||
ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] {
|
||||
client.admin().indices().prepareValidateQuery(),
|
||||
client.admin().indices().prepareCreate("test"),
|
||||
client.admin().indices().prepareAliases(),
|
||||
client.admin().indices().prepareAnalyze("text"),
|
||||
client.admin().indices().prepareDeleteWarmer(),
|
||||
client.admin().indices().prepareTypesExists("type"),
|
||||
client.admin().indices().prepareClose()
|
||||
};
|
||||
|
||||
for (ActionRequestBuilder requestBuilder : requestBuilders) {
|
||||
putHeaders(requestBuilder.request(), existingTransportHeaders);
|
||||
assertHeaders(requestBuilder.request(), existingTransportHeaders);
|
||||
requestBuilder.get();
|
||||
assertHeaders(requestBuilder.request(), expectedHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> randomHeaders(int count) {
|
||||
return randomHeaders(count, "header-");
|
||||
}
|
||||
|
||||
private static Map<String, String> randomHeaders(int count, String prefix) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
headers.put(prefix + randomInt(30), randomRealisticUnicodeOfLengthBetween(1, 20));
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
private static Map<String, String> randomHeadersFrom(Map<String, String> headers) {
|
||||
Map<String, String> newHeaders = new HashMap<>();
|
||||
if (headers.isEmpty()) {
|
||||
return newHeaders;
|
||||
}
|
||||
int i = randomInt(headers.size() - 1);
|
||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||
if (randomInt(i) == 0) {
|
||||
newHeaders.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return newHeaders;
|
||||
}
|
||||
|
||||
private static Client client(Client noOpClient, RestRequest restRequest, Set<String> usefulRestHeaders) {
|
||||
if (usefulRestHeaders.isEmpty() && randomBoolean()) {
|
||||
return noOpClient;
|
||||
}
|
||||
return new HeadersCopyClient(noOpClient, restRequest, usefulRestHeaders.toArray(new String[usefulRestHeaders.size()]));
|
||||
}
|
||||
|
||||
private static void putHeaders(ActionRequest<?> request, Map<String, String> headers) {
|
||||
for (Map.Entry<String, String> header : headers.entrySet()) {
|
||||
request.putHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertHeaders(ActionRequest<?> request, Map<String, String> headers) {
|
||||
if (headers.size() == 0) {
|
||||
assertThat(request.getHeaders() == null || request.getHeaders().size() == 0, equalTo(true));
|
||||
} else {
|
||||
assertThat(request.getHeaders(), notNullValue());
|
||||
assertThat(request.getHeaders().size(), equalTo(headers.size()));
|
||||
for (Map.Entry<String, Object> entry : request.getHeaders().entrySet()) {
|
||||
assertThat(headers.get(entry.getKey()), equalTo(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class FakeRestRequest extends RestRequest {
|
||||
|
||||
private final Map<String, String> headers;
|
||||
|
||||
private FakeRestRequest(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method method() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uri() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rawPath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contentUnsafe() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesReference content() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String header(String name) {
|
||||
return headers.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Map.Entry<String, String>> headers() {
|
||||
return headers.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParam(String key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String param(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String param(String key, String defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> params() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NoOpClient extends AbstractClient implements AdminClient {
|
||||
|
||||
@Override
|
||||
public AdminClient admin() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings settings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, Client> action, Request request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> void execute(Action<Request, Response, RequestBuilder, Client> action, Request request, ActionListener<Response> listener) {
|
||||
listener.onResponse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPool threadPool() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ElasticsearchException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterAdminClient cluster() {
|
||||
return new AbstractClusterAdminClient() {
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, ClusterAdminClient>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, ClusterAdminClient> action, Request request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, ClusterAdminClient>> void execute(Action<Request, Response, RequestBuilder, ClusterAdminClient> action, Request request, ActionListener<Response> listener) {
|
||||
listener.onResponse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPool threadPool() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicesAdminClient indices() {
|
||||
return new AbstractIndicesAdminClient() {
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, IndicesAdminClient>> ActionFuture<Response> execute(Action<Request, Response, RequestBuilder, IndicesAdminClient> action, Request request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, IndicesAdminClient>> void execute(Action<Request, Response, RequestBuilder, IndicesAdminClient> action, Request request, ActionListener<Response> listener) {
|
||||
listener.onResponse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadPool threadPool() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue