diff --git a/src/main/java/org/elasticsearch/action/Action.java b/src/main/java/org/elasticsearch/action/Action.java index 9b02edc05bf..369e660ac4f 100644 --- a/src/main/java/org/elasticsearch/action/Action.java +++ b/src/main/java/org/elasticsearch/action/Action.java @@ -24,7 +24,7 @@ import org.elasticsearch.client.Client; /** * Main action (used with {@link Client} API. */ -public abstract class Action> +public abstract class Action> extends GenericAction { protected Action(String name) { diff --git a/src/main/java/org/elasticsearch/action/ActionRequest.java b/src/main/java/org/elasticsearch/action/ActionRequest.java index 40d6584a275..714d462facb 100644 --- a/src/main/java/org/elasticsearch/action/ActionRequest.java +++ b/src/main/java/org/elasticsearch/action/ActionRequest.java @@ -19,14 +19,29 @@ package org.elasticsearch.action; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.transport.TransportRequest; + +import java.io.IOException; /** * */ -public interface ActionRequest extends Streamable { +public abstract class ActionRequest extends TransportRequest { - ActionRequestValidationException validate(); + private boolean listenerThreaded = false; + + protected ActionRequest() { + super(); + } + + protected ActionRequest(ActionRequest request) { + super(request); + // this does not set the listenerThreaded API, if needed, its up to the caller to set it + // since most times, we actually want it to not be threaded... + //this.listenerThreaded = request.listenerThreaded(); + } /** * Should the response listener be executed on a thread or not. @@ -34,10 +49,28 @@ public interface ActionRequest extends Streamable { *

When not executing on a thread, it will either be executed on the calling thread, or * on an expensive, IO based, thread. */ - boolean listenerThreaded(); + public final boolean listenerThreaded() { + return this.listenerThreaded; + } /** * Sets if the response listener be executed on a thread or not. */ - ActionRequest listenerThreaded(boolean listenerThreaded); + @SuppressWarnings("unchecked") + public final T listenerThreaded(boolean listenerThreaded) { + this.listenerThreaded = listenerThreaded; + return (T) this; + } + + public abstract ActionRequestValidationException validate(); + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + } } diff --git a/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java b/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java index a40663ef910..b4515969b03 100644 --- a/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/ActionRequestBuilder.java @@ -19,14 +19,48 @@ package org.elasticsearch.action; +import org.elasticsearch.action.support.PlainListenableActionFuture; +import org.elasticsearch.client.internal.InternalGenericClient; + /** * */ -public interface ActionRequestBuilder { +public abstract class ActionRequestBuilder { - Request request(); + protected final Request request; - ListenableActionFuture execute(); + protected final InternalGenericClient client; - void execute(ActionListener listener); + protected ActionRequestBuilder(InternalGenericClient client, Request request) { + this.client = client; + this.request = request; + } + + public Request request() { + return this.request; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setListenerThreaded(boolean listenerThreaded) { + request.listenerThreaded(listenerThreaded); + return (RequestBuilder) this; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder putHeader(String key, Object value) { + request.putHeader(key, value); + return (RequestBuilder) this; + } + + public ListenableActionFuture execute() { + PlainListenableActionFuture future = new PlainListenableActionFuture(request.listenerThreaded(), client.threadPool()); + execute(future); + return future; + } + + public void execute(ActionListener listener) { + doExecute(listener); + } + + protected abstract void doExecute(ActionListener listener); } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java index 94f463f7f04..cc59a249a10 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java @@ -28,7 +28,7 @@ import org.elasticsearch.client.ClusterAdminClient; /** * Cluster action (used with {@link ClusterAdminClient} API. */ -public abstract class ClusterAction> +public abstract class ClusterAction> extends GenericAction { protected ClusterAction(String name) { diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java index 8f445bda60a..30a86f0b554 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java @@ -34,7 +34,7 @@ import static org.elasticsearch.common.unit.TimeValue.readTimeValue; /** * */ -public class ClusterHealthRequest extends MasterNodeOperationRequest { +public class ClusterHealthRequest extends MasterNodeOperationRequest { private String[] indices; @@ -141,7 +141,7 @@ public class ClusterHealthRequest extends MasterNodeOperationRequest { } else { indices = new String[size]; for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); + indices[i] = in.readString(); } } timeout = readTimeValue(in); @@ -150,7 +150,7 @@ public class ClusterHealthRequest extends MasterNodeOperationRequest { } waitForRelocatingShards = in.readInt(); waitForActiveShards = in.readInt(); - waitForNodes = in.readUTF(); + waitForNodes = in.readString(); } @Override @@ -161,7 +161,7 @@ public class ClusterHealthRequest extends MasterNodeOperationRequest { } else { out.writeVInt(indices.length); for (String index : indices) { - out.writeUTF(index); + out.writeString(index); } } timeout.writeTo(out); @@ -173,6 +173,6 @@ public class ClusterHealthRequest extends MasterNodeOperationRequest { } out.writeInt(waitForRelocatingShards); out.writeInt(waitForActiveShards); - out.writeUTF(waitForNodes); + out.writeString(waitForNodes); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java index df62b48a564..eaf231e91b2 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java @@ -20,17 +20,18 @@ package org.elasticsearch.action.admin.cluster.health; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class ClusterHealthRequestBuilder extends BaseClusterRequestBuilder { +public class ClusterHealthRequestBuilder extends MasterNodeOperationRequestBuilder { public ClusterHealthRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterHealthRequest()); + super((InternalClusterAdminClient) clusterClient, new ClusterHealthRequest()); } public ClusterHealthRequestBuilder setIndices(String... indices) { @@ -38,14 +39,6 @@ public class ClusterHealthRequestBuilder extends BaseClusterRequestBuilder listener) { - client.health(request, listener); + ((ClusterAdminClient) client).health(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequest.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequest.java index 9b888ed64c5..5121514a54c 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequest.java @@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit; /** */ -public class NodesHotThreadsRequest extends NodesOperationRequest { +public class NodesHotThreadsRequest extends NodesOperationRequest { int threads = 3; String type = "cpu"; diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequestBuilder.java index 5a75884a239..795d82536dd 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequestBuilder.java @@ -20,21 +20,17 @@ package org.elasticsearch.action.admin.cluster.node.hotthreads; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.common.unit.TimeValue; /** */ -public class NodesHotThreadsRequestBuilder extends BaseClusterRequestBuilder { +public class NodesHotThreadsRequestBuilder extends NodesOperationRequestBuilder { public NodesHotThreadsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesHotThreadsRequest()); - } - - public NodesHotThreadsRequestBuilder setNodesIds(String... nodesIds) { - request.nodesIds(nodesIds); - return this; + super((InternalClusterAdminClient) clusterClient, new NodesHotThreadsRequest()); } public NodesHotThreadsRequestBuilder setThreads(int threads) { @@ -54,6 +50,6 @@ public class NodesHotThreadsRequestBuilder extends BaseClusterRequestBuilder listener) { - client.nodesHotThreads(request, listener); + ((ClusterAdminClient) client).nodesHotThreads(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java index 2df3c0e9cb9..5e482f64fdb 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/TransportNodesHotThreadsAction.java @@ -117,7 +117,7 @@ public class TransportNodesHotThreadsAction extends TransportNodesOperationActio } NodeRequest(String nodeId, NodesHotThreadsRequest request) { - super(nodeId); + super(request, nodeId); this.request = request; } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java index cc5e0fb9aae..561aacb9a1a 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java @@ -28,7 +28,7 @@ import java.io.IOException; /** * A request to get node (cluster) level information. */ -public class NodesInfoRequest extends NodesOperationRequest { +public class NodesInfoRequest extends NodesOperationRequest { private boolean settings = false; private boolean os = false; diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java index 0bd380973fc..a6acaf8ddf6 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java @@ -20,21 +20,17 @@ package org.elasticsearch.action.admin.cluster.node.info; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; /** * */ -public class NodesInfoRequestBuilder extends BaseClusterRequestBuilder { +public class NodesInfoRequestBuilder extends NodesOperationRequestBuilder { public NodesInfoRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesInfoRequest()); - } - - public NodesInfoRequestBuilder setNodesIds(String... nodesIds) { - request.nodesIds(nodesIds); - return this; + super((InternalClusterAdminClient) clusterClient, new NodesInfoRequest()); } /** @@ -120,6 +116,6 @@ public class NodesInfoRequestBuilder extends BaseClusterRequestBuilder listener) { - client.nodesInfo(request, listener); + ((ClusterAdminClient) client).nodesInfo(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java index c94c3be7ef9..d608785d938 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java @@ -113,7 +113,7 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction { TimeValue delay = TimeValue.timeValueSeconds(1); diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/NodesRestartRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/NodesRestartRequestBuilder.java index bf06fbaf8bc..92e9e1eb707 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/NodesRestartRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/NodesRestartRequestBuilder.java @@ -20,25 +20,18 @@ package org.elasticsearch.action.admin.cluster.node.restart; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class NodesRestartRequestBuilder extends BaseClusterRequestBuilder { +public class NodesRestartRequestBuilder extends NodesOperationRequestBuilder { public NodesRestartRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesRestartRequest()); - } - - /** - * The nodes ids to restart. - */ - public NodesRestartRequestBuilder setNodesIds(String... nodesIds) { - request.nodesIds(nodesIds); - return this; + super((InternalClusterAdminClient) clusterClient, new NodesRestartRequest()); } /** @@ -59,6 +52,6 @@ public class NodesRestartRequestBuilder extends BaseClusterRequestBuilder listener) { - client.nodesRestart(request, listener); + ((ClusterAdminClient) client).nodesRestart(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java index bece014156d..7318fcc87f7 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java @@ -102,7 +102,7 @@ public class TransportNodesRestartAction extends TransportNodesOperationAction { String[] nodesIds = Strings.EMPTY_ARRAY; @@ -96,13 +96,7 @@ public class NodesShutdownRequest extends MasterNodeOperationRequest { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); delay = readTimeValue(in); - int size = in.readVInt(); - if (size > 0) { - nodesIds = new String[size]; - for (int i = 0; i < nodesIds.length; i++) { - nodesIds[i] = in.readUTF(); - } - } + nodesIds = in.readStringArray(); exit = in.readBoolean(); } @@ -110,14 +104,7 @@ public class NodesShutdownRequest extends MasterNodeOperationRequest { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); delay.writeTo(out); - if (nodesIds == null) { - out.writeVInt(0); - } else { - out.writeVInt(nodesIds.length); - for (String nodeId : nodesIds) { - out.writeUTF(nodeId); - } - } + out.writeStringArrayNullable(nodesIds); out.writeBoolean(exit); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownRequestBuilder.java index 9a1b7514022..8d7a2fd545d 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownRequestBuilder.java @@ -20,17 +20,18 @@ package org.elasticsearch.action.admin.cluster.node.shutdown; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class NodesShutdownRequestBuilder extends BaseClusterRequestBuilder { +public class NodesShutdownRequestBuilder extends MasterNodeOperationRequestBuilder { public NodesShutdownRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesShutdownRequest()); + super((InternalClusterAdminClient) clusterClient, new NodesShutdownRequest()); } /** @@ -65,17 +66,8 @@ public class NodesShutdownRequestBuilder extends BaseClusterRequestBuilder listener) { - client.nodesShutdown(request, listener); + ((ClusterAdminClient) client).nodesShutdown(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java index 475623108ff..a066d38542a 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.VoidStreamable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -129,7 +128,7 @@ public class TransportNodesShutdownAction extends TransportMasterNodeOperationAc latch.countDown(); } else { logger.trace("[cluster_shutdown]: sending shutdown request to [{}]", node); - transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request.exit), new VoidTransportResponseHandler(ThreadPool.Names.SAME) { + transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new VoidTransportResponseHandler(ThreadPool.Names.SAME) { @Override public void handleResponse(VoidStreamable response) { logger.trace("[cluster_shutdown]: received shutdown response from [{}]", node); @@ -153,7 +152,7 @@ public class TransportNodesShutdownAction extends TransportMasterNodeOperationAc // now, kill the master logger.trace("[cluster_shutdown]: shutting down the master [{}]", state.nodes().masterNode()); - transportService.sendRequest(state.nodes().masterNode(), NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request.exit), new VoidTransportResponseHandler(ThreadPool.Names.SAME) { + transportService.sendRequest(state.nodes().masterNode(), NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new VoidTransportResponseHandler(ThreadPool.Names.SAME) { @Override public void handleResponse(VoidStreamable response) { logger.trace("[cluster_shutdown]: received shutdown response from master"); @@ -197,7 +196,7 @@ public class TransportNodesShutdownAction extends TransportMasterNodeOperationAc } logger.trace("[partial_cluster_shutdown]: sending shutdown request to [{}]", node); - transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request.exit), new VoidTransportResponseHandler(ThreadPool.Names.SAME) { + transportService.sendRequest(node, NodeShutdownRequestHandler.ACTION, new NodeShutdownRequest(request), new VoidTransportResponseHandler(ThreadPool.Names.SAME) { @Override public void handleResponse(VoidStreamable response) { logger.trace("[partial_cluster_shutdown]: received shutdown response from [{}]", node); @@ -293,24 +292,27 @@ public class TransportNodesShutdownAction extends TransportMasterNodeOperationAc } } - static class NodeShutdownRequest implements Streamable { + static class NodeShutdownRequest extends TransportRequest { boolean exit; NodeShutdownRequest() { } - NodeShutdownRequest(boolean exit) { - this.exit = exit; + NodeShutdownRequest(NodesShutdownRequest request) { + super(request); + this.exit = request.exit(); } @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); exit = in.readBoolean(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeBoolean(exit); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequest.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequest.java index 36018f18e0e..2dba2aaa9d6 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequest.java @@ -28,7 +28,7 @@ import java.io.IOException; /** * A request to get node (cluster) level stats. */ -public class NodesStatsRequest extends NodesOperationRequest { +public class NodesStatsRequest extends NodesOperationRequest { private boolean indices = true; private boolean os; diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java index cf126290c7c..4392e0d9c34 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java @@ -20,21 +20,17 @@ package org.elasticsearch.action.admin.cluster.node.stats; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; /** * */ -public class NodesStatsRequestBuilder extends BaseClusterRequestBuilder { +public class NodesStatsRequestBuilder extends NodesOperationRequestBuilder { public NodesStatsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesStatsRequest()); - } - - public NodesStatsRequestBuilder setNodesIds(String... nodesIds) { - request.nodesIds(nodesIds); - return this; + super((InternalClusterAdminClient) clusterClient, new NodesStatsRequest()); } /** @@ -127,6 +123,6 @@ public class NodesStatsRequestBuilder extends BaseClusterRequestBuilder listener) { - client.nodesStats(request, listener); + ((ClusterAdminClient) client).nodesStats(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java index 1ad7aa966d3..50583033d1f 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java @@ -113,7 +113,7 @@ public class TransportNodesStatsAction extends TransportNodesOperationAction { AllocationCommands commands = new AllocationCommands(); boolean dryRun; diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java index 88d8edf39fa..468c609bf24 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java @@ -20,18 +20,18 @@ package org.elasticsearch.action.admin.cluster.reroute; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommand; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.unit.TimeValue; /** */ -public class ClusterRerouteRequestBuilder extends BaseClusterRequestBuilder { +public class ClusterRerouteRequestBuilder extends MasterNodeOperationRequestBuilder { public ClusterRerouteRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterRerouteRequest()); + super((InternalClusterAdminClient) clusterClient, new ClusterRerouteRequest()); } /** @@ -57,24 +57,8 @@ public class ClusterRerouteRequestBuilder extends BaseClusterRequestBuilder listener) { - client.reroute(request, listener); + ((ClusterAdminClient) client).reroute(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java index 3108139dc4c..094a589bad4 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java @@ -40,7 +40,7 @@ import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsT /** */ -public class ClusterUpdateSettingsRequest extends MasterNodeOperationRequest { +public class ClusterUpdateSettingsRequest extends MasterNodeOperationRequest { private Settings transientSettings = EMPTY_SETTINGS; private Settings persistentSettings = EMPTY_SETTINGS; diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java index c343d836460..d7a849cc358 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java @@ -20,19 +20,19 @@ package org.elasticsearch.action.admin.cluster.settings; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; import java.util.Map; /** */ -public class ClusterUpdateSettingsRequestBuilder extends BaseClusterRequestBuilder { +public class ClusterUpdateSettingsRequestBuilder extends MasterNodeOperationRequestBuilder { public ClusterUpdateSettingsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterUpdateSettingsRequest()); + super((InternalClusterAdminClient) clusterClient, new ClusterUpdateSettingsRequest()); } public ClusterUpdateSettingsRequestBuilder setTransientSettings(Settings settings) { @@ -75,24 +75,8 @@ public class ClusterUpdateSettingsRequestBuilder extends BaseClusterRequestBuild return this; } - /** - * Sets the master node timeout in case the master has not yet been discovered. - */ - public ClusterUpdateSettingsRequestBuilder setMasterNodeTimeout(TimeValue timeout) { - request.masterNodeTimeout(timeout); - return this; - } - - /** - * Sets the master node timeout in case the master has not yet been discovered. - */ - public ClusterUpdateSettingsRequestBuilder setMasterNodeTimeout(String timeout) { - request.masterNodeTimeout(timeout); - return this; - } - @Override protected void doExecute(ActionListener listener) { - client.updateSettings(request, listener); + ((ClusterAdminClient) client).updateSettings(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java index 7dabb7f4c3e..382070e0489 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java @@ -30,7 +30,7 @@ import java.io.IOException; /** * */ -public class ClusterStateRequest extends MasterNodeOperationRequest { +public class ClusterStateRequest extends MasterNodeOperationRequest { private boolean filterRoutingTable = false; @@ -127,12 +127,6 @@ public class ClusterStateRequest extends MasterNodeOperationRequest { return this.local; } - @Override - public ClusterStateRequest listenerThreaded(boolean listenerThreaded) { - super.listenerThreaded(listenerThreaded); - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -140,20 +134,8 @@ public class ClusterStateRequest extends MasterNodeOperationRequest { filterNodes = in.readBoolean(); filterMetaData = in.readBoolean(); filterBlocks = in.readBoolean(); - int size = in.readVInt(); - if (size > 0) { - filteredIndices = new String[size]; - for (int i = 0; i < filteredIndices.length; i++) { - filteredIndices[i] = in.readUTF(); - } - } - size = in.readVInt(); - if (size > 0) { - filteredIndexTemplates = new String[size]; - for (int i = 0; i < filteredIndexTemplates.length; i++) { - filteredIndexTemplates[i] = in.readUTF(); - } - } + filteredIndices = in.readStringArray(); + filteredIndexTemplates = in.readStringArray(); local = in.readBoolean(); } @@ -164,14 +146,8 @@ public class ClusterStateRequest extends MasterNodeOperationRequest { out.writeBoolean(filterNodes); out.writeBoolean(filterMetaData); out.writeBoolean(filterBlocks); - out.writeVInt(filteredIndices.length); - for (String filteredIndex : filteredIndices) { - out.writeUTF(filteredIndex); - } - out.writeVInt(filteredIndexTemplates.length); - for (String filteredIndexTemplate : filteredIndexTemplates) { - out.writeUTF(filteredIndexTemplate); - } + out.writeStringArray(filteredIndices); + out.writeStringArray(filteredIndexTemplates); out.writeBoolean(local); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestBuilder.java index 83aaa234393..044a9ae2489 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestBuilder.java @@ -20,17 +20,17 @@ package org.elasticsearch.action.admin.cluster.state; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.client.internal.InternalClusterAdminClient; /** * */ -public class ClusterStateRequestBuilder extends BaseClusterRequestBuilder { +public class ClusterStateRequestBuilder extends MasterNodeOperationRequestBuilder { public ClusterStateRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterStateRequest()); + super((InternalClusterAdminClient) clusterClient, new ClusterStateRequest()); } /** @@ -87,22 +87,6 @@ public class ClusterStateRequestBuilder extends BaseClusterRequestBuilder listener) { - client.state(request, listener); + ((ClusterAdminClient) client).state(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/support/BaseClusterRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/cluster/support/BaseClusterRequestBuilder.java deleted file mode 100644 index 1318a7cb398..00000000000 --- a/src/main/java/org/elasticsearch/action/admin/cluster/support/BaseClusterRequestBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon 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.action.admin.cluster.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.action.support.PlainListenableActionFuture; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.internal.InternalClusterAdminClient; - -/** - * - */ -public abstract class BaseClusterRequestBuilder implements ActionRequestBuilder { - - protected final InternalClusterAdminClient client; - - protected final Request request; - - protected BaseClusterRequestBuilder(ClusterAdminClient client, Request request) { - this.client = (InternalClusterAdminClient) client; - this.request = request; - } - - @Override - public Request request() { - return request; - } - - @Override - public ListenableActionFuture execute() { - PlainListenableActionFuture future = new PlainListenableActionFuture(request.listenerThreaded(), client.threadPool()); - execute(future); - return future; - } - - @Override - public void execute(ActionListener listener) { - doExecute(listener); - } - - protected abstract void doExecute(ActionListener listener); -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java index 6d215ef2369..efed633ee47 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java @@ -28,7 +28,7 @@ import org.elasticsearch.client.IndicesAdminClient; /** * Indices action (used with {@link IndicesAdminClient} API. */ -public abstract class IndicesAction> +public abstract class IndicesAction> extends GenericAction { protected IndicesAction(String name) { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java index 3a826772b8b..633e6846958 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java @@ -44,7 +44,7 @@ import static org.elasticsearch.common.unit.TimeValue.readTimeValue; /** * A request to add/remove aliases for one or more indices. */ -public class IndicesAliasesRequest extends MasterNodeOperationRequest { +public class IndicesAliasesRequest extends MasterNodeOperationRequest { private List aliasActions = Lists.newArrayList(); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequestBuilder.java index 99e7ceefca9..812630dc818 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequestBuilder.java @@ -20,8 +20,9 @@ package org.elasticsearch.action.admin.indices.alias; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.FilterBuilder; @@ -31,10 +32,10 @@ import java.util.Map; /** * */ -public class IndicesAliasesRequestBuilder extends BaseIndicesRequestBuilder { +public class IndicesAliasesRequestBuilder extends MasterNodeOperationRequestBuilder { public IndicesAliasesRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesAliasesRequest()); + super((InternalIndicesAdminClient) indicesClient, new IndicesAliasesRequest()); } /** @@ -105,14 +106,6 @@ public class IndicesAliasesRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.aliases(request, listener); + ((IndicesAdminClient) client).aliases(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java index a8ca44449f4..bca9cdf14a8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java @@ -33,7 +33,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; * A request to analyze a text associated with a specific index. Allow to provide * the actual analyzer name to perform the analysis with. */ -public class AnalyzeRequest extends SingleCustomOperationRequest { +public class AnalyzeRequest extends SingleCustomOperationRequest { private String index; @@ -120,16 +120,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest { return this.field; } - /** - * if this operation hits a node with a local relevant shard, should it be preferred - * to be executed on, or just do plain round robin. Defaults to true - */ - @Override - public AnalyzeRequest preferLocal(boolean preferLocal) { - super.preferLocal(preferLocal); - return this; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); @@ -142,35 +132,35 @@ public class AnalyzeRequest extends SingleCustomOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readOptionalUTF(); - text = in.readUTF(); - analyzer = in.readOptionalUTF(); - tokenizer = in.readOptionalUTF(); + index = in.readOptionalString(); + text = in.readString(); + analyzer = in.readOptionalString(); + tokenizer = in.readOptionalString(); int size = in.readVInt(); if (size > 0) { tokenFilters = new String[size]; for (int i = 0; i < size; i++) { - tokenFilters[i] = in.readUTF(); + tokenFilters[i] = in.readString(); } } - field = in.readOptionalUTF(); + field = in.readOptionalString(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeOptionalUTF(index); - out.writeUTF(text); - out.writeOptionalUTF(analyzer); - out.writeOptionalUTF(tokenizer); + out.writeOptionalString(index); + out.writeString(text); + out.writeOptionalString(analyzer); + out.writeOptionalString(tokenizer); if (tokenFilters == null) { out.writeVInt(0); } else { out.writeVInt(tokenFilters.length); for (String tokenFilter : tokenFilters) { - out.writeUTF(tokenFilter); + out.writeString(tokenFilter); } } - out.writeOptionalUTF(field); + out.writeOptionalString(field); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java index 9160054f0b8..7986375a7cc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java @@ -20,20 +20,21 @@ package org.elasticsearch.action.admin.indices.analyze; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class AnalyzeRequestBuilder extends BaseIndicesRequestBuilder { +public class AnalyzeRequestBuilder extends SingleCustomOperationRequestBuilder { public AnalyzeRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new AnalyzeRequest()); + super((InternalIndicesAdminClient) indicesClient, new AnalyzeRequest()); } public AnalyzeRequestBuilder(IndicesAdminClient indicesClient, String index, String text) { - super(indicesClient, new AnalyzeRequest(index, text)); + super((InternalIndicesAdminClient) indicesClient, new AnalyzeRequest(index, text)); } /** @@ -81,17 +82,8 @@ public class AnalyzeRequestBuilder extends BaseIndicesRequestBuildertrue - */ - public AnalyzeRequestBuilder setPreferLocal(boolean preferLocal) { - request.preferLocal(preferLocal); - return this; - } - @Override protected void doExecute(ActionListener listener) { - client.analyze(request, listener); + ((IndicesAdminClient) client).analyze(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java index c956107836a..6bf1193596e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java @@ -29,7 +29,7 @@ import java.io.IOException; /** * */ -public class ClearIndicesCacheRequest extends BroadcastOperationRequest { +public class ClearIndicesCacheRequest extends BroadcastOperationRequest { private boolean filterCache = false; private boolean fieldDataCache = false; @@ -46,24 +46,6 @@ public class ClearIndicesCacheRequest extends BroadcastOperationRequest { operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD); } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public ClearIndicesCacheRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - /** - * Controls the operation threading model. - */ - @Override - public ClearIndicesCacheRequest operationThreading(BroadcastOperationThreading operationThreading) { - super.operationThreading(operationThreading); - return this; - } - public boolean filterCache() { return filterCache; } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java index c4903f6d870..27b32ab3d14 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequestBuilder.java @@ -20,23 +20,17 @@ package org.elasticsearch.action.admin.indices.cache.clear; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class ClearIndicesCacheRequestBuilder extends BaseIndicesRequestBuilder { +public class ClearIndicesCacheRequestBuilder extends BroadcastOperationRequestBuilder { public ClearIndicesCacheRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new ClearIndicesCacheRequest()); - } - - public ClearIndicesCacheRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalIndicesAdminClient) indicesClient, new ClearIndicesCacheRequest()); } public ClearIndicesCacheRequestBuilder setFilterCache(boolean filterCache) { @@ -64,32 +58,8 @@ public class ClearIndicesCacheRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.clearCache(request, listener); + ((IndicesAdminClient) client).clearCache(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java index d988d8910d9..02ed102db1f 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java @@ -40,7 +40,7 @@ class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest { } public ShardClearIndicesCacheRequest(String index, int shardId, ClearIndicesCacheRequest request) { - super(index, shardId); + super(index, shardId, request); filterCache = request.filterCache(); fieldDataCache = request.fieldDataCache(); idCache = request.idCache(); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequest.java index 36dd4d8de1b..23d152c4810 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequest.java @@ -34,7 +34,7 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; /** * A request to close an index. */ -public class CloseIndexRequest extends MasterNodeOperationRequest { +public class CloseIndexRequest extends MasterNodeOperationRequest { private String index; @@ -99,14 +99,14 @@ public class CloseIndexRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readUTF(); + index = in.readString(); timeout = readTimeValue(in); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(index); + out.writeString(index); timeout.writeTo(out); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequestBuilder.java index d4b4f253f28..99a16b5301e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexRequestBuilder.java @@ -20,21 +20,22 @@ package org.elasticsearch.action.admin.indices.close; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class CloseIndexRequestBuilder extends BaseIndicesRequestBuilder { +public class CloseIndexRequestBuilder extends MasterNodeOperationRequestBuilder { public CloseIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new CloseIndexRequest()); + super((InternalIndicesAdminClient) indicesClient, new CloseIndexRequest()); } public CloseIndexRequestBuilder(IndicesAdminClient indicesClient, String index) { - super(indicesClient, new CloseIndexRequest(index)); + super((InternalIndicesAdminClient) indicesClient, new CloseIndexRequest(index)); } public CloseIndexRequestBuilder setIndex(String index) { @@ -60,24 +61,8 @@ public class CloseIndexRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.close(request, listener); + ((IndicesAdminClient) client).close(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java index ac29cd6084d..01d1f7d42d2 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java @@ -58,7 +58,7 @@ import static org.elasticsearch.common.unit.TimeValue.readTimeValue; * @see org.elasticsearch.client.Requests#createIndexRequest(String) * @see CreateIndexResponse */ -public class CreateIndexRequest extends MasterNodeOperationRequest { +public class CreateIndexRequest extends MasterNodeOperationRequest { private String cause = ""; @@ -345,29 +345,20 @@ public class CreateIndexRequest extends MasterNodeOperationRequest { return timeout(TimeValue.parseTimeValue(timeout, null)); } - /** - * A timeout value in case the master has not been discovered yet or disconnected. - */ - @Override - public CreateIndexRequest masterNodeTimeout(TimeValue timeout) { - this.masterNodeTimeout = timeout; - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - cause = in.readUTF(); - index = in.readUTF(); + cause = in.readString(); + index = in.readString(); settings = readSettingsFromStream(in); timeout = readTimeValue(in); int size = in.readVInt(); for (int i = 0; i < size; i++) { - mappings.put(in.readUTF(), in.readUTF()); + mappings.put(in.readString(), in.readString()); } int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { - String type = in.readUTF(); + String type = in.readString(); IndexMetaData.Custom customIndexMetaData = IndexMetaData.lookupFactorySafe(type).readFrom(in); customs.put(type, customIndexMetaData); } @@ -376,18 +367,18 @@ public class CreateIndexRequest extends MasterNodeOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(cause); - out.writeUTF(index); + out.writeString(cause); + out.writeString(index); writeSettingsToStream(settings, out); timeout.writeTo(out); out.writeVInt(mappings.size()); for (Map.Entry entry : mappings.entrySet()) { - out.writeUTF(entry.getKey()); - out.writeUTF(entry.getValue()); + out.writeString(entry.getKey()); + out.writeString(entry.getValue()); } out.writeVInt(customs.size()); for (Map.Entry entry : customs.entrySet()) { - out.writeUTF(entry.getKey()); + out.writeString(entry.getKey()); IndexMetaData.lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java index cc22d2fc22c..26a02150348 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java @@ -20,8 +20,9 @@ package org.elasticsearch.action.admin.indices.create; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -33,14 +34,14 @@ import java.util.Map; /** * */ -public class CreateIndexRequestBuilder extends BaseIndicesRequestBuilder { +public class CreateIndexRequestBuilder extends MasterNodeOperationRequestBuilder { public CreateIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new CreateIndexRequest()); + super((InternalIndicesAdminClient) indicesClient, new CreateIndexRequest()); } public CreateIndexRequestBuilder(IndicesAdminClient indicesClient, String index) { - super(indicesClient, new CreateIndexRequest(index)); + super((InternalIndicesAdminClient) indicesClient, new CreateIndexRequest(index)); } public CreateIndexRequestBuilder setIndex(String index) { @@ -200,24 +201,8 @@ public class CreateIndexRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.create(request, listener); + ((IndicesAdminClient) client).create(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java index bf3ab045709..309dfaaaf2b 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequest.java @@ -34,7 +34,7 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; /** * A request to delete an index. Best created with {@link org.elasticsearch.client.Requests#deleteIndexRequest(String)}. */ -public class DeleteIndexRequest extends MasterNodeOperationRequest { +public class DeleteIndexRequest extends MasterNodeOperationRequest { private String[] indices; @@ -105,7 +105,7 @@ public class DeleteIndexRequest extends MasterNodeOperationRequest { super.readFrom(in); indices = new String[in.readVInt()]; for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); + indices[i] = in.readString(); } timeout = readTimeValue(in); } @@ -118,7 +118,7 @@ public class DeleteIndexRequest extends MasterNodeOperationRequest { } else { out.writeVInt(indices.length); for (String index : indices) { - out.writeUTF(index); + out.writeString(index); } } timeout.writeTo(out); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequestBuilder.java index 510eed6f779..5dad6b24218 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexRequestBuilder.java @@ -20,17 +20,18 @@ package org.elasticsearch.action.admin.indices.delete; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class DeleteIndexRequestBuilder extends BaseIndicesRequestBuilder { +public class DeleteIndexRequestBuilder extends MasterNodeOperationRequestBuilder { public DeleteIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new DeleteIndexRequest(indices)); + super((InternalIndicesAdminClient) indicesClient, new DeleteIndexRequest(indices)); } /** @@ -51,24 +52,8 @@ public class DeleteIndexRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.delete(request, listener); + ((IndicesAdminClient) client).delete(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java index 31a93938c38..a974d678f05 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.exists.indices; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeOperationRequest; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -28,9 +29,9 @@ import java.io.IOException; import static org.elasticsearch.action.ValidateActions.addValidationError; -public class IndicesExistsRequest extends MasterNodeOperationRequest { +public class IndicesExistsRequest extends MasterNodeOperationRequest { - private String[] indices; + private String[] indices = Strings.EMPTY_ARRAY; public IndicesExistsRequest(String... indices) { this.indices = indices; @@ -56,18 +57,12 @@ public class IndicesExistsRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - indices = new String[in.readVInt()]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); - } + indices = in.readStringArray(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeVInt(indices.length); - for (String index : indices) { - out.writeUTF(index); - } + out.writeStringArray(indices); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java index 7b15d82e43b..3b8c69819d3 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java @@ -20,16 +20,17 @@ package org.elasticsearch.action.admin.indices.exists.indices; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class IndicesExistsRequestBuilder extends BaseIndicesRequestBuilder { +public class IndicesExistsRequestBuilder extends MasterNodeOperationRequestBuilder { public IndicesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new IndicesExistsRequest(indices)); + super((InternalIndicesAdminClient) indicesClient, new IndicesExistsRequest(indices)); } public IndicesExistsRequestBuilder setIndices(String... indices) { @@ -39,6 +40,6 @@ public class IndicesExistsRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.exists(request, listener); + ((IndicesAdminClient) client).exists(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequest.java index b37826279a0..41ab13d5cbe 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequest.java @@ -31,7 +31,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** */ -public class TypesExistsRequest extends MasterNodeOperationRequest { +public class TypesExistsRequest extends MasterNodeOperationRequest { private String[] indices; private String[] types; diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequestBuilder.java index c8ad7b04fff..13144a9707f 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsRequestBuilder.java @@ -20,25 +20,26 @@ package org.elasticsearch.action.admin.indices.exists.types; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.Strings; /** * A builder for {@link TypesExistsRequest}. */ -public class TypesExistsRequestBuilder extends BaseIndicesRequestBuilder { +public class TypesExistsRequestBuilder extends MasterNodeOperationRequestBuilder { /** * @param indices What indices to check for types */ public TypesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY)); + super((InternalIndicesAdminClient) indicesClient, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY)); } TypesExistsRequestBuilder(IndicesAdminClient client) { - super(client, new TypesExistsRequest()); + super((InternalIndicesAdminClient) client, new TypesExistsRequest()); } /** @@ -66,6 +67,6 @@ public class TypesExistsRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.typesExists(request, listener); + ((IndicesAdminClient) client).typesExists(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequest.java index 41b3e53961f..ea5ccd45964 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequest.java @@ -33,12 +33,11 @@ import java.io.IOException; *

*

Best created with {@link org.elasticsearch.client.Requests#flushRequest(String...)}. * - * * @see org.elasticsearch.client.Requests#flushRequest(String...) * @see org.elasticsearch.client.IndicesAdminClient#flush(FlushRequest) * @see FlushResponse */ -public class FlushRequest extends BroadcastOperationRequest { +public class FlushRequest extends BroadcastOperationRequest { private boolean refresh = false; @@ -105,24 +104,6 @@ public class FlushRequest extends BroadcastOperationRequest { return this; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public FlushRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - /** - * Controls the operation threading model. - */ - @Override - public FlushRequest operationThreading(BroadcastOperationThreading operationThreading) { - super.operationThreading(operationThreading); - return this; - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java index 89f70f220dd..9f250e13472 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushRequestBuilder.java @@ -20,22 +20,17 @@ package org.elasticsearch.action.admin.indices.flush; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class FlushRequestBuilder extends BaseIndicesRequestBuilder { +public class FlushRequestBuilder extends BroadcastOperationRequestBuilder { public FlushRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new FlushRequest()); - } - - public FlushRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalIndicesAdminClient) indicesClient, new FlushRequest()); } public FlushRequestBuilder setRefresh(boolean refresh) { @@ -48,16 +43,8 @@ public class FlushRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.flush(request, listener); + ((IndicesAdminClient) client).flush(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/flush/ShardFlushRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/flush/ShardFlushRequest.java index 1803b0cff77..ded8ddce241 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/flush/ShardFlushRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/flush/ShardFlushRequest.java @@ -38,7 +38,7 @@ class ShardFlushRequest extends BroadcastShardOperationRequest { } public ShardFlushRequest(String index, int shardId, FlushRequest request) { - super(index, shardId); + super(index, shardId, request); this.refresh = request.refresh(); this.full = request.full(); this.force = request.force(); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequest.java index 6de18cb689f..23fea7507b5 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequest.java @@ -26,12 +26,11 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; * By default, each index gateway periodically snapshot changes, though it can be disabled and be controlled completely * through this API. Best created using {@link org.elasticsearch.client.Requests#gatewaySnapshotRequest(String...)}. * - * * @see org.elasticsearch.client.Requests#gatewaySnapshotRequest(String...) * @see org.elasticsearch.client.IndicesAdminClient#gatewaySnapshot(GatewaySnapshotRequest) * @see GatewaySnapshotResponse */ -public class GatewaySnapshotRequest extends BroadcastOperationRequest { +public class GatewaySnapshotRequest extends BroadcastOperationRequest { GatewaySnapshotRequest() { @@ -44,13 +43,4 @@ public class GatewaySnapshotRequest extends BroadcastOperationRequest { public GatewaySnapshotRequest(String... indices) { this.indices = indices; } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public GatewaySnapshotRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java index f41ea74f838..9c2f69e00e8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/GatewaySnapshotRequestBuilder.java @@ -20,34 +20,21 @@ package org.elasticsearch.action.admin.indices.gateway.snapshot; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class GatewaySnapshotRequestBuilder extends BaseIndicesRequestBuilder { +public class GatewaySnapshotRequestBuilder extends BroadcastOperationRequestBuilder { public GatewaySnapshotRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new GatewaySnapshotRequest()); - } - - public GatewaySnapshotRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; - } - - /** - * Specifies what type of requested indices to ignore. For example indices that don't exist. - */ - public GatewaySnapshotRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) { - request().ignoreIndices(ignoreIndices); - return this; + super((InternalIndicesAdminClient) indicesClient, new GatewaySnapshotRequest()); } @Override protected void doExecute(ActionListener listener) { - client.gatewaySnapshot(request, listener); + ((IndicesAdminClient) client).gatewaySnapshot(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/ShardGatewaySnapshotRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/ShardGatewaySnapshotRequest.java index b80deca242b..00f2c79c4b0 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/ShardGatewaySnapshotRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/ShardGatewaySnapshotRequest.java @@ -33,8 +33,8 @@ class ShardGatewaySnapshotRequest extends BroadcastShardOperationRequest { ShardGatewaySnapshotRequest() { } - public ShardGatewaySnapshotRequest(String index, int shardId) { - super(index, shardId); + public ShardGatewaySnapshotRequest(String index, int shardId, GatewaySnapshotRequest request) { + super(index, shardId, request); } @Override diff --git a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java index 58afd949c6a..ab4da90c5aa 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java @@ -104,7 +104,7 @@ public class TransportGatewaySnapshotAction extends TransportBroadcastOperationA @Override protected ShardGatewaySnapshotRequest newShardRequest(ShardRouting shard, GatewaySnapshotRequest request) { - return new ShardGatewaySnapshotRequest(shard.index(), shard.id()); + return new ShardGatewaySnapshotRequest(shard.index(), shard.id(), request); } @Override diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java index 63926d0b788..a89c14349e2 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequest.java @@ -31,7 +31,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * */ -public class DeleteMappingRequest extends MasterNodeOperationRequest { +public class DeleteMappingRequest extends MasterNodeOperationRequest { private String[] indices; @@ -92,10 +92,10 @@ public class DeleteMappingRequest extends MasterNodeOperationRequest { super.readFrom(in); indices = new String[in.readVInt()]; for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); + indices[i] = in.readString(); } if (in.readBoolean()) { - mappingType = in.readUTF(); + mappingType = in.readString(); } } @@ -107,14 +107,14 @@ public class DeleteMappingRequest extends MasterNodeOperationRequest { } else { out.writeVInt(indices.length); for (String index : indices) { - out.writeUTF(index); + out.writeString(index); } } if (mappingType == null) { out.writeBoolean(false); } else { out.writeBoolean(true); - out.writeUTF(mappingType); + out.writeString(mappingType); } } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java index c3f0739da1d..3df1d0a885a 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/delete/DeleteMappingRequestBuilder.java @@ -20,17 +20,17 @@ package org.elasticsearch.action.admin.indices.mapping.delete; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class DeleteMappingRequestBuilder extends BaseIndicesRequestBuilder { +public class DeleteMappingRequestBuilder extends MasterNodeOperationRequestBuilder { public DeleteMappingRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteMappingRequest()); + super((InternalIndicesAdminClient) indicesClient, new DeleteMappingRequest()); } public DeleteMappingRequestBuilder setIndices(String... indices) { @@ -46,16 +46,8 @@ public class DeleteMappingRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.deleteMapping(request, listener); + ((IndicesAdminClient) client).deleteMapping(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 14c5f4daa8c..13697aaaab7 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -50,7 +50,7 @@ import static org.elasticsearch.common.unit.TimeValue.readTimeValue; * @see org.elasticsearch.client.IndicesAdminClient#putMapping(PutMappingRequest) * @see PutMappingResponse */ -public class PutMappingRequest extends MasterNodeOperationRequest { +public class PutMappingRequest extends MasterNodeOperationRequest { private String[] indices; @@ -205,14 +205,9 @@ public class PutMappingRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - indices = new String[in.readVInt()]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); - } - if (in.readBoolean()) { - mappingType = in.readUTF(); - } - mappingSource = in.readUTF(); + indices = in.readStringArray(); + mappingType = in.readOptionalString(); + mappingSource = in.readString(); timeout = readTimeValue(in); ignoreConflicts = in.readBoolean(); } @@ -220,21 +215,9 @@ public class PutMappingRequest extends MasterNodeOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (indices == null) { - out.writeVInt(0); - } else { - out.writeVInt(indices.length); - for (String index : indices) { - out.writeUTF(index); - } - } - if (mappingType == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(mappingType); - } - out.writeUTF(mappingSource); + out.writeStringArrayNullable(indices); + out.writeOptionalString(mappingType); + out.writeString(mappingSource); timeout.writeTo(out); out.writeBoolean(ignoreConflicts); } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index 76301b5a9a2..1738f5546d3 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -20,8 +20,9 @@ package org.elasticsearch.action.admin.indices.mapping.put; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.Required; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -31,10 +32,10 @@ import java.util.Map; /** * */ -public class PutMappingRequestBuilder extends BaseIndicesRequestBuilder { +public class PutMappingRequestBuilder extends MasterNodeOperationRequestBuilder { public PutMappingRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutMappingRequest()); + super((InternalIndicesAdminClient) indicesClient, new PutMappingRequest()); } public PutMappingRequestBuilder setIndices(String... indices) { @@ -93,14 +94,6 @@ public class PutMappingRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.putMapping(request, listener); + ((IndicesAdminClient) client).putMapping(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java index fe148615129..804b5b7d45b 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java @@ -34,7 +34,7 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; /** * A request to open an index. */ -public class OpenIndexRequest extends MasterNodeOperationRequest { +public class OpenIndexRequest extends MasterNodeOperationRequest { private String index; @@ -99,14 +99,14 @@ public class OpenIndexRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readUTF(); + index = in.readString(); timeout = readTimeValue(in); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(index); + out.writeString(index); timeout.writeTo(out); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequestBuilder.java index e87e4c8b652..ce1e6fb8603 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequestBuilder.java @@ -20,21 +20,22 @@ package org.elasticsearch.action.admin.indices.open; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class OpenIndexRequestBuilder extends BaseIndicesRequestBuilder { +public class OpenIndexRequestBuilder extends MasterNodeOperationRequestBuilder { public OpenIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new OpenIndexRequest()); + super((InternalIndicesAdminClient) indicesClient, new OpenIndexRequest()); } public OpenIndexRequestBuilder(IndicesAdminClient indicesClient, String index) { - super(indicesClient, new OpenIndexRequest(index)); + super((InternalIndicesAdminClient) indicesClient, new OpenIndexRequest(index)); } public OpenIndexRequestBuilder setIndex(String index) { @@ -60,24 +61,8 @@ public class OpenIndexRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.open(request, listener); + ((IndicesAdminClient) client).open(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequest.java index b488681364d..8275857889e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequest.java @@ -36,12 +36,11 @@ import java.io.IOException; *

{@link #maxNumSegments(int)} allows to control the number of segments to optimize down to. By default, will * cause the optimize process to optimize down to half the configured number of segments. * - * * @see org.elasticsearch.client.Requests#optimizeRequest(String...) * @see org.elasticsearch.client.IndicesAdminClient#optimize(OptimizeRequest) * @see OptimizeResponse */ -public class OptimizeRequest extends BroadcastOperationRequest { +public class OptimizeRequest extends BroadcastOperationRequest { public static final class Defaults { public static final boolean WAIT_FOR_MERGE = true; @@ -76,18 +75,6 @@ public class OptimizeRequest extends BroadcastOperationRequest { } - @Override - public OptimizeRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - @Override - public OptimizeRequest operationThreading(BroadcastOperationThreading operationThreading) { - super.operationThreading(operationThreading); - return this; - } - /** * Should the call block until the optimize completes. Defaults to true. */ diff --git a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java index 24a6286dc05..e7e6bac4ed5 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeRequestBuilder.java @@ -20,10 +20,9 @@ package org.elasticsearch.action.admin.indices.optimize; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * A request to optimize one or more indices. In order to optimize on all the indices, pass an empty array or @@ -35,15 +34,10 @@ import org.elasticsearch.client.IndicesAdminClient; *

{@link #setMaxNumSegments(int)} allows to control the number of segments to optimize down to. By default, will * cause the optimize process to optimize down to half the configured number of segments. */ -public class OptimizeRequestBuilder extends BaseIndicesRequestBuilder { +public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder { public OptimizeRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new OptimizeRequest()); - } - - public OptimizeRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalIndicesAdminClient) indicesClient, new OptimizeRequest()); } /** @@ -88,32 +82,8 @@ public class OptimizeRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.optimize(request, listener); + ((IndicesAdminClient) client).optimize(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/optimize/ShardOptimizeRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/optimize/ShardOptimizeRequest.java index b847709b344..1ac84db94cd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/optimize/ShardOptimizeRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/optimize/ShardOptimizeRequest.java @@ -31,20 +31,16 @@ import java.io.IOException; class ShardOptimizeRequest extends BroadcastShardOperationRequest { private boolean waitForMerge = OptimizeRequest.Defaults.WAIT_FOR_MERGE; - private int maxNumSegments = OptimizeRequest.Defaults.MAX_NUM_SEGMENTS; - private boolean onlyExpungeDeletes = OptimizeRequest.Defaults.ONLY_EXPUNGE_DELETES; - private boolean flush = OptimizeRequest.Defaults.FLUSH; - private boolean refresh = OptimizeRequest.Defaults.REFRESH; ShardOptimizeRequest() { } public ShardOptimizeRequest(String index, int shardId, OptimizeRequest request) { - super(index, shardId); + super(index, shardId, request); waitForMerge = request.waitForMerge(); maxNumSegments = request.maxNumSegments(); onlyExpungeDeletes = request.onlyExpungeDeletes(); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequest.java index aaef8c0f1e4..8919732e964 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequest.java @@ -31,12 +31,11 @@ import java.io.IOException; * capabilities depends on the index engine used. For example, the robin one requires refresh to be called, but by * default a refresh is scheduled periodically. * - * * @see org.elasticsearch.client.Requests#refreshRequest(String...) * @see org.elasticsearch.client.IndicesAdminClient#refresh(RefreshRequest) * @see RefreshResponse */ -public class RefreshRequest extends BroadcastOperationRequest { +public class RefreshRequest extends BroadcastOperationRequest { private boolean waitForOperations = true; @@ -49,24 +48,6 @@ public class RefreshRequest extends BroadcastOperationRequest { operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD); } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public RefreshRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - /** - * Controls the operation threading model. - */ - @Override - public RefreshRequest operationThreading(BroadcastOperationThreading operationThreading) { - super.operationThreading(operationThreading); - return this; - } - public boolean waitForOperations() { return waitForOperations; } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java index 87f4379f509..3f42db9f08d 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshRequestBuilder.java @@ -20,25 +20,19 @@ package org.elasticsearch.action.admin.indices.refresh; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * A refresh request making all operations performed since the last refresh available for search. The (near) real-time * capabilities depends on the index engine used. For example, the robin one requires refresh to be called, but by * default a refresh is scheduled periodically. */ -public class RefreshRequestBuilder extends BaseIndicesRequestBuilder { +public class RefreshRequestBuilder extends BroadcastOperationRequestBuilder { public RefreshRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new RefreshRequest()); - } - - public RefreshRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalIndicesAdminClient) indicesClient, new RefreshRequest()); } public RefreshRequestBuilder setWaitForOperations(boolean waitForOperations) { @@ -46,32 +40,8 @@ public class RefreshRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.refresh(request, listener); + ((IndicesAdminClient) client).refresh(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/refresh/ShardRefreshRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/refresh/ShardRefreshRequest.java index 8305aab9744..d2998a290e4 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/refresh/ShardRefreshRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/refresh/ShardRefreshRequest.java @@ -36,7 +36,7 @@ class ShardRefreshRequest extends BroadcastShardOperationRequest { } public ShardRefreshRequest(String index, int shardId, RefreshRequest request) { - super(index, shardId); + super(index, shardId, request); waitForOperations = request.waitForOperations(); } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java index 43565ef7031..b80e6ccae16 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java @@ -22,7 +22,7 @@ package org.elasticsearch.action.admin.indices.segments; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; import org.elasticsearch.common.Strings; -public class IndicesSegmentsRequest extends BroadcastOperationRequest { +public class IndicesSegmentsRequest extends BroadcastOperationRequest { public IndicesSegmentsRequest() { this(Strings.EMPTY_ARRAY); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java index 6fa10cb94ce..b2aa688e9e4 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestBuilder.java @@ -20,34 +20,21 @@ package org.elasticsearch.action.admin.indices.segments; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class IndicesSegmentsRequestBuilder extends BaseIndicesRequestBuilder { +public class IndicesSegmentsRequestBuilder extends BroadcastOperationRequestBuilder { public IndicesSegmentsRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesSegmentsRequest()); - } - - public IndicesSegmentsRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; - } - - /** - * Specifies what type of requested indices to ignore. For example indices that don't exist. - */ - public IndicesSegmentsRequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) { - request().ignoreIndices(ignoreIndices); - return this; + super((InternalIndicesAdminClient) indicesClient, new IndicesSegmentsRequest()); } @Override protected void doExecute(ActionListener listener) { - client.segments(request, listener); + ((IndicesAdminClient) client).segments(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java index bc04afd6bbe..69ee7b206bb 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/TransportIndicesSegmentsAction.java @@ -151,7 +151,7 @@ public class TransportIndicesSegmentsAction extends TransportBroadcastOperationA } IndexShardSegmentRequest(String index, int shardId, IndicesSegmentsRequest request) { - super(index, shardId); + super(index, shardId, request); } @Override diff --git a/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequest.java index 21c5879c53a..b461ab3e538 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequest.java @@ -41,7 +41,7 @@ import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsT /** * */ -public class UpdateSettingsRequest extends MasterNodeOperationRequest { +public class UpdateSettingsRequest extends MasterNodeOperationRequest { private String[] indices; @@ -128,24 +128,14 @@ public class UpdateSettingsRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - indices = new String[in.readVInt()]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); - } + indices = in.readStringArray(); settings = readSettingsFromStream(in); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - if (indices == null) { - out.writeVInt(0); - } else { - out.writeVInt(indices.length); - for (String index : indices) { - out.writeUTF(index); - } - } + out.writeStringArrayNullable(indices); writeSettingsToStream(settings, out); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequestBuilder.java index 5d86f35b33d..f78d3e571dc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/settings/UpdateSettingsRequestBuilder.java @@ -20,8 +20,9 @@ package org.elasticsearch.action.admin.indices.settings; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.settings.Settings; import java.util.Map; @@ -29,10 +30,10 @@ import java.util.Map; /** * */ -public class UpdateSettingsRequestBuilder extends BaseIndicesRequestBuilder { +public class UpdateSettingsRequestBuilder extends MasterNodeOperationRequestBuilder { public UpdateSettingsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new UpdateSettingsRequest(indices)); + super((InternalIndicesAdminClient) indicesClient, new UpdateSettingsRequest(indices)); } public UpdateSettingsRequestBuilder setIndices(String... indices) { @@ -74,6 +75,6 @@ public class UpdateSettingsRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.updateSettings(request, listener); + ((IndicesAdminClient) client).updateSettings(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java index b4948046f77..e88193245c7 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java @@ -34,7 +34,7 @@ import java.io.IOException; *

All the stats to be returned can be cleared using {@link #clear()}, at which point, specific * stats can be enabled. */ -public class IndicesStatsRequest extends BroadcastOperationRequest { +public class IndicesStatsRequest extends BroadcastOperationRequest { private boolean docs = true; private boolean store = true; @@ -48,11 +48,6 @@ public class IndicesStatsRequest extends BroadcastOperationRequest { private String[] types = null; private String[] groups = null; - public IndicesStatsRequest indices(String... indices) { - this.indices = indices; - return this; - } - /** * Sets all flags to return all stats. */ diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java index 751014b3f03..0ccbe30dc77 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequestBuilder.java @@ -20,9 +20,9 @@ package org.elasticsearch.action.admin.indices.stats; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * A request to get indices level stats. Allow to enable different stats to be returned. @@ -33,10 +33,10 @@ import org.elasticsearch.client.IndicesAdminClient; *

All the stats to be returned can be cleared using {@link #clear()}, at which point, specific * stats can be enabled. */ -public class IndicesStatsRequestBuilder extends BaseIndicesRequestBuilder { +public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder { public IndicesStatsRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesStatsRequest()); + super((InternalIndicesAdminClient) indicesClient, new IndicesStatsRequest()); } /** @@ -55,14 +55,6 @@ public class IndicesStatsRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.stats(request, listener); + ((IndicesAdminClient) client).stats(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java index b0417bf5be2..235817b1954 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java @@ -178,13 +178,14 @@ public class TransportIndicesStatsAction extends TransportBroadcastOperationActi public static class IndexShardStatsRequest extends BroadcastShardOperationRequest { + // TODO if there are many indices, the request might hold a large indices array..., we don't really need to serialize it IndicesStatsRequest request; IndexShardStatsRequest() { } IndexShardStatsRequest(String index, int shardId, IndicesStatsRequest request) { - super(index, shardId); + super(index, shardId, request); this.request = request; } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequest.java index 4483cd51960..41f7aee1ccc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequest.java @@ -20,7 +20,6 @@ package org.elasticsearch.action.admin.indices.status; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -30,7 +29,7 @@ import java.io.IOException; /** * */ -public class IndicesStatusRequest extends BroadcastOperationRequest { +public class IndicesStatusRequest extends BroadcastOperationRequest { private boolean recovery = false; @@ -68,17 +67,6 @@ public class IndicesStatusRequest extends BroadcastOperationRequest { return this.snapshot; } - @Override - public IndicesStatusRequest listenerThreaded(boolean listenerThreaded) { - super.listenerThreaded(listenerThreaded); - return this; - } - - @Override - public BroadcastOperationRequest operationThreading(BroadcastOperationThreading operationThreading) { - return super.operationThreading(operationThreading); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java index a85c83808b8..58393ce3648 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusRequestBuilder.java @@ -20,25 +20,17 @@ package org.elasticsearch.action.admin.indices.status; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class IndicesStatusRequestBuilder extends BaseIndicesRequestBuilder { +public class IndicesStatusRequestBuilder extends BroadcastOperationRequestBuilder { public IndicesStatusRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesStatusRequest()); - } - - /** - * Sets specific indices to return the status for. - */ - public IndicesStatusRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalIndicesAdminClient) indicesClient, new IndicesStatusRequest()); } /** @@ -57,16 +49,8 @@ public class IndicesStatusRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.status(request, listener); + ((IndicesAdminClient) client).status(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java b/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java index c2378c1fc20..dc76ebdc771 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java @@ -277,7 +277,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct } IndexShardStatusRequest(String index, int shardId, IndicesStatusRequest request) { - super(index, shardId); + super(index, shardId, request); recovery = request.recovery(); snapshot = request.snapshot(); } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/support/BaseIndicesRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/support/BaseIndicesRequestBuilder.java deleted file mode 100644 index 30462a903e9..00000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/support/BaseIndicesRequestBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon 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.action.admin.indices.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.action.support.PlainListenableActionFuture; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.internal.InternalIndicesAdminClient; - -/** - * - */ -public abstract class BaseIndicesRequestBuilder implements ActionRequestBuilder { - - protected final InternalIndicesAdminClient client; - - protected final Request request; - - protected BaseIndicesRequestBuilder(IndicesAdminClient client, Request request) { - this.client = (InternalIndicesAdminClient) client; - this.request = request; - } - - @Override - public Request request() { - return request; - } - - @Override - public ListenableActionFuture execute() { - PlainListenableActionFuture future = new PlainListenableActionFuture(request.listenerThreaded(), client.threadPool()); - execute(future); - return future; - } - - @Override - public void execute(ActionListener listener) { - doExecute(listener); - } - - protected abstract void doExecute(ActionListener listener); -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequest.java index 1424bfc2539..893ade0800c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequest.java @@ -34,7 +34,7 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; /** * A request to delete an index template. */ -public class DeleteIndexTemplateRequest extends MasterNodeOperationRequest { +public class DeleteIndexTemplateRequest extends MasterNodeOperationRequest { private String name; @@ -94,14 +94,14 @@ public class DeleteIndexTemplateRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - name = in.readUTF(); + name = in.readString(); timeout = readTimeValue(in); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(name); + out.writeString(name); timeout.writeTo(out); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequestBuilder.java index cd5915da31e..f36719494e8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateRequestBuilder.java @@ -20,21 +20,22 @@ package org.elasticsearch.action.admin.indices.template.delete; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * */ -public class DeleteIndexTemplateRequestBuilder extends BaseIndicesRequestBuilder { +public class DeleteIndexTemplateRequestBuilder extends MasterNodeOperationRequestBuilder { public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteIndexTemplateRequest()); + super((InternalIndicesAdminClient) indicesClient, new DeleteIndexTemplateRequest()); } public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new DeleteIndexTemplateRequest(name)); + super((InternalIndicesAdminClient) indicesClient, new DeleteIndexTemplateRequest(name)); } /** @@ -55,24 +56,8 @@ public class DeleteIndexTemplateRequestBuilder extends BaseIndicesRequestBuilder return this; } - /** - * Sets the master node timeout in case the master has not yet been discovered. - */ - public DeleteIndexTemplateRequestBuilder setMasterNodeTimeout(TimeValue timeout) { - request.masterNodeTimeout(timeout); - return this; - } - - /** - * Sets the master node timeout in case the master has not yet been discovered. - */ - public DeleteIndexTemplateRequestBuilder setMasterNodeTimeout(String timeout) { - request.masterNodeTimeout(timeout); - return this; - } - @Override protected void doExecute(ActionListener listener) { - client.deleteTemplate(request, listener); + ((IndicesAdminClient) client).deleteTemplate(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index ce0ea8e009e..26526f825c2 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -51,7 +51,7 @@ import static org.elasticsearch.common.unit.TimeValue.readTimeValue; /** * A request to create an index template. */ -public class PutIndexTemplateRequest extends MasterNodeOperationRequest { +public class PutIndexTemplateRequest extends MasterNodeOperationRequest { private String name; @@ -370,20 +370,20 @@ public class PutIndexTemplateRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - cause = in.readUTF(); - name = in.readUTF(); - template = in.readUTF(); + cause = in.readString(); + name = in.readString(); + template = in.readString(); order = in.readInt(); create = in.readBoolean(); settings = readSettingsFromStream(in); timeout = readTimeValue(in); int size = in.readVInt(); for (int i = 0; i < size; i++) { - mappings.put(in.readUTF(), in.readUTF()); + mappings.put(in.readString(), in.readString()); } int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { - String type = in.readUTF(); + String type = in.readString(); IndexMetaData.Custom customIndexMetaData = IndexMetaData.lookupFactorySafe(type).readFrom(in); customs.put(type, customIndexMetaData); } @@ -392,21 +392,21 @@ public class PutIndexTemplateRequest extends MasterNodeOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(cause); - out.writeUTF(name); - out.writeUTF(template); + out.writeString(cause); + out.writeString(name); + out.writeString(template); out.writeInt(order); out.writeBoolean(create); writeSettingsToStream(settings, out); timeout.writeTo(out); out.writeVInt(mappings.size()); for (Map.Entry entry : mappings.entrySet()) { - out.writeUTF(entry.getKey()); - out.writeUTF(entry.getValue()); + out.writeString(entry.getKey()); + out.writeString(entry.getValue()); } out.writeVInt(customs.size()); for (Map.Entry entry : customs.entrySet()) { - out.writeUTF(entry.getKey()); + out.writeString(entry.getKey()); IndexMetaData.lookupFactorySafe(entry.getKey()).writeTo(entry.getValue(), out); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java index a900ff8af30..65810c1cc23 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java @@ -20,8 +20,9 @@ package org.elasticsearch.action.admin.indices.template.put; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -32,14 +33,14 @@ import java.util.Map; /** * */ -public class PutIndexTemplateRequestBuilder extends BaseIndicesRequestBuilder { +public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBuilder { public PutIndexTemplateRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutIndexTemplateRequest()); + super((InternalIndicesAdminClient) indicesClient, new PutIndexTemplateRequest()); } public PutIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new PutIndexTemplateRequest(name)); + super((InternalIndicesAdminClient) indicesClient, new PutIndexTemplateRequest(name)); } /** @@ -206,24 +207,8 @@ public class PutIndexTemplateRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.putTemplate(request, listener); + ((IndicesAdminClient) client).putTemplate(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ShardValidateQueryRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ShardValidateQueryRequest.java index 082b1d1fb31..bd3c22cc303 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ShardValidateQueryRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ShardValidateQueryRequest.java @@ -34,9 +34,7 @@ import java.io.IOException; class ShardValidateQueryRequest extends BroadcastShardOperationRequest { private BytesReference querySource; - private String[] types = Strings.EMPTY_ARRAY; - private boolean explain; @Nullable @@ -47,7 +45,7 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest { } public ShardValidateQueryRequest(String index, int shardId, @Nullable String[] filteringAliases, ValidateQueryRequest request) { - super(index, shardId); + super(index, shardId, request); this.querySource = request.querySource(); this.types = request.types(); this.explain = request.explain(); @@ -79,14 +77,14 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest { if (typesSize > 0) { types = new String[typesSize]; for (int i = 0; i < typesSize; i++) { - types[i] = in.readUTF(); + types[i] = in.readString(); } } int aliasesSize = in.readVInt(); if (aliasesSize > 0) { filteringAliases = new String[aliasesSize]; for (int i = 0; i < aliasesSize; i++) { - filteringAliases[i] = in.readUTF(); + filteringAliases[i] = in.readString(); } } @@ -100,12 +98,12 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest { out.writeVInt(types.length); for (String type : types) { - out.writeUTF(type); + out.writeString(type); } if (filteringAliases != null) { out.writeVInt(filteringAliases.length); for (String alias : filteringAliases) { - out.writeUTF(alias); + out.writeString(alias); } } else { out.writeVInt(0); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index 7925b99ad9a..c918119f45d 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -40,8 +40,8 @@ import org.elasticsearch.index.service.IndexService; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.SearchContext; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -166,7 +166,7 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct valid = true; } else { SearchContext.setCurrent(new SearchContext(0, - new InternalSearchRequest().types(request.types()), + new ShardSearchRequest().types(request.types()), null, indexShard.searcher(), indexService, indexShard, scriptService)); try { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java index 4e70cbbb7de..b37c304da8e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.indices.validate.query; import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Requests; import org.elasticsearch.common.Required; import org.elasticsearch.common.Strings; @@ -46,7 +45,7 @@ import java.util.Map; *

The request requires the query source to be set either using {@link #query(org.elasticsearch.index.query.QueryBuilder)}, * or {@link #query(byte[])}. */ -public class ValidateQueryRequest extends BroadcastOperationRequest { +public class ValidateQueryRequest extends BroadcastOperationRequest { private static final XContentType contentType = Requests.CONTENT_TYPE; @@ -74,15 +73,6 @@ public class ValidateQueryRequest extends BroadcastOperationRequest { return validationException; } - /** - * Controls the operation threading model. - */ - @Override - public ValidateQueryRequest operationThreading(BroadcastOperationThreading operationThreading) { - super.operationThreading(operationThreading); - return this; - } - @Override protected void beforeStart() { if (querySourceUnsafe) { @@ -91,20 +81,6 @@ public class ValidateQueryRequest extends BroadcastOperationRequest { } } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public ValidateQueryRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - public ValidateQueryRequest indices(String... indices) { - this.indices = indices; - return this; - } - /** * The query source to execute. */ diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java index 69e6e245c3d..c0c6477a39c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java @@ -1,27 +1,38 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.action.admin.indices.validate.query; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.index.query.QueryBuilder; /** * */ -public class ValidateQueryRequestBuilder extends BaseIndicesRequestBuilder { - public ValidateQueryRequestBuilder(IndicesAdminClient client) { - super(client, new ValidateQueryRequest()); - } +public class ValidateQueryRequestBuilder extends BroadcastOperationRequestBuilder { - /** - * Sets the indices the query validation will run against. - */ - public ValidateQueryRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + public ValidateQueryRequestBuilder(IndicesAdminClient client) { + super((InternalIndicesAdminClient) client, new ValidateQueryRequest()); } /** @@ -82,32 +93,8 @@ public class ValidateQueryRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.validateQuery(request, listener); + ((IndicesAdminClient) client).validateQuery(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequest.java index 9519acc9ad9..edb56bb0e58 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequest.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.warmer.delete; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeOperationRequest; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -30,11 +31,11 @@ import java.io.IOException; /** * A request to delete an index warmer. */ -public class DeleteWarmerRequest extends MasterNodeOperationRequest { +public class DeleteWarmerRequest extends MasterNodeOperationRequest { private String name; - private String[] indices; + private String[] indices = Strings.EMPTY_ARRAY; DeleteWarmerRequest() { } @@ -89,24 +90,14 @@ public class DeleteWarmerRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - name = in.readOptionalUTF(); - indices = new String[in.readVInt()]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); - } + name = in.readOptionalString(); + indices = in.readStringArray(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeOptionalUTF(name); - if (indices == null) { - out.writeVInt(0); - } else { - out.writeVInt(indices.length); - for (String index : indices) { - out.writeUTF(index); - } - } + out.writeOptionalString(name); + out.writeStringArrayNullable(indices); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequestBuilder.java index ceadce77315..4950308c5b3 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerRequestBuilder.java @@ -20,17 +20,17 @@ package org.elasticsearch.action.admin.indices.warmer.delete; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class DeleteWarmerRequestBuilder extends BaseIndicesRequestBuilder { +public class DeleteWarmerRequestBuilder extends MasterNodeOperationRequestBuilder { public DeleteWarmerRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteWarmerRequest()); + super((InternalIndicesAdminClient) indicesClient, new DeleteWarmerRequest()); } public DeleteWarmerRequestBuilder setIndices(String... indices) { @@ -47,16 +47,8 @@ public class DeleteWarmerRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.deleteWarmer(request, listener); + ((IndicesAdminClient) client).deleteWarmer(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequest.java index cc623674aed..3824431b53b 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequest.java @@ -34,7 +34,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * A request to put a search warmer. */ -public class PutWarmerRequest extends MasterNodeOperationRequest { +public class PutWarmerRequest extends MasterNodeOperationRequest { private String name; @@ -98,7 +98,7 @@ public class PutWarmerRequest extends MasterNodeOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - name = in.readUTF(); + name = in.readString(); if (in.readBoolean()) { searchRequest = new SearchRequest(); searchRequest.readFrom(in); @@ -108,7 +108,7 @@ public class PutWarmerRequest extends MasterNodeOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(name); + out.writeString(name); if (searchRequest == null) { out.writeBoolean(false); } else { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequestBuilder.java index 065ccd37947..3edd12724a3 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequestBuilder.java @@ -20,23 +20,23 @@ package org.elasticsearch.action.admin.indices.warmer.put; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.client.internal.InternalIndicesAdminClient; /** * */ -public class PutWarmerRequestBuilder extends BaseIndicesRequestBuilder { +public class PutWarmerRequestBuilder extends MasterNodeOperationRequestBuilder { public PutWarmerRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new PutWarmerRequest().name(name)); + super((InternalIndicesAdminClient) indicesClient, new PutWarmerRequest().name(name)); } public PutWarmerRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutWarmerRequest()); + super((InternalIndicesAdminClient) indicesClient, new PutWarmerRequest()); } /** @@ -63,16 +63,8 @@ public class PutWarmerRequestBuilder extends BaseIndicesRequestBuilder listener) { - client.putWarmer(request, listener); + ((IndicesAdminClient) client).putWarmer(request, listener); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index 0d5fe5ea8b6..ad96e9fa3df 100644 --- a/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -49,14 +49,12 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; * * @see org.elasticsearch.client.Client#bulk(BulkRequest) */ -public class BulkRequest implements ActionRequest { +public class BulkRequest extends ActionRequest { private static final int REQUEST_OVERHEAD = 50; final List requests = Lists.newArrayList(); - private boolean listenerThreaded = false; - private ReplicationType replicationType = ReplicationType.DEFAULT; private WriteConsistencyLevel consistencyLevel = WriteConsistencyLevel.DEFAULT; private boolean refresh = false; @@ -329,19 +327,9 @@ public class BulkRequest implements ActionRequest { return validationException; } - @Override - public boolean listenerThreaded() { - return listenerThreaded; - } - - @Override - public BulkRequest listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); replicationType = ReplicationType.fromId(in.readByte()); consistencyLevel = WriteConsistencyLevel.fromId(in.readByte()); int size = in.readVInt(); @@ -362,6 +350,7 @@ public class BulkRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeByte(replicationType.id()); out.writeByte(consistencyLevel.id()); out.writeVInt(requests.size()); diff --git a/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java b/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java index 0013d039104..53b4b4def10 100644 --- a/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java @@ -20,24 +20,25 @@ package org.elasticsearch.action.bulk; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.WriteConsistencyLevel; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexRequestBuilder; -import org.elasticsearch.action.support.BaseRequestBuilder; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.Nullable; /** * A bulk request holds an ordered {@link IndexRequest}s and {@link DeleteRequest}s and allows to executes * it in a single batch. */ -public class BulkRequestBuilder extends BaseRequestBuilder { +public class BulkRequestBuilder extends ActionRequestBuilder { public BulkRequestBuilder(Client client) { - super(client, new BulkRequest()); + super((InternalClient) client, new BulkRequest()); } /** @@ -125,6 +126,6 @@ public class BulkRequestBuilder extends BaseRequestBuilder listener) { - client.bulk(request, listener); + ((Client) client).bulk(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java b/src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java index b12b4c0ba65..afa983ff891 100644 --- a/src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java +++ b/src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java @@ -28,7 +28,7 @@ import java.io.IOException; /** * */ -public class BulkShardRequest extends ShardReplicationOperationRequest { +public class BulkShardRequest extends ShardReplicationOperationRequest { private int shardId; diff --git a/src/main/java/org/elasticsearch/action/count/CountRequest.java b/src/main/java/org/elasticsearch/action/count/CountRequest.java index 6e838915e55..e47545f746e 100644 --- a/src/main/java/org/elasticsearch/action/count/CountRequest.java +++ b/src/main/java/org/elasticsearch/action/count/CountRequest.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.count; import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Requests; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Required; @@ -52,7 +51,7 @@ import java.util.Map; * @see org.elasticsearch.client.Client#count(CountRequest) * @see org.elasticsearch.client.Requests#countRequest(String...) */ -public class CountRequest extends BroadcastOperationRequest { +public class CountRequest extends BroadcastOperationRequest { private static final XContentType contentType = Requests.CONTENT_TYPE; @@ -92,15 +91,6 @@ public class CountRequest extends BroadcastOperationRequest { return queryHint; } - /** - * Controls the operation threading model. - */ - @Override - public CountRequest operationThreading(BroadcastOperationThreading operationThreading) { - super.operationThreading(operationThreading); - return this; - } - @Override protected void beforeStart() { if (querySourceUnsafe) { @@ -109,20 +99,6 @@ public class CountRequest extends BroadcastOperationRequest { } } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public CountRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - public CountRequest indices(String... indices) { - this.indices = indices; - return this; - } - /** * A query hint to optionally later be used when routing the request. */ diff --git a/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java b/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java index 5c195cc06f0..3a4f45f533e 100644 --- a/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/count/CountRequestBuilder.java @@ -20,28 +20,19 @@ package org.elasticsearch.action.count; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; -import org.elasticsearch.action.support.IgnoreIndices; -import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.index.query.QueryBuilder; /** * A count action request builder. */ -public class CountRequestBuilder extends BaseRequestBuilder { +public class CountRequestBuilder extends BroadcastOperationRequestBuilder { public CountRequestBuilder(Client client) { - super(client, new CountRequest()); - } - - /** - * Sets the indices the count query will run against. - */ - public CountRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalClient) client, new CountRequest()); } /** @@ -125,32 +116,8 @@ public class CountRequestBuilder extends BaseRequestBuilder listener) { - client.count(request, listener); + ((InternalClient) client).count(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/count/ShardCountRequest.java b/src/main/java/org/elasticsearch/action/count/ShardCountRequest.java index 6ec712ec497..106f9207f20 100644 --- a/src/main/java/org/elasticsearch/action/count/ShardCountRequest.java +++ b/src/main/java/org/elasticsearch/action/count/ShardCountRequest.java @@ -36,8 +36,6 @@ class ShardCountRequest extends BroadcastShardOperationRequest { private float minScore; private BytesReference querySource; - private int querySourceOffset; - private int querySourceLength; private String[] types = Strings.EMPTY_ARRAY; @@ -49,7 +47,7 @@ class ShardCountRequest extends BroadcastShardOperationRequest { } public ShardCountRequest(String index, int shardId, @Nullable String[] filteringAliases, CountRequest request) { - super(index, shardId); + super(index, shardId, request); this.minScore = request.minScore(); this.querySource = request.querySource(); this.types = request.types(); diff --git a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java index f97d4d91580..a222d480436 100644 --- a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java +++ b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java @@ -40,8 +40,8 @@ import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchShardTarget; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.SearchContext; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QueryPhaseExecutionException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -148,7 +148,7 @@ public class TransportCountAction extends TransportBroadcastOperationAction { private String type; private String id; @@ -101,52 +98,6 @@ public class DeleteRequest extends ShardReplicationOperationRequest { return validationException; } - /** - * Sets the index the delete will happen on. - */ - @Override - public DeleteRequest index(String index) { - super.index(index); - return this; - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public DeleteRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - /** - * Controls if the operation will be executed on a separate thread when executed locally. Defaults - * to true when running in embedded mode. - */ - @Override - public DeleteRequest operationThreaded(boolean threadedOperation) { - super.operationThreaded(threadedOperation); - return this; - } - - /** - * Set the replication type for this operation. - */ - @Override - public DeleteRequest replicationType(ReplicationType replicationType) { - super.replicationType(replicationType); - return this; - } - - /** - * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} - */ - @Override - public DeleteRequest consistencyLevel(WriteConsistencyLevel consistencyLevel) { - super.consistencyLevel(consistencyLevel); - return this; - } - /** * The type of the document to delete. */ @@ -179,14 +130,6 @@ public class DeleteRequest extends ShardReplicationOperationRequest { return this; } - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public DeleteRequest timeout(TimeValue timeout) { - this.timeout = timeout; - return this; - } - /** * Sets the parent id of this document. Will simply set the routing to this value, as it is only * used for routing with delete requests. @@ -258,11 +201,9 @@ public class DeleteRequest extends ShardReplicationOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - type = in.readUTF(); - id = in.readUTF(); - if (in.readBoolean()) { - routing = in.readUTF(); - } + type = in.readString(); + id = in.readString(); + routing = in.readOptionalString(); refresh = in.readBoolean(); version = in.readLong(); versionType = VersionType.fromValue(in.readByte()); @@ -271,14 +212,9 @@ public class DeleteRequest extends ShardReplicationOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(type); - out.writeUTF(id); - if (routing == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(routing); - } + out.writeString(type); + out.writeString(id); + out.writeOptionalString(routing()); out.writeBoolean(refresh); out.writeLong(version); out.writeByte(versionType.getValue()); diff --git a/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java b/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java index 4b3881a7454..e6186a8f58a 100644 --- a/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/delete/DeleteRequestBuilder.java @@ -21,31 +21,24 @@ package org.elasticsearch.action.delete; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.WriteConsistencyLevel; -import org.elasticsearch.action.support.BaseRequestBuilder; import org.elasticsearch.action.support.replication.ReplicationType; +import org.elasticsearch.action.support.replication.ShardReplicationOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.Nullable; import org.elasticsearch.index.VersionType; /** * A delete document action request builder. */ -public class DeleteRequestBuilder extends BaseRequestBuilder { +public class DeleteRequestBuilder extends ShardReplicationOperationRequestBuilder { public DeleteRequestBuilder(Client client) { - super(client, new DeleteRequest()); + super((InternalClient) client, new DeleteRequest()); } public DeleteRequestBuilder(Client client, @Nullable String index) { - super(client, new DeleteRequest(index)); - } - - /** - * Sets the index the delete will happen on. - */ - public DeleteRequestBuilder setIndex(String index) { - request.index(index); - return this; + super((InternalClient) client, new DeleteRequest(index)); } /** @@ -109,23 +102,6 @@ public class DeleteRequestBuilder extends BaseRequestBuildertrue when running in embedded mode. - */ - public DeleteRequestBuilder setOperationThreaded(boolean threadedOperation) { - request.operationThreaded(threadedOperation); - return this; - } - /** * Set the replication type for this operation. */ @@ -144,6 +120,6 @@ public class DeleteRequestBuilder extends BaseRequestBuilder listener) { - client.delete(request, listener); + ((Client) client).delete(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/delete/index/IndexDeleteRequest.java b/src/main/java/org/elasticsearch/action/delete/index/IndexDeleteRequest.java index f5b2d1e56b8..ba2779eebf0 100644 --- a/src/main/java/org/elasticsearch/action/delete/index/IndexDeleteRequest.java +++ b/src/main/java/org/elasticsearch/action/delete/index/IndexDeleteRequest.java @@ -29,14 +29,11 @@ import java.io.IOException; /** * */ -public class IndexDeleteRequest extends IndexReplicationOperationRequest { +public class IndexDeleteRequest extends IndexReplicationOperationRequest { private String type; - private String id; - private boolean refresh = false; - private long version; IndexDeleteRequest() { @@ -72,8 +69,8 @@ public class IndexDeleteRequest extends IndexReplicationOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - type = in.readUTF(); - id = in.readUTF(); + type = in.readString(); + id = in.readString(); refresh = in.readBoolean(); version = in.readLong(); } @@ -81,8 +78,8 @@ public class IndexDeleteRequest extends IndexReplicationOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(type); - out.writeUTF(id); + out.writeString(type); + out.writeString(id); out.writeBoolean(refresh); out.writeLong(version); } diff --git a/src/main/java/org/elasticsearch/action/delete/index/ShardDeleteRequest.java b/src/main/java/org/elasticsearch/action/delete/index/ShardDeleteRequest.java index 7bfa78cae64..efd62601b9e 100644 --- a/src/main/java/org/elasticsearch/action/delete/index/ShardDeleteRequest.java +++ b/src/main/java/org/elasticsearch/action/delete/index/ShardDeleteRequest.java @@ -31,7 +31,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * Delete by query request to execute on a specific shard. */ -public class ShardDeleteRequest extends ShardReplicationOperationRequest { +public class ShardDeleteRequest extends ShardReplicationOperationRequest { private int shardId; private String type; @@ -40,6 +40,7 @@ public class ShardDeleteRequest extends ShardReplicationOperationRequest { private long version; ShardDeleteRequest(IndexDeleteRequest request, int shardId) { + super(request); this.index = request.index(); this.shardId = shardId; this.type = request.type(); @@ -94,8 +95,8 @@ public class ShardDeleteRequest extends ShardReplicationOperationRequest { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); shardId = in.readVInt(); - type = in.readUTF(); - id = in.readUTF(); + type = in.readString(); + id = in.readString(); refresh = in.readBoolean(); version = in.readLong(); } @@ -104,8 +105,8 @@ public class ShardDeleteRequest extends ShardReplicationOperationRequest { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(shardId); - out.writeUTF(type); - out.writeUTF(id); + out.writeString(type); + out.writeString(id); out.writeBoolean(refresh); out.writeLong(version); } diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java b/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java index ac0d6c495ce..2c3f3be9fb6 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java @@ -22,9 +22,7 @@ package org.elasticsearch.action.deletebyquery; import com.google.common.base.Charsets; import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.WriteConsistencyLevel; import org.elasticsearch.action.support.replication.IndicesReplicationOperationRequest; -import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Requests; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Required; @@ -33,7 +31,6 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; @@ -57,7 +54,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; * @see org.elasticsearch.client.Requests#deleteByQueryRequest(String...) * @see org.elasticsearch.client.Client#deleteByQuery(DeleteByQueryRequest) */ -public class DeleteByQueryRequest extends IndicesReplicationOperationRequest { +public class DeleteByQueryRequest extends IndicesReplicationOperationRequest { private static final XContentType contentType = Requests.CONTENT_TYPE; @@ -79,15 +76,6 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest { public DeleteByQueryRequest() { } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public DeleteByQueryRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); @@ -97,14 +85,6 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest { return validationException; } - /** - * The indices the delete by query will run against. - */ - public DeleteByQueryRequest indices(String... indices) { - this.indices = indices; - return this; - } - /** * The query source to execute. */ @@ -193,7 +173,6 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest { /** * A comma separated list of routing values to control the shards the search will be executed on. */ - @Override public String routing() { return this.routing; } @@ -222,80 +201,19 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest { return this; } - /** - * A timeout to wait if the delete by query operation can't be performed immediately. Defaults to 1m. - */ - public DeleteByQueryRequest timeout(TimeValue timeout) { - this.timeout = timeout; - return this; - } - - /** - * A timeout to wait if the delete by query operation can't be performed immediately. Defaults to 1m. - */ - public DeleteByQueryRequest timeout(String timeout) { - this.timeout = TimeValue.parseTimeValue(timeout, null); - return this; - } - - /** - * The replication type to use with this operation. - */ - public DeleteByQueryRequest replicationType(ReplicationType replicationType) { - this.replicationType = replicationType; - return this; - } - - public DeleteByQueryRequest consistencyLevel(WriteConsistencyLevel consistencyLevel) { - this.consistencyLevel = consistencyLevel; - return this; - } - - /** - * The replication type to use with this operation. - */ - public DeleteByQueryRequest replicationType(String replicationType) { - this.replicationType = ReplicationType.fromString(replicationType); - return this; - } - public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - querySourceUnsafe = false; querySource = in.readBytesReference(); - - if (in.readBoolean()) { - routing = in.readUTF(); - } - - int size = in.readVInt(); - if (size == 0) { - types = Strings.EMPTY_ARRAY; - } else { - types = new String[size]; - for (int i = 0; i < size; i++) { - types[i] = in.readUTF(); - } - } + routing = in.readOptionalString(); + types = in.readStringArray(); } public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeBytesReference(querySource); - - if (routing == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(routing); - } - - out.writeVInt(types.length); - for (String type : types) { - out.writeUTF(type); - } + out.writeOptionalString(routing); + out.writeStringArray(types); } @Override diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequestBuilder.java b/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequestBuilder.java index a3b9c0474c2..6c635f4c840 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequestBuilder.java @@ -21,11 +21,11 @@ package org.elasticsearch.action.deletebyquery; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.WriteConsistencyLevel; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.replication.IndicesReplicationOperationRequestBuilder; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; @@ -34,18 +34,10 @@ import java.util.Map; /** * */ -public class DeleteByQueryRequestBuilder extends BaseRequestBuilder { +public class DeleteByQueryRequestBuilder extends IndicesReplicationOperationRequestBuilder { public DeleteByQueryRequestBuilder(Client client) { - super(client, new DeleteByQueryRequest()); - } - - /** - * The indices the delete by query will run against. - */ - public DeleteByQueryRequestBuilder setIndices(String... indices) { - request.indices(indices); - return this; + super((InternalClient) client, new DeleteByQueryRequest()); } /** @@ -140,22 +132,6 @@ public class DeleteByQueryRequestBuilder extends BaseRequestBuilder1m. - */ - public DeleteByQueryRequestBuilder setTimeout(TimeValue timeout) { - request.timeout(timeout); - return this; - } - - /** - * A timeout to wait if the delete by query operation can't be performed immediately. Defaults to 1m. - */ - public DeleteByQueryRequestBuilder setTimeout(String timeout) { - request.timeout(timeout); - return this; - } - /** * The replication type to use with this operation. */ @@ -177,16 +153,8 @@ public class DeleteByQueryRequestBuilder extends BaseRequestBuilder listener) { - client.deleteByQuery(request, listener); + ((Client) client).deleteByQuery(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java b/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java index 808cf5f1e74..dca42990289 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.deletebyquery; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import java.io.IOException; import java.util.Iterator; @@ -33,10 +32,8 @@ import static com.google.common.collect.Maps.newHashMap; /** * The response of delete by query action. Holds the {@link IndexDeleteByQueryResponse}s from all the * different indices. - * - * */ -public class DeleteByQueryResponse implements ActionResponse, Streamable, Iterable { +public class DeleteByQueryResponse implements ActionResponse, Iterable { private Map indices = newHashMap(); diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/IndexDeleteByQueryRequest.java b/src/main/java/org/elasticsearch/action/deletebyquery/IndexDeleteByQueryRequest.java index 5ee94be2f2f..a3689f9ea9b 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/IndexDeleteByQueryRequest.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/IndexDeleteByQueryRequest.java @@ -37,7 +37,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * Delete by query request to execute on a specific index. */ -public class IndexDeleteByQueryRequest extends IndexReplicationOperationRequest { +public class IndexDeleteByQueryRequest extends IndexReplicationOperationRequest { private BytesReference querySource; private String[] types = Strings.EMPTY_ARRAY; @@ -97,21 +97,21 @@ public class IndexDeleteByQueryRequest extends IndexReplicationOperationRequest if (typesSize > 0) { types = new String[typesSize]; for (int i = 0; i < typesSize; i++) { - types[i] = in.readUTF(); + types[i] = in.readString(); } } int routingSize = in.readVInt(); if (routingSize > 0) { routing = new THashSet(routingSize); for (int i = 0; i < routingSize; i++) { - routing.add(in.readUTF()); + routing.add(in.readString()); } } int aliasesSize = in.readVInt(); if (aliasesSize > 0) { filteringAliases = new String[aliasesSize]; for (int i = 0; i < aliasesSize; i++) { - filteringAliases[i] = in.readUTF(); + filteringAliases[i] = in.readString(); } } } @@ -121,12 +121,12 @@ public class IndexDeleteByQueryRequest extends IndexReplicationOperationRequest out.writeBytesReference(querySource); out.writeVInt(types.length); for (String type : types) { - out.writeUTF(type); + out.writeString(type); } if (routing != null) { out.writeVInt(routing.size()); for (String r : routing) { - out.writeUTF(r); + out.writeString(r); } } else { out.writeVInt(0); @@ -134,7 +134,7 @@ public class IndexDeleteByQueryRequest extends IndexReplicationOperationRequest if (filteringAliases != null) { out.writeVInt(filteringAliases.length); for (String alias : filteringAliases) { - out.writeUTF(alias); + out.writeString(alias); } } else { out.writeVInt(0); diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/ShardDeleteByQueryRequest.java b/src/main/java/org/elasticsearch/action/deletebyquery/ShardDeleteByQueryRequest.java index 60f8d9c323d..4fb5fea318a 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/ShardDeleteByQueryRequest.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/ShardDeleteByQueryRequest.java @@ -38,7 +38,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * Delete by query request to execute on a specific shard. */ -public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest { +public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest { private int shardId; private BytesReference querySource; @@ -49,6 +49,7 @@ public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest private String[] filteringAliases; ShardDeleteByQueryRequest(IndexDeleteByQueryRequest request, int shardId) { + super(request); this.index = request.index(); this.querySource = request.querySource(); this.types = request.types(); @@ -97,25 +98,19 @@ public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest super.readFrom(in); querySource = in.readBytesReference(); shardId = in.readVInt(); - int typesSize = in.readVInt(); - if (typesSize > 0) { - types = new String[typesSize]; - for (int i = 0; i < typesSize; i++) { - types[i] = in.readUTF(); - } - } + types = in.readStringArray(); int routingSize = in.readVInt(); if (routingSize > 0) { routing = new THashSet(routingSize); for (int i = 0; i < routingSize; i++) { - routing.add(in.readUTF()); + routing.add(in.readString()); } } int aliasesSize = in.readVInt(); if (aliasesSize > 0) { filteringAliases = new String[aliasesSize]; for (int i = 0; i < aliasesSize; i++) { - filteringAliases[i] = in.readUTF(); + filteringAliases[i] = in.readString(); } } } @@ -125,14 +120,11 @@ public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest super.writeTo(out); out.writeBytesReference(querySource); out.writeVInt(shardId); - out.writeVInt(types.length); - for (String type : types) { - out.writeUTF(type); - } + out.writeStringArray(types); if (routing != null) { out.writeVInt(routing.size()); for (String r : routing) { - out.writeUTF(r); + out.writeString(r); } } else { out.writeVInt(0); @@ -140,7 +132,7 @@ public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest if (filteringAliases != null) { out.writeVInt(filteringAliases.length); for (String alias : filteringAliases) { - out.writeUTF(alias); + out.writeString(alias); } } else { out.writeVInt(0); diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java b/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java index bec8f09d365..3daef80783b 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.deletebyquery; +import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.support.replication.TransportIndicesReplicationOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; @@ -29,6 +30,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReferenceArray; @@ -42,6 +44,11 @@ public class TransportDeleteByQueryAction extends TransportIndicesReplicationOpe super(settings, transportService, clusterService, threadPool, indexDeleteByQueryAction); } + @Override + protected Map> resolveRouting(ClusterState clusterState, DeleteByQueryRequest request) throws ElasticSearchException { + return clusterState.metaData().resolveSearchRouting(request.routing(), request.indices()); + } + @Override protected DeleteByQueryRequest newRequestInstance() { return new DeleteByQueryRequest(); diff --git a/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java b/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java index da3a8f25665..84c9cd8a6eb 100644 --- a/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java +++ b/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java @@ -34,7 +34,7 @@ import java.io.IOException; /** * Explain request encapsulating the explain query and document identifier to get an explanation for. */ -public class ExplainRequest extends SingleShardOperationRequest { +public class ExplainRequest extends SingleShardOperationRequest { private static final XContentType contentType = Requests.CONTENT_TYPE; @@ -57,11 +57,6 @@ public class ExplainRequest extends SingleShardOperationRequest { this.id = id; } - public ExplainRequest index(String index) { - this.index = index; - return this; - } - public String type() { return type; } @@ -147,18 +142,6 @@ public class ExplainRequest extends SingleShardOperationRequest { this.filteringAlias = filteringAlias; } - @Override - public ExplainRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - @Override - public ExplainRequest operationThreaded(boolean threadedOperation) { - super.operationThreaded(threadedOperation); - return this; - } - @Override protected void beforeLocalFork() { if (sourceUnsafe) { diff --git a/src/main/java/org/elasticsearch/action/explain/ExplainRequestBuilder.java b/src/main/java/org/elasticsearch/action/explain/ExplainRequestBuilder.java index 820b93307c5..46b471be65a 100644 --- a/src/main/java/org/elasticsearch/action/explain/ExplainRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/explain/ExplainRequestBuilder.java @@ -20,35 +20,25 @@ package org.elasticsearch.action.explain; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.single.shard.SingleShardOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.index.query.QueryBuilder; /** * A builder for {@link ExplainRequest}. */ -public class ExplainRequestBuilder extends BaseRequestBuilder { +public class ExplainRequestBuilder extends SingleShardOperationRequestBuilder { private ExplainSourceBuilder sourceBuilder; ExplainRequestBuilder(Client client) { - super(client, new ExplainRequest()); + super((InternalClient) client, new ExplainRequest()); } public ExplainRequestBuilder(Client client, String index, String type, String id) { - super(client, new ExplainRequest()); - request().index(index); - request().type(type); - request().id(id); - } - - /** - * Sets the index to get a score explanation for. - */ - public ExplainRequestBuilder setIndex(String index) { - request().index(index); - return this; + super((InternalClient) client, new ExplainRequest().index(index).type(type).id(id)); } /** @@ -136,7 +126,7 @@ public class ExplainRequestBuilder extends BaseRequestBuilder { protected String type; protected String id; @@ -91,15 +91,6 @@ public class GetRequest extends SingleShardOperationRequest { return validationException; } - /** - * Sets the index of the document to fetch. - */ - @Required - public GetRequest index(String index) { - this.index = index; - return this; - } - /** * Sets the type of the document to fetch. */ @@ -206,43 +197,19 @@ public class GetRequest extends SingleShardOperationRequest { return this; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public GetRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - /** - * Controls if the operation will be executed on a separate thread when executed locally. - */ - @Override - public GetRequest operationThreaded(boolean threadedOperation) { - super.operationThreaded(threadedOperation); - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - - type = in.readUTF(); - id = in.readUTF(); - if (in.readBoolean()) { - routing = in.readUTF(); - } - if (in.readBoolean()) { - preference = in.readUTF(); - } - + type = in.readString(); + id = in.readString(); + routing = in.readOptionalString(); + preference = in.readOptionalString(); refresh = in.readBoolean(); int size = in.readInt(); if (size >= 0) { fields = new String[size]; for (int i = 0; i < size; i++) { - fields[i] = in.readUTF(); + fields[i] = in.readString(); } } byte realtime = in.readByte(); @@ -256,21 +223,10 @@ public class GetRequest extends SingleShardOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - - out.writeUTF(type); - out.writeUTF(id); - if (routing == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(routing); - } - if (preference == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(preference); - } + out.writeString(type); + out.writeString(id); + out.writeOptionalString(routing); + out.writeOptionalString(preference); out.writeBoolean(refresh); if (fields == null) { @@ -278,7 +234,7 @@ public class GetRequest extends SingleShardOperationRequest { } else { out.writeInt(fields.length); for (String field : fields) { - out.writeUTF(field); + out.writeString(field); } } if (realtime == null) { diff --git a/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java b/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java index d43c27e4ef5..39993db9443 100644 --- a/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/get/GetRequestBuilder.java @@ -20,29 +20,22 @@ package org.elasticsearch.action.get; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.single.shard.SingleShardOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.Nullable; /** * A get document action request builder. */ -public class GetRequestBuilder extends BaseRequestBuilder { +public class GetRequestBuilder extends SingleShardOperationRequestBuilder { public GetRequestBuilder(Client client) { - super(client, new GetRequest()); + super((InternalClient) client, new GetRequest()); } public GetRequestBuilder(Client client, @Nullable String index) { - super(client, new GetRequest(index)); - } - - /** - * Sets the index of the document to fetch. - */ - public GetRequestBuilder setIndex(String index) { - request.index(index); - return this; + super((InternalClient) client, new GetRequest(index)); } /** @@ -114,24 +107,8 @@ public class GetRequestBuilder extends BaseRequestBuilder listener) { - client.get(request, listener); + ((Client) client).get(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java b/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java index 65bbde08e25..d88761363c3 100644 --- a/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java +++ b/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java @@ -36,7 +36,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class MultiGetRequest implements ActionRequest { +public class MultiGetRequest extends ActionRequest { /** * A single get item. @@ -173,17 +173,6 @@ public class MultiGetRequest implements ActionRequest { return this; } - @Override - public boolean listenerThreaded() { - return listenerThreaded; - } - - @Override - public MultiGetRequest listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return this; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -305,9 +294,8 @@ public class MultiGetRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { - if (in.readBoolean()) { - preference = in.readUTF(); - } + super.readFrom(in); + preference = in.readOptionalString(); refresh = in.readBoolean(); byte realtime = in.readByte(); if (realtime == 0) { @@ -325,12 +313,8 @@ public class MultiGetRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { - if (preference == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(preference); - } + super.writeTo(out); + out.writeOptionalString(preference); out.writeBoolean(refresh); if (realtime == null) { out.writeByte((byte) -1); diff --git a/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java b/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java index 39fe159d41a..0d79537ac8e 100644 --- a/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/get/MultiGetRequestBuilder.java @@ -20,17 +20,18 @@ package org.elasticsearch.action.get; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.Nullable; /** * A multi get document action request builder. */ -public class MultiGetRequestBuilder extends BaseRequestBuilder { +public class MultiGetRequestBuilder extends ActionRequestBuilder { public MultiGetRequestBuilder(Client client) { - super(client, new MultiGetRequest()); + super((InternalClient) client, new MultiGetRequest()); } public MultiGetRequestBuilder add(String index, @Nullable String type, String id) { @@ -82,16 +83,8 @@ public class MultiGetRequestBuilder extends BaseRequestBuilder listener) { - client.multiGet(request, listener); + ((Client) client).multiGet(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/get/MultiGetShardRequest.java b/src/main/java/org/elasticsearch/action/get/MultiGetShardRequest.java index e2b272e328d..c5d807938dd 100644 --- a/src/main/java/org/elasticsearch/action/get/MultiGetShardRequest.java +++ b/src/main/java/org/elasticsearch/action/get/MultiGetShardRequest.java @@ -29,7 +29,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class MultiGetShardRequest extends SingleShardOperationRequest { +public class MultiGetShardRequest extends SingleShardOperationRequest { private int shardId; private String preference; @@ -108,16 +108,16 @@ public class MultiGetShardRequest extends SingleShardOperationRequest { for (int i = 0; i < size; i++) { locations.add(in.readVInt()); if (in.readBoolean()) { - types.add(in.readUTF()); + types.add(in.readString()); } else { types.add(null); } - ids.add(in.readUTF()); + ids.add(in.readString()); int size1 = in.readVInt(); if (size1 > 0) { String[] fields = new String[size1]; for (int j = 0; j < size1; j++) { - fields[j] = in.readUTF(); + fields[j] = in.readString(); } this.fields.add(fields); } else { @@ -125,9 +125,7 @@ public class MultiGetShardRequest extends SingleShardOperationRequest { } } - if (in.readBoolean()) { - preference = in.readUTF(); - } + preference = in.readOptionalString(); refresh = in.readBoolean(); byte realtime = in.readByte(); if (realtime == 0) { @@ -147,25 +145,20 @@ public class MultiGetShardRequest extends SingleShardOperationRequest { out.writeBoolean(false); } else { out.writeBoolean(true); - out.writeUTF(types.get(i)); + out.writeString(types.get(i)); } - out.writeUTF(ids.get(i)); + out.writeString(ids.get(i)); if (fields.get(i) == null) { out.writeVInt(0); } else { out.writeVInt(fields.get(i).length); for (String field : fields.get(i)) { - out.writeUTF(field); + out.writeString(field); } } } - if (preference == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(preference); - } + out.writeOptionalString(preference); out.writeBoolean(refresh); if (realtime == null) { out.writeByte((byte) -1); diff --git a/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/src/main/java/org/elasticsearch/action/index/IndexRequest.java index b4ef4ded5d2..3e4b014cd1c 100644 --- a/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -26,8 +26,6 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.RoutingMissingException; -import org.elasticsearch.action.WriteConsistencyLevel; -import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.action.support.replication.ShardReplicationOperationRequest; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.metadata.MappingMetaData; @@ -39,7 +37,6 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.*; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; @@ -66,7 +63,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; * @see org.elasticsearch.client.Requests#indexRequest(String) * @see org.elasticsearch.client.Client#index(IndexRequest) */ -public class IndexRequest extends ShardReplicationOperationRequest { +public class IndexRequest extends ShardReplicationOperationRequest { /** * Operation type controls if the type of the index operation. @@ -177,15 +174,6 @@ public class IndexRequest extends ShardReplicationOperationRequest { safeSource(); } - /** - * Sets the index the index operation will happen on. - */ - @Override - public IndexRequest index(String index) { - super.index(index); - return this; - } - /** * Sets the content type that will be used when generating a document from user provided objects (like Map). */ @@ -194,25 +182,6 @@ public class IndexRequest extends ShardReplicationOperationRequest { return this; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public IndexRequest listenerThreaded(boolean threadedListener) { - super.listenerThreaded(threadedListener); - return this; - } - - /** - * Controls if the operation will be executed on a separate thread when executed locally. Defaults - * to true when running in embedded mode. - */ - @Override - public IndexRequest operationThreaded(boolean threadedOperation) { - super.operationThreaded(threadedOperation); - return this; - } - /** * The type of the indexed document. */ @@ -468,21 +437,6 @@ public class IndexRequest extends ShardReplicationOperationRequest { return this; } - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public IndexRequest timeout(TimeValue timeout) { - this.timeout = timeout; - return this; - } - - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public IndexRequest timeout(String timeout) { - return timeout(TimeValue.parseTimeValue(timeout, null)); - } - /** * Sets the type of operation to perform. */ @@ -505,32 +459,6 @@ public class IndexRequest extends ShardReplicationOperationRequest { } } - /** - * Set the replication type for this operation. - */ - @Override - public IndexRequest replicationType(ReplicationType replicationType) { - super.replicationType(replicationType); - return this; - } - - /** - * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} - */ - @Override - public IndexRequest consistencyLevel(WriteConsistencyLevel consistencyLevel) { - super.consistencyLevel(consistencyLevel); - return this; - } - - /** - * Set the replication type for this operation. - */ - public IndexRequest replicationType(String replicationType) { - super.replicationType(ReplicationType.fromString(replicationType)); - return this; - } - /** * Set to true to force this index to use {@link OpType#CREATE}. */ @@ -662,19 +590,11 @@ public class IndexRequest extends ShardReplicationOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - type = in.readUTF(); - if (in.readBoolean()) { - id = in.readUTF(); - } - if (in.readBoolean()) { - routing = in.readUTF(); - } - if (in.readBoolean()) { - parent = in.readUTF(); - } - if (in.readBoolean()) { - timestamp = in.readUTF(); - } + type = in.readString(); + id = in.readOptionalString(); + routing = in.readOptionalString(); + parent = in.readOptionalString(); + timestamp = in.readOptionalString(); ttl = in.readLong(); source = in.readBytesReference(); sourceUnsafe = false; @@ -682,51 +602,24 @@ public class IndexRequest extends ShardReplicationOperationRequest { opType = OpType.fromId(in.readByte()); refresh = in.readBoolean(); version = in.readLong(); - if (in.readBoolean()) { - percolate = in.readUTF(); - } + percolate = in.readOptionalString(); versionType = VersionType.fromValue(in.readByte()); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(type); - if (id == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(id); - } - if (routing == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(routing); - } - if (parent == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(parent); - } - if (timestamp == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(timestamp); - } + out.writeString(type); + out.writeOptionalString(id); + out.writeOptionalString(routing); + out.writeOptionalString(parent); + out.writeOptionalString(timestamp); out.writeLong(ttl); out.writeBytesReference(source); out.writeByte(opType.id()); out.writeBoolean(refresh); out.writeLong(version); - if (percolate == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(percolate); - } + out.writeOptionalString(percolate); out.writeByte(versionType.getValue()); } diff --git a/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java b/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java index f013a88afa5..9311187e87d 100644 --- a/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java @@ -21,12 +21,12 @@ package org.elasticsearch.action.index; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.WriteConsistencyLevel; -import org.elasticsearch.action.support.BaseRequestBuilder; import org.elasticsearch.action.support.replication.ReplicationType; +import org.elasticsearch.action.support.replication.ShardReplicationOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.VersionType; @@ -36,22 +36,14 @@ import java.util.Map; /** * An index document action request builder. */ -public class IndexRequestBuilder extends BaseRequestBuilder { +public class IndexRequestBuilder extends ShardReplicationOperationRequestBuilder { public IndexRequestBuilder(Client client) { - super(client, new IndexRequest()); + super((InternalClient) client, new IndexRequest()); } public IndexRequestBuilder(Client client, @Nullable String index) { - super(client, new IndexRequest(index)); - } - - /** - * Sets the index to index the document to. - */ - public IndexRequestBuilder setIndex(String index) { - request.index(index); - return this; + super((InternalClient) client, new IndexRequest(index)); } /** @@ -218,22 +210,6 @@ public class IndexRequestBuilder extends BaseRequestBuilder1m. - */ - public IndexRequestBuilder setTimeout(TimeValue timeout) { - request.timeout(timeout); - return this; - } - - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public IndexRequestBuilder setTimeout(String timeout) { - request.timeout(timeout); - return this; - } - /** * Sets the type of operation to perform. */ @@ -334,25 +310,8 @@ public class IndexRequestBuilder extends BaseRequestBuildertrue when running in embedded mode. - */ - public IndexRequestBuilder setOperationThreaded(boolean operationThreaded) { - request.operationThreaded(operationThreaded); - return this; - } - @Override protected void doExecute(ActionListener listener) { - client.index(request, listener); + ((Client) client).index(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/index/IndexResponse.java b/src/main/java/org/elasticsearch/action/index/IndexResponse.java index 7cce896d115..5410d02bbc0 100644 --- a/src/main/java/org/elasticsearch/action/index/IndexResponse.java +++ b/src/main/java/org/elasticsearch/action/index/IndexResponse.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import java.io.IOException; import java.util.ArrayList; @@ -32,11 +31,10 @@ import java.util.List; /** * A response of an index operation, * - * * @see org.elasticsearch.action.index.IndexRequest * @see org.elasticsearch.client.Client#index(IndexRequest) */ -public class IndexResponse implements ActionResponse, Streamable { +public class IndexResponse implements ActionResponse { private String index; diff --git a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java index 3d80424b296..57cd5e9c07f 100644 --- a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java +++ b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java @@ -53,7 +53,7 @@ import static org.elasticsearch.search.Scroll.readScroll; * @see org.elasticsearch.client.Requests#moreLikeThisRequest(String) * @see org.elasticsearch.action.search.SearchResponse */ -public class MoreLikeThisRequest implements ActionRequest { +public class MoreLikeThisRequest extends ActionRequest { private static final XContentType contentType = Requests.CONTENT_TYPE; @@ -86,8 +86,6 @@ public class MoreLikeThisRequest implements ActionRequest { private BytesReference searchSource; private boolean searchSourceUnsafe; - private boolean threadedListener = false; - MoreLikeThisRequest() { } @@ -516,28 +514,12 @@ public class MoreLikeThisRequest implements ActionRequest { return validationException; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return threadedListener; - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public ActionRequest listenerThreaded(boolean listenerThreaded) { - this.threadedListener = listenerThreaded; - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { - index = in.readUTF(); - type = in.readUTF(); - id = in.readUTF(); + super.readFrom(in); + index = in.readString(); + type = in.readString(); + id = in.readString(); // no need to pass threading over the network, they are always false when coming throw a thread pool int size = in.readVInt(); if (size == 0) { @@ -576,7 +558,7 @@ public class MoreLikeThisRequest implements ActionRequest { } else { searchIndices = new String[size - 1]; for (int i = 0; i < searchIndices.length; i++) { - searchIndices[i] = in.readUTF(); + searchIndices[i] = in.readString(); } } size = in.readVInt(); @@ -587,7 +569,7 @@ public class MoreLikeThisRequest implements ActionRequest { } else { searchTypes = new String[size - 1]; for (int i = 0; i < searchTypes.length; i++) { - searchTypes[i] = in.readUTF(); + searchTypes[i] = in.readString(); } } if (in.readBoolean()) { @@ -603,15 +585,16 @@ public class MoreLikeThisRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(index); - out.writeUTF(type); - out.writeUTF(id); + super.writeTo(out); + out.writeString(index); + out.writeString(type); + out.writeString(id); if (fields == null) { out.writeVInt(0); } else { out.writeVInt(fields.length); for (String field : fields) { - out.writeUTF(field); + out.writeString(field); } } @@ -623,7 +606,7 @@ public class MoreLikeThisRequest implements ActionRequest { } else { out.writeVInt(stopWords.length); for (String stopWord : stopWords) { - out.writeUTF(stopWord); + out.writeString(stopWord); } } out.writeVInt(minDocFreq); @@ -637,14 +620,14 @@ public class MoreLikeThisRequest implements ActionRequest { out.writeBoolean(false); } else { out.writeBoolean(true); - out.writeUTF(searchQueryHint); + out.writeString(searchQueryHint); } if (searchIndices == null) { out.writeVInt(0); } else { out.writeVInt(searchIndices.length + 1); for (String index : searchIndices) { - out.writeUTF(index); + out.writeString(index); } } if (searchTypes == null) { @@ -652,7 +635,7 @@ public class MoreLikeThisRequest implements ActionRequest { } else { out.writeVInt(searchTypes.length + 1); for (String type : searchTypes) { - out.writeUTF(type); + out.writeString(type); } } if (searchScroll == null) { diff --git a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequestBuilder.java b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequestBuilder.java index 9c9ab4d91e3..12bba71b500 100644 --- a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequestBuilder.java @@ -21,10 +21,11 @@ package org.elasticsearch.action.mlt; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.action.support.BaseRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; @@ -33,14 +34,14 @@ import java.util.Map; /** */ -public class MoreLikeThisRequestBuilder extends BaseRequestBuilder { +public class MoreLikeThisRequestBuilder extends ActionRequestBuilder { public MoreLikeThisRequestBuilder(Client client) { - super(client, new MoreLikeThisRequest()); + super((InternalClient) client, new MoreLikeThisRequest()); } public MoreLikeThisRequestBuilder(Client client, String index, String type, String id) { - super(client, new MoreLikeThisRequest(index).type(type).id(id)); + super((InternalClient) client, new MoreLikeThisRequest(index).type(type).id(id)); } /** @@ -238,6 +239,6 @@ public class MoreLikeThisRequestBuilder extends BaseRequestBuilder listener) { - client.moreLikeThis(request, listener); + ((Client) client).moreLikeThis(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/percolate/PercolateRequest.java b/src/main/java/org/elasticsearch/action/percolate/PercolateRequest.java index f2a91d8d08b..45ae1d8594b 100644 --- a/src/main/java/org/elasticsearch/action/percolate/PercolateRequest.java +++ b/src/main/java/org/elasticsearch/action/percolate/PercolateRequest.java @@ -39,7 +39,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * */ -public class PercolateRequest extends SingleCustomOperationRequest { +public class PercolateRequest extends SingleCustomOperationRequest { private String index; private String type; @@ -146,16 +146,6 @@ public class PercolateRequest extends SingleCustomOperationRequest { return this; } - /** - * if this operation hits a node with a local relevant shard, should it be preferred - * to be executed on, or just do plain round robin. Defaults to true - */ - @Override - public PercolateRequest preferLocal(boolean preferLocal) { - super.preferLocal(preferLocal); - return this; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); @@ -174,8 +164,8 @@ public class PercolateRequest extends SingleCustomOperationRequest { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readUTF(); - type = in.readUTF(); + index = in.readString(); + type = in.readString(); sourceUnsafe = false; source = in.readBytesReference(); @@ -184,8 +174,8 @@ public class PercolateRequest extends SingleCustomOperationRequest { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeUTF(index); - out.writeUTF(type); + out.writeString(index); + out.writeString(type); out.writeBytesReference(source); } } diff --git a/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java b/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java index 4e81ba2175b..16672cf90bb 100644 --- a/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/percolate/PercolateRequestBuilder.java @@ -20,8 +20,9 @@ package org.elasticsearch.action.percolate; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; @@ -31,14 +32,14 @@ import java.util.Map; /** * */ -public class PercolateRequestBuilder extends BaseRequestBuilder { +public class PercolateRequestBuilder extends SingleCustomOperationRequestBuilder { public PercolateRequestBuilder(Client client) { - super(client, new PercolateRequest()); + super((InternalClient) client, new PercolateRequest()); } public PercolateRequestBuilder(Client client, String index, String type) { - super(client, new PercolateRequest(index, type)); + super((InternalClient) client, new PercolateRequest(index, type)); } /** @@ -146,35 +147,9 @@ public class PercolateRequestBuilder extends BaseRequestBuildertrue - */ - public PercolateRequestBuilder setPreferLocal(boolean preferLocal) { - request.preferLocal(preferLocal); - return this; - } - - /** - * Controls if the operation will be executed on a separate thread when executed locally. Defaults - * to true when running in embedded mode. - */ - public PercolateRequestBuilder setOperationThreaded(boolean operationThreaded) { - request.operationThreaded(operationThreaded); - return this; - } - @Override protected void doExecute(ActionListener listener) { - client.percolate(request, listener); + ((Client) client).percolate(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java b/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java index 4eaaa03c72b..e3671cfc78b 100644 --- a/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java +++ b/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java @@ -41,11 +41,10 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * A multi search API request. */ -public class MultiSearchRequest implements ActionRequest { +public class MultiSearchRequest extends ActionRequest { private List requests = Lists.newArrayList(); - private boolean listenerThreaded = false; private IgnoreIndices ignoreIndices = IgnoreIndices.DEFAULT; /** @@ -183,17 +182,6 @@ public class MultiSearchRequest implements ActionRequest { return validationException; } - @Override - public boolean listenerThreaded() { - return listenerThreaded; - } - - @Override - public MultiSearchRequest listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return this; - } - public IgnoreIndices ignoreIndices() { return ignoreIndices; } @@ -205,6 +193,7 @@ public class MultiSearchRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); int size = in.readVInt(); for (int i = 0; i < size; i++) { SearchRequest request = new SearchRequest(); @@ -215,6 +204,7 @@ public class MultiSearchRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeVInt(requests.size()); for (SearchRequest request : requests) { request.writeTo(out); diff --git a/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java b/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java index daa285b50fd..f0a3ce42d9d 100644 --- a/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/search/MultiSearchRequestBuilder.java @@ -20,23 +20,24 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; /** * A request builder for multiple search requests. */ -public class MultiSearchRequestBuilder extends BaseRequestBuilder { +public class MultiSearchRequestBuilder extends ActionRequestBuilder { public MultiSearchRequestBuilder(Client client) { - super(client, new MultiSearchRequest()); + super((InternalClient) client, new MultiSearchRequest()); } /** * Add a search request to execute. Note, the order is important, the search response will be returned in the * same order as the search requests. - * + *

* If ignoreIndices has been set on the search request, then the ignoreIndices of the multi search request * will not be used (if set). */ @@ -73,6 +74,6 @@ public class MultiSearchRequestBuilder extends BaseRequestBuilder listener) { - client.multiSearch(request, listener); + ((Client) client).multiSearch(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/src/main/java/org/elasticsearch/action/search/SearchRequest.java index f841db1e3a1..2ac914b8121 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -56,7 +56,7 @@ import static org.elasticsearch.search.Scroll.readScroll; * @see org.elasticsearch.client.Client#search(SearchRequest) * @see SearchResponse */ -public class SearchRequest implements ActionRequest { +public class SearchRequest extends ActionRequest { private static final XContentType contentType = Requests.CONTENT_TYPE; @@ -81,7 +81,6 @@ public class SearchRequest implements ActionRequest { private String[] types = Strings.EMPTY_ARRAY; - private boolean listenerThreaded = false; private SearchOperationThreading operationThreading = SearchOperationThreading.THREAD_PER_SHARD; private IgnoreIndices ignoreIndices = IgnoreIndices.DEFAULT; @@ -134,14 +133,6 @@ public class SearchRequest implements ActionRequest { public void beforeLocalFork() { } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return listenerThreaded; - } - /** * Sets the indices the search will be executed on. */ @@ -150,15 +141,6 @@ public class SearchRequest implements ActionRequest { return this; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public SearchRequest listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return this; - } - /** * Controls the the search operation threading model. */ @@ -473,23 +455,18 @@ public class SearchRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); operationThreading = SearchOperationThreading.fromId(in.readByte()); searchType = SearchType.fromId(in.readByte()); indices = new String[in.readVInt()]; for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); + indices[i] = in.readString(); } - if (in.readBoolean()) { - queryHint = in.readUTF(); - } - if (in.readBoolean()) { - routing = in.readUTF(); - } - if (in.readBoolean()) { - preference = in.readUTF(); - } + queryHint = in.readOptionalString(); + routing = in.readOptionalString(); + preference = in.readOptionalString(); if (in.readBoolean()) { scroll = readScroll(in); @@ -501,44 +478,24 @@ public class SearchRequest implements ActionRequest { extraSourceUnsafe = false; extraSource = in.readBytesReference(); - int typesSize = in.readVInt(); - if (typesSize > 0) { - types = new String[typesSize]; - for (int i = 0; i < typesSize; i++) { - types[i] = in.readUTF(); - } - } + types = in.readStringArray(); ignoreIndices = IgnoreIndices.fromId(in.readByte()); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeByte(operationThreading.id()); out.writeByte(searchType.id()); out.writeVInt(indices.length); for (String index : indices) { - out.writeUTF(index); + out.writeString(index); } - if (queryHint == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(queryHint); - } - if (routing == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(routing); - } - if (preference == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(preference); - } + out.writeOptionalString(queryHint); + out.writeOptionalString(routing); + out.writeOptionalString(preference); if (scroll == null) { out.writeBoolean(false); @@ -548,10 +505,7 @@ public class SearchRequest implements ActionRequest { } out.writeBytesReference(source); out.writeBytesReference(extraSource); - out.writeVInt(types.length); - for (String type : types) { - out.writeUTF(type); - } + out.writeStringArray(types); out.writeByte(ignoreIndices.id()); } } diff --git a/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java b/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java index 01eaf35b330..632d9450f64 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -21,9 +21,10 @@ package org.elasticsearch.action.search; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.support.IgnoreIndices; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.unit.TimeValue; @@ -42,12 +43,12 @@ import java.util.Map; /** * A search action request builder. */ -public class SearchRequestBuilder extends BaseRequestBuilder { +public class SearchRequestBuilder extends ActionRequestBuilder { private SearchSourceBuilder sourceBuilder; public SearchRequestBuilder(Client client) { - super(client, new SearchRequest()); + super((InternalClient) client, new SearchRequest()); } /** @@ -176,14 +177,6 @@ public class SearchRequestBuilder extends BaseRequestBuilder { private String scrollId; private Scroll scroll; - private boolean listenerThreaded = false; private SearchOperationThreading operationThreading = SearchOperationThreading.THREAD_PER_SHARD; public SearchScrollRequest() { @@ -74,23 +73,6 @@ public class SearchScrollRequest implements ActionRequest { return this; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return listenerThreaded; - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public SearchScrollRequest listenerThreaded(boolean threadedListener) { - this.listenerThreaded = threadedListener; - return this; - } - /** * The scroll id used to scroll the search. */ @@ -134,8 +116,9 @@ public class SearchScrollRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); operationThreading = SearchOperationThreading.fromId(in.readByte()); - scrollId = in.readUTF(); + scrollId = in.readString(); if (in.readBoolean()) { scroll = readScroll(in); } @@ -143,8 +126,9 @@ public class SearchScrollRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeByte(operationThreading.id()); - out.writeUTF(scrollId); + out.writeString(scrollId); if (scroll == null) { out.writeBoolean(false); } else { diff --git a/src/main/java/org/elasticsearch/action/search/SearchScrollRequestBuilder.java b/src/main/java/org/elasticsearch/action/search/SearchScrollRequestBuilder.java index 4e12d64aa33..7f4fdef1098 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchScrollRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/search/SearchScrollRequestBuilder.java @@ -20,22 +20,23 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.BaseRequestBuilder; +import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.search.Scroll; /** * A search scroll action request builder. */ -public class SearchScrollRequestBuilder extends BaseRequestBuilder { +public class SearchScrollRequestBuilder extends ActionRequestBuilder { public SearchScrollRequestBuilder(Client client) { - super(client, new SearchScrollRequest()); + super((InternalClient) client, new SearchScrollRequest()); } public SearchScrollRequestBuilder(Client client, String scrollId) { - super(client, new SearchScrollRequest(scrollId)); + super((InternalClient) client, new SearchScrollRequest(scrollId)); } /** @@ -88,6 +89,6 @@ public class SearchScrollRequestBuilder extends BaseRequestBuilder listener) { - client.searchScroll(request, listener); + ((Client) client).searchScroll(request, listener); } } diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchCountAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchCountAction.java index 5dd81bd722f..030d69cff69 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchCountAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchCountAction.java @@ -34,8 +34,8 @@ import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.controller.ShardDoc; import org.elasticsearch.search.fetch.FetchSearchResultProvider; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; @@ -74,7 +74,7 @@ public class TransportSearchCountAction extends TransportSearchTypeAction { } @Override - protected void sendExecuteFirstPhase(DiscoveryNode node, InternalSearchRequest request, SearchServiceListener listener) { + protected void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener) { searchService.sendExecuteQuery(node, request, listener); } diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java index 3f2aa17e33f..221dc454a8a 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java @@ -33,8 +33,8 @@ import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.QueryFetchSearchResult; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.threadpool.ThreadPool; @@ -77,7 +77,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc } @Override - protected void sendExecuteFirstPhase(DiscoveryNode node, InternalSearchRequest request, SearchServiceListener listener) { + protected void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener) { searchService.sendExecuteDfs(node, request, listener); } @@ -97,7 +97,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc if (node.id().equals(nodes.localNodeId())) { localOperations++; } else { - QuerySearchRequest querySearchRequest = new QuerySearchRequest(dfsResult.id(), dfs); + QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); executeSecondPhase(dfsResult, counter, node, querySearchRequest); } } @@ -109,7 +109,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc for (final DfsSearchResult dfsResult : dfsResults) { DiscoveryNode node = nodes.get(dfsResult.shardTarget().nodeId()); if (node.id().equals(nodes.localNodeId())) { - QuerySearchRequest querySearchRequest = new QuerySearchRequest(dfsResult.id(), dfs); + QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); executeSecondPhase(dfsResult, counter, node, querySearchRequest); } } @@ -120,7 +120,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc for (final DfsSearchResult dfsResult : dfsResults) { final DiscoveryNode node = nodes.get(dfsResult.shardTarget().nodeId()); if (node.id().equals(nodes.localNodeId())) { - final QuerySearchRequest querySearchRequest = new QuerySearchRequest(dfsResult.id(), dfs); + final QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); if (localAsync) { threadPool.executor(ThreadPool.Names.SEARCH).execute(new Runnable() { @Override diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java index 53a0aee72c9..ff43951f0d1 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java @@ -35,8 +35,8 @@ import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.FetchSearchRequest; import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; @@ -82,7 +82,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA } @Override - protected void sendExecuteFirstPhase(DiscoveryNode node, InternalSearchRequest request, SearchServiceListener listener) { + protected void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener) { searchService.sendExecuteDfs(node, request, listener); } @@ -103,7 +103,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA if (node.id().equals(nodes.localNodeId())) { localOperations++; } else { - QuerySearchRequest querySearchRequest = new QuerySearchRequest(dfsResult.id(), dfs); + QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); executeQuery(dfsResult, counter, querySearchRequest, node); } } @@ -116,7 +116,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA for (final DfsSearchResult dfsResult : dfsResults) { DiscoveryNode node = nodes.get(dfsResult.shardTarget().nodeId()); if (node.id().equals(nodes.localNodeId())) { - QuerySearchRequest querySearchRequest = new QuerySearchRequest(dfsResult.id(), dfs); + QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); executeQuery(dfsResult, counter, querySearchRequest, node); } } @@ -127,7 +127,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA for (final DfsSearchResult dfsResult : dfsResults) { final DiscoveryNode node = nodes.get(dfsResult.shardTarget().nodeId()); if (node.id().equals(nodes.localNodeId())) { - final QuerySearchRequest querySearchRequest = new QuerySearchRequest(dfsResult.id(), dfs); + final QuerySearchRequest querySearchRequest = new QuerySearchRequest(request, dfsResult.id(), dfs); if (localAsync) { threadPool.executor(ThreadPool.Names.SEARCH).execute(new Runnable() { @Override @@ -194,7 +194,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA if (node.id().equals(nodes.localNodeId())) { localOperations++; } else { - FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(entry.getKey()).id(), entry.getValue()); + FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(entry.getKey()).id(), entry.getValue()); executeFetch(entry.getKey(), counter, fetchSearchRequest, node); } } @@ -207,7 +207,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA for (final Map.Entry entry : docIdsToLoad.entrySet()) { DiscoveryNode node = nodes.get(entry.getKey().nodeId()); if (node.id().equals(nodes.localNodeId())) { - FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(entry.getKey()).id(), entry.getValue()); + FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(entry.getKey()).id(), entry.getValue()); executeFetch(entry.getKey(), counter, fetchSearchRequest, node); } } @@ -218,7 +218,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA for (final Map.Entry entry : docIdsToLoad.entrySet()) { final DiscoveryNode node = nodes.get(entry.getKey().nodeId()); if (node.id().equals(nodes.localNodeId())) { - final FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(entry.getKey()).id(), entry.getValue()); + final FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(entry.getKey()).id(), entry.getValue()); if (localAsync) { threadPool.executor(ThreadPool.Names.SEARCH).execute(new Runnable() { @Override diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java index a345c95ba62..ea7ef97e283 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java @@ -34,7 +34,7 @@ import org.elasticsearch.common.Unicode; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.search.SearchPhaseResult; import org.elasticsearch.search.internal.InternalScrollSearchRequest; -import org.elasticsearch.search.internal.InternalSearchRequest; +import org.elasticsearch.search.internal.ShardSearchRequest; import java.io.IOException; import java.util.Collection; @@ -45,22 +45,15 @@ import java.util.Map; */ public abstract class TransportSearchHelper { - - public static InternalSearchRequest internalSearchRequest(ShardRouting shardRouting, int numberOfShards, SearchRequest request, String[] filteringAliases, long nowInMillis) { - InternalSearchRequest internalRequest = new InternalSearchRequest(shardRouting, numberOfShards, request.searchType()); - internalRequest.source(request.source()); - internalRequest.extraSource(request.extraSource()); - internalRequest.scroll(request.scroll()); - internalRequest.filteringAliases(filteringAliases); - internalRequest.types(request.types()); - internalRequest.nowInMillis(nowInMillis); - return internalRequest; + public static ShardSearchRequest internalSearchRequest(ShardRouting shardRouting, int numberOfShards, SearchRequest request, String[] filteringAliases, long nowInMillis) { + ShardSearchRequest shardRequest = new ShardSearchRequest(request, shardRouting, numberOfShards); + shardRequest.filteringAliases(filteringAliases); + shardRequest.nowInMillis(nowInMillis); + return shardRequest; } public static InternalScrollSearchRequest internalScrollSearchRequest(long id, SearchScrollRequest request) { - InternalScrollSearchRequest internalRequest = new InternalScrollSearchRequest(id); - internalRequest.scroll(request.scroll()); - return internalRequest; + return new InternalScrollSearchRequest(request, id); } public static String buildScrollId(SearchType searchType, Collection searchPhaseResults, @Nullable Map attributes) throws IOException { diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java index 92665a0d7f9..2f2ddd889d0 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java @@ -32,8 +32,8 @@ import org.elasticsearch.search.action.SearchServiceListener; import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.QueryFetchSearchResult; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.threadpool.ThreadPool; import java.util.Map; @@ -71,7 +71,7 @@ public class TransportSearchQueryAndFetchAction extends TransportSearchTypeActio } @Override - protected void sendExecuteFirstPhase(DiscoveryNode node, InternalSearchRequest request, SearchServiceListener listener) { + protected void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener) { searchService.sendExecuteFetch(node, request, listener); } diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java index b4ef8124a8a..eaad04749ba 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java @@ -33,8 +33,8 @@ import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.fetch.FetchSearchRequest; import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; @@ -76,7 +76,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi } @Override - protected void sendExecuteFirstPhase(DiscoveryNode node, InternalSearchRequest request, SearchServiceListener listener) { + protected void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener) { searchService.sendExecuteQuery(node, request, listener); } @@ -104,7 +104,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi if (node.id().equals(nodes.localNodeId())) { localOperations++; } else { - FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(entry.getKey()).id(), entry.getValue()); + FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(entry.getKey()).id(), entry.getValue()); executeFetch(entry.getKey(), counter, fetchSearchRequest, node); } } @@ -117,7 +117,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi for (final Map.Entry entry : docIdsToLoad.entrySet()) { DiscoveryNode node = nodes.get(entry.getKey().nodeId()); if (node.id().equals(nodes.localNodeId())) { - FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(entry.getKey()).id(), entry.getValue()); + FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(entry.getKey()).id(), entry.getValue()); executeFetch(entry.getKey(), counter, fetchSearchRequest, node); } } @@ -128,7 +128,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi for (final Map.Entry entry : docIdsToLoad.entrySet()) { final DiscoveryNode node = nodes.get(entry.getKey().nodeId()); if (node.id().equals(nodes.localNodeId())) { - final FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(entry.getKey()).id(), entry.getValue()); + final FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(entry.getKey()).id(), entry.getValue()); if (localAsync) { threadPool.executor(ThreadPool.Names.SEARCH).execute(new Runnable() { @Override diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchScanAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchScanAction.java index 39e5612bf9a..8bf406b24c7 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchScanAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchScanAction.java @@ -34,8 +34,8 @@ import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.controller.ShardDoc; import org.elasticsearch.search.fetch.FetchSearchResultProvider; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; @@ -71,7 +71,7 @@ public class TransportSearchScanAction extends TransportSearchTypeAction { } @Override - protected void sendExecuteFirstPhase(DiscoveryNode node, InternalSearchRequest request, SearchServiceListener listener) { + protected void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener) { searchService.sendExecuteScan(node, request, listener); } diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java index 3f17d79b9ef..3576353f745 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java @@ -224,7 +224,7 @@ public class TransportSearchScrollQueryThenFetchAction extends AbstractComponent for (final Map.Entry entry : docIdsToLoad.entrySet()) { SearchShardTarget shardTarget = entry.getKey(); ExtTIntArrayList docIds = entry.getValue(); - FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(queryResults.get(shardTarget).id(), docIds); + FetchSearchRequest fetchSearchRequest = new FetchSearchRequest(request, queryResults.get(shardTarget).id(), docIds); DiscoveryNode node = nodes.get(shardTarget.nodeId()); searchService.sendExecuteFetch(node, fetchSearchRequest, new SearchServiceListener() { @Override diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java index b803f74cca1..38db8dc2a85 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java @@ -40,7 +40,7 @@ import org.elasticsearch.search.action.SearchServiceListener; import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.controller.ShardDoc; -import org.elasticsearch.search.internal.InternalSearchRequest; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; @@ -339,14 +339,14 @@ public abstract class TransportSearchTypeAction extends TransportAction listener); + protected abstract void sendExecuteFirstPhase(DiscoveryNode node, ShardSearchRequest request, SearchServiceListener listener); protected abstract void processFirstPhaseResult(ShardRouting shard, FirstResult result); diff --git a/src/main/java/org/elasticsearch/action/support/BaseRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/BaseRequestBuilder.java deleted file mode 100644 index f4a5d1c9a91..00000000000 --- a/src/main/java/org/elasticsearch/action/support/BaseRequestBuilder.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon 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.action.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.internal.InternalClient; - -/** - * - */ -public abstract class BaseRequestBuilder implements ActionRequestBuilder { - - protected final InternalClient client; - - protected final Request request; - - protected BaseRequestBuilder(Client client, Request request) { - this.client = (InternalClient) client; - this.request = request; - } - - public Request request() { - return this.request; - } - - @Override - public ListenableActionFuture execute() { - PlainListenableActionFuture future = new PlainListenableActionFuture(request.listenerThreaded(), client.threadPool()); - execute(future); - return future; - } - - @Override - public void execute(ActionListener listener) { - doExecute(listener); - } - - protected abstract void doExecute(ActionListener listener); -} diff --git a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java index 58a44cdbc43..d4c2dc3699b 100644 --- a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.support.broadcast; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.IgnoreIndices; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -31,12 +30,10 @@ import java.io.IOException; /** * */ -public abstract class BroadcastOperationRequest implements ActionRequest { +public abstract class BroadcastOperationRequest extends ActionRequest { protected String[] indices; - - private boolean listenerThreaded = false; private BroadcastOperationThreading operationThreading = BroadcastOperationThreading.SINGLE_THREAD; private IgnoreIndices ignoreIndices = IgnoreIndices.NONE; @@ -52,9 +49,10 @@ public abstract class BroadcastOperationRequest implements ActionRequest { return indices; } - public BroadcastOperationRequest indices(String... indices) { + @SuppressWarnings("unchecked") + public final T indices(String... indices) { this.indices = indices; - return this; + return (T) this; } @Override @@ -62,23 +60,6 @@ public abstract class BroadcastOperationRequest implements ActionRequest { return null; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return this.listenerThreaded; - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public BroadcastOperationRequest listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return this; - } - /** * Controls the operation threading model. */ @@ -89,15 +70,16 @@ public abstract class BroadcastOperationRequest implements ActionRequest { /** * Controls the operation threading model. */ - public BroadcastOperationRequest operationThreading(BroadcastOperationThreading operationThreading) { + @SuppressWarnings("unchecked") + public final T operationThreading(BroadcastOperationThreading operationThreading) { this.operationThreading = operationThreading; - return this; + return (T) this; } /** * Controls the operation threading model. */ - public BroadcastOperationRequest operationThreading(String operationThreading) { + public T operationThreading(String operationThreading) { return operationThreading(BroadcastOperationThreading.fromString(operationThreading, this.operationThreading)); } @@ -105,9 +87,10 @@ public abstract class BroadcastOperationRequest implements ActionRequest { return ignoreIndices; } - public BroadcastOperationRequest ignoreIndices(IgnoreIndices ignoreIndices) { + @SuppressWarnings("unchecked") + public final T ignoreIndices(IgnoreIndices ignoreIndices) { this.ignoreIndices = ignoreIndices; - return this; + return (T) this; } protected void beforeStart() { @@ -120,29 +103,16 @@ public abstract class BroadcastOperationRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { - if (indices == null) { - out.writeVInt(0); - } else { - out.writeVInt(indices.length); - for (String index : indices) { - out.writeUTF(index); - } - } + super.writeTo(out); + out.writeStringArrayNullable(indices); out.writeByte(operationThreading.id()); out.writeByte(ignoreIndices.id()); } @Override public void readFrom(StreamInput in) throws IOException { - int size = in.readVInt(); - if (size == 0) { - indices = Strings.EMPTY_ARRAY; - } else { - indices = new String[size]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); - } - } + super.readFrom(in); + indices = in.readStringArray(); operationThreading = BroadcastOperationThreading.fromId(in.readByte()); ignoreIndices = IgnoreIndices.fromId(in.readByte()); } diff --git a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java new file mode 100644 index 00000000000..1f309cd825e --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java @@ -0,0 +1,64 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.action.support.broadcast; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.support.IgnoreIndices; +import org.elasticsearch.client.internal.InternalGenericClient; + +/** + */ +public abstract class BroadcastOperationRequestBuilder, Response extends BroadcastOperationResponse, RequestBuilder extends BroadcastOperationRequestBuilder> + extends ActionRequestBuilder { + + protected BroadcastOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setIndices(String... indices) { + request.indices(indices); + return (RequestBuilder) this; + } + + /** + * Controls the operation threading model. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setOperationThreading(BroadcastOperationThreading operationThreading) { + request.operationThreading(operationThreading); + return (RequestBuilder) this; + } + + /** + * Controls the operation threading model. + */ + @SuppressWarnings("unchecked") + public RequestBuilder setOperationThreading(String operationThreading) { + request.operationThreading(operationThreading); + return (RequestBuilder) this; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setIgnoreIndices(IgnoreIndices ignoreIndices) { + request.ignoreIndices(ignoreIndices); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationRequest.java b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationRequest.java index 0ce7209d896..020b7f10c22 100644 --- a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastShardOperationRequest.java @@ -21,23 +21,23 @@ package org.elasticsearch.action.support.broadcast; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; /** * */ -public abstract class BroadcastShardOperationRequest implements Streamable { +public abstract class BroadcastShardOperationRequest extends TransportRequest { private String index; - private int shardId; protected BroadcastShardOperationRequest() { } - protected BroadcastShardOperationRequest(String index, int shardId) { + protected BroadcastShardOperationRequest(String index, int shardId, BroadcastOperationRequest request) { + super(request); this.index = index; this.shardId = shardId; } @@ -52,13 +52,15 @@ public abstract class BroadcastShardOperationRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { - index = in.readUTF(); + super.readFrom(in); + index = in.readString(); shardId = in.readVInt(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(index); + super.writeTo(out); + out.writeString(index); out.writeVInt(shardId); } } diff --git a/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java b/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java index 9ac53394c55..9b968b33c3e 100644 --- a/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequest.java @@ -29,50 +29,41 @@ import java.io.IOException; /** * A based request for master based operation. */ -public abstract class MasterNodeOperationRequest implements ActionRequest { +public abstract class MasterNodeOperationRequest extends ActionRequest { public static TimeValue DEFAULT_MASTER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30); protected TimeValue masterNodeTimeout = DEFAULT_MASTER_NODE_TIMEOUT; - @Override - public boolean listenerThreaded() { - // always threaded - return true; - } - - @Override - public MasterNodeOperationRequest listenerThreaded(boolean listenerThreaded) { - // really, does not mean anything in this case - return this; - } - /** * A timeout value in case the master has not been discovered yet or disconnected. */ - public MasterNodeOperationRequest masterNodeTimeout(TimeValue timeout) { + @SuppressWarnings("unchecked") + public final T masterNodeTimeout(TimeValue timeout) { this.masterNodeTimeout = timeout; - return this; + return (T) this; } /** * A timeout value in case the master has not been discovered yet or disconnected. */ - public MasterNodeOperationRequest masterNodeTimeout(String timeout) { + public final T masterNodeTimeout(String timeout) { return masterNodeTimeout(TimeValue.parseTimeValue(timeout, null)); } - public TimeValue masterNodeTimeout() { + public final TimeValue masterNodeTimeout() { return this.masterNodeTimeout; } @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); masterNodeTimeout = TimeValue.readTimeValue(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); masterNodeTimeout.writeTo(out); } } diff --git a/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java new file mode 100644 index 00000000000..7c29bef6ac5 --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/master/MasterNodeOperationRequestBuilder.java @@ -0,0 +1,54 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.action.support.master; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.client.internal.InternalGenericClient; +import org.elasticsearch.common.unit.TimeValue; + +/** + */ +public abstract class MasterNodeOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeOperationRequestBuilder> + extends ActionRequestBuilder { + + protected MasterNodeOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + /** + * Sets the master node timeout in case the master has not yet been discovered. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setMasterNodeTimeout(TimeValue timeout) { + request.masterNodeTimeout(timeout); + return (RequestBuilder) this; + } + + /** + * Sets the master node timeout in case the master has not yet been discovered. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setMasterNodeTimeout(String timeout) { + request.masterNodeTimeout(timeout); + return (RequestBuilder) this; + } + +} diff --git a/src/main/java/org/elasticsearch/action/support/nodes/NodeOperationRequest.java b/src/main/java/org/elasticsearch/action/support/nodes/NodeOperationRequest.java index f23f35700c4..0579ce9f22e 100644 --- a/src/main/java/org/elasticsearch/action/support/nodes/NodeOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/nodes/NodeOperationRequest.java @@ -21,14 +21,14 @@ package org.elasticsearch.action.support.nodes; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; /** * */ -public abstract class NodeOperationRequest implements Streamable { +public abstract class NodeOperationRequest extends TransportRequest { private String nodeId; @@ -36,17 +36,20 @@ public abstract class NodeOperationRequest implements Streamable { } - protected NodeOperationRequest(String nodeId) { + protected NodeOperationRequest(NodesOperationRequest request, String nodeId) { + super(request); this.nodeId = nodeId; } @Override public void readFrom(StreamInput in) throws IOException { - nodeId = in.readUTF(); + super.readFrom(in); + nodeId = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(nodeId); + super.writeTo(out); + out.writeString(nodeId); } } diff --git a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequest.java b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequest.java index d10e1456c0d..f6a08f9512f 100644 --- a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequest.java @@ -31,14 +31,12 @@ import java.io.IOException; /** * */ -public abstract class NodesOperationRequest implements ActionRequest { +public abstract class NodesOperationRequest extends ActionRequest { public static String[] ALL_NODES = Strings.EMPTY_ARRAY; private String[] nodesIds; - private boolean listenerThreaded = false; - private TimeValue timeout; protected NodesOperationRequest() { @@ -49,33 +47,30 @@ public abstract class NodesOperationRequest implements ActionRequest { this.nodesIds = nodesIds; } - @Override - public NodesOperationRequest listenerThreaded(boolean listenerThreaded) { - this.listenerThreaded = listenerThreaded; - return this; - } - - @Override - public boolean listenerThreaded() { - return this.listenerThreaded; - } - - public String[] nodesIds() { + public final String[] nodesIds() { return nodesIds; } - public NodesOperationRequest nodesIds(String... nodesIds) { + @SuppressWarnings("unchecked") + public final T nodesIds(String... nodesIds) { this.nodesIds = nodesIds; - return this; + return (T) this; } public TimeValue timeout() { return this.timeout; } - public NodesOperationRequest timeout(TimeValue timeout) { + @SuppressWarnings("unchecked") + public final T timeout(TimeValue timeout) { this.timeout = timeout; - return this; + return (T) this; + } + + @SuppressWarnings("unchecked") + public final T timeout(String timeout) { + this.timeout = TimeValue.parseTimeValue(timeout, null); + return (T) this; } @Override @@ -85,10 +80,8 @@ public abstract class NodesOperationRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { - nodesIds = new String[in.readVInt()]; - for (int i = 0; i < nodesIds.length; i++) { - nodesIds[i] = in.readUTF(); - } + super.readFrom(in); + nodesIds = in.readStringArray(); if (in.readBoolean()) { timeout = TimeValue.readTimeValue(in); } @@ -96,14 +89,8 @@ public abstract class NodesOperationRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { - if (nodesIds == null) { - out.writeVInt(0); - } else { - out.writeVInt(nodesIds.length); - for (String nodeId : nodesIds) { - out.writeUTF(nodeId); - } - } + super.writeTo(out); + out.writeStringArrayNullable(nodesIds); if (timeout == null) { out.writeBoolean(false); } else { diff --git a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java new file mode 100644 index 00000000000..bb5ca640189 --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java @@ -0,0 +1,52 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.action.support.nodes; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.client.internal.InternalGenericClient; +import org.elasticsearch.common.unit.TimeValue; + +/** + */ +public abstract class NodesOperationRequestBuilder, Response extends NodesOperationResponse, RequestBuilder extends NodesOperationRequestBuilder> + extends ActionRequestBuilder { + + protected NodesOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setNodesIds(String... nodesIds) { + request.nodesIds(nodesIds); + return (RequestBuilder) this; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(TimeValue timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(String timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/replication/IndexReplicationOperationRequest.java b/src/main/java/org/elasticsearch/action/support/replication/IndexReplicationOperationRequest.java index 130ed65cf66..d698bd7aba1 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/IndexReplicationOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/replication/IndexReplicationOperationRequest.java @@ -33,14 +33,12 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * */ -public class IndexReplicationOperationRequest implements ActionRequest { +public class IndexReplicationOperationRequest extends ActionRequest { protected TimeValue timeout = ShardReplicationOperationRequest.DEFAULT_TIMEOUT; protected String index; - private boolean threadedListener = false; - protected ReplicationType replicationType = ReplicationType.DEFAULT; protected WriteConsistencyLevel consistencyLevel = WriteConsistencyLevel.DEFAULT; @@ -52,14 +50,26 @@ public class IndexReplicationOperationRequest implements ActionRequest { return this.index; } - public IndexReplicationOperationRequest index(String index) { + @SuppressWarnings("unchecked") + public T index(String index) { this.index = index; - return this; + return (T) this; } - @Override - public boolean listenerThreaded() { - return this.threadedListener; + /** + * Sets the replication type. + */ + @SuppressWarnings("unchecked") + public T replicationType(ReplicationType replicationType) { + this.replicationType = replicationType; + return (T) this; + } + + /** + * Sets the replication type. + */ + public T replicationType(String replicationType) { + return replicationType(ReplicationType.fromString(replicationType)); } public ReplicationType replicationType() { @@ -70,10 +80,13 @@ public class IndexReplicationOperationRequest implements ActionRequest { return this.consistencyLevel; } - @Override - public IndexReplicationOperationRequest listenerThreaded(boolean threadedListener) { - this.threadedListener = threadedListener; - return this; + /** + * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} + */ + @SuppressWarnings("unchecked") + public T consistencyLevel(WriteConsistencyLevel consistencyLevel) { + this.consistencyLevel = consistencyLevel; + return (T) this; } @Override @@ -87,17 +100,19 @@ public class IndexReplicationOperationRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); replicationType = ReplicationType.fromId(in.readByte()); consistencyLevel = WriteConsistencyLevel.fromId(in.readByte()); timeout = TimeValue.readTimeValue(in); - index = in.readUTF(); + index = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeByte(replicationType.id()); out.writeByte(consistencyLevel.id()); timeout.writeTo(out); - out.writeUTF(index); + out.writeString(index); } } diff --git a/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequest.java b/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequest.java index bac676de527..f51cb1ef725 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequest.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.support.replication; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.WriteConsistencyLevel; -import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; @@ -32,17 +31,10 @@ import java.io.IOException; /** * */ -public class IndicesReplicationOperationRequest implements ActionRequest { +public class IndicesReplicationOperationRequest extends ActionRequest { protected TimeValue timeout = ShardReplicationOperationRequest.DEFAULT_TIMEOUT; - protected String[] indices; - - private boolean threadedListener = false; - @Nullable - private String routing; - - protected ReplicationType replicationType = ReplicationType.DEFAULT; protected WriteConsistencyLevel consistencyLevel = WriteConsistencyLevel.DEFAULT; @@ -50,13 +42,68 @@ public class IndicesReplicationOperationRequest implements ActionRequest { return timeout; } + /** + * A timeout to wait if the delete by query operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final T timeout(TimeValue timeout) { + this.timeout = timeout; + return (T) this; + } + + /** + * A timeout to wait if the delete by query operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public T timeout(String timeout) { + this.timeout = TimeValue.parseTimeValue(timeout, null); + return (T) this; + } + public String[] indices() { return this.indices; } - public IndicesReplicationOperationRequest indices(String[] indices) { + /** + * The indices the request will execute against. + */ + @SuppressWarnings("unchecked") + public final T indices(String[] indices) { this.indices = indices; - return this; + return (T) this; + } + + public ReplicationType replicationType() { + return this.replicationType; + } + + /** + * Sets the replication type. + */ + @SuppressWarnings("unchecked") + public final T replicationType(ReplicationType replicationType) { + this.replicationType = replicationType; + return (T) this; + } + + /** + * Sets the replication type. + */ + public final T replicationType(String replicationType) { + return replicationType(ReplicationType.fromString(replicationType)); + } + + public WriteConsistencyLevel consistencyLevel() { + return this.consistencyLevel; + } + + /** + * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} + */ + @SuppressWarnings("unchecked") + public final T consistencyLevel(WriteConsistencyLevel consistencyLevel) { + this.consistencyLevel = consistencyLevel; + return (T) this; } @Override @@ -64,54 +111,21 @@ public class IndicesReplicationOperationRequest implements ActionRequest { return null; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return this.threadedListener; - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public IndicesReplicationOperationRequest listenerThreaded(boolean threadedListener) { - this.threadedListener = threadedListener; - return this; - } - - public ReplicationType replicationType() { - return this.replicationType; - } - - public WriteConsistencyLevel consistencyLevel() { - return this.consistencyLevel; - } - - public String routing() { - return null; - } - @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); replicationType = ReplicationType.fromId(in.readByte()); consistencyLevel = WriteConsistencyLevel.fromId(in.readByte()); timeout = TimeValue.readTimeValue(in); - indices = new String[in.readVInt()]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readUTF(); - } + indices = in.readStringArray(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeByte(replicationType.id()); out.writeByte(consistencyLevel.id()); timeout.writeTo(out); - out.writeVInt(indices.length); - for (String index : indices) { - out.writeUTF(index); - } + out.writeStringArrayNullable(indices); } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequestBuilder.java new file mode 100644 index 00000000000..9bd7553d636 --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/replication/IndicesReplicationOperationRequestBuilder.java @@ -0,0 +1,87 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.action.support.replication; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.WriteConsistencyLevel; +import org.elasticsearch.client.internal.InternalGenericClient; +import org.elasticsearch.common.unit.TimeValue; + +/** + */ +public abstract class IndicesReplicationOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends IndicesReplicationOperationRequestBuilder> + extends ActionRequestBuilder { + + protected IndicesReplicationOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(TimeValue timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(String timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setIndices(String... indices) { + request.indices(indices); + return (RequestBuilder) this; + } + + /** + * Sets the replication type. + */ + @SuppressWarnings("unchecked") + public RequestBuilder setReplicationType(ReplicationType replicationType) { + request.replicationType(replicationType); + return (RequestBuilder) this; + } + + /** + * Sets the replication type. + */ + @SuppressWarnings("unchecked") + public RequestBuilder setReplicationType(String replicationType) { + request.replicationType(replicationType); + return (RequestBuilder) this; + } + + /** + * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} + */ + @SuppressWarnings("unchecked") + public RequestBuilder setConsistencyLevel(WriteConsistencyLevel consistencyLevel) { + request.consistencyLevel(consistencyLevel); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java index b0a30e8fc10..970063a1df8 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequest.java @@ -34,8 +34,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; /** * */ -public abstract class ShardReplicationOperationRequest implements ActionRequest { - +public abstract class ShardReplicationOperationRequest extends ActionRequest { public static final TimeValue DEFAULT_TIMEOUT = new TimeValue(1, TimeUnit.MINUTES); @@ -43,11 +42,60 @@ public abstract class ShardReplicationOperationRequest implements ActionRequest protected String index; - private boolean threadedListener = false; private boolean threadedOperation = true; private ReplicationType replicationType = ReplicationType.DEFAULT; private WriteConsistencyLevel consistencyLevel = WriteConsistencyLevel.DEFAULT; + protected ShardReplicationOperationRequest() { + + } + + public ShardReplicationOperationRequest(ActionRequest request) { + super(request); + } + + public ShardReplicationOperationRequest(T request) { + super(request); + this.timeout = request.timeout(); + this.index = request.index(); + this.threadedOperation = request.threadedOperation; + this.replicationType = request.replicationType(); + this.consistencyLevel = request.consistencyLevel(); + } + + /** + * Controls if the operation will be executed on a separate thread when executed locally. + */ + public final boolean operationThreaded() { + return threadedOperation; + } + + /** + * Controls if the operation will be executed on a separate thread when executed locally. Defaults + * to true when running in embedded mode. + */ + @SuppressWarnings("unchecked") + public final T operationThreaded(boolean threadedOperation) { + this.threadedOperation = threadedOperation; + return (T) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final T timeout(TimeValue timeout) { + this.timeout = timeout; + return (T) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + public final T timeout(String timeout) { + return timeout(TimeValue.parseTimeValue(timeout, null)); + } + public TimeValue timeout() { return timeout; } @@ -56,56 +104,10 @@ public abstract class ShardReplicationOperationRequest implements ActionRequest return this.index; } - public ShardReplicationOperationRequest index(String index) { + @SuppressWarnings("unchecked") + public final T index(String index) { this.index = index; - return this; - } - - protected ShardReplicationOperationRequest() { - - } - - public ShardReplicationOperationRequest(ShardReplicationOperationRequest request) { - this.timeout = request.timeout(); - this.index = request.index(); - this.threadedListener = request.threadedListener; - this.threadedOperation = request.threadedOperation; - this.replicationType = request.replicationType(); - this.consistencyLevel = request.consistencyLevel(); - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return threadedListener; - } - - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public ShardReplicationOperationRequest listenerThreaded(boolean threadedListener) { - this.threadedListener = threadedListener; - return this; - } - - - /** - * Controls if the operation will be executed on a separate thread when executed locally. - */ - public boolean operationThreaded() { - return threadedOperation; - } - - /** - * Controls if the operation will be executed on a separate thread when executed locally. Defaults - * to true when running in embedded mode. - */ - public ShardReplicationOperationRequest operationThreaded(boolean threadedOperation) { - this.threadedOperation = threadedOperation; - return this; + return (T) this; } /** @@ -118,18 +120,30 @@ public abstract class ShardReplicationOperationRequest implements ActionRequest /** * Sets the replication type. */ - public ShardReplicationOperationRequest replicationType(ReplicationType replicationType) { + @SuppressWarnings("unchecked") + public final T replicationType(ReplicationType replicationType) { this.replicationType = replicationType; - return this; + return (T) this; + } + + /** + * Sets the replication type. + */ + public final T replicationType(String replicationType) { + return replicationType(ReplicationType.fromString(replicationType)); } public WriteConsistencyLevel consistencyLevel() { return this.consistencyLevel; } - public ShardReplicationOperationRequest consistencyLevel(WriteConsistencyLevel consistencyLevel) { + /** + * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} + */ + @SuppressWarnings("unchecked") + public final T consistencyLevel(WriteConsistencyLevel consistencyLevel) { this.consistencyLevel = consistencyLevel; - return this; + return (T) this; } @Override @@ -143,19 +157,21 @@ public abstract class ShardReplicationOperationRequest implements ActionRequest @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); replicationType = ReplicationType.fromId(in.readByte()); consistencyLevel = WriteConsistencyLevel.fromId(in.readByte()); timeout = TimeValue.readTimeValue(in); - index = in.readUTF(); + index = in.readString(); // no need to serialize threaded* parameters, since they only matter locally } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeByte(replicationType.id()); out.writeByte(consistencyLevel.id()); timeout.writeTo(out); - out.writeUTF(index); + out.writeString(index); } /** diff --git a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java new file mode 100644 index 00000000000..f0db8fa444f --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java @@ -0,0 +1,97 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.action.support.replication; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.WriteConsistencyLevel; +import org.elasticsearch.client.internal.InternalGenericClient; +import org.elasticsearch.common.unit.TimeValue; + +/** + */ +public abstract class ShardReplicationOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends ShardReplicationOperationRequestBuilder> + extends ActionRequestBuilder { + + protected ShardReplicationOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + /** + * Controls if the operation will be executed on a separate thread when executed locally. Defaults + * to true when running in embedded mode. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setOperationThreaded(boolean threadedOperation) { + request.operationThreaded(threadedOperation); + return (RequestBuilder) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(TimeValue timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(String timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setIndex(String index) { + request.index(index); + return (RequestBuilder) this; + } + + /** + * Sets the replication type. + */ + @SuppressWarnings("unchecked") + public RequestBuilder setReplicationType(ReplicationType replicationType) { + request.replicationType(replicationType); + return (RequestBuilder) this; + } + + /** + * Sets the replication type. + */ + @SuppressWarnings("unchecked") + public RequestBuilder setReplicationType(String replicationType) { + request.replicationType(replicationType); + return (RequestBuilder) this; + } + + /** + * Sets the consistency level of write. Defaults to {@link org.elasticsearch.action.WriteConsistencyLevel#DEFAULT} + */ + @SuppressWarnings("unchecked") + public RequestBuilder setConsistencyLevel(WriteConsistencyLevel consistencyLevel) { + request.consistencyLevel(consistencyLevel); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java b/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java index 4ffcf480c35..0b5865fae64 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.support.replication; +import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; @@ -63,6 +64,9 @@ public abstract class TransportIndicesReplicationOperationAction> resolveRouting(ClusterState clusterState, Request request) throws ElasticSearchException; + @Override protected void doExecute(final Request request, final ActionListener listener) { ClusterState clusterState = clusterService.state(); @@ -81,7 +85,7 @@ public abstract class TransportIndicesReplicationOperationAction indexResponses = new AtomicReferenceArray(concreteIndices.length); - Map> routingMap = clusterState.metaData().resolveSearchRouting(request.routing(), request.indices()); + Map> routingMap = resolveRouting(clusterState, request); for (final String index : concreteIndices) { Set routing = null; diff --git a/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java b/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java index e7590acb584..8acc6182de7 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java @@ -285,22 +285,23 @@ public abstract class TransportShardReplicationOperationAction extends ActionRequest { - private boolean threadedListener = false; private boolean threadedOperation = true; private boolean preferLocal = true; @@ -43,20 +42,6 @@ public abstract class SingleCustomOperationRequest implements ActionRequest { return null; } - /** - * Should the listener be called on a separate thread if needed. - */ - @Override - public boolean listenerThreaded() { - return threadedListener; - } - - @Override - public SingleCustomOperationRequest listenerThreaded(boolean threadedListener) { - this.threadedListener = threadedListener; - return this; - } - /** * Controls if the operation will be executed on a separate thread when executed locally. */ @@ -67,18 +52,20 @@ public abstract class SingleCustomOperationRequest implements ActionRequest { /** * Controls if the operation will be executed on a separate thread when executed locally. */ - public SingleCustomOperationRequest operationThreaded(boolean threadedOperation) { + @SuppressWarnings("unchecked") + public final T operationThreaded(boolean threadedOperation) { this.threadedOperation = threadedOperation; - return this; + return (T) this; } /** * if this operation hits a node with a local relevant shard, should it be preferred * to be executed on, or just do plain round robin. Defaults to true */ - public SingleCustomOperationRequest preferLocal(boolean preferLocal) { + @SuppressWarnings("unchecked") + public final T preferLocal(boolean preferLocal) { this.preferLocal = preferLocal; - return this; + return (T) this; } /** @@ -95,12 +82,13 @@ public abstract class SingleCustomOperationRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { - // no need to pass threading over the network, they are always false when coming throw a thread pool + super.readFrom(in); preferLocal = in.readBoolean(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeBoolean(preferLocal); } } diff --git a/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java new file mode 100644 index 00000000000..d0a18e043dd --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java @@ -0,0 +1,53 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.action.support.single.custom; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.client.internal.InternalGenericClient; + +/** + */ +public abstract class SingleCustomOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleCustomOperationRequestBuilder> + extends ActionRequestBuilder { + + protected SingleCustomOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + /** + * Controls if the operation will be executed on a separate thread when executed locally. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setOperationThreaded(boolean threadedOperation) { + request.operationThreaded(threadedOperation); + return (RequestBuilder) this; + } + + /** + * if this operation hits a node with a local relevant shard, should it be preferred + * to be executed on, or just do plain round robin. Defaults to true + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setPreferLocal(boolean preferLocal) { + request.preferLocal(preferLocal); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/single/custom/TransportSingleCustomOperationAction.java b/src/main/java/org/elasticsearch/action/support/single/custom/TransportSingleCustomOperationAction.java index 61c22bc1f41..c8263e9c046 100644 --- a/src/main/java/org/elasticsearch/action/support/single/custom/TransportSingleCustomOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/single/custom/TransportSingleCustomOperationAction.java @@ -33,7 +33,6 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; @@ -331,16 +330,16 @@ public abstract class TransportSingleCustomOperationAction extends ActionRequest { public static final TimeValue DEFAULT_TIMEOUT = new TimeValue(1, TimeUnit.MINUTES); @@ -42,8 +42,6 @@ public abstract class InstanceShardOperationRequest implements ActionRequest { // -1 means its not set, allows to explicitly direct a request to a specific shard protected int shardId = -1; - private boolean threadedListener = false; - protected InstanceShardOperationRequest() { } @@ -51,10 +49,6 @@ public abstract class InstanceShardOperationRequest implements ActionRequest { this.index = index; } - public TimeValue timeout() { - return timeout; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -68,28 +62,36 @@ public abstract class InstanceShardOperationRequest implements ActionRequest { return index; } - InstanceShardOperationRequest index(String index) { + @SuppressWarnings("unchecked") + public final T index(String index) { this.index = index; - return this; + return (T) this; + } + + public TimeValue timeout() { + return timeout; } /** - * Should the listener be called on a separate thread if needed. + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. */ - @Override - public boolean listenerThreaded() { - return threadedListener; + @SuppressWarnings("unchecked") + public final T timeout(TimeValue timeout) { + this.timeout = timeout; + return (T) this; } - @Override - public InstanceShardOperationRequest listenerThreaded(boolean threadedListener) { - this.threadedListener = threadedListener; - return this; + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + public final T timeout(String timeout) { + return timeout(TimeValue.parseTimeValue(timeout, null)); } @Override public void readFrom(StreamInput in) throws IOException { - index = in.readUTF(); + super.readFrom(in); + index = in.readString(); shardId = in.readInt(); timeout = TimeValue.readTimeValue(in); // no need to pass threading over the network, they are always false when coming throw a thread pool @@ -97,7 +99,8 @@ public abstract class InstanceShardOperationRequest implements ActionRequest { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(index); + super.writeTo(out); + out.writeString(index); out.writeInt(shardId); timeout.writeTo(out); } diff --git a/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java new file mode 100644 index 00000000000..996b98cd5af --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java @@ -0,0 +1,59 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.action.support.single.instance; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.client.internal.InternalGenericClient; +import org.elasticsearch.common.unit.TimeValue; + +/** + */ +public abstract class InstanceShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends InstanceShardOperationRequestBuilder> + extends ActionRequestBuilder { + + protected InstanceShardOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + @SuppressWarnings("unchecked") + public final RequestBuilder setIndex(String index) { + request.index(index); + return (RequestBuilder) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(TimeValue timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } + + /** + * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setTimeout(String timeout) { + request.timeout(timeout); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequest.java b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequest.java index 6a3258c6546..84972355061 100644 --- a/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequest.java @@ -30,11 +30,10 @@ import java.io.IOException; /** * */ -public abstract class SingleShardOperationRequest implements ActionRequest { +public abstract class SingleShardOperationRequest extends ActionRequest { protected String index; - private boolean threadedListener = false; private boolean threadedOperation = true; protected SingleShardOperationRequest() { @@ -57,23 +56,13 @@ public abstract class SingleShardOperationRequest implements ActionRequest { return index; } - SingleShardOperationRequest index(String index) { - this.index = index; - return this; - } - /** - * Should the listener be called on a separate thread if needed. + * Sets the index. */ - @Override - public boolean listenerThreaded() { - return threadedListener; - } - - @Override - public SingleShardOperationRequest listenerThreaded(boolean threadedListener) { - this.threadedListener = threadedListener; - return this; + @SuppressWarnings("unchecked") + public final T index(String index) { + this.index = index; + return (T) this; } /** @@ -86,9 +75,10 @@ public abstract class SingleShardOperationRequest implements ActionRequest { /** * Controls if the operation will be executed on a separate thread when executed locally. */ - public SingleShardOperationRequest operationThreaded(boolean threadedOperation) { + @SuppressWarnings("unchecked") + public final T operationThreaded(boolean threadedOperation) { this.threadedOperation = threadedOperation; - return this; + return (T) this; } protected void beforeLocalFork() { @@ -96,13 +86,15 @@ public abstract class SingleShardOperationRequest implements ActionRequest { @Override public void readFrom(StreamInput in) throws IOException { - index = in.readUTF(); + super.readFrom(in); + index = in.readString(); // no need to pass threading over the network, they are always false when coming throw a thread pool } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(index); + super.writeTo(out); + out.writeString(index); } } diff --git a/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java new file mode 100644 index 00000000000..652f923178f --- /dev/null +++ b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java @@ -0,0 +1,52 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.action.support.single.shard; + +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.client.internal.InternalGenericClient; + +/** + */ +public abstract class SingleShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleShardOperationRequestBuilder> + extends ActionRequestBuilder { + + protected SingleShardOperationRequestBuilder(InternalGenericClient client, Request request) { + super(client, request); + } + + /** + * Sets the index. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setIndex(String index) { + request.index(index); + return (RequestBuilder) this; + } + + /** + * Controls if the operation will be executed on a separate thread when executed locally. + */ + @SuppressWarnings("unchecked") + public final RequestBuilder setOperationThreaded(boolean threadedOperation) { + request.operationThreaded(threadedOperation); + return (RequestBuilder) this; + } +} diff --git a/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java b/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java index ce87bb1d6f4..c9ef9deee15 100644 --- a/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/single/shard/TransportShardSingleOperationAction.java @@ -34,7 +34,6 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; @@ -256,7 +255,7 @@ public abstract class TransportShardSingleOperationAction { private String type; private String id; @@ -98,14 +97,6 @@ public class UpdateRequest extends InstanceShardOperationRequest { return validationException; } - /** - * Sets the index the document will exists on. - */ - public UpdateRequest index(String index) { - this.index = index; - return this; - } - /** * The type of the indexed document. */ @@ -295,21 +286,6 @@ public class UpdateRequest extends InstanceShardOperationRequest { return this.percolate; } - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public UpdateRequest timeout(TimeValue timeout) { - this.timeout = timeout; - return this; - } - - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public UpdateRequest timeout(String timeout) { - return timeout(TimeValue.parseTimeValue(timeout, null)); - } - /** * Should a refresh be executed post this update operation causing the operation to * be searchable. Note, heavy indexing should not set this to true. Defaults @@ -533,14 +509,14 @@ public class UpdateRequest extends InstanceShardOperationRequest { super.readFrom(in); replicationType = ReplicationType.fromId(in.readByte()); consistencyLevel = WriteConsistencyLevel.fromId(in.readByte()); - type = in.readUTF(); - id = in.readUTF(); - routing = in.readOptionalUTF(); - script = in.readOptionalUTF(); - scriptLang = in.readOptionalUTF(); + type = in.readString(); + id = in.readString(); + routing = in.readOptionalString(); + script = in.readOptionalString(); + scriptLang = in.readOptionalString(); scriptParams = in.readMap(); retryOnConflict = in.readVInt(); - percolate = in.readOptionalUTF(); + percolate = in.readOptionalString(); refresh = in.readBoolean(); if (in.readBoolean()) { doc = new IndexRequest(); @@ -550,7 +526,7 @@ public class UpdateRequest extends InstanceShardOperationRequest { if (size >= 0) { fields = new String[size]; for (int i = 0; i < size; i++) { - fields[i] = in.readUTF(); + fields[i] = in.readString(); } } if (in.readBoolean()) { @@ -564,14 +540,14 @@ public class UpdateRequest extends InstanceShardOperationRequest { super.writeTo(out); out.writeByte(replicationType.id()); out.writeByte(consistencyLevel.id()); - out.writeUTF(type); - out.writeUTF(id); - out.writeOptionalUTF(routing); - out.writeOptionalUTF(script); - out.writeOptionalUTF(scriptLang); + out.writeString(type); + out.writeString(id); + out.writeOptionalString(routing); + out.writeOptionalString(script); + out.writeOptionalString(scriptLang); out.writeMap(scriptParams); out.writeVInt(retryOnConflict); - out.writeOptionalUTF(percolate); + out.writeOptionalString(percolate); out.writeBoolean(refresh); if (doc == null) { out.writeBoolean(false); @@ -588,7 +564,7 @@ public class UpdateRequest extends InstanceShardOperationRequest { } else { out.writeInt(fields.length); for (String field : fields) { - out.writeUTF(field); + out.writeString(field); } } if (upsertRequest == null) { diff --git a/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java b/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java index a4fb239a711..2dc38e8f358 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java @@ -22,11 +22,11 @@ package org.elasticsearch.action.update; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.WriteConsistencyLevel; import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.support.BaseRequestBuilder; import org.elasticsearch.action.support.replication.ReplicationType; +import org.elasticsearch.action.support.single.instance.InstanceShardOperationRequestBuilder; import org.elasticsearch.client.Client; +import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; @@ -34,22 +34,14 @@ import java.util.Map; /** */ -public class UpdateRequestBuilder extends BaseRequestBuilder { +public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder { public UpdateRequestBuilder(Client client) { - super(client, new UpdateRequest()); + super((InternalClient) client, new UpdateRequest()); } public UpdateRequestBuilder(Client client, String index, String type, String id) { - super(client, new UpdateRequest(index, type, id)); - } - - /** - * Sets the index the document will exists on. - */ - public UpdateRequestBuilder setIndex(String index) { - request.index(index); - return this; + super((InternalClient) client, new UpdateRequest(index, type, id)); } /** @@ -132,22 +124,6 @@ public class UpdateRequestBuilder extends BaseRequestBuilder1m. - */ - public UpdateRequestBuilder setTimeout(TimeValue timeout) { - request.timeout(timeout); - return this; - } - - /** - * A timeout to wait if the index operation can't be performed immediately. Defaults to 1m. - */ - public UpdateRequestBuilder setTimeout(String timeout) { - request.timeout(timeout); - return this; - } - /** * Should a refresh be executed post this update operation causing the operation to * be searchable. Note, heavy indexing should not set this to true. Defaults @@ -319,6 +295,6 @@ public class UpdateRequestBuilder extends BaseRequestBuilder listener) { - client.update(request, listener); + ((Client) client).update(request, listener); } } diff --git a/src/main/java/org/elasticsearch/client/Client.java b/src/main/java/org/elasticsearch/client/Client.java index 06243dfef0b..14f3acfef03 100644 --- a/src/main/java/org/elasticsearch/client/Client.java +++ b/src/main/java/org/elasticsearch/client/Client.java @@ -85,7 +85,7 @@ public interface Client { * @param The request builder type. * @return A future allowing to get back the response. */ - > ActionFuture execute(final Action action, final Request request); + > ActionFuture execute(final Action action, final Request request); /** * Executes a generic action, denoted by an {@link Action}. @@ -97,7 +97,7 @@ public interface Client { * @param The response type. * @param The request builder type. */ - > void execute(final Action action, final Request request, ActionListener listener); + > void execute(final Action action, final Request request, ActionListener listener); /** * Prepares a request builder to execute, specified by {@link Action}. @@ -108,7 +108,7 @@ public interface Client { * @param The request builder. * @return The request builder, that can, at a later stage, execute the request. */ - > RequestBuilder prepareExecute(final Action action); + > RequestBuilder prepareExecute(final Action action); /** @@ -439,8 +439,8 @@ public interface Client { * Computes a score explanation for the specified request. * * @param index The index this explain is targeted for - * @param type The type this explain is targeted for - * @param id The document identifier this explain is targeted for + * @param type The type this explain is targeted for + * @param id The document identifier this explain is targeted for */ ExplainRequestBuilder prepareExplain(String index, String type, String id); @@ -454,8 +454,8 @@ public interface Client { /** * Computes a score explanation for the specified request. * - * @param request The request encapsulating the query and document identifier to compute a score explanation for - * @param listener A listener to be notified of the result + * @param request The request encapsulating the query and document identifier to compute a score explanation for + * @param listener A listener to be notified of the result */ void explain(ExplainRequest request, ActionListener listener); diff --git a/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 4a4d5b212e3..754ac1ceeac 100644 --- a/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -56,11 +56,11 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; */ public interface ClusterAdminClient { - > ActionFuture execute(final ClusterAction action, final Request request); + > ActionFuture execute(final ClusterAction action, final Request request); - > void execute(final ClusterAction action, final Request request, ActionListener listener); + > void execute(final ClusterAction action, final Request request, ActionListener listener); - > RequestBuilder prepareExecute(final ClusterAction action); + > RequestBuilder prepareExecute(final ClusterAction action); /** * The health of the cluster. diff --git a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index a109f0a4c8a..6a75457b0b1 100644 --- a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -102,11 +102,11 @@ import org.elasticsearch.common.Nullable; */ public interface IndicesAdminClient { - > ActionFuture execute(final IndicesAction action, final Request request); + > ActionFuture execute(final IndicesAction action, final Request request); - > void execute(final IndicesAction action, final Request request, ActionListener listener); + > void execute(final IndicesAction action, final Request request, ActionListener listener); - > RequestBuilder prepareExecute(final IndicesAction action); + > RequestBuilder prepareExecute(final IndicesAction action); /** diff --git a/src/main/java/org/elasticsearch/client/internal/InternalClient.java b/src/main/java/org/elasticsearch/client/internal/InternalClient.java index 26ebea05870..6fc2237e988 100644 --- a/src/main/java/org/elasticsearch/client/internal/InternalClient.java +++ b/src/main/java/org/elasticsearch/client/internal/InternalClient.java @@ -21,14 +21,11 @@ package org.elasticsearch.client.internal; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; /** * */ -public interface InternalClient extends Client { +public interface InternalClient extends Client, InternalGenericClient { Settings settings(); - - ThreadPool threadPool(); } diff --git a/src/main/java/org/elasticsearch/client/internal/InternalClusterAdminClient.java b/src/main/java/org/elasticsearch/client/internal/InternalClusterAdminClient.java index 71bf96c451f..3d88ca69311 100644 --- a/src/main/java/org/elasticsearch/client/internal/InternalClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/internal/InternalClusterAdminClient.java @@ -20,12 +20,9 @@ package org.elasticsearch.client.internal; import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.threadpool.ThreadPool; /** * */ -public interface InternalClusterAdminClient extends ClusterAdminClient { - - ThreadPool threadPool(); +public interface InternalClusterAdminClient extends ClusterAdminClient, InternalGenericClient { } diff --git a/src/main/java/org/elasticsearch/transport/ActionTransportRequestHandler.java b/src/main/java/org/elasticsearch/client/internal/InternalGenericClient.java similarity index 78% rename from src/main/java/org/elasticsearch/transport/ActionTransportRequestHandler.java rename to src/main/java/org/elasticsearch/client/internal/InternalGenericClient.java index e04fed1d40a..2776ed9a054 100644 --- a/src/main/java/org/elasticsearch/transport/ActionTransportRequestHandler.java +++ b/src/main/java/org/elasticsearch/client/internal/InternalGenericClient.java @@ -17,14 +17,13 @@ * under the License. */ -package org.elasticsearch.transport; +package org.elasticsearch.client.internal; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.threadpool.ThreadPool; /** - * */ -public interface ActionTransportRequestHandler extends TransportRequestHandler { +public interface InternalGenericClient { - String action(); -} \ No newline at end of file + ThreadPool threadPool(); +} diff --git a/src/main/java/org/elasticsearch/client/internal/InternalIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/internal/InternalIndicesAdminClient.java index c6f31108e6f..d19f2d9026a 100644 --- a/src/main/java/org/elasticsearch/client/internal/InternalIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/internal/InternalIndicesAdminClient.java @@ -20,12 +20,10 @@ package org.elasticsearch.client.internal; import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.threadpool.ThreadPool; /** * */ -public interface InternalIndicesAdminClient extends IndicesAdminClient { +public interface InternalIndicesAdminClient extends IndicesAdminClient, InternalGenericClient { - ThreadPool threadPool(); } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClient.java b/src/main/java/org/elasticsearch/client/node/NodeClient.java index 27d33213575..63b1cfff81d 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClient.java @@ -78,14 +78,16 @@ public class NodeClient extends AbstractClient implements InternalClient { return this.admin; } + @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(Action action, Request request) { + public > ActionFuture execute(Action action, Request request) { TransportAction transportAction = actions.get(action); return transportAction.execute(request); } + @SuppressWarnings("unchecked") @Override - public > void execute(Action action, Request request, ActionListener listener) { + public > void execute(Action action, Request request, ActionListener listener) { TransportAction transportAction = actions.get(action); transportAction.execute(request, listener); } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java index 5dd880698f3..26961589b01 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java @@ -58,14 +58,16 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement return this.threadPool; } + @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(ClusterAction action, Request request) { + public > ActionFuture execute(ClusterAction action, Request request) { TransportAction transportAction = actions.get(action); return transportAction.execute(request); } + @SuppressWarnings("unchecked") @Override - public > void execute(ClusterAction action, Request request, ActionListener listener) { + public > void execute(ClusterAction action, Request request, ActionListener listener) { TransportAction transportAction = actions.get(action); transportAction.execute(request, listener); } diff --git a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java index cb75b4f7029..d315385cc90 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java @@ -58,14 +58,16 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement return this.threadPool; } + @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(IndicesAction action, Request request) { + public > ActionFuture execute(IndicesAction action, Request request) { TransportAction transportAction = actions.get(action); return transportAction.execute(request); } + @SuppressWarnings("unchecked") @Override - public > void execute(IndicesAction action, Request request, ActionListener listener) { + public > void execute(IndicesAction action, Request request, ActionListener listener) { TransportAction transportAction = actions.get(action); transportAction.execute(request, listener); } diff --git a/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 0c80799a43f..09a10fd8efd 100644 --- a/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -66,7 +66,7 @@ import org.elasticsearch.common.Nullable; public abstract class AbstractClient implements InternalClient { @Override - public > RequestBuilder prepareExecute(final Action action) { + public > RequestBuilder prepareExecute(final Action action) { return action.newRequestBuilder(this); } diff --git a/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java index 6ecf9d93ebf..a613b202895 100644 --- a/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java @@ -65,7 +65,7 @@ import org.elasticsearch.client.internal.InternalClusterAdminClient; public abstract class AbstractClusterAdminClient implements InternalClusterAdminClient { @Override - public > RequestBuilder prepareExecute(ClusterAction action) { + public > RequestBuilder prepareExecute(ClusterAction action) { return action.newRequestBuilder(this); } diff --git a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java index 6b85a2c5610..14cd1eb3d72 100644 --- a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java @@ -126,7 +126,7 @@ import org.elasticsearch.common.Nullable; public abstract class AbstractIndicesAdminClient implements InternalIndicesAdminClient { @Override - public > RequestBuilder prepareExecute(final IndicesAction action) { + public > RequestBuilder prepareExecute(final IndicesAction action) { return action.newRequestBuilder(this); } diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 24e107e8424..d7e7de24cf5 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -289,12 +289,12 @@ public class TransportClient extends AbstractClient { } @Override - public > ActionFuture execute(Action action, Request request) { + public > ActionFuture execute(Action action, Request request) { return internalClient.execute(action, request); } @Override - public > void execute(Action action, Request request, ActionListener listener) { + public > void execute(Action action, Request request, ActionListener listener) { internalClient.execute(action, request, listener); } diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java index d5b3e75c404..f2813ddd1be 100644 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java @@ -87,8 +87,9 @@ public class InternalTransportClient extends AbstractClient implements InternalC return adminClient; } + @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(final Action action, final Request request) { + public > ActionFuture execute(final Action action, final Request request) { final TransportActionNodeProxy proxy = actions.get(action); return nodesService.execute(new TransportClientNodesService.NodeCallback>() { @Override @@ -98,8 +99,9 @@ public class InternalTransportClient extends AbstractClient implements InternalC }); } + @SuppressWarnings("unchecked") @Override - public > void execute(final Action action, final Request request, ActionListener listener) { + public > void execute(final Action action, final Request request, ActionListener listener) { final TransportActionNodeProxy proxy = actions.get(action); nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { @Override diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java index 7b59e5f11d5..b14dd716828 100644 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java @@ -38,6 +38,7 @@ import java.util.Map; /** * */ +@SuppressWarnings("unchecked") public class InternalTransportClusterAdminClient extends AbstractClusterAdminClient implements InternalClusterAdminClient { private final TransportClientNodesService nodesService; @@ -65,8 +66,9 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli return this.threadPool; } + @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(final ClusterAction action, final Request request) { + public > ActionFuture execute(final ClusterAction action, final Request request) { final TransportActionNodeProxy proxy = actions.get(action); return nodesService.execute(new TransportClientNodesService.NodeCallback>() { @Override @@ -76,8 +78,9 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli }); } + @SuppressWarnings("unchecked") @Override - public > void execute(final ClusterAction action, final Request request, final ActionListener listener) { + public > void execute(final ClusterAction action, final Request request, final ActionListener listener) { final TransportActionNodeProxy proxy = actions.get(action); nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { @Override diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java index f4d00ed8e13..586f48e2b88 100644 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java @@ -38,6 +38,7 @@ import java.util.Map; /** * */ +@SuppressWarnings("unchecked") public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { private final TransportClientNodesService nodesService; @@ -65,8 +66,9 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli return this.threadPool; } + @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(final IndicesAction action, final Request request) { + public > ActionFuture execute(final IndicesAction action, final Request request) { final TransportActionNodeProxy proxy = actions.get(action); return nodesService.execute(new TransportClientNodesService.NodeCallback>() { @Override @@ -76,8 +78,9 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli }); } + @SuppressWarnings("unchecked") @Override - public > void execute(final IndicesAction action, final Request request, ActionListener listener) { + public > void execute(final IndicesAction action, final Request request, ActionListener listener) { final TransportActionNodeProxy proxy = actions.get(action); nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { @Override diff --git a/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java b/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java index 95673827ff6..7b8f1a7281a 100644 --- a/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java +++ b/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java @@ -114,7 +114,7 @@ public class MappingUpdatedAction extends TransportMasterNodeOperationAction { private String index; @@ -151,16 +151,16 @@ public class MappingUpdatedAction extends TransportMasterNodeOperationAction { + class ShardStartedTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "cluster/shardStarted"; @@ -237,7 +236,7 @@ public class ShardStateAction extends AbstractComponent { } } - private static class ShardRoutingEntry implements Streamable { + static class ShardRoutingEntry extends TransportRequest { private ShardRouting shardRouting; @@ -253,14 +252,16 @@ public class ShardStateAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); shardRouting = readShardRoutingEntry(in); - reason = in.readUTF(); + reason = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); shardRouting.writeTo(out); - out.writeUTF(reason); + out.writeString(reason); } } } diff --git a/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index d692c9f4cb1..27173ff7181 100644 --- a/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -345,6 +345,8 @@ public abstract class StreamInput extends InputStream { return new DateTime(readLong()); case 14: return readBytesReference(); + case 15: + return readText(); default: throw new IOException("Can't read unknown type [" + type + "]"); } diff --git a/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 1d87a490320..fa98ee8cde5 100644 --- a/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -271,6 +271,20 @@ public abstract class StreamOutput extends OutputStream { } } + /** + * Writes a string array, for nullable string, writes it as 0 (empty string). + */ + public void writeStringArrayNullable(@Nullable String[] array) throws IOException { + if (array == null) { + writeVInt(0); + } else { + writeVInt(array.length); + for (String s : array) { + writeString(s); + } + } + } + public void writeMap(@Nullable Map map) throws IOException { writeGenericValue(map); } @@ -326,7 +340,7 @@ public abstract class StreamOutput extends OutputStream { Map map = (Map) value; writeVInt(map.size()); for (Map.Entry entry : map.entrySet()) { - writeUTF(entry.getKey()); + writeString(entry.getKey()); writeGenericValue(entry.getValue()); } } else if (type == Byte.class) { @@ -341,6 +355,9 @@ public abstract class StreamOutput extends OutputStream { } else if (value instanceof BytesReference) { writeByte((byte) 14); writeBytesReference((BytesReference) value); + } else if (value instanceof Text) { + writeByte((byte) 15); + writeText((Text) value); } else { throw new IOException("Can't write type [" + type + "]"); } diff --git a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index b1c10731ec0..370439bf335 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -38,7 +38,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.internal.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.VoidStreamable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -770,7 +769,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen } } - static class RejoinClusterRequest implements Streamable { + static class RejoinClusterRequest extends TransportRequest { private String fromNodeId; @@ -783,11 +782,13 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); fromNodeId = in.readOptionalString(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeOptionalString(fromNodeId); } } diff --git a/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java b/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java index 34c73991f1e..e517d089f9d 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java +++ b/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java @@ -395,7 +395,7 @@ public class MasterFaultDetection extends AbstractComponent { } - private static class MasterPingRequest implements Streamable { + private static class MasterPingRequest extends TransportRequest { private String nodeId; @@ -411,14 +411,16 @@ public class MasterFaultDetection extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { - nodeId = in.readUTF(); - masterNodeId = in.readUTF(); + super.readFrom(in); + nodeId = in.readString(); + masterNodeId = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(nodeId); - out.writeUTF(masterNodeId); + super.writeTo(out); + out.writeString(nodeId); + out.writeString(masterNodeId); } } diff --git a/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java b/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java index 0bdac9040e2..fe6c3100ae7 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java +++ b/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java @@ -305,7 +305,7 @@ public class NodesFaultDetection extends AbstractComponent { } - static class PingRequest implements Streamable { + static class PingRequest extends TransportRequest { // the (assumed) node id we are pinging private String nodeId; @@ -319,12 +319,14 @@ public class NodesFaultDetection extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { - nodeId = in.readUTF(); + super.readFrom(in); + nodeId = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(nodeId); + super.writeTo(out); + out.writeString(nodeId); } } diff --git a/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java b/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java index da63a9448a1..fcd6ee7144c 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java +++ b/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java @@ -99,7 +99,7 @@ public class MembershipAction extends AbstractComponent { .txGet(timeout.millis(), TimeUnit.MILLISECONDS); } - static class JoinRequest implements Streamable { + static class JoinRequest extends TransportRequest { DiscoveryNode node; @@ -115,12 +115,14 @@ public class MembershipAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); node = DiscoveryNode.readNode(in); withClusterState = in.readBoolean(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); node.writeTo(out); out.writeBoolean(withClusterState); } @@ -173,7 +175,7 @@ public class MembershipAction extends AbstractComponent { } } - class ValidateJoinRequest implements Streamable { + class ValidateJoinRequest extends TransportRequest { ClusterState clusterState; @@ -186,11 +188,13 @@ public class MembershipAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); clusterState = ClusterState.Builder.readFrom(in, nodesProvider.nodes().localNode()); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); ClusterState.Builder.writeTo(clusterState, out); } } @@ -216,7 +220,7 @@ public class MembershipAction extends AbstractComponent { } } - private static class LeaveRequest implements Streamable { + static class LeaveRequest extends TransportRequest { private DiscoveryNode node; @@ -229,11 +233,13 @@ public class MembershipAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); node = DiscoveryNode.readNode(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); node.writeTo(out); } } diff --git a/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java b/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java index 37487dc6dd9..68ed75d5cde 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java @@ -325,7 +325,7 @@ public class MulticastZenPing extends AbstractLifecycleComponent implem } } - static class MulticastPingResponse implements Streamable { + static class MulticastPingResponse extends TransportRequest { int id; @@ -336,12 +336,14 @@ public class MulticastZenPing extends AbstractLifecycleComponent implem @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); id = in.readInt(); pingResponse = PingResponse.readPingResponse(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeInt(id); pingResponse.writeTo(out); } diff --git a/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index 766e6e23dbb..a6f090b6a93 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -403,7 +403,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen } } - static class UnicastPingRequest implements Streamable { + static class UnicastPingRequest extends TransportRequest { int id; @@ -416,6 +416,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); id = in.readInt(); timeout = readTimeValue(in); pingResponse = readPingResponse(in); @@ -423,6 +424,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeInt(id); timeout.writeTo(out); pingResponse.writeTo(out); diff --git a/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java b/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java index 31a8d622b0d..cffa4b24b94 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java +++ b/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java @@ -109,7 +109,7 @@ public class PublishClusterStateAction extends AbstractComponent { } } - class PublishClusterStateRequest implements Streamable { + class PublishClusterStateRequest extends TransportRequest { BytesReference clusterStateInBytes; Version version = Version.CURRENT; @@ -123,12 +123,14 @@ public class PublishClusterStateAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); clusterStateInBytes = in.readBytesReference(); version = in.getVersion(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeBytesReference(clusterStateInBytes); } } diff --git a/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalAllocateDangledIndices.java b/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalAllocateDangledIndices.java index 754d5b7dafd..e678183cb69 100644 --- a/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalAllocateDangledIndices.java +++ b/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalAllocateDangledIndices.java @@ -60,7 +60,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent { this.transportService = transportService; this.clusterService = clusterService; this.allocationService = allocationService; - transportService.registerHandler(new AllocateDangledRequestHandler()); + transportService.registerHandler(AllocateDangledRequestHandler.ACTION, new AllocateDangledRequestHandler()); } public void allocateDangled(IndexMetaData[] indices, final Listener listener) { @@ -100,15 +100,10 @@ public class LocalAllocateDangledIndices extends AbstractComponent { void onFailure(Throwable e); } - class AllocateDangledRequestHandler implements ActionTransportRequestHandler { + class AllocateDangledRequestHandler implements TransportRequestHandler { public static final String ACTION = "/gateway/local/allocate_dangled"; - @Override - public String action() { - return ACTION; - } - @Override public AllocateDangledRequest newInstance() { return new AllocateDangledRequest(); @@ -173,7 +168,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent { } } - static class AllocateDangledRequest implements Streamable { + static class AllocateDangledRequest extends TransportRequest { DiscoveryNode fromNode; IndexMetaData[] indices; @@ -188,6 +183,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); fromNode = DiscoveryNode.readNode(in); indices = new IndexMetaData[in.readVInt()]; for (int i = 0; i < indices.length; i++) { @@ -197,6 +193,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); fromNode.writeTo(out); out.writeVInt(indices.length); for (IndexMetaData indexMetaData : indices) { diff --git a/src/main/java/org/elasticsearch/gateway/local/state/meta/TransportNodesListGatewayMetaState.java b/src/main/java/org/elasticsearch/gateway/local/state/meta/TransportNodesListGatewayMetaState.java index f150fd8134c..8a8d5f8ca2a 100644 --- a/src/main/java/org/elasticsearch/gateway/local/state/meta/TransportNodesListGatewayMetaState.java +++ b/src/main/java/org/elasticsearch/gateway/local/state/meta/TransportNodesListGatewayMetaState.java @@ -90,7 +90,7 @@ public class TransportNodesListGatewayMetaState extends TransportNodesOperationA @Override protected NodeRequest newNodeRequest(String nodeId, Request request) { - return new NodeRequest(nodeId); + return new NodeRequest(nodeId, request); } @Override @@ -128,7 +128,7 @@ public class TransportNodesListGatewayMetaState extends TransportNodesOperationA return true; } - static class Request extends NodesOperationRequest { + static class Request extends NodesOperationRequest { public Request() { } @@ -137,12 +137,6 @@ public class TransportNodesListGatewayMetaState extends TransportNodesOperationA super(nodesIds.toArray(new String[nodesIds.size()])); } - @Override - public Request timeout(TimeValue timeout) { - super.timeout(timeout); - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -196,8 +190,8 @@ public class TransportNodesListGatewayMetaState extends TransportNodesOperationA NodeRequest() { } - NodeRequest(String nodeId) { - super(nodeId); + NodeRequest(String nodeId, TransportNodesListGatewayMetaState.Request request) { + super(request, nodeId); } @Override diff --git a/src/main/java/org/elasticsearch/gateway/local/state/shards/TransportNodesListGatewayStartedShards.java b/src/main/java/org/elasticsearch/gateway/local/state/shards/TransportNodesListGatewayStartedShards.java index 8b2ef1adeed..c2b38900bb3 100644 --- a/src/main/java/org/elasticsearch/gateway/local/state/shards/TransportNodesListGatewayStartedShards.java +++ b/src/main/java/org/elasticsearch/gateway/local/state/shards/TransportNodesListGatewayStartedShards.java @@ -90,7 +90,7 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesOperat @Override protected NodeRequest newNodeRequest(String nodeId, Request request) { - return new NodeRequest(request.shardId(), nodeId); + return new NodeRequest(nodeId, request); } @Override @@ -132,7 +132,7 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesOperat return true; } - static class Request extends NodesOperationRequest { + static class Request extends NodesOperationRequest { private ShardId shardId; @@ -148,12 +148,6 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesOperat return this.shardId; } - @Override - public Request timeout(TimeValue timeout) { - super.timeout(timeout); - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -211,9 +205,9 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesOperat NodeRequest() { } - NodeRequest(ShardId shardId, String nodeId) { - super(nodeId); - this.shardId = shardId; + NodeRequest(String nodeId, TransportNodesListGatewayStartedShards.Request request) { + super(request, nodeId); + this.shardId = request.shardId(); } @Override diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryCleanFilesRequest.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryCleanFilesRequest.java index 1dd920fe2d1..8fcca8d9d33 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryCleanFilesRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryCleanFilesRequest.java @@ -22,8 +22,8 @@ package org.elasticsearch.indices.recovery; import com.google.common.collect.Sets; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; import java.util.Set; @@ -31,7 +31,7 @@ import java.util.Set; /** * */ -class RecoveryCleanFilesRequest implements Streamable { +class RecoveryCleanFilesRequest extends TransportRequest { private long recoveryId; private ShardId shardId; @@ -61,22 +61,24 @@ class RecoveryCleanFilesRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); int size = in.readVInt(); snapshotFiles = Sets.newHashSetWithExpectedSize(size); for (int i = 0; i < size; i++) { - snapshotFiles.add(in.readUTF()); + snapshotFiles.add(in.readString()); } } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); out.writeVInt(snapshotFiles.size()); for (String snapshotFile : snapshotFiles) { - out.writeUTF(snapshotFile); + out.writeString(snapshotFile); } } } diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryFileChunkRequest.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryFileChunkRequest.java index 4acc735f154..0628f3e52b6 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryFileChunkRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryFileChunkRequest.java @@ -24,15 +24,15 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; /** * */ -class RecoveryFileChunkRequest implements Streamable { +class RecoveryFileChunkRequest extends TransportRequest { private long recoveryId; private ShardId shardId; @@ -92,30 +92,25 @@ class RecoveryFileChunkRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); - name = in.readUTF(); + name = in.readString(); position = in.readVLong(); length = in.readVLong(); - if (in.readBoolean()) { - checksum = in.readUTF(); - } + checksum = in.readOptionalString(); content = in.readBytesReference(); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); - out.writeUTF(name); + out.writeString(name); out.writeVLong(position); out.writeVLong(length); - if (checksum == null) { - out.writeBoolean(false); - } else { - out.writeBoolean(true); - out.writeUTF(checksum); - } + out.writeOptionalString(checksum); out.writeBytesReference(content); } diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryFilesInfoRequest.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryFilesInfoRequest.java index faac88de09f..569dfe3912b 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryFilesInfoRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryFilesInfoRequest.java @@ -21,8 +21,8 @@ package org.elasticsearch.indices.recovery; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; import java.util.ArrayList; @@ -31,7 +31,7 @@ import java.util.List; /** * */ -class RecoveryFilesInfoRequest implements Streamable { +class RecoveryFilesInfoRequest extends TransportRequest { private long recoveryId; private ShardId shardId; @@ -67,12 +67,13 @@ class RecoveryFilesInfoRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); int size = in.readVInt(); phase1FileNames = new ArrayList(size); for (int i = 0; i < size; i++) { - phase1FileNames.add(in.readUTF()); + phase1FileNames.add(in.readString()); } size = in.readVInt(); @@ -84,7 +85,7 @@ class RecoveryFilesInfoRequest implements Streamable { size = in.readVInt(); phase1ExistingFileNames = new ArrayList(size); for (int i = 0; i < size; i++) { - phase1ExistingFileNames.add(in.readUTF()); + phase1ExistingFileNames.add(in.readString()); } size = in.readVInt(); @@ -99,12 +100,13 @@ class RecoveryFilesInfoRequest implements Streamable { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); out.writeVInt(phase1FileNames.size()); for (String phase1FileName : phase1FileNames) { - out.writeUTF(phase1FileName); + out.writeString(phase1FileName); } out.writeVInt(phase1FileSizes.size()); @@ -114,7 +116,7 @@ class RecoveryFilesInfoRequest implements Streamable { out.writeVInt(phase1ExistingFileNames.size()); for (String phase1ExistingFileName : phase1ExistingFileNames) { - out.writeUTF(phase1ExistingFileName); + out.writeString(phase1ExistingFileName); } out.writeVInt(phase1ExistingFileSizes.size()); diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java index ae6485dd7bc..a30ae65fac7 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryFinalizeRecoveryRequest.java @@ -21,15 +21,15 @@ package org.elasticsearch.indices.recovery; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; /** * */ -class RecoveryFinalizeRecoveryRequest implements Streamable { +class RecoveryFinalizeRecoveryRequest extends TransportRequest { private long recoveryId; @@ -53,12 +53,14 @@ class RecoveryFinalizeRecoveryRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); } diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java index e7fa0b9b3b8..423b9e2405c 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryPrepareForTranslogOperationsRequest.java @@ -21,18 +21,17 @@ package org.elasticsearch.indices.recovery; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; /** * */ -class RecoveryPrepareForTranslogOperationsRequest implements Streamable { +class RecoveryPrepareForTranslogOperationsRequest extends TransportRequest { private long recoveryId; - private ShardId shardId; RecoveryPrepareForTranslogOperationsRequest() { @@ -53,12 +52,14 @@ class RecoveryPrepareForTranslogOperationsRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); } diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsRequest.java b/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsRequest.java index c27d8446b61..8b4cb474e61 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoveryTranslogOperationsRequest.java @@ -22,10 +22,10 @@ package org.elasticsearch.indices.recovery; import com.google.common.collect.Lists; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.TranslogStreams; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; import java.util.List; @@ -33,7 +33,7 @@ import java.util.List; /** * */ -class RecoveryTranslogOperationsRequest implements Streamable { +class RecoveryTranslogOperationsRequest extends TransportRequest { private long recoveryId; private ShardId shardId; @@ -62,6 +62,7 @@ class RecoveryTranslogOperationsRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); int size = in.readVInt(); @@ -73,6 +74,7 @@ class RecoveryTranslogOperationsRequest implements Streamable { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); out.writeVInt(operations.size()); diff --git a/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java b/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java index 65a712475b4..58a82940236 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java +++ b/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java @@ -23,9 +23,9 @@ import com.google.common.collect.Maps; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.StoreFileMetaData; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; import java.util.Map; @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicLong; /** * */ -public class StartRecoveryRequest implements Streamable { +public class StartRecoveryRequest extends TransportRequest { private static final AtomicLong recoveryIdGenerator = new AtomicLong(); @@ -97,6 +97,7 @@ public class StartRecoveryRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); recoveryId = in.readLong(); shardId = ShardId.readShardId(in); sourceNode = DiscoveryNode.readNode(in); @@ -112,6 +113,7 @@ public class StartRecoveryRequest implements Streamable { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(recoveryId); shardId.writeTo(out); sourceNode.writeTo(out); diff --git a/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index f7819db2782..f8671e1d84a 100644 --- a/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -98,7 +98,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio @Override protected NodeRequest newNodeRequest(String nodeId, Request request) { - return new NodeRequest(nodeId, request.shardId, request.unallocated); + return new NodeRequest(nodeId, request); } @Override @@ -281,7 +281,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio } - static class Request extends NodesOperationRequest { + static class Request extends NodesOperationRequest { private ShardId shardId; @@ -302,12 +302,6 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio this.unallocated = unallocated; } - @Override - public Request timeout(TimeValue timeout) { - super.timeout(timeout); - return this; - } - @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); @@ -368,10 +362,10 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio NodeRequest() { } - NodeRequest(String nodeId, ShardId shardId, boolean unallocated) { - super(nodeId); - this.shardId = shardId; - this.unallocated = unallocated; + NodeRequest(String nodeId, TransportNodesListShardStoreMetaData.Request request) { + super(request, nodeId); + this.shardId = request.shardId; + this.unallocated = request.unallocated; } @Override diff --git a/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java b/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java index b91612a9aae..c2ff257457e 100644 --- a/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java +++ b/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java @@ -25,14 +25,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StringStreamable; -import org.elasticsearch.common.io.stream.VoidStreamable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.jmx.JmxService; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.BaseTransportRequestHandler; -import org.elasticsearch.transport.FutureTransportResponseHandler; -import org.elasticsearch.transport.TransportChannel; -import org.elasticsearch.transport.TransportService; +import org.elasticsearch.transport.*; /** * @@ -60,7 +56,7 @@ public class GetJmxServiceUrlAction extends AbstractComponent { if (clusterService.state().nodes().localNodeId().equals(node.id())) { return jmxService.publishUrl(); } else { - return transportService.submitRequest(node, GetJmxServiceUrlTransportHandler.ACTION, VoidStreamable.INSTANCE, new FutureTransportResponseHandler() { + return transportService.submitRequest(node, GetJmxServiceUrlTransportHandler.ACTION, TransportRequest.Empty.INSTANCE, new FutureTransportResponseHandler() { @Override public StringStreamable newInstance() { return new StringStreamable(); @@ -69,13 +65,13 @@ public class GetJmxServiceUrlAction extends AbstractComponent { } } - private class GetJmxServiceUrlTransportHandler extends BaseTransportRequestHandler { + private class GetJmxServiceUrlTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "jmx/publishUrl"; @Override - public VoidStreamable newInstance() { - return VoidStreamable.INSTANCE; + public TransportRequest.Empty newInstance() { + return TransportRequest.Empty.INSTANCE; } @Override @@ -84,7 +80,7 @@ public class GetJmxServiceUrlAction extends AbstractComponent { } @Override - public void messageReceived(VoidStreamable request, TransportChannel channel) throws Exception { + public void messageReceived(TransportRequest.Empty request, TransportChannel channel) throws Exception { channel.sendResponse(new StringStreamable(jmxService.publishUrl())); } } diff --git a/src/main/java/org/elasticsearch/river/cluster/PublishRiverClusterStateAction.java b/src/main/java/org/elasticsearch/river/cluster/PublishRiverClusterStateAction.java index 51ce936b096..bc550aa87d8 100644 --- a/src/main/java/org/elasticsearch/river/cluster/PublishRiverClusterStateAction.java +++ b/src/main/java/org/elasticsearch/river/cluster/PublishRiverClusterStateAction.java @@ -25,7 +25,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.VoidStreamable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; @@ -86,7 +85,7 @@ public class PublishRiverClusterStateAction extends AbstractComponent { } } - private class PublishClusterStateRequest implements Streamable { + private class PublishClusterStateRequest extends TransportRequest { private RiverClusterState clusterState; @@ -99,11 +98,13 @@ public class PublishRiverClusterStateAction extends AbstractComponent { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); clusterState = RiverClusterState.Builder.readFrom(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); RiverClusterState.Builder.writeTo(clusterState, out); } } diff --git a/src/main/java/org/elasticsearch/search/SearchService.java b/src/main/java/org/elasticsearch/search/SearchService.java index 0bf279eb4c6..4ef419f07c9 100644 --- a/src/main/java/org/elasticsearch/search/SearchService.java +++ b/src/main/java/org/elasticsearch/search/SearchService.java @@ -51,8 +51,8 @@ import org.elasticsearch.search.dfs.DfsPhase; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.*; import org.elasticsearch.search.internal.InternalScrollSearchRequest; -import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.SearchContext; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.*; import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.threadpool.ThreadPool; @@ -164,7 +164,7 @@ public class SearchService extends AbstractLifecycleComponent { } } - public DfsSearchResult executeDfsPhase(InternalSearchRequest request) throws ElasticSearchException { + public DfsSearchResult executeDfsPhase(ShardSearchRequest request) throws ElasticSearchException { SearchContext context = createContext(request); activeContexts.put(context.id(), context); try { @@ -181,7 +181,7 @@ public class SearchService extends AbstractLifecycleComponent { } } - public QuerySearchResult executeScan(InternalSearchRequest request) throws ElasticSearchException { + public QuerySearchResult executeScan(ShardSearchRequest request) throws ElasticSearchException { SearchContext context = createContext(request); assert context.searchType() == SearchType.SCAN; context.searchType(SearchType.COUNT); // move to COUNT, and then, when scrolling, move to SCAN @@ -232,7 +232,7 @@ public class SearchService extends AbstractLifecycleComponent { } } - public QuerySearchResult executeQueryPhase(InternalSearchRequest request) throws ElasticSearchException { + public QuerySearchResult executeQueryPhase(ShardSearchRequest request) throws ElasticSearchException { SearchContext context = createContext(request); activeContexts.put(context.id(), context); try { @@ -305,7 +305,7 @@ public class SearchService extends AbstractLifecycleComponent { } } - public QueryFetchSearchResult executeFetchPhase(InternalSearchRequest request) throws ElasticSearchException { + public QueryFetchSearchResult executeFetchPhase(ShardSearchRequest request) throws ElasticSearchException { SearchContext context = createContext(request); activeContexts.put(context.id(), context); contextProcessing(context); @@ -462,11 +462,11 @@ public class SearchService extends AbstractLifecycleComponent { return context; } - SearchContext createContext(InternalSearchRequest request) throws ElasticSearchException { + SearchContext createContext(ShardSearchRequest request) throws ElasticSearchException { return createContext(request, null); } - SearchContext createContext(InternalSearchRequest request, @Nullable Engine.Searcher searcher) throws ElasticSearchException { + SearchContext createContext(ShardSearchRequest request, @Nullable Engine.Searcher searcher) throws ElasticSearchException { IndexService indexService = indicesService.indexServiceSafe(request.index()); IndexShard indexShard = indexService.shardSafe(request.shardId()); @@ -639,7 +639,7 @@ public class SearchService extends AbstractLifecycleComponent { SearchContext context = null; try { long now = System.nanoTime(); - InternalSearchRequest request = new InternalSearchRequest(indexShard.shardId().index().name(), indexShard.shardId().id(), indexMetaData.numberOfShards(), SearchType.COUNT) + ShardSearchRequest request = new ShardSearchRequest(indexShard.shardId().index().name(), indexShard.shardId().id(), indexMetaData.numberOfShards(), SearchType.COUNT) .source(entry.source()) .types(entry.types()); context = createContext(request, warmerContext.newSearcher()); diff --git a/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java b/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java index 510645a01bc..a37bd76eec8 100644 --- a/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java +++ b/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java @@ -19,11 +19,13 @@ package org.elasticsearch.search.action; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.stream.LongStreamable; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.VoidStreamable; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; @@ -34,13 +36,15 @@ import org.elasticsearch.search.fetch.FetchSearchResult; import org.elasticsearch.search.fetch.QueryFetchSearchResult; import org.elasticsearch.search.fetch.ScrollQueryFetchSearchResult; import org.elasticsearch.search.internal.InternalScrollSearchRequest; -import org.elasticsearch.search.internal.InternalSearchRequest; +import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.ScrollQuerySearchResult; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; +import java.io.IOException; + /** * An encapsulation of {@link org.elasticsearch.search.SearchService} operations exposed through * transport. @@ -90,15 +94,15 @@ public class SearchServiceTransportAction extends AbstractComponent { transportService.registerHandler(SearchScanScrollTransportHandler.ACTION, new SearchScanScrollTransportHandler()); } - public void sendFreeContext(DiscoveryNode node, final long contextId) { + public void sendFreeContext(DiscoveryNode node, final long contextId, SearchRequest request) { if (clusterService.state().nodes().localNodeId().equals(node.id())) { searchService.freeContext(contextId); } else { - transportService.sendRequest(node, SearchFreeContextTransportHandler.ACTION, new LongStreamable(contextId), freeContextResponseHandler); + transportService.sendRequest(node, SearchFreeContextTransportHandler.ACTION, new SearchFreeContextRequest(request, contextId), freeContextResponseHandler); } } - public void sendExecuteDfs(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener listener) { + public void sendExecuteDfs(DiscoveryNode node, final ShardSearchRequest request, final SearchServiceListener listener) { if (clusterService.state().nodes().localNodeId().equals(node.id())) { try { DfsSearchResult result = searchService.executeDfsPhase(request); @@ -132,7 +136,7 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - public void sendExecuteQuery(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener listener) { + public void sendExecuteQuery(DiscoveryNode node, final ShardSearchRequest request, final SearchServiceListener listener) { if (clusterService.state().nodes().localNodeId().equals(node.id())) { try { QuerySearchResult result = searchService.executeQueryPhase(request); @@ -234,7 +238,7 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - public void sendExecuteFetch(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener listener) { + public void sendExecuteFetch(DiscoveryNode node, final ShardSearchRequest request, final SearchServiceListener listener) { if (clusterService.state().nodes().localNodeId().equals(node.id())) { try { QueryFetchSearchResult result = searchService.executeFetchPhase(request); @@ -370,7 +374,7 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - public void sendExecuteScan(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener listener) { + public void sendExecuteScan(DiscoveryNode node, final ShardSearchRequest request, final SearchServiceListener listener) { if (clusterService.state().nodes().localNodeId().equals(node.id())) { try { QuerySearchResult result = searchService.executeScan(request); @@ -438,18 +442,47 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - private class SearchFreeContextTransportHandler extends BaseTransportRequestHandler { + class SearchFreeContextRequest extends TransportRequest { + + private long id; + + SearchFreeContextRequest() { + } + + SearchFreeContextRequest(SearchRequest request, long id) { + super(request); + this.id = id; + } + + public long id() { + return this.id; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + id = in.readLong(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeLong(id); + } + } + + class SearchFreeContextTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "search/freeContext"; @Override - public LongStreamable newInstance() { - return new LongStreamable(); + public SearchFreeContextRequest newInstance() { + return new SearchFreeContextRequest(); } @Override - public void messageReceived(LongStreamable request, TransportChannel channel) throws Exception { - searchService.freeContext(request.get()); + public void messageReceived(SearchFreeContextRequest request, TransportChannel channel) throws Exception { + searchService.freeContext(request.id()); channel.sendResponse(VoidStreamable.INSTANCE); } @@ -462,17 +495,17 @@ public class SearchServiceTransportAction extends AbstractComponent { } - private class SearchDfsTransportHandler extends BaseTransportRequestHandler { + private class SearchDfsTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "search/phase/dfs"; @Override - public InternalSearchRequest newInstance() { - return new InternalSearchRequest(); + public ShardSearchRequest newInstance() { + return new ShardSearchRequest(); } @Override - public void messageReceived(InternalSearchRequest request, TransportChannel channel) throws Exception { + public void messageReceived(ShardSearchRequest request, TransportChannel channel) throws Exception { DfsSearchResult result = searchService.executeDfsPhase(request); channel.sendResponse(result); } @@ -483,17 +516,17 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - private class SearchQueryTransportHandler extends BaseTransportRequestHandler { + private class SearchQueryTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "search/phase/query"; @Override - public InternalSearchRequest newInstance() { - return new InternalSearchRequest(); + public ShardSearchRequest newInstance() { + return new ShardSearchRequest(); } @Override - public void messageReceived(InternalSearchRequest request, TransportChannel channel) throws Exception { + public void messageReceived(ShardSearchRequest request, TransportChannel channel) throws Exception { QuerySearchResult result = searchService.executeQueryPhase(request); channel.sendResponse(result); } @@ -546,17 +579,17 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - private class SearchQueryFetchTransportHandler extends BaseTransportRequestHandler { + private class SearchQueryFetchTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "search/phase/query+fetch"; @Override - public InternalSearchRequest newInstance() { - return new InternalSearchRequest(); + public ShardSearchRequest newInstance() { + return new ShardSearchRequest(); } @Override - public void messageReceived(InternalSearchRequest request, TransportChannel channel) throws Exception { + public void messageReceived(ShardSearchRequest request, TransportChannel channel) throws Exception { QueryFetchSearchResult result = searchService.executeFetchPhase(request); channel.sendResponse(result); } @@ -630,17 +663,17 @@ public class SearchServiceTransportAction extends AbstractComponent { } } - private class SearchScanTransportHandler extends BaseTransportRequestHandler { + private class SearchScanTransportHandler extends BaseTransportRequestHandler { static final String ACTION = "search/phase/scan"; @Override - public InternalSearchRequest newInstance() { - return new InternalSearchRequest(); + public ShardSearchRequest newInstance() { + return new ShardSearchRequest(); } @Override - public void messageReceived(InternalSearchRequest request, TransportChannel channel) throws Exception { + public void messageReceived(ShardSearchRequest request, TransportChannel channel) throws Exception { QuerySearchResult result = searchService.executeScan(request); channel.sendResponse(result); } diff --git a/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java b/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java index ed33703ed07..244a675c750 100644 --- a/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java +++ b/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java @@ -21,15 +21,15 @@ package org.elasticsearch.search.fetch; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.trove.ExtTIntArrayList; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; /** * */ -public class FetchSearchRequest implements Streamable { +public class FetchSearchRequest extends TransportRequest { private long id; @@ -40,18 +40,13 @@ public class FetchSearchRequest implements Streamable { public FetchSearchRequest() { } - public FetchSearchRequest(long id, ExtTIntArrayList list) { + public FetchSearchRequest(TransportRequest request, long id, ExtTIntArrayList list) { + super(request); this.id = id; this.docIds = list.unsafeArray(); this.size = list.size(); } - public FetchSearchRequest(long id, int[] docIds) { - this.id = id; - this.docIds = docIds; - this.size = docIds.length; - } - public long id() { return id; } @@ -66,6 +61,7 @@ public class FetchSearchRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); id = in.readLong(); size = in.readVInt(); docIds = new int[size]; @@ -76,6 +72,7 @@ public class FetchSearchRequest implements Streamable { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(id); out.writeVInt(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java b/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java index 4eb97cdb6a9..5984f44997e 100644 --- a/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java +++ b/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java @@ -19,10 +19,11 @@ package org.elasticsearch.search.internal; +import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.search.Scroll; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -31,7 +32,7 @@ import static org.elasticsearch.search.Scroll.readScroll; /** * */ -public class InternalScrollSearchRequest implements Streamable { +public class InternalScrollSearchRequest extends TransportRequest { private long id; @@ -40,6 +41,12 @@ public class InternalScrollSearchRequest implements Streamable { public InternalScrollSearchRequest() { } + public InternalScrollSearchRequest(SearchScrollRequest request, long id) { + super(request); + this.id = id; + this.scroll = request.scroll(); + } + public InternalScrollSearchRequest(long id) { this.id = id; } @@ -59,6 +66,7 @@ public class InternalScrollSearchRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); id = in.readLong(); if (in.readBoolean()) { scroll = readScroll(in); @@ -67,6 +75,7 @@ public class InternalScrollSearchRequest implements Streamable { @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(id); if (scroll == null) { out.writeBoolean(false); diff --git a/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/src/main/java/org/elasticsearch/search/internal/SearchContext.java index 0b58c3995aa..eec9f9d5b60 100644 --- a/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -85,7 +85,7 @@ public class SearchContext implements Releasable { private final long id; - private final InternalSearchRequest request; + private final ShardSearchRequest request; private final SearchShardTarget shardTarget; @@ -168,7 +168,7 @@ public class SearchContext implements Releasable { private Map nestedQueries; - public SearchContext(long id, InternalSearchRequest request, SearchShardTarget shardTarget, + public SearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget, Engine.Searcher engineSearcher, IndexService indexService, IndexShard indexShard, ScriptService scriptService) { this.id = id; this.request = request; @@ -235,7 +235,7 @@ public class SearchContext implements Releasable { return this.id; } - public InternalSearchRequest request() { + public ShardSearchRequest request() { return this.request; } diff --git a/src/main/java/org/elasticsearch/search/internal/InternalSearchRequest.java b/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java similarity index 70% rename from src/main/java/org/elasticsearch/search/internal/InternalSearchRequest.java rename to src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java index 86073944a4f..c2c063ec286 100644 --- a/src/main/java/org/elasticsearch/search/internal/InternalSearchRequest.java +++ b/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java @@ -19,14 +19,15 @@ package org.elasticsearch.search.internal; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.search.Scroll; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -49,7 +50,7 @@ import static org.elasticsearch.search.Scroll.readScroll; * } * */ -public class InternalSearchRequest implements Streamable { +public class ShardSearchRequest extends TransportRequest { private String index; @@ -70,14 +71,27 @@ public class InternalSearchRequest implements Streamable { private long nowInMillis; - public InternalSearchRequest() { + public ShardSearchRequest() { } - public InternalSearchRequest(ShardRouting shardRouting, int numberOfShards, SearchType searchType) { + public ShardSearchRequest(SearchRequest searchRequest, ShardRouting shardRouting, int numberOfShards) { + super(searchRequest); + this.index = shardRouting.index(); + this.shardId = shardRouting.id(); + this.numberOfShards = numberOfShards; + this.searchType = searchRequest.searchType(); + this.source = searchRequest.source(); + this.extraSource = searchRequest.extraSource(); + this.scroll = searchRequest.scroll(); + this.types = searchRequest.types(); + + } + + public ShardSearchRequest(ShardRouting shardRouting, int numberOfShards, SearchType searchType) { this(shardRouting.index(), shardRouting.id(), numberOfShards, searchType); } - public InternalSearchRequest(String index, int shardId, int numberOfShards, SearchType searchType) { + public ShardSearchRequest(String index, int shardId, int numberOfShards, SearchType searchType) { this.index = index; this.shardId = shardId; this.numberOfShards = numberOfShards; @@ -108,17 +122,17 @@ public class InternalSearchRequest implements Streamable { return this.extraSource; } - public InternalSearchRequest source(BytesReference source) { + public ShardSearchRequest source(BytesReference source) { this.source = source; return this; } - public InternalSearchRequest extraSource(BytesReference extraSource) { + public ShardSearchRequest extraSource(BytesReference extraSource) { this.extraSource = extraSource; return this; } - public InternalSearchRequest nowInMillis(long nowInMillis) { + public ShardSearchRequest nowInMillis(long nowInMillis) { this.nowInMillis = nowInMillis; return this; } @@ -131,7 +145,7 @@ public class InternalSearchRequest implements Streamable { return scroll; } - public InternalSearchRequest scroll(Scroll scroll) { + public ShardSearchRequest scroll(Scroll scroll) { this.scroll = scroll; return this; } @@ -140,7 +154,7 @@ public class InternalSearchRequest implements Streamable { return filteringAliases; } - public InternalSearchRequest filteringAliases(String[] filteringAliases) { + public ShardSearchRequest filteringAliases(String[] filteringAliases) { this.filteringAliases = filteringAliases; return this; } @@ -149,14 +163,15 @@ public class InternalSearchRequest implements Streamable { return types; } - public InternalSearchRequest types(String[] types) { + public ShardSearchRequest types(String[] types) { this.types = types; return this; } @Override public void readFrom(StreamInput in) throws IOException { - index = in.readUTF(); + super.readFrom(in); + index = in.readString(); shardId = in.readVInt(); searchType = SearchType.fromId(in.readByte()); numberOfShards = in.readVInt(); @@ -167,28 +182,15 @@ public class InternalSearchRequest implements Streamable { source = in.readBytesReference(); extraSource = in.readBytesReference(); - int typesSize = in.readVInt(); - if (typesSize > 0) { - types = new String[typesSize]; - for (int i = 0; i < typesSize; i++) { - types[i] = in.readUTF(); - } - } - int indicesSize = in.readVInt(); - if (indicesSize > 0) { - filteringAliases = new String[indicesSize]; - for (int i = 0; i < indicesSize; i++) { - filteringAliases[i] = in.readUTF(); - } - } else { - filteringAliases = null; - } + types = in.readStringArray(); + filteringAliases = in.readStringArray(); nowInMillis = in.readVLong(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(index); + super.writeTo(out); + out.writeString(index); out.writeVInt(shardId); out.writeByte(searchType.id()); out.writeVInt(numberOfShards); @@ -200,18 +202,8 @@ public class InternalSearchRequest implements Streamable { } out.writeBytesReference(source); out.writeBytesReference(extraSource); - out.writeVInt(types.length); - for (String type : types) { - out.writeUTF(type); - } - if (filteringAliases != null) { - out.writeVInt(filteringAliases.length); - for (String index : filteringAliases) { - out.writeUTF(index); - } - } else { - out.writeVInt(0); - } + out.writeStringArray(types); + out.writeStringArrayNullable(filteringAliases); out.writeVLong(nowInMillis); } } diff --git a/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java b/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java index f5f1cd050d0..bc64d008d26 100644 --- a/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java +++ b/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java @@ -19,10 +19,11 @@ package org.elasticsearch.search.query; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.search.dfs.AggregatedDfs; +import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -31,7 +32,7 @@ import static org.elasticsearch.search.dfs.AggregatedDfs.readAggregatedDfs; /** * */ -public class QuerySearchRequest implements Streamable { +public class QuerySearchRequest extends TransportRequest { private long id; @@ -40,7 +41,8 @@ public class QuerySearchRequest implements Streamable { public QuerySearchRequest() { } - public QuerySearchRequest(long id, AggregatedDfs dfs) { + public QuerySearchRequest(SearchRequest request, long id, AggregatedDfs dfs) { + super(request); this.id = id; this.dfs = dfs; } @@ -55,12 +57,14 @@ public class QuerySearchRequest implements Streamable { @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); id = in.readLong(); dfs = readAggregatedDfs(in); } @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeLong(id); dfs.writeTo(out); } diff --git a/src/main/java/org/elasticsearch/transport/BaseTransportRequestHandler.java b/src/main/java/org/elasticsearch/transport/BaseTransportRequestHandler.java index 296b78012fc..7cc4f163de4 100644 --- a/src/main/java/org/elasticsearch/transport/BaseTransportRequestHandler.java +++ b/src/main/java/org/elasticsearch/transport/BaseTransportRequestHandler.java @@ -19,13 +19,9 @@ package org.elasticsearch.transport; -import org.elasticsearch.common.io.stream.Streamable; - /** * A simple based class that always spawns. - * - * */ -public abstract class BaseTransportRequestHandler implements TransportRequestHandler { +public abstract class BaseTransportRequestHandler implements TransportRequestHandler { } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/transport/Transport.java b/src/main/java/org/elasticsearch/transport/Transport.java index 112121bc020..741a34cf2b1 100644 --- a/src/main/java/org/elasticsearch/transport/Transport.java +++ b/src/main/java/org/elasticsearch/transport/Transport.java @@ -21,7 +21,6 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; @@ -73,7 +72,7 @@ public interface Transport extends LifecycleComponent { /** * Sends the request to the node. */ - void sendRequest(DiscoveryNode node, long requestId, String action, Streamable message, TransportRequestOptions options) throws IOException, TransportException; + void sendRequest(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException; long serverOpen(); } diff --git a/src/main/java/org/elasticsearch/transport/TransportRequest.java b/src/main/java/org/elasticsearch/transport/TransportRequest.java new file mode 100644 index 00000000000..1cfb196dd78 --- /dev/null +++ b/src/main/java/org/elasticsearch/transport/TransportRequest.java @@ -0,0 +1,99 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.transport; + +import com.google.common.collect.Maps; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Streamable; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + */ +public abstract class TransportRequest implements Streamable { + + public static class Empty extends TransportRequest { + + public static final Empty INSTANCE = new Empty(); + + public Empty() { + super(); + } + + public Empty(TransportRequest request) { + super(request); + } + } + + private Map headers; + + protected TransportRequest() { + + } + + protected TransportRequest(TransportRequest request) { + // create a new copy of the headers, since we are creating a new request which might have + // its headers changed in the context of that specific request + if (request.getHeaders() != null) { + this.headers = new HashMap(request.getHeaders()); + } + } + + @SuppressWarnings("unchecked") + public final TransportRequest putHeader(String key, Object value) { + if (headers == null) { + headers = Maps.newHashMap(); + } + headers.put(key, value); + return this; + } + + @SuppressWarnings("unchecked") + public final V getHeader(String key) { + if (headers == null) { + return null; + } + return (V) headers.get(key); + } + + public Map getHeaders() { + return this.headers; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + if (in.readBoolean()) { + headers = in.readMap(); + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + if (headers == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + out.writeMap(headers); + } + } +} diff --git a/src/main/java/org/elasticsearch/transport/TransportRequestHandler.java b/src/main/java/org/elasticsearch/transport/TransportRequestHandler.java index 9986c065e63..7bb82e9a0a4 100644 --- a/src/main/java/org/elasticsearch/transport/TransportRequestHandler.java +++ b/src/main/java/org/elasticsearch/transport/TransportRequestHandler.java @@ -19,12 +19,10 @@ package org.elasticsearch.transport; -import org.elasticsearch.common.io.stream.Streamable; - /** * */ -public interface TransportRequestHandler { +public interface TransportRequestHandler { T newInstance(); diff --git a/src/main/java/org/elasticsearch/transport/TransportService.java b/src/main/java/org/elasticsearch/transport/TransportService.java index 6cc181697d6..25eab8a26d2 100644 --- a/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/src/main/java/org/elasticsearch/transport/TransportService.java @@ -155,24 +155,24 @@ public class TransportService extends AbstractLifecycleComponent TransportFuture submitRequest(DiscoveryNode node, String action, Streamable message, + public TransportFuture submitRequest(DiscoveryNode node, String action, TransportRequest request, TransportResponseHandler handler) throws TransportException { - return submitRequest(node, action, message, TransportRequestOptions.EMPTY, handler); + return submitRequest(node, action, request, TransportRequestOptions.EMPTY, handler); } - public TransportFuture submitRequest(DiscoveryNode node, String action, Streamable message, + public TransportFuture submitRequest(DiscoveryNode node, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler handler) throws TransportException { PlainTransportFuture futureHandler = new PlainTransportFuture(handler); - sendRequest(node, action, message, options, futureHandler); + sendRequest(node, action, request, options, futureHandler); return futureHandler; } - public void sendRequest(final DiscoveryNode node, final String action, final Streamable message, + public void sendRequest(final DiscoveryNode node, final String action, final TransportRequest request, final TransportResponseHandler handler) throws TransportException { - sendRequest(node, action, message, TransportRequestOptions.EMPTY, handler); + sendRequest(node, action, request, TransportRequestOptions.EMPTY, handler); } - public void sendRequest(final DiscoveryNode node, final String action, final Streamable message, + public void sendRequest(final DiscoveryNode node, final String action, final TransportRequest request, final TransportRequestOptions options, final TransportResponseHandler handler) throws TransportException { final long requestId = newRequestId(); TimeoutHandler timeoutHandler = null; @@ -182,7 +182,7 @@ public class TransportService extends AbstractLifecycleComponent(handler, node, action, timeoutHandler)); - transport.sendRequest(node, requestId, action, message, options); + transport.sendRequest(node, requestId, action, request, options); } catch (final Exception e) { // usually happen either because we failed to connect to the node // or because we failed serializing the message @@ -215,10 +215,6 @@ public class TransportService extends AbstractLifecycleComponent implem } @Override - public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final Streamable message, TransportRequestOptions options) throws IOException, TransportException { + public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { CachedStreamOutput.Entry cachedEntry = CachedStreamOutput.popEntry(); try { StreamOutput stream = cachedEntry.handles(); @@ -166,8 +166,8 @@ public class LocalTransport extends AbstractLifecycleComponent implem status = TransportStatus.setRequest(status); stream.writeByte(status); // 0 for request, 1 for response. - stream.writeUTF(action); - message.writeTo(stream); + stream.writeString(action); + request.writeTo(stream); stream.close(); @@ -231,16 +231,16 @@ public class LocalTransport extends AbstractLifecycleComponent implem } private void handleRequest(StreamInput stream, long requestId, LocalTransport sourceTransport) throws Exception { - final String action = stream.readUTF(); + final String action = stream.readString(); final LocalTransportChannel transportChannel = new LocalTransportChannel(this, sourceTransport, action, requestId); try { final TransportRequestHandler handler = transportServiceAdapter.handler(action); if (handler == null) { throw new ActionNotFoundTransportException("Action [" + action + "] not found"); } - final Streamable streamable = handler.newInstance(); - streamable.readFrom(stream); - handler.messageReceived(streamable, transportChannel); + final TransportRequest request = handler.newInstance(); + request.readFrom(stream); + handler.messageReceived(request, transportChannel); } catch (Exception e) { try { transportChannel.sendResponse(e); diff --git a/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java b/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java index 888175bba8d..8bf8a459f71 100644 --- a/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java +++ b/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java @@ -204,13 +204,13 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { if (handler == null) { throw new ActionNotFoundTransportException(action); } - final Streamable streamable = handler.newInstance(); - streamable.readFrom(buffer); + final TransportRequest request = handler.newInstance(); + request.readFrom(buffer); if (handler.executor() == ThreadPool.Names.SAME) { //noinspection unchecked - handler.messageReceived(streamable, transportChannel); + handler.messageReceived(request, transportChannel); } else { - threadPool.executor(handler.executor()).execute(new RequestHandler(handler, streamable, transportChannel, action)); + threadPool.executor(handler.executor()).execute(new RequestHandler(handler, request, transportChannel, action)); } } catch (Exception e) { try { @@ -251,13 +251,13 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { class RequestHandler implements Runnable { private final TransportRequestHandler handler; - private final Streamable streamable; + private final TransportRequest request; private final NettyTransportChannel transportChannel; private final String action; - public RequestHandler(TransportRequestHandler handler, Streamable streamable, NettyTransportChannel transportChannel, String action) { + public RequestHandler(TransportRequestHandler handler, TransportRequest request, NettyTransportChannel transportChannel, String action) { this.handler = handler; - this.streamable = streamable; + this.request = request; this.transportChannel = transportChannel; this.action = action; } @@ -266,7 +266,7 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { @Override public void run() { try { - handler.messageReceived(streamable, transportChannel); + handler.messageReceived(request, transportChannel); } catch (Throwable e) { if (transport.lifecycleState() == Lifecycle.State.STARTED) { // we can only send a response transport is started.... diff --git a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index 44b40d6eba6..53e194b1009 100644 --- a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.compress.CompressorFactory; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.CachedStreamOutput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.netty.NettyStaticSetup; import org.elasticsearch.common.netty.OpenChannelsHandler; import org.elasticsearch.common.network.NetworkService; @@ -508,7 +507,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem } @Override - public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final Streamable message, TransportRequestOptions options) throws IOException, TransportException { + public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { Channel targetChannel = nodeChannel(node, options); if (compress) { @@ -526,14 +525,14 @@ public class NettyTransport extends AbstractLifecycleComponent implem StreamOutput stream = cachedEntry.handles(CompressorFactory.defaultCompressor()); stream.setVersion(node.version()); stream.writeString(action); - message.writeTo(stream); + request.writeTo(stream); stream.close(); } else { StreamOutput stream = cachedEntry.handles(); cachedEntry.bytes().skip(NettyHeader.HEADER_SIZE); stream.setVersion(node.version()); stream.writeString(action); - message.writeTo(stream); + request.writeTo(stream); stream.close(); } ChannelBuffer buffer = cachedEntry.bytes().bytes().toChannelBuffer(); diff --git a/src/test/java/org/elasticsearch/benchmark/transport/BenchmarkNettyLargeMessages.java b/src/test/java/org/elasticsearch/benchmark/transport/BenchmarkNettyLargeMessages.java index 5f2455ffa97..7b273d34fd6 100644 --- a/src/test/java/org/elasticsearch/benchmark/transport/BenchmarkNettyLargeMessages.java +++ b/src/test/java/org/elasticsearch/benchmark/transport/BenchmarkNettyLargeMessages.java @@ -19,6 +19,7 @@ package org.elasticsearch.benchmark.transport; +import org.elasticsearch.benchmark.transport.netty.BenchmarkMessageRequest; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Bytes; import org.elasticsearch.common.settings.ImmutableSettings; @@ -59,10 +60,10 @@ public class BenchmarkNettyLargeMessages { transportServiceClient.connectToNode(bigNode); transportServiceClient.connectToNode(smallNode); - transportServiceServer.registerHandler("benchmark", new BaseTransportRequestHandler() { + transportServiceServer.registerHandler("benchmark", new BaseTransportRequestHandler() { @Override - public BenchmarkMessage newInstance() { - return new BenchmarkMessage(); + public BenchmarkMessageRequest newInstance() { + return new BenchmarkMessageRequest(); } @Override @@ -71,7 +72,7 @@ public class BenchmarkNettyLargeMessages { } @Override - public void messageReceived(BenchmarkMessage request, TransportChannel channel) throws Exception { + public void messageReceived(BenchmarkMessageRequest request, TransportChannel channel) throws Exception { channel.sendResponse(request); } }); @@ -82,7 +83,7 @@ public class BenchmarkNettyLargeMessages { @Override public void run() { for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { - BenchmarkMessage message = new BenchmarkMessage(1, payload); + BenchmarkMessageRequest message = new BenchmarkMessageRequest(1, payload); transportServiceClient.submitRequest(bigNode, "benchmark", message, options().withLowType(), new BaseTransportResponseHandler() { @Override public BenchmarkMessage newInstance() { @@ -113,7 +114,7 @@ public class BenchmarkNettyLargeMessages { @Override public void run() { for (int i = 0; i < 1; i++) { - BenchmarkMessage message = new BenchmarkMessage(2, Bytes.EMPTY_ARRAY); + BenchmarkMessageRequest message = new BenchmarkMessageRequest(2, Bytes.EMPTY_ARRAY); long start = System.currentTimeMillis(); transportServiceClient.submitRequest(smallNode, "benchmark", message, options().withHighType(), new BaseTransportResponseHandler() { @Override diff --git a/src/test/java/org/elasticsearch/benchmark/transport/TransportBenchmark.java b/src/test/java/org/elasticsearch/benchmark/transport/TransportBenchmark.java index 8dc42ba5e29..314762b004f 100644 --- a/src/test/java/org/elasticsearch/benchmark/transport/TransportBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/transport/TransportBenchmark.java @@ -19,6 +19,7 @@ package org.elasticsearch.benchmark.transport; +import org.elasticsearch.benchmark.transport.netty.BenchmarkMessageRequest; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.StopWatch; import org.elasticsearch.common.settings.ImmutableSettings; @@ -77,10 +78,10 @@ public class TransportBenchmark { final DiscoveryNode node = new DiscoveryNode("server", serverTransportService.boundAddress().publishAddress()); - serverTransportService.registerHandler("benchmark", new BaseTransportRequestHandler() { + serverTransportService.registerHandler("benchmark", new BaseTransportRequestHandler() { @Override - public BenchmarkMessage newInstance() { - return new BenchmarkMessage(); + public BenchmarkMessageRequest newInstance() { + return new BenchmarkMessageRequest(); } @Override @@ -89,7 +90,7 @@ public class TransportBenchmark { } @Override - public void messageReceived(BenchmarkMessage request, TransportChannel channel) throws Exception { + public void messageReceived(BenchmarkMessageRequest request, TransportChannel channel) throws Exception { channel.sendResponse(request); } }); @@ -97,7 +98,7 @@ public class TransportBenchmark { clientTransportService.connectToNode(node); for (int i = 0; i < 10000; i++) { - BenchmarkMessage message = new BenchmarkMessage(1, payload); + BenchmarkMessageRequest message = new BenchmarkMessageRequest(1, payload); clientTransportService.submitRequest(node, "benchmark", message, new BaseTransportResponseHandler() { @Override public BenchmarkMessage newInstance() { @@ -129,7 +130,7 @@ public class TransportBenchmark { public void run() { for (int j = 0; j < NUMBER_OF_ITERATIONS; j++) { final long id = idGenerator.incrementAndGet(); - BenchmarkMessage message = new BenchmarkMessage(id, payload); + BenchmarkMessageRequest request = new BenchmarkMessageRequest(id, payload); BaseTransportResponseHandler handler = new BaseTransportResponseHandler() { @Override public BenchmarkMessage newInstance() { @@ -157,9 +158,9 @@ public class TransportBenchmark { }; if (waitForRequest) { - clientTransportService.submitRequest(node, "benchmark", message, handler).txGet(); + clientTransportService.submitRequest(node, "benchmark", request, handler).txGet(); } else { - clientTransportService.sendRequest(node, "benchmark", message, handler); + clientTransportService.sendRequest(node, "benchmark", request, handler); } } } diff --git a/src/test/java/org/elasticsearch/benchmark/transport/netty/BenchmarkMessageRequest.java b/src/test/java/org/elasticsearch/benchmark/transport/netty/BenchmarkMessageRequest.java new file mode 100644 index 00000000000..b7015a8eb38 --- /dev/null +++ b/src/test/java/org/elasticsearch/benchmark/transport/netty/BenchmarkMessageRequest.java @@ -0,0 +1,59 @@ +/* + * Licensed to ElasticSearch and Shay Banon 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.benchmark.transport.netty; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.transport.TransportRequest; + +import java.io.IOException; + +/** + * + */ +public class BenchmarkMessageRequest extends TransportRequest { + + long id; + byte[] payload; + + public BenchmarkMessageRequest(long id, byte[] payload) { + this.id = id; + this.payload = payload; + } + + public BenchmarkMessageRequest() { + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + id = in.readLong(); + payload = new byte[in.readVInt()]; + in.readFully(payload); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeLong(id); + out.writeVInt(payload.length); + out.writeBytes(payload); + } +} diff --git a/src/test/java/org/elasticsearch/test/integration/search/embedded/SingleShardEmbeddedSearchTests.java b/src/test/java/org/elasticsearch/test/integration/search/embedded/SingleShardEmbeddedSearchTests.java deleted file mode 100644 index 5ad5237cb32..00000000000 --- a/src/test/java/org/elasticsearch/test/integration/search/embedded/SingleShardEmbeddedSearchTests.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon 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.test.integration.search.embedded; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.trove.ExtTIntArrayList; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.search.*; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.controller.SearchPhaseController; -import org.elasticsearch.search.controller.ShardDoc; -import org.elasticsearch.search.dfs.AggregatedDfs; -import org.elasticsearch.search.dfs.DfsSearchResult; -import org.elasticsearch.search.fetch.FetchSearchRequest; -import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.fetch.QueryFetchSearchResult; -import org.elasticsearch.search.internal.InternalScrollSearchRequest; -import org.elasticsearch.search.internal.InternalSearchRequest; -import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.search.query.QuerySearchRequest; -import org.elasticsearch.search.query.QuerySearchResult; -import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.test.integration.AbstractNodesTests; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.Map; -import java.util.Set; - -import static com.google.common.collect.Lists.newArrayList; -import static org.elasticsearch.client.Requests.indexRequest; -import static org.elasticsearch.client.Requests.refreshRequest; -import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.elasticsearch.index.query.QueryBuilders.termQuery; -import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * - */ -public class SingleShardEmbeddedSearchTests extends AbstractNodesTests { - - private SearchService searchService; - - private SearchPhaseController searchPhaseController; - - private Client client; - - protected boolean optimizeSingleShard() { - return true; - } - - @BeforeClass - public void createNodeAndInitWithData() throws Exception { - putDefaultSettings(settingsBuilder().put("search.controller.optimize_single_shard", optimizeSingleShard())); - startNode("server1"); - client = client("server1"); - - client.admin().indices().prepareCreate("test") - .setSettings(settingsBuilder().put("number_of_shards", 1).put("number_of_replicas", 0)) - .execute().actionGet(); - client("server1").admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); - index("1", "test1", 1); - index("2", "test2", 2); - index("3", "test3", 3); - index("4", "test4", 4); - index("5", "test5", 5); - client.admin().indices().refresh(refreshRequest("test")).actionGet(); - - searchService = ((InternalNode) node("server1")).injector().getInstance(SearchService.class); - searchPhaseController = ((InternalNode) node("server1")).injector().getInstance(SearchPhaseController.class); - } - - @AfterClass - public void closeNode() { - closeAllNodes(); - } - - @Test - public void verifyOptimizeSingleShardSetting() { - assertThat(searchPhaseController.optimizeSingleShard(), equalTo(optimizeSingleShard())); - } - - @Test - public void testDirectDfs() throws Exception { - DfsSearchResult dfsResult = searchService.executeDfsPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.DFS_QUERY_THEN_FETCH)); - - assertThat(dfsResult.terms().length, equalTo(1)); - assertThat(dfsResult.freqs().length, equalTo(1)); - assertThat(dfsResult.terms()[0].field(), equalTo("name")); - assertThat(dfsResult.terms()[0].text(), equalTo("test1")); - assertThat(dfsResult.freqs()[0], equalTo(1)); - } - - @Test - public void testDirectQuery() throws Exception { - QuerySearchResult queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(1)); - } - - @Test - public void testDirectFetch() throws Exception { - QueryFetchSearchResult queryFetchResult = searchService.executeFetchPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_AND_FETCH)); - assertThat(queryFetchResult.queryResult().topDocs().totalHits, equalTo(1)); - assertThat(queryFetchResult.fetchResult().hits().hits().length, equalTo(1)); - assertThat(queryFetchResult.fetchResult().hits().hits()[0].sourceAsString(), equalTo(source("1", "test1", 1))); - assertThat(queryFetchResult.fetchResult().hits().hits()[0].id(), equalTo("1")); - assertThat(queryFetchResult.fetchResult().hits().hits()[0].type(), equalTo("type1")); - } - - @Test - public void testScan() throws Exception { - Scroll scroll = new Scroll(TimeValue.timeValueMillis(500)); - QuerySearchResult scanResult = searchService.executeScan(searchRequest(searchSource().query(matchAllQuery()).size(2), SearchType.SCAN).scroll(scroll)); - assertThat(scanResult.queryResult().topDocs().totalHits, equalTo(5)); - - Set idsLoaded = Sets.newHashSet(); - // start scrolling - FetchSearchResult fetchResult = searchService.executeScan(new InternalScrollSearchRequest(scanResult.id()).scroll(scroll)).result().fetchResult(); - assertThat(fetchResult.hits().hits().length, equalTo(2)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - // and again... - fetchResult = searchService.executeScan(new InternalScrollSearchRequest(scanResult.id()).scroll(scroll)).result().fetchResult(); - assertThat(fetchResult.hits().hits().length, equalTo(2)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - fetchResult = searchService.executeScan(new InternalScrollSearchRequest(scanResult.id()).scroll(scroll)).result().fetchResult(); - assertThat(fetchResult.hits().hits().length, equalTo(1)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - - Set expectedIds = Sets.newHashSet("1", "2", "3", "4", "5"); - assertThat(idsLoaded, equalTo(expectedIds)); - - // do another one for fun, should be expired context - try { - searchService.executeScan(new InternalScrollSearchRequest(scanResult.id()).scroll(scroll)).result().fetchResult(); - assert false; - } catch (SearchContextMissingException e) { - // ignore - } - } - - @Test - public void testQueryThenFetch() throws Exception { - QuerySearchResult queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(1)); - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(1)); - - FetchSearchResult fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits()[0].sourceAsString(), equalTo(source("1", "test1", 1))); - assertThat(fetchResult.hits().hits()[0].id(), equalTo("1")); - assertThat(fetchResult.hits().hits()[0].type(), equalTo("type1")); - } - - @Test - public void testQueryThenFetchIterateWithFrom() throws Exception { - QuerySearchResult queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(matchAllQuery()).from(0).size(2), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(5)); - - Set idsLoaded = Sets.newHashSet(); - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(2)); - - FetchSearchResult fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits().length, equalTo(2)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - // iterate to the next 2 - queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(matchAllQuery()).from(2).size(2), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(5)); - - sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(2)); - - fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits().length, equalTo(2)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - // iterate to the next 2 - queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(matchAllQuery()).from(4).size(2), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(5)); - - sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(1)); - - fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits().length, equalTo(1)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - // verify all ids were loaded - Set expectedIds = Sets.newHashSet("1", "2", "3", "4", "5"); - assertThat(idsLoaded, equalTo(expectedIds)); - } - - @Test - public void testQueryThenFetchIterateWithFromSortedByAge() throws Exception { - QuerySearchResult queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(matchAllQuery()).from(0).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(5)); - - Set idsLoaded = Sets.newHashSet(); - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(2)); - - FetchSearchResult fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits().length, equalTo(2)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - // iterate to the next 2 - queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(matchAllQuery()).from(2).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(5)); - - sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(2)); - - fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits().length, equalTo(2)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - // iterate to the next 2 - queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(matchAllQuery()).from(4).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_THEN_FETCH)); - assertThat(queryResult.topDocs().totalHits, equalTo(5)); - - sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(1)); - - fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits().length, equalTo(1)); - for (SearchHit hit : fetchResult.hits()) { - idsLoaded.add(hit.id()); - } - - // verify all ids were loaded - Set expectedIds = Sets.newHashSet("1", "2", "3", "4", "5"); - assertThat(idsLoaded, equalTo(expectedIds)); - } - - @Test - public void testQueryAndFetch() throws Exception { - QueryFetchSearchResult result = searchService.executeFetchPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_AND_FETCH)); - FetchSearchResult fetchResult = result.fetchResult(); - assertThat(fetchResult.hits().hits()[0].sourceAsString(), equalTo(source("1", "test1", 1))); - assertThat(fetchResult.hits().hits()[0].id(), equalTo("1")); - assertThat(fetchResult.hits().hits()[0].type(), equalTo("type1")); - } - - @Test - public void testQueryAndFetchIterateWithFrom() throws Exception { - QueryFetchSearchResult result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(0).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH)); - assertThat(result.queryResult().topDocs().totalHits, equalTo(5)); - - Set idsLoaded = Sets.newHashSet(); - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(result)); - Map queryResults = Maps.newHashMap(); - queryResults.put(result.queryResult().shardTarget(), result); - InternalSearchResponse searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults); - - for (SearchHit hit : searchResponse.hits()) { - idsLoaded.add(hit.id()); - } - - // iterate to the next 2 - result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(2).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH)); - assertThat(result.queryResult().topDocs().totalHits, equalTo(5)); - - sortedShardList = searchPhaseController.sortDocs(newArrayList(result)); - queryResults = Maps.newHashMap(); - queryResults.put(result.queryResult().shardTarget(), result); - searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults); - - for (SearchHit hit : searchResponse.hits()) { - idsLoaded.add(hit.id()); - } - result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(4).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH)); - assertThat(result.queryResult().topDocs().totalHits, equalTo(5)); - - sortedShardList = searchPhaseController.sortDocs(newArrayList(result)); - queryResults = Maps.newHashMap(); - queryResults.put(result.queryResult().shardTarget(), result); - searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults); - - for (SearchHit hit : searchResponse.hits()) { - idsLoaded.add(hit.id()); - } - - // verify all ids were loaded - Set expectedIds = Sets.newHashSet("1", "2", "3", "4", "5"); - assertThat(idsLoaded, equalTo(expectedIds)); - } - - @Test - public void testDfsQueryThenFetch() throws Exception { - DfsSearchResult dfsResult = searchService.executeDfsPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.DFS_QUERY_THEN_FETCH)); - AggregatedDfs dfs = searchPhaseController.aggregateDfs(newArrayList(dfsResult)); - - QuerySearchResult queryResult = searchService.executeQueryPhase(new QuerySearchRequest(dfsResult.id(), dfs)); - assertThat(queryResult.topDocs().totalHits, equalTo(1)); - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(1)); - - FetchSearchResult fetchResult = searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assertThat(fetchResult.hits().hits()[0].sourceAsString(), equalTo(source("1", "test1", 1))); - assertThat(fetchResult.hits().hits()[0].id(), equalTo("1")); - assertThat(fetchResult.hits().hits()[0].type(), equalTo("type1")); - } - - @Test - public void testQueryFetchKeepAliveTimeout() throws Exception { - QuerySearchResult queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_THEN_FETCH).scroll(new Scroll(TimeValue.timeValueMillis(10)))); - assertThat(queryResult.topDocs().totalHits, equalTo(1)); - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(queryResult)); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - assertThat(docIdsToLoad.size(), equalTo(1)); - assertThat(docIdsToLoad.values().iterator().next().size(), equalTo(1)); - - // sleep more than the 100ms the timeout wheel it set to - Thread.sleep(300); - - try { - searchService.executeFetchPhase(new FetchSearchRequest(queryResult.id(), docIdsToLoad.values().iterator().next())); - assert true : "context should be missing since it timed out"; - } catch (SearchContextMissingException e) { - // all is well - } - } - - - private InternalSearchRequest searchRequest(SearchSourceBuilder builder, SearchType searchType) { - return new InternalSearchRequest("test", 0, 1, searchType).source(builder.buildAsBytes()); - } - - private void index(String id, String nameValue, int age) { - client.index(indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet(); - } - - private String source(String id, String nameValue, int age) { - return "{ type1 : { \"id\" : \"" + id + "\", \"name\" : \"" + nameValue + "\", age : " + age + " } }"; - } -} diff --git a/src/test/java/org/elasticsearch/test/integration/search/embedded/SingleShardNoOptimizationEmbeddedSearchTests.java b/src/test/java/org/elasticsearch/test/integration/search/embedded/SingleShardNoOptimizationEmbeddedSearchTests.java deleted file mode 100644 index 51e64d623b9..00000000000 --- a/src/test/java/org/elasticsearch/test/integration/search/embedded/SingleShardNoOptimizationEmbeddedSearchTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search 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.test.integration.search.embedded; - -public class SingleShardNoOptimizationEmbeddedSearchTests extends SingleShardEmbeddedSearchTests { - - @Override - protected boolean optimizeSingleShard() { - return false; - } -} \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/test/integration/search/embedded/ThreeShardsEmbeddedSearchTests.java b/src/test/java/org/elasticsearch/test/integration/search/embedded/ThreeShardsEmbeddedSearchTests.java deleted file mode 100644 index 3f2fbababe4..00000000000 --- a/src/test/java/org/elasticsearch/test/integration/search/embedded/ThreeShardsEmbeddedSearchTests.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon 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.test.integration.search.embedded; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.Requests; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.cluster.routing.ShardIterator; -import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.common.trove.ExtTIntArrayList; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.search.*; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.controller.SearchPhaseController; -import org.elasticsearch.search.controller.ShardDoc; -import org.elasticsearch.search.dfs.AggregatedDfs; -import org.elasticsearch.search.dfs.DfsSearchResult; -import org.elasticsearch.search.facet.FacetBuilders; -import org.elasticsearch.search.facet.query.QueryFacet; -import org.elasticsearch.search.fetch.FetchSearchRequest; -import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.fetch.QueryFetchSearchResult; -import org.elasticsearch.search.internal.InternalScrollSearchRequest; -import org.elasticsearch.search.internal.InternalSearchRequest; -import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.search.query.QuerySearchRequest; -import org.elasticsearch.search.query.QuerySearchResult; -import org.elasticsearch.search.query.QuerySearchResultProvider; -import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.test.integration.AbstractNodesTests; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; -import static org.elasticsearch.client.Requests.indexRequest; -import static org.elasticsearch.client.Requests.refreshRequest; -import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; -import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes; -import static org.elasticsearch.index.query.QueryBuilders.termQuery; -import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; - -/** - * - */ -public class ThreeShardsEmbeddedSearchTests extends AbstractNodesTests { - - private ClusterService clusterService; - - private Map nodeToSearchService; - - private SearchPhaseController searchPhaseController; - - @BeforeClass - public void createNodeAndInitWithData() throws Exception { - startNode("server1"); - startNode("server2"); - - clusterService = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class); - client("server1").admin().indices().create(Requests.createIndexRequest("test") - .settings(settingsBuilder().put("number_of_shards", 3).put("number_of_replicas", 0))) - .actionGet(); - - for (int i = 0; i < 100; i++) { - index(client("server1"), Integer.toString(i), "test", i); - } - client("server1").admin().indices().refresh(refreshRequest("test")).actionGet(); - - SearchService searchService1 = ((InternalNode) node("server1")).injector().getInstance(SearchService.class); - SearchService searchService2 = ((InternalNode) node("server2")).injector().getInstance(SearchService.class); - - nodeToSearchService = ImmutableMap.builder() - .put(((InternalNode) node("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService1) - .put(((InternalNode) node("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService2) - .build(); - - searchPhaseController = ((InternalNode) node("server1")).injector().getInstance(SearchPhaseController.class); - } - - @AfterClass - public void closeServers() { - closeAllNodes(); - } - - @Test - public void testDfsQueryThenFetch() throws Exception { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(60).explain(true).indexBoost("test", 1.0f).indexBoost("test2", 2.0f); - - List dfsResults = newArrayList(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_THEN_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - dfsResults.add(nodeToSearchService.get(shardRouting.currentNodeId()).executeDfsPhase(searchRequest)); - } - } - - AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults); - Map queryResults = newHashMap(); - for (DfsSearchResult dfsResult : dfsResults) { - queryResults.put(dfsResult.shardTarget(), nodeToSearchService.get(dfsResult.shardTarget().nodeId()).executeQueryPhase(new QuerySearchRequest(dfsResult.id(), dfs))); - } - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - Map fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - SearchHits hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(60)); - for (int i = 0; i < 60; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.explanation()); - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1))); - } - - // now try and scroll to the next batch of results - Map scrollQueryResults = newHashMap(); - for (QuerySearchResultProvider queryResult : queryResults.values()) { - scrollQueryResults.put(queryResult.queryResult().shardTarget(), nodeToSearchService.get(queryResult.shardTarget().nodeId()).executeQueryPhase(new InternalScrollSearchRequest(queryResult.id())).queryResult()); - } - queryResults = scrollQueryResults; - - sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(40)); - for (int i = 0; i < 40; i++) { - SearchHit hit = hits.hits()[i]; - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - 60 - 1 - i))); - } - } - - @Test - public void testDfsQueryThenFetchWithSort() throws Exception { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(60).explain(true).sort("age", SortOrder.ASC); - - List dfsResults = newArrayList(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_THEN_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - dfsResults.add(nodeToSearchService.get(shardRouting.currentNodeId()).executeDfsPhase(searchRequest)); - } - } - - AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults); - Map queryResults = newHashMap(); - for (DfsSearchResult dfsResult : dfsResults) { - queryResults.put(dfsResult.shardTarget(), nodeToSearchService.get(dfsResult.shardTarget().nodeId()).executeQueryPhase(new QuerySearchRequest(dfsResult.id(), dfs))); - } - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - Map fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - SearchHits hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(60)); - for (int i = 0; i < 60; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.explanation()); - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(i))); - } - - // now try and scroll to the next batch of results - Map scrollQueryResults = newHashMap(); - for (QuerySearchResultProvider queryResult : queryResults.values()) { - scrollQueryResults.put(queryResult.queryResult().shardTarget(), nodeToSearchService.get(queryResult.shardTarget().nodeId()).executeQueryPhase(new InternalScrollSearchRequest(queryResult.id()).scroll(new Scroll(timeValueMinutes(10)))).queryResult()); - } - queryResults = scrollQueryResults; - - sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(40)); - for (int i = 0; i < 40; i++) { - SearchHit hit = hits.hits()[i]; - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(i + 60))); - } - - // now try and scroll to the next next batch of results - scrollQueryResults = newHashMap(); - for (QuerySearchResultProvider queryResult : queryResults.values()) { - scrollQueryResults.put(queryResult.queryResult().shardTarget(), nodeToSearchService.get(queryResult.shardTarget().nodeId()).executeQueryPhase(new InternalScrollSearchRequest(queryResult.id())).queryResult()); - } - queryResults = scrollQueryResults; - - sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(0)); - } - - @Test - public void testQueryAndFetch() { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(20).explain(true); - - Set expectedIds = Sets.newHashSet(); - for (int i = 0; i < 100; i++) { - expectedIds.add(Integer.toString(i)); - } - - Map queryFetchResults = newHashMap(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_AND_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(shardRouting.currentNodeId()).executeFetchPhase(searchRequest); - queryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult); - } - } - - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values()); - SearchHits hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits(); - - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(60)); // 60 results, with size 20, since we have 3 shards - for (int i = 0; i < 60; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.id() + " " + hit.explanation()); -// assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1))); - assertThat("make sure we don't have duplicates", expectedIds.remove(hit.id()), notNullValue()); - } - - // scrolling with query+fetch is not perfect when it comes to dist sorting - Map scrollQueryFetchResults = newHashMap(); - for (QueryFetchSearchResult searchResult : queryFetchResults.values()) { - QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(searchResult.shardTarget().nodeId()).executeFetchPhase(new InternalScrollSearchRequest(searchResult.id()).scroll(new Scroll(timeValueMinutes(10)))).result(); - scrollQueryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult); - } - queryFetchResults = scrollQueryFetchResults; - - sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values()); - hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(40)); - for (int i = 0; i < 40; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.id() + " " + hit.explanation()); - // we don't do perfect sorting when it comes to scroll with Query+Fetch -// assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - 60 - 1 - i))); - assertThat("make sure we don't have duplicates", expectedIds.remove(hit.id()), notNullValue()); - } - assertThat("make sure we got all [" + expectedIds + "]", expectedIds.size(), equalTo(0)); - } - - @Test - public void testSimpleFacets() { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(20).explain(true).sort("age", SortOrder.ASC) - .facet(FacetBuilders.queryFacet("all", termQuery("multi", "test"))) - .facet(FacetBuilders.queryFacet("test1", termQuery("name", "test1"))); - - Map queryResults = newHashMap(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_THEN_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - QuerySearchResult queryResult = nodeToSearchService.get(shardRouting.currentNodeId()).executeQueryPhase(searchRequest); - queryResults.put(queryResult.shardTarget(), queryResult); - } - } - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - Map fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - InternalSearchResponse searchResponse = searchPhaseController.merge(sortedShardList, queryResults, fetchResults); - assertThat(searchResponse.hits().totalHits(), equalTo(100l)); - - assertThat(searchResponse.facets().facet(QueryFacet.class, "test1").count(), equalTo(1l)); - assertThat(searchResponse.facets().facet(QueryFacet.class, "all").count(), equalTo(100l)); - } - - @Test - public void testSimpleFacetsTwice() { - testSimpleFacets(); - testSimpleFacets(); - } - - private InternalSearchRequest searchRequest(ShardRouting shardRouting, SearchSourceBuilder builder, SearchType searchType) { - return new InternalSearchRequest(shardRouting, 3, searchType).source(builder.buildAsBytes()); - } - - private void index(Client client, String id, String nameValue, int age) { - client.index(indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet(); - } - - private String source(String id, String nameValue, int age) { - StringBuilder multi = new StringBuilder().append(nameValue); - for (int i = 0; i < age; i++) { - multi.append(" ").append(nameValue); - } - return "{ type1 : { \"id\" : \"" + id + "\", \"nid\" : " + id + ", \"name\" : \"" + (nameValue + id) + "\", age : " + age + ", multi : \"" + multi.toString() + "\", _boost : " + (age * 10) + " } }"; - } -} diff --git a/src/test/java/org/elasticsearch/test/integration/search/embedded/ThreeShardsUnbalancedShardsEmbeddedSearchTests.java b/src/test/java/org/elasticsearch/test/integration/search/embedded/ThreeShardsUnbalancedShardsEmbeddedSearchTests.java deleted file mode 100644 index 0ef74c28776..00000000000 --- a/src/test/java/org/elasticsearch/test/integration/search/embedded/ThreeShardsUnbalancedShardsEmbeddedSearchTests.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon 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.test.integration.search.embedded; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.Requests; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.cluster.routing.ShardIterator; -import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; -import org.elasticsearch.cluster.routing.operation.OperationRouting; -import org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.trove.ExtTIntArrayList; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.node.settings.NodeSettingsService; -import org.elasticsearch.search.*; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.controller.SearchPhaseController; -import org.elasticsearch.search.controller.ShardDoc; -import org.elasticsearch.search.dfs.AggregatedDfs; -import org.elasticsearch.search.dfs.DfsSearchResult; -import org.elasticsearch.search.facet.query.QueryFacet; -import org.elasticsearch.search.fetch.FetchSearchRequest; -import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.fetch.QueryFetchSearchResult; -import org.elasticsearch.search.internal.InternalScrollSearchRequest; -import org.elasticsearch.search.internal.InternalSearchRequest; -import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.search.query.QuerySearchRequest; -import org.elasticsearch.search.query.QuerySearchResult; -import org.elasticsearch.search.query.QuerySearchResultProvider; -import org.elasticsearch.search.sort.SortOrder; -import org.elasticsearch.test.integration.AbstractNodesTests; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; -import static org.elasticsearch.client.Requests.indexRequest; -import static org.elasticsearch.client.Requests.refreshRequest; -import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; -import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes; -import static org.elasticsearch.index.query.QueryBuilders.termQuery; -import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; -import static org.elasticsearch.search.facet.FacetBuilders.queryFacet; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * - */ -public class ThreeShardsUnbalancedShardsEmbeddedSearchTests extends AbstractNodesTests { - - private ClusterService clusterService; - - private Map nodeToSearchService; - - private SearchPhaseController searchPhaseController; - - @BeforeClass - public void createNodeAndInitWithData() throws Exception { - ImmutableSettings.Builder nodeSettings = ImmutableSettings.settingsBuilder() - .put("cluster.routing.operation.type", "org.elasticsearch.test.integration.search.embedded.ThreeShardsUnbalancedShardsEmbeddedSearchTests$UnevenOperationRoutingModule"); - startNode("server1", nodeSettings); - startNode("server2", nodeSettings); - - clusterService = ((InternalNode) node("server1")).injector().getInstance(ClusterService.class); - - client("server1").admin().indices().create(Requests.createIndexRequest("test") - .settings(settingsBuilder().put("number_of_shards", 3).put("number_of_replicas", 0))) - .actionGet(); - client("server1").admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); - - for (int i = 0; i < 100; i++) { - index(client("server1"), Integer.toString(i), "test", i); - } - client("server1").admin().indices().refresh(refreshRequest("test")).actionGet(); - - SearchService searchService1 = ((InternalNode) node("server1")).injector().getInstance(SearchService.class); - SearchService searchService2 = ((InternalNode) node("server2")).injector().getInstance(SearchService.class); - - nodeToSearchService = ImmutableMap.builder() - .put(((InternalNode) node("server1")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService1) - .put(((InternalNode) node("server2")).injector().getInstance(ClusterService.class).state().nodes().localNodeId(), searchService2) - .build(); - - searchPhaseController = ((InternalNode) node("server1")).injector().getInstance(SearchPhaseController.class); - } - - @AfterClass - public void closeNodes() { - closeAllNodes(); - } - - @Test - public void testDfsQueryFetch() throws Exception { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(60).explain(true); - - List dfsResults = newArrayList(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.DFS_QUERY_THEN_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - dfsResults.add(nodeToSearchService.get(shardRouting.currentNodeId()).executeDfsPhase(searchRequest)); - } - } - - AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults); - Map queryResults = newHashMap(); - for (DfsSearchResult dfsResult : dfsResults) { - queryResults.put(dfsResult.shardTarget(), nodeToSearchService.get(dfsResult.shardTarget().nodeId()).executeQueryPhase(new QuerySearchRequest(dfsResult.id(), dfs))); - } - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - Map fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - SearchHits hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(60)); - for (int i = 0; i < 60; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.explanation()); - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1))); - } - - // now try and scroll to the next batch of results - Map scollQueryResults = newHashMap(); - for (QuerySearchResultProvider queryResult : queryResults.values()) { - scollQueryResults.put(queryResult.queryResult().shardTarget(), nodeToSearchService.get(queryResult.shardTarget().nodeId()).executeQueryPhase(new InternalScrollSearchRequest(queryResult.id())).queryResult()); - } - queryResults = scollQueryResults; - - sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(40)); - for (int i = 0; i < 40; i++) { - SearchHit hit = hits.hits()[i]; - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - 60 - 1 - i))); - } - } - - @Test - public void testDfsQueryFetchWithSort() throws Exception { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(60).explain(true).sort("age", SortOrder.ASC); - - List dfsResults = newArrayList(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.DFS_QUERY_THEN_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - dfsResults.add(nodeToSearchService.get(shardRouting.currentNodeId()).executeDfsPhase(searchRequest)); - } - } - - AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults); - Map queryResults = newHashMap(); - for (DfsSearchResult dfsResult : dfsResults) { - queryResults.put(dfsResult.shardTarget(), nodeToSearchService.get(dfsResult.shardTarget().nodeId()).executeQueryPhase(new QuerySearchRequest(dfsResult.id(), dfs))); - } - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - Map fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - SearchHits hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(60)); - for (int i = 0; i < 60; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.explanation()); - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(i))); - } - - // now try and scroll to the next batch of results - Map scollQueryResults = newHashMap(); - for (QuerySearchResultProvider queryResult : queryResults.values()) { - scollQueryResults.put(queryResult.queryResult().shardTarget(), nodeToSearchService.get(queryResult.shardTarget().nodeId()).executeQueryPhase(new InternalScrollSearchRequest(queryResult.id()).scroll(new Scroll(timeValueMinutes(10)))).queryResult()); - } - queryResults = scollQueryResults; - - sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(40)); - for (int i = 0; i < 40; i++) { - SearchHit hit = hits.hits()[i]; - assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(i + 60))); - } - - // now try and scroll to the next next batch of results - scollQueryResults = newHashMap(); - for (QuerySearchResultProvider queryResult : queryResults.values()) { - scollQueryResults.put(queryResult.queryResult().shardTarget(), nodeToSearchService.get(queryResult.shardTarget().nodeId()).executeQueryPhase(new InternalScrollSearchRequest(queryResult.id())).queryResult()); - } - queryResults = scollQueryResults; - - sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - hits = searchPhaseController.merge(sortedShardList, queryResults, fetchResults).hits(); - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(0)); - } - - @Test - public void testQueryFetchInOneGo() { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(20).explain(true); - - // do this with dfs, since we have uneven distribution of docs between shards - List dfsResults = newArrayList(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_AND_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - dfsResults.add(nodeToSearchService.get(shardRouting.currentNodeId()).executeDfsPhase(searchRequest)); - } - } - - AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults); - Map queryFetchResults = newHashMap(); - for (DfsSearchResult dfsResult : dfsResults) { - QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(dfsResult.shardTarget().nodeId()).executeFetchPhase(new QuerySearchRequest(dfsResult.id(), dfs)); - queryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult); - } - - - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values()); - SearchHits hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits(); - - assertThat(hits.totalHits(), equalTo(100l)); - assertThat(hits.hits().length, equalTo(50)); // 50 results, 20 from first shard, 20 from second shard, but 3rh shard only has total of 10 docs - for (int i = 0; i < 50; i++) { - SearchHit hit = hits.hits()[i]; -// System.out.println(hit.id() + " " + hit.explanation()); -// System.out.println(hit.id()); -// long lId = Long.parseLong(hit.id()); -// assertTrue("id[" + hit.id() + "]", lId >= 49 ); - } - - // TODO we need to support scrolling for query+fetch -// Map scollQueryFetchResults = newHashMap(); -// for (QueryFetchSearchResult searchResult : queryFetchResults.values()) { -// QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(searchResult.shardTarget().nodeId()).executeFetchPhase(new InternalScrollSearchRequest(searchResult.id()).scroll(new Scroll(timeValueMinutes(10)))); -// scollQueryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult); -// } -// queryFetchResults = scollQueryFetchResults; -// -// sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values()); -// hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits(); -// assertEquals(100, hits.totalHits()); -// assertEquals(40, hits.hits().length); -// for (int i = 0; i < 40; i++) { -// SearchHit hit = hits.hits()[i]; -// assertEquals("id[" + hit.id() + "]", Integer.toString(100 - 60 - 1 - i), hit.id()); -// } - } - - @Test - public void testSimpleFacets() { - SearchSourceBuilder sourceBuilder = searchSource() - .query(termQuery("multi", "test")) - .from(0).size(20).explain(true).sort("age", SortOrder.ASC) - .facet(queryFacet("all").query(termQuery("multi", "test"))) - .facet(queryFacet("test1").query(termQuery("name", "test1"))); - - Map queryResults = newHashMap(); - for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) { - for (ShardRouting shardRouting : shardIt.asUnordered()) { - InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_THEN_FETCH) - .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES))); - QuerySearchResult queryResult = nodeToSearchService.get(shardRouting.currentNodeId()).executeQueryPhase(searchRequest); - queryResults.put(queryResult.shardTarget(), queryResult); - } - } - ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryResults.values()); - Map docIdsToLoad = searchPhaseController.docIdsToLoad(sortedShardList); - - Map fetchResults = newHashMap(); - for (Map.Entry entry : docIdsToLoad.entrySet()) { - SearchShardTarget shardTarget = entry.getKey(); - ExtTIntArrayList docIds = entry.getValue(); - FetchSearchResult fetchResult = nodeToSearchService.get(shardTarget.nodeId()).executeFetchPhase(new FetchSearchRequest(queryResults.get(shardTarget).queryResult().id(), docIds)); - fetchResults.put(fetchResult.shardTarget(), fetchResult.initCounter()); - } - - InternalSearchResponse searchResponse = searchPhaseController.merge(sortedShardList, queryResults, fetchResults); - assertThat(searchResponse.hits().totalHits(), equalTo(100l)); - - assertThat(searchResponse.facets().facet(QueryFacet.class, "test1").count(), equalTo(1l)); - assertThat(searchResponse.facets().facet(QueryFacet.class, "all").count(), equalTo(100l)); - } - - @Test - public void testSimpleFacetsTwice() { - testSimpleFacets(); - testSimpleFacets(); - } - - private static InternalSearchRequest searchRequest(ShardRouting shardRouting, SearchSourceBuilder builder, SearchType searchType) { - return new InternalSearchRequest(shardRouting, 3, searchType).source(builder.buildAsBytes()); - } - - private void index(Client client, String id, String nameValue, int age) { - client.index(indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet(); - } - - private String source(String id, String nameValue, int age) { - StringBuilder multi = new StringBuilder().append(nameValue); - for (int i = 0; i < age; i++) { - multi.append(" ").append(nameValue); - } - return "{ type1 : { \"id\" : \"" + id + "\", \"name\" : \"" + (nameValue + id) + "\", age : " + age + ", multi : \"" + multi.toString() + "\", _boost : " + (age * 10) + " } }"; - } - - public static class UnevenOperationRoutingModule extends AbstractModule { - @Override - protected void configure() { - bind(OperationRouting.class).to(UnevenOperationRoutingStrategy.class).asEagerSingleton(); - } - } - - /** - * First 60 go to the first shard, - * Next 30 go to the second shard, - * Next 10 go to the third shard - */ - public static class UnevenOperationRoutingStrategy extends PlainOperationRouting { - - @Inject - public UnevenOperationRoutingStrategy(Settings settings) { - super(settings, null, new AwarenessAllocationDecider(ImmutableSettings.Builder.EMPTY_SETTINGS, new NodeSettingsService(ImmutableSettings.Builder.EMPTY_SETTINGS))); - } - - @Override - protected int hash(String routing) { - long lId = Long.parseLong(routing); - if (lId < 60) { - return 0; - } - if (lId >= 60 && lId < 90) { - return 1; - } - return 2; - } - - @Override - protected int hash(String type, String id) { - long lId = Long.parseLong(id); - if (lId < 60) { - return 0; - } - if (lId >= 60 && lId < 90) { - return 1; - } - return 2; - } - } -} \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java b/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java index 38cfb25667c..4376bf006dc 100644 --- a/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java +++ b/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java @@ -71,10 +71,10 @@ public abstract class AbstractSimpleTransportTests { @Test public void testHelloWorld() { - serviceA.registerHandler("sayHello", new BaseTransportRequestHandler() { + serviceA.registerHandler("sayHello", new BaseTransportRequestHandler() { @Override - public StringMessage newInstance() { - return new StringMessage(); + public StringMessageRequest newInstance() { + return new StringMessageRequest(); } @Override @@ -83,7 +83,7 @@ public abstract class AbstractSimpleTransportTests { } @Override - public void messageReceived(StringMessage request, TransportChannel channel) { + public void messageReceived(StringMessageRequest request, TransportChannel channel) { assertThat("moshe", equalTo(request.message)); try { channel.sendResponse(new StringMessage("hello " + request.message)); @@ -95,7 +95,7 @@ public abstract class AbstractSimpleTransportTests { }); TransportFuture res = serviceB.submitRequest(serviceANode, "sayHello", - new StringMessage("moshe"), new BaseTransportResponseHandler() { + new StringMessageRequest("moshe"), new BaseTransportResponseHandler() { @Override public StringMessage newInstance() { return new StringMessage(); @@ -130,10 +130,10 @@ public abstract class AbstractSimpleTransportTests { @Test public void testVoidMessageCompressed() { - serviceA.registerHandler("sayHello", new BaseTransportRequestHandler() { + serviceA.registerHandler("sayHello", new BaseTransportRequestHandler() { @Override - public VoidStreamable newInstance() { - return VoidStreamable.INSTANCE; + public TransportRequest.Empty newInstance() { + return TransportRequest.Empty.INSTANCE; } @Override @@ -142,7 +142,7 @@ public abstract class AbstractSimpleTransportTests { } @Override - public void messageReceived(VoidStreamable request, TransportChannel channel) { + public void messageReceived(TransportRequest.Empty request, TransportChannel channel) { try { channel.sendResponse(VoidStreamable.INSTANCE, TransportResponseOptions.options().withCompress(true)); } catch (IOException e) { @@ -153,7 +153,7 @@ public abstract class AbstractSimpleTransportTests { }); TransportFuture res = serviceB.submitRequest(serviceANode, "sayHello", - VoidStreamable.INSTANCE, TransportRequestOptions.options().withCompress(true), new BaseTransportResponseHandler() { + TransportRequest.Empty.INSTANCE, TransportRequestOptions.options().withCompress(true), new BaseTransportResponseHandler() { @Override public VoidStreamable newInstance() { return VoidStreamable.INSTANCE; @@ -187,10 +187,10 @@ public abstract class AbstractSimpleTransportTests { @Test public void testHelloWorldCompressed() { - serviceA.registerHandler("sayHello", new BaseTransportRequestHandler() { + serviceA.registerHandler("sayHello", new BaseTransportRequestHandler() { @Override - public StringMessage newInstance() { - return new StringMessage(); + public StringMessageRequest newInstance() { + return new StringMessageRequest(); } @Override @@ -199,7 +199,7 @@ public abstract class AbstractSimpleTransportTests { } @Override - public void messageReceived(StringMessage request, TransportChannel channel) { + public void messageReceived(StringMessageRequest request, TransportChannel channel) { assertThat("moshe", equalTo(request.message)); try { channel.sendResponse(new StringMessage("hello " + request.message), TransportResponseOptions.options().withCompress(true)); @@ -211,7 +211,7 @@ public abstract class AbstractSimpleTransportTests { }); TransportFuture res = serviceB.submitRequest(serviceANode, "sayHello", - new StringMessage("moshe"), TransportRequestOptions.options().withCompress(true), new BaseTransportResponseHandler() { + new StringMessageRequest("moshe"), TransportRequestOptions.options().withCompress(true), new BaseTransportResponseHandler() { @Override public StringMessage newInstance() { return new StringMessage(); @@ -246,10 +246,10 @@ public abstract class AbstractSimpleTransportTests { @Test public void testErrorMessage() { - serviceA.registerHandler("sayHelloException", new BaseTransportRequestHandler() { + serviceA.registerHandler("sayHelloException", new BaseTransportRequestHandler() { @Override - public StringMessage newInstance() { - return new StringMessage(); + public StringMessageRequest newInstance() { + return new StringMessageRequest(); } @Override @@ -258,14 +258,14 @@ public abstract class AbstractSimpleTransportTests { } @Override - public void messageReceived(StringMessage request, TransportChannel channel) throws Exception { + public void messageReceived(StringMessageRequest request, TransportChannel channel) throws Exception { assertThat("moshe", equalTo(request.message)); throw new RuntimeException("bad message !!!"); } }); TransportFuture res = serviceB.submitRequest(serviceANode, "sayHelloException", - new StringMessage("moshe"), new BaseTransportResponseHandler() { + new StringMessageRequest("moshe"), new BaseTransportResponseHandler() { @Override public StringMessage newInstance() { return new StringMessage(); @@ -318,10 +318,10 @@ public abstract class AbstractSimpleTransportTests { @Test public void testTimeoutSendExceptionWithNeverSendingBackResponse() throws Exception { - serviceA.registerHandler("sayHelloTimeoutNoResponse", new BaseTransportRequestHandler() { + serviceA.registerHandler("sayHelloTimeoutNoResponse", new BaseTransportRequestHandler() { @Override - public StringMessage newInstance() { - return new StringMessage(); + public StringMessageRequest newInstance() { + return new StringMessageRequest(); } @Override @@ -330,7 +330,7 @@ public abstract class AbstractSimpleTransportTests { } @Override - public void messageReceived(StringMessage request, TransportChannel channel) { + public void messageReceived(StringMessageRequest request, TransportChannel channel) { assertThat("moshe", equalTo(request.message)); // don't send back a response // try { @@ -343,7 +343,7 @@ public abstract class AbstractSimpleTransportTests { }); TransportFuture res = serviceB.submitRequest(serviceANode, "sayHelloTimeoutNoResponse", - new StringMessage("moshe"), options().withTimeout(100), new BaseTransportResponseHandler() { + new StringMessageRequest("moshe"), options().withTimeout(100), new BaseTransportResponseHandler() { @Override public StringMessage newInstance() { return new StringMessage(); @@ -377,10 +377,10 @@ public abstract class AbstractSimpleTransportTests { @Test public void testTimeoutSendExceptionWithDelayedResponse() throws Exception { - serviceA.registerHandler("sayHelloTimeoutDelayedResponse", new BaseTransportRequestHandler() { + serviceA.registerHandler("sayHelloTimeoutDelayedResponse", new BaseTransportRequestHandler() { @Override - public StringMessage newInstance() { - return new StringMessage(); + public StringMessageRequest newInstance() { + return new StringMessageRequest(); } @Override @@ -389,7 +389,7 @@ public abstract class AbstractSimpleTransportTests { } @Override - public void messageReceived(StringMessage request, TransportChannel channel) { + public void messageReceived(StringMessageRequest request, TransportChannel channel) { TimeValue sleep = TimeValue.parseTimeValue(request.message, null); try { Thread.sleep(sleep.millis()); @@ -406,7 +406,7 @@ public abstract class AbstractSimpleTransportTests { }); TransportFuture res = serviceB.submitRequest(serviceANode, "sayHelloTimeoutDelayedResponse", - new StringMessage("300ms"), options().withTimeout(100), new BaseTransportResponseHandler() { + new StringMessageRequest("300ms"), options().withTimeout(100), new BaseTransportResponseHandler() { @Override public StringMessage newInstance() { return new StringMessage(); @@ -442,7 +442,7 @@ public abstract class AbstractSimpleTransportTests { final int counter = i; // now, try and send another request, this times, with a short timeout res = serviceB.submitRequest(serviceANode, "sayHelloTimeoutDelayedResponse", - new StringMessage(counter + "ms"), options().withTimeout(100), new BaseTransportResponseHandler() { + new StringMessageRequest(counter + "ms"), options().withTimeout(100), new BaseTransportResponseHandler() { @Override public StringMessage newInstance() { return new StringMessage(); @@ -472,25 +472,49 @@ public abstract class AbstractSimpleTransportTests { serviceA.removeHandler("sayHelloTimeoutDelayedResponse"); } - private class StringMessage implements Streamable { + class StringMessageRequest extends TransportRequest { private String message; - private StringMessage(String message) { + StringMessageRequest(String message) { this.message = message; } - private StringMessage() { + StringMessageRequest() { } @Override public void readFrom(StreamInput in) throws IOException { - message = in.readUTF(); + super.readFrom(in); + message = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(message); + super.writeTo(out); + out.writeString(message); + } + } + + class StringMessage implements Streamable { + + private String message; + + StringMessage(String message) { + this.message = message; + } + + StringMessage() { + } + + @Override + public void readFrom(StreamInput in) throws IOException { + message = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(message); } } } diff --git a/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java b/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java index abe6212dbb8..a5ba6abccd0 100644 --- a/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java +++ b/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java @@ -41,16 +41,6 @@ public class SimpleNettyTransportTests extends AbstractSimpleTransportTests { serviceBNode = new DiscoveryNode("B", serviceB.boundAddress().publishAddress()); } - @Override - public void testHelloWorld() { - super.testHelloWorld(); //To change body of overridden methods use File | Settings | File Templates. - } - - @Override - public void testVoidMessageCompressed() { - super.testVoidMessageCompressed(); //To change body of overridden methods use File | Settings | File Templates. - } - @Test public void testConnectException() { try {