diff --git a/docs/java-api/client.asciidoc b/docs/java-api/client.asciidoc index be946673491..0dccd485c2a 100644 --- a/docs/java-api/client.asciidoc +++ b/docs/java-api/client.asciidoc @@ -134,7 +134,7 @@ be "two hop" operations). -------------------------------------------------- // on startup -Client client = new TransportClient() +Client client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress("host1", 9300)) .addTransportAddress(new InetSocketTransportAddress("host2", 9300)); @@ -150,7 +150,7 @@ Note that you have to set the cluster name if you use one different than -------------------------------------------------- Settings settings = ImmutableSettings.settingsBuilder() .put("cluster.name", "myClusterName").build(); -Client client = new TransportClient(settings); +Client client = TransportClient.builder().settings(settings).build(); //Add transport addresses and do something with the client... -------------------------------------------------- @@ -166,7 +166,7 @@ used will be the ones that the other nodes were started with (the -------------------------------------------------- Settings settings = ImmutableSettings.settingsBuilder() .put("client.transport.sniff", true).build(); -TransportClient client = new TransportClient(settings); +TransportClient client = TransportClient.builder().settings(settings).build(); -------------------------------------------------- Other transport client level settings include: diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index d9409406742..9f0cefbd370 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -463,3 +463,23 @@ The `index.store.distributor` setting has also been removed. The parameter `indices.analysis.hunspell.dictionary.location` has been removed, and `/hunspell` is always used. + +=== Java API Transport API construction + +The `TransportClient` construction code has changed, it now uses the builder +pattern. Instead of using: + +[source,java] +-------------------------------------------------- +Settings settings = ImmutableSettings.settingsBuilder() + .put("cluster.name", "myClusterName").build(); +Client client = new TransportClient(settings); + +Use: + +[source,java] +-------------------------------------------------- +Settings settings = ImmutableSettings.settingsBuilder() + .put("cluster.name", "myClusterName").build(); +Client client = TransportClient.builder().settings(settings).build(); +-------------------------------------------------- diff --git a/src/main/java/org/elasticsearch/action/Action.java b/src/main/java/org/elasticsearch/action/Action.java index f45e525c58f..51e3f5440ea 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.ElasticsearchClient; /** * Base action. Supports building the Request through a RequestBuilder. */ -public abstract class Action, Client extends ElasticsearchClient> +public abstract class Action> extends GenericAction { protected Action(String name) { @@ -34,5 +34,5 @@ public abstract class Action { +public abstract class ActionRequestBuilder> { + protected final Action action; protected final Request request; private final ThreadPool threadPool; - protected final Client client; + protected final ElasticsearchClient client; - protected ActionRequestBuilder(Client client, Request request) { + protected ActionRequestBuilder(ElasticsearchClient client, Action action, Request request) { + Preconditions.checkNotNull(action, "action must not be null"); + this.action = action; this.request = request; this.client = client; threadPool = client.threadPool(); @@ -81,9 +86,14 @@ public abstract class ActionRequestBuilder listener) { - doExecute(listener); + public final void execute(ActionListener listener) { + client.execute(action, beforeExecute(request), listener); } - protected abstract void doExecute(ActionListener listener); + /** + * A callback to additionally process the request before its executed + */ + protected Request beforeExecute(Request request) { + return request; + } } diff --git a/src/main/java/org/elasticsearch/action/ClientAction.java b/src/main/java/org/elasticsearch/action/ClientAction.java deleted file mode 100644 index a38b8dad1e0..00000000000 --- a/src/main/java/org/elasticsearch/action/ClientAction.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action; - -import org.elasticsearch.client.Client; - -/** - * Action (used with {@link Client} API). - */ -public abstract class ClientAction> - extends Action { - - protected ClientAction(String name) { - super(name); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java deleted file mode 100644 index 91ce66543d4..00000000000 --- a/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.admin.cluster; - -import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.client.ClusterAdminClient; - -/** - * Cluster action (used with {@link ClusterAdminClient} API). - */ -public abstract class ClusterAction> - extends Action { - - protected ClusterAction(String name) { - super(name); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java index b8ec1c70d07..9770b05bae0 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.health; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterHealthAction extends ClusterAction { +public class ClusterHealthAction extends Action { public static final ClusterHealthAction INSTANCE = new ClusterHealthAction(); public static final String NAME = "cluster:monitor/health"; @@ -39,7 +39,7 @@ public class ClusterHealthAction extends ClusterAction { +public class ClusterHealthRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public ClusterHealthRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterHealthRequest()); + public ClusterHealthRequestBuilder(ElasticsearchClient client, ClusterHealthAction action) { + super(client, action, new ClusterHealthRequest()); } public ClusterHealthRequestBuilder setIndices(String... indices) { @@ -86,9 +85,4 @@ public class ClusterHealthRequestBuilder extends MasterNodeReadOperationRequestB request.waitForEvents(waitForEvents); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.health(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java index 64b3c3cfcd8..7010b4cb143 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.hotthreads; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class NodesHotThreadsAction extends ClusterAction { +public class NodesHotThreadsAction extends Action { public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction(); public static final String NAME = "cluster:monitor/nodes/hot_threads"; @@ -39,7 +39,7 @@ public class NodesHotThreadsAction extends ClusterAction { - public NodesHotThreadsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesHotThreadsRequest()); + public NodesHotThreadsRequestBuilder(ElasticsearchClient client, NodesHotThreadsAction action) { + super(client, action, new NodesHotThreadsRequest()); } public NodesHotThreadsRequestBuilder setThreads(int threads) { @@ -51,9 +52,4 @@ public class NodesHotThreadsRequestBuilder extends NodesOperationRequestBuilder< request.interval(interval); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.nodesHotThreads(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java index 47d6fae7616..adfd9481e74 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.info; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class NodesInfoAction extends ClusterAction { +public class NodesInfoAction extends Action { public static final NodesInfoAction INSTANCE = new NodesInfoAction(); public static final String NAME = "cluster:monitor/nodes/info"; @@ -39,7 +39,7 @@ public class NodesInfoAction extends ClusterAction { - public NodesInfoRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesInfoRequest()); + public NodesInfoRequestBuilder(ElasticsearchClient client, NodesInfoAction action) { + super(client, action, new NodesInfoRequest()); } /** @@ -119,9 +118,4 @@ public class NodesInfoRequestBuilder extends NodesOperationRequestBuilder listener) { - client.nodesInfo(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java index 252eb1cc1db..3c322e3335e 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.stats; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class NodesStatsAction extends ClusterAction { +public class NodesStatsAction extends Action { public static final NodesStatsAction INSTANCE = new NodesStatsAction(); public static final String NAME = "cluster:monitor/nodes/stats"; @@ -39,7 +39,7 @@ public class NodesStatsAction extends ClusterAction { - public NodesStatsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesStatsRequest()); + public NodesStatsRequestBuilder(ElasticsearchClient client, NodesStatsAction action) { + super(client, action, new NodesStatsRequest()); } /** @@ -133,9 +133,4 @@ public class NodesStatsRequestBuilder extends NodesOperationRequestBuilder listener) { - client.nodesStats(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java index 2a9be85e37e..83166753b27 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.delete; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Unregister repository action */ -public class DeleteRepositoryAction extends ClusterAction { +public class DeleteRepositoryAction extends Action { public static final DeleteRepositoryAction INSTANCE = new DeleteRepositoryAction(); public static final String NAME = "cluster:admin/repository/delete"; @@ -40,8 +40,8 @@ public class DeleteRepositoryAction extends ClusterAction { +public class DeleteRepositoryRequestBuilder extends AcknowledgedRequestBuilder { /** * Constructs unregister repository request builder - * - * @param clusterAdminClient cluster admin client */ - public DeleteRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new DeleteRepositoryRequest()); + public DeleteRepositoryRequestBuilder(ElasticsearchClient client, DeleteRepositoryAction action) { + super(client, action, new DeleteRepositoryRequest()); } /** * Constructs unregister repository request builder with specified repository name - * - * @param clusterAdminClient cluster adming client */ - public DeleteRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient, String name) { - super(clusterAdminClient, new DeleteRepositoryRequest(name)); + public DeleteRepositoryRequestBuilder(ElasticsearchClient client, DeleteRepositoryAction action, String name) { + super(client, action, new DeleteRepositoryRequest(name)); } /** @@ -55,9 +50,4 @@ public class DeleteRepositoryRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.deleteRepository(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java index befe51fdeb5..c0d1d1bcde7 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.get; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Get repositories action */ -public class GetRepositoriesAction extends ClusterAction { +public class GetRepositoriesAction extends Action { public static final GetRepositoriesAction INSTANCE = new GetRepositoriesAction(); public static final String NAME = "cluster:admin/repository/get"; @@ -40,8 +40,8 @@ public class GetRepositoriesAction extends ClusterAction { +public class GetRepositoriesRequestBuilder extends MasterNodeReadOperationRequestBuilder { /** * Creates new get repository request builder - * - * @param clusterAdminClient cluster admin client */ - public GetRepositoriesRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new GetRepositoriesRequest()); + public GetRepositoriesRequestBuilder(ElasticsearchClient client, GetRepositoriesAction action) { + super(client, action, new GetRepositoriesRequest()); } /** * Creates new get repository request builder - * - * @param clusterAdminClient cluster admin client - * @param repositories list of repositories to get */ - public GetRepositoriesRequestBuilder(ClusterAdminClient clusterAdminClient, String... repositories) { - super(clusterAdminClient, new GetRepositoriesRequest(repositories)); + public GetRepositoriesRequestBuilder(ElasticsearchClient client, GetRepositoriesAction action, String... repositories) { + super(client, action, new GetRepositoriesRequest(repositories)); } /** @@ -69,9 +63,4 @@ public class GetRepositoriesRequestBuilder extends MasterNodeReadOperationReques request.repositories(ObjectArrays.concat(request.repositories(), repositories, String.class)); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.getRepositories(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java index 30e9733663c..f3f8b51eeea 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.put; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Register repository action */ -public class PutRepositoryAction extends ClusterAction { +public class PutRepositoryAction extends Action { public static final PutRepositoryAction INSTANCE = new PutRepositoryAction(); public static final String NAME = "cluster:admin/repository/put"; @@ -40,8 +40,8 @@ public class PutRepositoryAction extends ClusterAction { +public class PutRepositoryRequestBuilder extends AcknowledgedRequestBuilder { /** * Constructs register repository request - * - * @param clusterAdminClient cluster admin client */ - public PutRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new PutRepositoryRequest()); + public PutRepositoryRequestBuilder(ElasticsearchClient client, PutRepositoryAction action) { + super(client, action, new PutRepositoryRequest()); } /** * Constructs register repository request for the repository with a given name - * - * @param clusterAdminClient cluster admin client - * @param name repository name */ - public PutRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient, String name) { - super(clusterAdminClient, new PutRepositoryRequest(name)); + public PutRepositoryRequestBuilder(ElasticsearchClient client, PutRepositoryAction action, String name) { + super(client, action, new PutRepositoryRequest(name)); } /** @@ -126,9 +121,4 @@ public class PutRepositoryRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.putRepository(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java index 25f1b5004cd..d52945ac28c 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.verify; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Unregister repository action */ -public class VerifyRepositoryAction extends ClusterAction { +public class VerifyRepositoryAction extends Action { public static final VerifyRepositoryAction INSTANCE = new VerifyRepositoryAction(); public static final String NAME = "cluster:admin/repository/verify"; @@ -40,8 +40,8 @@ public class VerifyRepositoryAction extends ClusterAction { +public class VerifyRepositoryRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs unregister repository request builder - * - * @param clusterAdminClient cluster admin client */ - public VerifyRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new VerifyRepositoryRequest()); + public VerifyRepositoryRequestBuilder(ElasticsearchClient client, VerifyRepositoryAction action) { + super(client, action, new VerifyRepositoryRequest()); } /** * Constructs unregister repository request builder with specified repository name - * - * @param clusterAdminClient cluster adming client */ - public VerifyRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient, String name) { - super(clusterAdminClient, new VerifyRepositoryRequest(name)); + public VerifyRepositoryRequestBuilder(ElasticsearchClient client, VerifyRepositoryAction action, String name) { + super(client, action, new VerifyRepositoryRequest(name)); } /** @@ -56,9 +50,4 @@ public class VerifyRepositoryRequestBuilder extends MasterNodeOperationRequestBu request.name(name); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.verifyRepository(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java index d2fc5a313ec..7aa6dc25cdc 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.reroute; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterRerouteAction extends ClusterAction { +public class ClusterRerouteAction extends Action { public static final ClusterRerouteAction INSTANCE = new ClusterRerouteAction(); public static final String NAME = "cluster:admin/reroute"; @@ -39,7 +39,7 @@ public class ClusterRerouteAction extends ClusterAction { +public class ClusterRerouteRequestBuilder extends AcknowledgedRequestBuilder { - public ClusterRerouteRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterRerouteRequest()); + public ClusterRerouteRequestBuilder(ElasticsearchClient client, ClusterRerouteAction action) { + super(client, action, new ClusterRerouteRequest()); } /** @@ -68,9 +67,4 @@ public class ClusterRerouteRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.reroute(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java index 8e8a6bdb365..15b3e70dd04 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.settings; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterUpdateSettingsAction extends ClusterAction { +public class ClusterUpdateSettingsAction extends Action { public static final ClusterUpdateSettingsAction INSTANCE = new ClusterUpdateSettingsAction(); public static final String NAME = "cluster:admin/settings/update"; @@ -39,7 +39,7 @@ public class ClusterUpdateSettingsAction extends ClusterAction { +public class ClusterUpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder { - public ClusterUpdateSettingsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterUpdateSettingsRequest()); + public ClusterUpdateSettingsRequestBuilder(ElasticsearchClient client, ClusterUpdateSettingsAction action) { + super(client, action, new ClusterUpdateSettingsRequest()); } /** @@ -98,9 +97,4 @@ public class ClusterUpdateSettingsRequestBuilder extends AcknowledgedRequestBuil request.persistentSettings(settings); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.updateSettings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java index 15a218fc1f1..28f7557a2e2 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.shards; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterSearchShardsAction extends ClusterAction { +public class ClusterSearchShardsAction extends Action { public static final ClusterSearchShardsAction INSTANCE = new ClusterSearchShardsAction(); public static final String NAME = "indices:admin/shards/search_shards"; @@ -39,7 +39,7 @@ public class ClusterSearchShardsAction extends ClusterAction { +public class ClusterSearchShardsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public ClusterSearchShardsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterSearchShardsRequest()); + public ClusterSearchShardsRequestBuilder(ElasticsearchClient client, ClusterSearchShardsAction action) { + super(client, action, new ClusterSearchShardsRequest()); } /** @@ -83,10 +82,4 @@ public class ClusterSearchShardsRequestBuilder extends MasterNodeReadOperationRe request().indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.searchShards(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java index 0bbeb2d5279..9bdcd2c96bd 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.create; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Create snapshot action */ -public class CreateSnapshotAction extends ClusterAction { +public class CreateSnapshotAction extends Action { public static final CreateSnapshotAction INSTANCE = new CreateSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/create"; @@ -40,8 +40,8 @@ public class CreateSnapshotAction extends ClusterAction { +public class CreateSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs a new create snapshot request builder - * - * @param clusterAdminClient cluster admin client */ - public CreateSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new CreateSnapshotRequest()); + public CreateSnapshotRequestBuilder(ElasticsearchClient client, CreateSnapshotAction action) { + super(client, action, new CreateSnapshotRequest()); } /** * Constructs a new create snapshot request builder with specified repository and snapshot names - * - * @param clusterAdminClient cluster admin client - * @param repository repository name - * @param snapshot snapshot name */ - public CreateSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient, String repository, String snapshot) { - super(clusterAdminClient, new CreateSnapshotRequest(repository, snapshot)); + public CreateSnapshotRequestBuilder(ElasticsearchClient client, CreateSnapshotAction action, String repository, String snapshot) { + super(client, action, new CreateSnapshotRequest(repository, snapshot)); } /** @@ -184,9 +178,4 @@ public class CreateSnapshotRequestBuilder extends MasterNodeOperationRequestBuil request.includeGlobalState(includeGlobalState); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.createSnapshot(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java index 3abf3937627..8a794a0c8ff 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.delete; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Delete snapshot action */ -public class DeleteSnapshotAction extends ClusterAction { +public class DeleteSnapshotAction extends Action { public static final DeleteSnapshotAction INSTANCE = new DeleteSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/delete"; @@ -40,8 +40,8 @@ public class DeleteSnapshotAction extends ClusterAction { +public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs delete snapshot request builder - * - * @param clusterAdminClient cluster admin client */ - public DeleteSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new DeleteSnapshotRequest()); + public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action) { + super(client, action, new DeleteSnapshotRequest()); } /** * Constructs delete snapshot request builder with specified repository and snapshot names - * - * @param clusterAdminClient cluster admin client - * @param repository repository name - * @param snapshot snapshot name */ - public DeleteSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient, String repository, String snapshot) { - super(clusterAdminClient, new DeleteSnapshotRequest(repository, snapshot)); + public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action, String repository, String snapshot) { + super(client, action, new DeleteSnapshotRequest(repository, snapshot)); } /** @@ -69,9 +63,4 @@ public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuil request.snapshot(snapshot); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteSnapshot(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java index 0613b3776c8..7d2cafb9ced 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.get; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Get snapshots action */ -public class GetSnapshotsAction extends ClusterAction { +public class GetSnapshotsAction extends Action { public static final GetSnapshotsAction INSTANCE = new GetSnapshotsAction(); public static final String NAME = "cluster:admin/snapshot/get"; @@ -40,8 +40,8 @@ public class GetSnapshotsAction extends ClusterAction { +public class GetSnapshotsRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs the new get snapshot request - * - * @param clusterAdminClient cluster admin client */ - public GetSnapshotsRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new GetSnapshotsRequest()); + public GetSnapshotsRequestBuilder(ElasticsearchClient client, GetSnapshotsAction action) { + super(client, action, new GetSnapshotsRequest()); } /** * Constructs the new get snapshot request with specified repository - * - * @param clusterAdminClient cluster admin client - * @param repository repository name */ - public GetSnapshotsRequestBuilder(ClusterAdminClient clusterAdminClient, String repository) { - super(clusterAdminClient, new GetSnapshotsRequest(repository)); + public GetSnapshotsRequestBuilder(ElasticsearchClient client, GetSnapshotsAction action, String repository) { + super(client, action, new GetSnapshotsRequest(repository)); } /** @@ -76,7 +70,7 @@ public class GetSnapshotsRequestBuilder extends MasterNodeOperationRequestBuilde * @return this builder */ public GetSnapshotsRequestBuilder setCurrentSnapshot() { - request.snapshots(new String[] {GetSnapshotsRequest.CURRENT_SNAPSHOT}); + request.snapshots(new String[]{GetSnapshotsRequest.CURRENT_SNAPSHOT}); return this; } @@ -90,9 +84,4 @@ public class GetSnapshotsRequestBuilder extends MasterNodeOperationRequestBuilde request.snapshots(ObjectArrays.concat(request.snapshots(), snapshots, String.class)); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.getSnapshots(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java index 3e7cbb5e602..3836d2d7fa5 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.restore; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Restore snapshot action */ -public class RestoreSnapshotAction extends ClusterAction { +public class RestoreSnapshotAction extends Action { public static final RestoreSnapshotAction INSTANCE = new RestoreSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/restore"; @@ -40,8 +40,8 @@ public class RestoreSnapshotAction extends ClusterAction { +public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs new restore snapshot request builder - * - * @param clusterAdminClient cluster admin client */ - public RestoreSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new RestoreSnapshotRequest()); + public RestoreSnapshotRequestBuilder(ElasticsearchClient client, RestoreSnapshotAction action) { + super(client, action, new RestoreSnapshotRequest()); } /** * Constructs new restore snapshot request builder with specified repository and snapshot names - * - * @param clusterAdminClient cluster admin client - * @param repository reposiory name - * @param name snapshot name */ - public RestoreSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient, String repository, String name) { - super(clusterAdminClient, new RestoreSnapshotRequest(repository, name)); + public RestoreSnapshotRequestBuilder(ElasticsearchClient client, RestoreSnapshotAction action, String repository, String name) { + super(client, action, new RestoreSnapshotRequest(repository, name)); } @@ -233,6 +226,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore + * * @param settings index settings * @return this builder */ @@ -243,7 +237,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore - + * * @param settings index settings * @return this builder */ @@ -254,7 +248,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore - + * * @param source index settings * @return this builder */ @@ -265,7 +259,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore - + * * @param source index settings * @return this builder */ @@ -290,10 +284,4 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui request.ignoreIndexSettings(ignoreIndexSettings); return this; } - - - @Override - protected void doExecute(ActionListener listener) { - client.restoreSnapshot(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java index adfea744547..0a2d26198ec 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.status; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Snapshots status action */ -public class SnapshotsStatusAction extends ClusterAction { +public class SnapshotsStatusAction extends Action { public static final SnapshotsStatusAction INSTANCE = new SnapshotsStatusAction(); public static final String NAME = "cluster:admin/snapshot/status"; @@ -40,8 +40,8 @@ public class SnapshotsStatusAction extends ClusterAction { +public class SnapshotsStatusRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs the new snapshotstatus request - * - * @param clusterAdminClient cluster admin client */ - public SnapshotsStatusRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new SnapshotsStatusRequest()); + public SnapshotsStatusRequestBuilder(ElasticsearchClient client, SnapshotsStatusAction action) { + super(client, action, new SnapshotsStatusRequest()); } /** * Constructs the new snapshot status request with specified repository - * - * @param clusterAdminClient cluster admin client - * @param repository repository name */ - public SnapshotsStatusRequestBuilder(ClusterAdminClient clusterAdminClient, String repository) { - super(clusterAdminClient, new SnapshotsStatusRequest(repository)); + public SnapshotsStatusRequestBuilder(ElasticsearchClient client, SnapshotsStatusAction action, String repository) { + super(client, action, new SnapshotsStatusRequest(repository)); } /** @@ -80,9 +75,4 @@ public class SnapshotsStatusRequestBuilder extends MasterNodeOperationRequestBui request.snapshots(ObjectArrays.concat(request.snapshots(), snapshots, String.class)); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.snapshotsStatus(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java index a339129ec09..70786f99e0d 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.state; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterStateAction extends ClusterAction { +public class ClusterStateAction extends Action { public static final ClusterStateAction INSTANCE = new ClusterStateAction(); public static final String NAME = "cluster:monitor/state"; @@ -39,7 +39,7 @@ public class ClusterStateAction extends ClusterAction { +public class ClusterStateRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public ClusterStateRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterStateRequest()); + public ClusterStateRequestBuilder(ElasticsearchClient client, ClusterStateAction action) { + super(client, action, new ClusterStateRequest()); } /** @@ -94,9 +93,4 @@ public class ClusterStateRequestBuilder extends MasterNodeReadOperationRequestBu request.indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.state(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java index 34bddac0234..1cddf37ad31 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.stats; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterStatsAction extends ClusterAction { +public class ClusterStatsAction extends Action { public static final ClusterStatsAction INSTANCE = new ClusterStatsAction(); public static final String NAME = "cluster:monitor/stats"; @@ -39,7 +39,7 @@ public class ClusterStatsAction extends ClusterAction { - public ClusterStatsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterStatsRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.clusterStats(request, listener); + public ClusterStatsRequestBuilder(ElasticsearchClient client, ClusterStatsAction action) { + super(client, action, new ClusterStatsRequest()); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java index b074d054e60..1e3eb3f6e81 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.tasks; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PendingClusterTasksAction extends ClusterAction { +public class PendingClusterTasksAction extends Action { public static final PendingClusterTasksAction INSTANCE = new PendingClusterTasksAction(); public static final String NAME = "cluster:monitor/task"; @@ -39,7 +39,7 @@ public class PendingClusterTasksAction extends ClusterAction { +public class PendingClusterTasksRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public PendingClusterTasksRequestBuilder(ClusterAdminClient client) { - super(client, new PendingClusterTasksRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.pendingClusterTasks(request, listener); + public PendingClusterTasksRequestBuilder(ElasticsearchClient client, PendingClusterTasksAction action) { + super(client, action, new PendingClusterTasksRequest()); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java deleted file mode 100644 index 4fae668f77e..00000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.admin.indices; - -import org.elasticsearch.action.*; -import org.elasticsearch.client.IndicesAdminClient; - -/** - * Indices action (used with {@link IndicesAdminClient} API). - */ -public abstract class IndicesAction> - extends Action { - - protected IndicesAction(String name) { - super(name); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java index c8dea4db2b9..3cf0ca574fb 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.alias; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesAliasesAction extends IndicesAction { +public class IndicesAliasesAction extends Action { public static final IndicesAliasesAction INSTANCE = new IndicesAliasesAction(); public static final String NAME = "indices:admin/aliases"; @@ -39,7 +39,7 @@ public class IndicesAliasesAction extends IndicesAction { +public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder { - public IndicesAliasesRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesAliasesRequest()); + public IndicesAliasesRequestBuilder(ElasticsearchClient client, IndicesAliasesAction action) { + super(client, action, new IndicesAliasesRequest()); } - + /** * Adds an alias to the index. * - * @param index The index - * @param alias The alias + * @param index The index + * @param alias The alias */ public IndicesAliasesRequestBuilder addAlias(String index, String alias) { request.addAlias(alias, index); return this; } - + /** * Adds an alias to the index. * * @param indices The indices - * @param alias The alias + * @param alias The alias */ public IndicesAliasesRequestBuilder addAlias(String[] indices, String alias) { request.addAlias(alias, indices); @@ -71,32 +70,32 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder filter) { request.addAlias(alias, filter, indices); return this; } - + /** * Adds an alias to the index. * @@ -120,11 +119,11 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.aliases(request, listener); - } - + /** * Adds an alias action to the request. * diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java index 18d281eb99a..23dc1e13a56 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.alias.exists; -import org.elasticsearch.action.admin.indices.IndicesAction; +import org.elasticsearch.action.Action; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class AliasesExistAction extends IndicesAction { +public class AliasesExistAction extends Action { public static final AliasesExistAction INSTANCE = new AliasesExistAction(); public static final String NAME = "indices:admin/aliases/exists"; @@ -35,8 +35,8 @@ public class AliasesExistAction extends IndicesAction { - public AliasesExistRequestBuilder(IndicesAdminClient client, String... aliases) { - super(client, aliases); + public AliasesExistRequestBuilder(ElasticsearchClient client, AliasesExistAction action, String... aliases) { + super(client, action, aliases); } - - @Override - protected void doExecute(ActionListener listener) { - client.aliasesExist(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java index 312a3f65d14..da7c505771c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java @@ -20,17 +20,19 @@ package org.elasticsearch.action.admin.indices.alias.get; import com.google.common.collect.ObjectArrays; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.IndicesAdminClient; /** */ -public abstract class BaseAliasesRequestBuilder> extends MasterNodeReadOperationRequestBuilder { +public abstract class BaseAliasesRequestBuilder> extends MasterNodeReadOperationRequestBuilder { - public BaseAliasesRequestBuilder(IndicesAdminClient client, String... aliases) { - super(client, new GetAliasesRequest(aliases)); + public BaseAliasesRequestBuilder(ElasticsearchClient client, Action action, String... aliases) { + super(client, action, new GetAliasesRequest(aliases)); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java index fd8acb8beba..188f72e1e34 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.alias.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetAliasesAction extends IndicesAction { +public class GetAliasesAction extends Action { public static final GetAliasesAction INSTANCE = new GetAliasesAction(); public static final String NAME = "indices:admin/aliases/get"; @@ -34,8 +34,8 @@ public class GetAliasesAction extends IndicesAction { - public GetAliasesRequestBuilder(IndicesAdminClient client, String... aliases) { - super(client, aliases); + public GetAliasesRequestBuilder(ElasticsearchClient client, GetAliasesAction action, String... aliases) { + super(client, action, aliases); } - - @Override - protected void doExecute(ActionListener listener) { - client.getAliases(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java index b2843e71099..b29ba7507f8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.analyze; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class AnalyzeAction extends IndicesAction { +public class AnalyzeAction extends Action { public static final AnalyzeAction INSTANCE = new AnalyzeAction(); public static final String NAME = "indices:admin/analyze"; @@ -39,7 +39,7 @@ public class AnalyzeAction extends IndicesAction { - public AnalyzeRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new AnalyzeRequest()); + public AnalyzeRequestBuilder(ElasticsearchClient client, AnalyzeAction action) { + super(client, action, new AnalyzeRequest()); } - public AnalyzeRequestBuilder(IndicesAdminClient indicesClient, String index, String text) { - super(indicesClient, new AnalyzeRequest(index).text(text)); + public AnalyzeRequestBuilder(ElasticsearchClient client, AnalyzeAction action, String index, String text) { + super(client, action, new AnalyzeRequest(index).text(text)); } /** @@ -87,9 +86,4 @@ public class AnalyzeRequestBuilder extends SingleCustomOperationRequestBuilder listener) { - client.analyze(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java index 16adc9cb1a4..0880c66802e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.cache.clear; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClearIndicesCacheAction extends IndicesAction { +public class ClearIndicesCacheAction extends Action { public static final ClearIndicesCacheAction INSTANCE = new ClearIndicesCacheAction(); public static final String NAME = "indices:admin/cache/clear"; @@ -39,7 +39,7 @@ public class ClearIndicesCacheAction extends IndicesAction { +public class ClearIndicesCacheRequestBuilder extends BroadcastOperationRequestBuilder { - public ClearIndicesCacheRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new ClearIndicesCacheRequest()); + public ClearIndicesCacheRequestBuilder(ElasticsearchClient client, ClearIndicesCacheAction action) { + super(client, action, new ClearIndicesCacheRequest()); } public ClearIndicesCacheRequestBuilder setFilterCache(boolean filterCache) { @@ -57,9 +55,4 @@ public class ClearIndicesCacheRequestBuilder extends BroadcastOperationRequestBu request.idCache(idCache); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.clearCache(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java index 01e6c3e37a3..fcb38b01da5 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.close; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class CloseIndexAction extends IndicesAction { +public class CloseIndexAction extends Action { public static final CloseIndexAction INSTANCE = new CloseIndexAction(); public static final String NAME = "indices:admin/close"; @@ -39,7 +39,7 @@ public class CloseIndexAction extends IndicesAction { +public class CloseIndexRequestBuilder extends AcknowledgedRequestBuilder { - public CloseIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new CloseIndexRequest()); + public CloseIndexRequestBuilder(ElasticsearchClient client, CloseIndexAction action) { + super(client, action, new CloseIndexRequest()); } - public CloseIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new CloseIndexRequest(indices)); + public CloseIndexRequestBuilder(ElasticsearchClient client, CloseIndexAction action, String... indices) { + super(client, action, new CloseIndexRequest(indices)); } /** * Sets the indices to be closed + * * @param indices the indices to be closed * @return the request itself */ @@ -58,9 +58,4 @@ public class CloseIndexRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.close(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java index 520b3d1a0a2..aa3d3ac92ad 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.create; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class CreateIndexAction extends IndicesAction { +public class CreateIndexAction extends Action { public static final CreateIndexAction INSTANCE = new CreateIndexAction(); public static final String NAME = "indices:admin/create"; @@ -39,7 +39,7 @@ public class CreateIndexAction extends IndicesAction { +public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder { - public CreateIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new CreateIndexRequest()); + public CreateIndexRequestBuilder(ElasticsearchClient client, CreateIndexAction action) { + super(client, action, new CreateIndexRequest()); } - public CreateIndexRequestBuilder(IndicesAdminClient indicesClient, String index) { - super(indicesClient, new CreateIndexRequest(index)); + public CreateIndexRequestBuilder(ElasticsearchClient client, CreateIndexAction action, String index) { + super(client, action, new CreateIndexRequest(index)); } /** @@ -244,9 +243,4 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.create(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java index ac9d5eba86f..135aacc197b 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.delete; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class DeleteIndexAction extends IndicesAction { +public class DeleteIndexAction extends Action { public static final DeleteIndexAction INSTANCE = new DeleteIndexAction(); public static final String NAME = "indices:admin/delete"; @@ -39,7 +39,7 @@ public class DeleteIndexAction extends IndicesAction { +public class DeleteIndexRequestBuilder extends MasterNodeOperationRequestBuilder { - public DeleteIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new DeleteIndexRequest(indices)); + public DeleteIndexRequestBuilder(ElasticsearchClient client, DeleteIndexAction action, String... indices) { + super(client, action, new DeleteIndexRequest(indices)); } /** @@ -54,16 +53,11 @@ public class DeleteIndexRequestBuilder extends MasterNodeOperationRequestBuilder /** * Specifies what type of requested indices to ignore and wildcard indices expressions. - * + *

* For example indices that don't exist. */ public DeleteIndexRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.delete(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java index 734e20e407f..b9bfa00d7a2 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.exists.indices; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesExistsAction extends IndicesAction { +public class IndicesExistsAction extends Action { public static final IndicesExistsAction INSTANCE = new IndicesExistsAction(); public static final String NAME = "indices:admin/exists"; @@ -39,7 +39,7 @@ public class IndicesExistsAction extends IndicesAction { +public class IndicesExistsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public IndicesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new IndicesExistsRequest(indices)); + public IndicesExistsRequestBuilder(ElasticsearchClient client, IndicesExistsAction action, String... indices) { + super(client, action, new IndicesExistsRequest(indices)); } public IndicesExistsRequestBuilder setIndices(String... indices) { @@ -40,16 +39,11 @@ public class IndicesExistsRequestBuilder extends MasterNodeReadOperationRequestB /** * Specifies what type of requested indices to ignore and wildcard indices expressions. - * + *

* For example indices that don't exist. */ public IndicesExistsRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.exists(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java index 9feb5568668..b7fea539d13 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java @@ -18,12 +18,12 @@ */ package org.elasticsearch.action.admin.indices.exists.types; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class TypesExistsAction extends IndicesAction { +public class TypesExistsAction extends Action { public static final TypesExistsAction INSTANCE = new TypesExistsAction(); public static final String NAME = "indices:admin/types/exists"; @@ -38,7 +38,7 @@ public class TypesExistsAction extends IndicesAction { +public class TypesExistsRequestBuilder extends MasterNodeReadOperationRequestBuilder { /** * @param indices What indices to check for types */ - public TypesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY)); + public TypesExistsRequestBuilder(ElasticsearchClient client, TypesExistsAction action, String... indices) { + super(client, action, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY)); } - TypesExistsRequestBuilder(IndicesAdminClient client) { - super(client, new TypesExistsRequest()); + TypesExistsRequestBuilder(ElasticsearchClient client, TypesExistsAction action) { + super(client, action, new TypesExistsRequest()); } /** @@ -63,9 +62,4 @@ public class TypesExistsRequestBuilder extends MasterNodeReadOperationRequestBui request.indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.typesExists(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java index 78e46715139..4cc116fd1dd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.flush; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class FlushAction extends IndicesAction { +public class FlushAction extends Action { public static final FlushAction INSTANCE = new FlushAction(); public static final String NAME = "indices:admin/flush"; @@ -39,7 +39,7 @@ public class FlushAction extends IndicesAction { +public class FlushRequestBuilder extends BroadcastOperationRequestBuilder { - public FlushRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new FlushRequest()); + public FlushRequestBuilder(ElasticsearchClient client, FlushAction action) { + super(client, action, new FlushRequest()); } public FlushRequestBuilder setForce(boolean force) { @@ -37,11 +36,6 @@ public class FlushRequestBuilder extends BroadcastOperationRequestBuilder listener) { - client.flush(request, listener); - } - public FlushRequestBuilder setWaitIfOngoing(boolean waitIfOngoing) { request.waitIfOngoing(waitIfOngoing); return this; diff --git a/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java index 6481808c616..74111c82b2f 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetIndexAction extends IndicesAction { +public class GetIndexAction extends Action { public static final GetIndexAction INSTANCE = new GetIndexAction(); public static final String NAME = "indices:admin/get"; @@ -34,8 +34,8 @@ public class GetIndexAction extends IndicesAction { - public GetIndexRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetIndexRequest().indices(indices)); + public GetIndexRequestBuilder(ElasticsearchClient client, GetIndexAction action, String... indices) { + super(client, action, new GetIndexRequest().indices(indices)); } public GetIndexRequestBuilder setFeatures(Feature... features) { @@ -42,9 +41,4 @@ public class GetIndexRequestBuilder extends ClusterInfoRequestBuilder listener) { - client.getIndex(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java index 222b99762c5..520ed7b2cd4 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetFieldMappingsAction extends IndicesAction { +public class GetFieldMappingsAction extends Action { public static final GetFieldMappingsAction INSTANCE = new GetFieldMappingsAction(); public static final String NAME = "indices:admin/mappings/fields/get"; @@ -34,8 +34,8 @@ public class GetFieldMappingsAction extends IndicesAction { +public class GetFieldMappingsRequestBuilder extends ActionRequestBuilder { - public GetFieldMappingsRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetFieldMappingsRequest().indices(indices)); + public GetFieldMappingsRequestBuilder(ElasticsearchClient client, GetFieldMappingsAction action, String... indices) { + super(client, action, new GetFieldMappingsRequest().indices(indices)); } public GetFieldMappingsRequestBuilder setIndices(String... indices) { @@ -69,10 +70,4 @@ public class GetFieldMappingsRequestBuilder extends ActionRequestBuilder listener) { - client.getFieldMappings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java index 2ac4d58bc88..d7dbebc600c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetMappingsAction extends IndicesAction { +public class GetMappingsAction extends Action { public static final GetMappingsAction INSTANCE = new GetMappingsAction(); public static final String NAME = "indices:admin/mappings/get"; @@ -34,8 +34,8 @@ public class GetMappingsAction extends IndicesAction { - public GetMappingsRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetMappingsRequest().indices(indices)); - } - - @Override - protected void doExecute(ActionListener listener) { - client.getMappings(request, listener); + public GetMappingsRequestBuilder(ElasticsearchClient client, GetMappingsAction action, String... indices) { + super(client, action, new GetMappingsRequest().indices(indices)); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java index 01bfccdb46c..5ed79ceca98 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.mapping.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PutMappingAction extends IndicesAction { +public class PutMappingAction extends Action { public static final PutMappingAction INSTANCE = new PutMappingAction(); public static final String NAME = "indices:admin/mapping/put"; @@ -39,7 +39,7 @@ public class PutMappingAction extends IndicesAction { +public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder { - public PutMappingRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutMappingRequest()); + public PutMappingRequestBuilder(ElasticsearchClient client, PutMappingAction action) { + super(client, action, new PutMappingRequest()); } public PutMappingRequestBuilder setIndices(String... indices) { @@ -43,7 +42,7 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder * For example indices that don't exist. */ public PutMappingRequestBuilder setIndicesOptions(IndicesOptions options) { @@ -101,9 +100,4 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.putMapping(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java index 09bd6ff8f5a..c12e8d23c9c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.open; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class OpenIndexAction extends IndicesAction { +public class OpenIndexAction extends Action { public static final OpenIndexAction INSTANCE = new OpenIndexAction(); public static final String NAME = "indices:admin/open"; @@ -39,7 +39,7 @@ public class OpenIndexAction extends IndicesAction { +public class OpenIndexRequestBuilder extends AcknowledgedRequestBuilder { - public OpenIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new OpenIndexRequest()); + public OpenIndexRequestBuilder(ElasticsearchClient client, OpenIndexAction action) { + super(client, action, new OpenIndexRequest()); } - public OpenIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new OpenIndexRequest(indices)); + public OpenIndexRequestBuilder(ElasticsearchClient client, OpenIndexAction action, String... indices) { + super(client, action, new OpenIndexRequest(indices)); } /** * Sets the indices to be opened + * * @param indices the indices to be opened * @return the request itself */ @@ -58,9 +58,4 @@ public class OpenIndexRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.open(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java index 65d2ce43f01..b44d372f7c9 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.optimize; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class OptimizeAction extends IndicesAction { +public class OptimizeAction extends Action { public static final OptimizeAction INSTANCE = new OptimizeAction(); public static final String NAME = "indices:admin/optimize"; @@ -39,7 +39,7 @@ public class OptimizeAction extends IndicesAction{@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 BroadcastOperationRequestBuilder { +public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder { - public OptimizeRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new OptimizeRequest()); + public OptimizeRequestBuilder(ElasticsearchClient client, OptimizeAction action) { + super(client, action, new OptimizeRequest()); } /** @@ -61,9 +60,4 @@ public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder listener) { - client.optimize(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java index 1b210c004a0..a8848a23edc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.recovery; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.action.admin.indices.IndicesAction; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Recovery information action */ -public class RecoveryAction extends IndicesAction { +public class RecoveryAction extends Action { public static final RecoveryAction INSTANCE = new RecoveryAction(); public static final String NAME = "indices:monitor/recovery"; @@ -35,8 +35,8 @@ public class RecoveryAction extends IndicesAction { +public class RecoveryRequestBuilder extends BroadcastOperationRequestBuilder { /** * Constructs a new recovery information request builder. - * - * @param indicesClient Indices admin client */ - public RecoveryRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new RecoveryRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.recoveries(request, listener); + public RecoveryRequestBuilder(ElasticsearchClient client, RecoveryAction action) { + super(client, action, new RecoveryRequest()); } public RecoveryRequestBuilder setDetailed(boolean detailed) { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java index 985de9fd85d..79db06ec3f0 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.refresh; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class RefreshAction extends IndicesAction { +public class RefreshAction extends Action { public static final RefreshAction INSTANCE = new RefreshAction(); public static final String NAME = "indices:admin/refresh"; @@ -39,7 +39,7 @@ public class RefreshAction extends IndicesAction { +public class RefreshRequestBuilder extends BroadcastOperationRequestBuilder { - public RefreshRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new RefreshRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.refresh(request, listener); + public RefreshRequestBuilder(ElasticsearchClient client, RefreshAction action) { + super(client, action, new RefreshRequest()); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java index 80a01d8ae3c..d98bc56aa5c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.segments; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesSegmentsAction extends IndicesAction { +public class IndicesSegmentsAction extends Action { public static final IndicesSegmentsAction INSTANCE = new IndicesSegmentsAction(); public static final String NAME = "indices:monitor/segments"; @@ -39,7 +39,7 @@ public class IndicesSegmentsAction extends IndicesAction { +public class IndicesSegmentsRequestBuilder extends BroadcastOperationRequestBuilder { - public IndicesSegmentsRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesSegmentsRequest()); + public IndicesSegmentsRequestBuilder(ElasticsearchClient client, IndicesSegmentsAction action) { + super(client, action, new IndicesSegmentsRequest()); } - + public IndicesSegmentsRequestBuilder setVerbose(boolean verbose) { request.verbose = verbose; return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.segments(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java index 0b729bd7999..448a5e25fbd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.settings.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetSettingsAction extends IndicesAction { +public class GetSettingsAction extends Action { public static final GetSettingsAction INSTANCE = new GetSettingsAction(); public static final String NAME = "indices:monitor/settings/get"; @@ -34,8 +34,8 @@ public class GetSettingsAction extends IndicesAction { +public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public GetSettingsRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetSettingsRequest().indices(indices)); + public GetSettingsRequestBuilder(ElasticsearchClient client, GetSettingsAction action, String... indices) { + super(client, action, new GetSettingsRequest().indices(indices)); } public GetSettingsRequestBuilder setIndices(String... indices) { @@ -45,7 +44,7 @@ public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBui /** * Specifies what type of requested indices to ignore and wildcard indices expressions. - * + *

* For example indices that don't exist. */ public GetSettingsRequestBuilder setIndicesOptions(IndicesOptions options) { @@ -57,9 +56,4 @@ public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBui request.names(names); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.getSettings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java index df67115bb3a..17001b7376d 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.settings.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class UpdateSettingsAction extends IndicesAction { +public class UpdateSettingsAction extends Action { public static final UpdateSettingsAction INSTANCE = new UpdateSettingsAction(); public static final String NAME = "indices:admin/settings/update"; @@ -39,7 +39,7 @@ public class UpdateSettingsAction extends IndicesAction { +public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder { - public UpdateSettingsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new UpdateSettingsRequest(indices)); + public UpdateSettingsRequestBuilder(ElasticsearchClient client, UpdateSettingsAction action, String... indices) { + super(client, action, new UpdateSettingsRequest(indices)); } /** @@ -46,7 +46,7 @@ public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder * For example indices that don't exist. */ public UpdateSettingsRequestBuilder setIndicesOptions(IndicesOptions options) { @@ -85,9 +85,4 @@ public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.updateSettings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java index 19b4f5ceca3..d83e368b216 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.stats; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesStatsAction extends IndicesAction { +public class IndicesStatsAction extends Action { public static final IndicesStatsAction INSTANCE = new IndicesStatsAction(); public static final String NAME = "indices:monitor/stats"; @@ -39,7 +39,7 @@ public class IndicesStatsAction extends IndicesActionAll the stats to be returned can be cleared using {@link #clear()}, at which point, specific * stats can be enabled. */ -public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder { +public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder { - public IndicesStatsRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesStatsRequest()); + public IndicesStatsRequestBuilder(ElasticsearchClient client, IndicesStatsAction action) { + super(client, action, new IndicesStatsRequest()); } /** @@ -172,9 +171,4 @@ public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder request.recovery(recovery); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.stats(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java index e826b76f971..570ced293d8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.template.delete; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class DeleteIndexTemplateAction extends IndicesAction { +public class DeleteIndexTemplateAction extends Action { public static final DeleteIndexTemplateAction INSTANCE = new DeleteIndexTemplateAction(); public static final String NAME = "indices:admin/template/delete"; @@ -39,7 +39,7 @@ public class DeleteIndexTemplateAction extends IndicesAction { +public class DeleteIndexTemplateRequestBuilder extends MasterNodeOperationRequestBuilder { - public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteIndexTemplateRequest()); + public DeleteIndexTemplateRequestBuilder(ElasticsearchClient client, DeleteIndexTemplateAction action) { + super(client, action, new DeleteIndexTemplateRequest()); } - public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new DeleteIndexTemplateRequest(name)); - } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteTemplate(request, listener); + public DeleteIndexTemplateRequestBuilder(ElasticsearchClient client, DeleteIndexTemplateAction action, String name) { + super(client, action, new DeleteIndexTemplateRequest(name)); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java index de3ded1a64e..b4db5e0529f 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java @@ -18,13 +18,13 @@ */ package org.elasticsearch.action.admin.indices.template.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * */ -public class GetIndexTemplatesAction extends IndicesAction { +public class GetIndexTemplatesAction extends Action { public static final GetIndexTemplatesAction INSTANCE = new GetIndexTemplatesAction(); public static final String NAME = "indices:admin/template/get"; @@ -39,7 +39,7 @@ public class GetIndexTemplatesAction extends IndicesAction { +public class GetIndexTemplatesRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public GetIndexTemplatesRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new GetIndexTemplatesRequest()); + public GetIndexTemplatesRequestBuilder(ElasticsearchClient client, GetIndexTemplatesAction action) { + super(client, action, new GetIndexTemplatesRequest()); } - public GetIndexTemplatesRequestBuilder(IndicesAdminClient indicesClient, String... names) { - super(indicesClient, new GetIndexTemplatesRequest(names)); - } - - @Override - protected void doExecute(ActionListener listener) { - client.getTemplates(request, listener); + public GetIndexTemplatesRequestBuilder(ElasticsearchClient client, GetIndexTemplatesAction action, String... names) { + super(client, action, new GetIndexTemplatesRequest(names)); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java index 00f98bc46b6..51adc0b5cfc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.template.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PutIndexTemplateAction extends IndicesAction { +public class PutIndexTemplateAction extends Action { public static final PutIndexTemplateAction INSTANCE = new PutIndexTemplateAction(); public static final String NAME = "indices:admin/template/put"; @@ -39,7 +39,7 @@ public class PutIndexTemplateAction extends IndicesAction { +public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBuilder { - public PutIndexTemplateRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutIndexTemplateRequest()); + public PutIndexTemplateRequestBuilder(ElasticsearchClient client, PutIndexTemplateAction action) { + super(client, action, new PutIndexTemplateRequest()); } - public PutIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new PutIndexTemplateRequest(name)); + public PutIndexTemplateRequestBuilder(ElasticsearchClient client, PutIndexTemplateAction action, String name) { + super(client, action, new PutIndexTemplateRequest(name)); } /** @@ -153,7 +153,7 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu /** * Adds an alias that will be added when the index template gets created. * - * @param alias The alias + * @param alias The alias * @return the request builder */ public PutIndexTemplateRequestBuilder addAlias(Alias alias) { @@ -238,9 +238,4 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu request.source(templateSource, offset, length); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.putTemplate(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java index 76bb9523183..fdec5490c97 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.validate.query; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ValidateQueryAction extends IndicesAction { +public class ValidateQueryAction extends Action { public static final ValidateQueryAction INSTANCE = new ValidateQueryAction(); public static final String NAME = "indices:admin/validate/query"; @@ -39,7 +39,7 @@ public class ValidateQueryAction extends IndicesAction { +public class ValidateQueryRequestBuilder extends BroadcastOperationRequestBuilder { private QuerySourceBuilder sourceBuilder; - public ValidateQueryRequestBuilder(IndicesAdminClient client) { - super(client, new ValidateQueryRequest()); + public ValidateQueryRequestBuilder(ElasticsearchClient client, ValidateQueryAction action) { + super(client, action, new ValidateQueryRequest()); } /** @@ -94,12 +94,11 @@ public class ValidateQueryRequestBuilder extends BroadcastOperationRequestBuilde } @Override - protected void doExecute(ActionListener listener) { + protected ValidateQueryRequest beforeExecute(ValidateQueryRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.validateQuery(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java index 9c3e4a001a0..86c447d3ca4 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.warmer.delete; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Action for the admin/warmers/delete API. */ -public class DeleteWarmerAction extends IndicesAction { +public class DeleteWarmerAction extends Action { public static final DeleteWarmerAction INSTANCE = new DeleteWarmerAction(); public static final String NAME = "indices:admin/warmers/delete"; @@ -40,7 +40,7 @@ public class DeleteWarmerAction extends IndicesAction { +public class DeleteWarmerRequestBuilder extends AcknowledgedRequestBuilder { - public DeleteWarmerRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteWarmerRequest()); + public DeleteWarmerRequestBuilder(ElasticsearchClient client, DeleteWarmerAction action) { + super(client, action, new DeleteWarmerRequest()); } public DeleteWarmerRequestBuilder setIndices(String... indices) { @@ -50,16 +50,11 @@ public class DeleteWarmerRequestBuilder extends AcknowledgedRequestBuilder * For example indices that don't exist. */ public DeleteWarmerRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteWarmer(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java index 4170509b904..e2debde72a6 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.warmer.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Action for the admin/warmers/get API. */ -public class GetWarmersAction extends IndicesAction { +public class GetWarmersAction extends Action { public static final GetWarmersAction INSTANCE = new GetWarmersAction(); public static final String NAME = "indices:admin/warmers/get"; @@ -35,8 +35,8 @@ public class GetWarmersAction extends IndicesAction { - public GetWarmersRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetWarmersRequest().indices(indices)); + public GetWarmersRequestBuilder(ElasticsearchClient client, GetWarmersAction action, String... indices) { + super(client, action, new GetWarmersRequest().indices(indices)); } public GetWarmersRequestBuilder setWarmers(String... warmers) { @@ -44,9 +43,4 @@ public class GetWarmersRequestBuilder extends ClusterInfoRequestBuilder listener) { - client.getWarmers(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java index 4b295286de3..3c5c8b7c412 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.warmer.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Action for the admin/warmers/put API. */ -public class PutWarmerAction extends IndicesAction { +public class PutWarmerAction extends Action { public static final PutWarmerAction INSTANCE = new PutWarmerAction(); public static final String NAME = "indices:admin/warmers/put"; @@ -40,7 +40,7 @@ public class PutWarmerAction extends IndicesAction { +public class PutWarmerRequestBuilder extends AcknowledgedRequestBuilder { /** * Creates a new {@link PutWarmerRequestBuilder} with a given name. */ - public PutWarmerRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new PutWarmerRequest().name(name)); + public PutWarmerRequestBuilder(ElasticsearchClient client, PutWarmerAction action, String name) { + super(client, action, new PutWarmerRequest().name(name)); } /** * Creates a new {@link PutWarmerRequestBuilder} * Note: {@link #setName(String)} must be called with a non-null value before this request is executed. */ - public PutWarmerRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutWarmerRequest()); + public PutWarmerRequestBuilder(ElasticsearchClient client, PutWarmerAction action) { + super(client, action, new PutWarmerRequest()); } /** @@ -69,9 +69,4 @@ public class PutWarmerRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.putWarmer(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/bulk/BulkAction.java b/src/main/java/org/elasticsearch/action/bulk/BulkAction.java index e7a8ea13de8..42d0c22508b 100644 --- a/src/main/java/org/elasticsearch/action/bulk/BulkAction.java +++ b/src/main/java/org/elasticsearch/action/bulk/BulkAction.java @@ -19,14 +19,14 @@ package org.elasticsearch.action.bulk; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportRequestOptions; /** */ -public class BulkAction extends ClientAction { +public class BulkAction extends Action { public static final BulkAction INSTANCE = new BulkAction(); public static final String NAME = "indices:data/write/bulk"; @@ -41,8 +41,8 @@ public class BulkAction extends ClientAction { +public class BulkRequestBuilder extends ActionRequestBuilder { - public BulkRequestBuilder(Client client) { - super(client, new BulkRequest()); + public BulkRequestBuilder(ElasticsearchClient client, BulkAction action) { + super(client, action, new BulkRequest()); } /** @@ -149,9 +148,4 @@ public class BulkRequestBuilder extends ActionRequestBuilder listener) { - client.bulk(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/count/CountAction.java b/src/main/java/org/elasticsearch/action/count/CountAction.java index 319ca5366d5..4c7c8a2fcc2 100644 --- a/src/main/java/org/elasticsearch/action/count/CountAction.java +++ b/src/main/java/org/elasticsearch/action/count/CountAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.count; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class CountAction extends ClientAction { +public class CountAction extends Action { public static final CountAction INSTANCE = new CountAction(); public static final String NAME = "indices:data/read/count"; @@ -39,7 +39,7 @@ public class CountAction extends ClientAction { +public class CountRequestBuilder extends BroadcastOperationRequestBuilder { private QuerySourceBuilder sourceBuilder; - public CountRequestBuilder(Client client) { - super(client, new CountRequest()); + public CountRequestBuilder(ElasticsearchClient client, CountAction action) { + super(client, action, new CountRequest()); } /** @@ -101,7 +100,7 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected CountRequest beforeExecute(CountRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.count(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { @@ -155,7 +153,7 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder { +public class DeleteAction extends Action { public static final DeleteAction INSTANCE = new DeleteAction(); public static final String NAME = "indices:data/write/delete"; @@ -39,7 +39,7 @@ public class DeleteAction extends ClientAction { - public DeleteRequestBuilder(Client client) { - super(client, new DeleteRequest()); + public DeleteRequestBuilder(ElasticsearchClient client, DeleteAction action) { + super(client, action, new DeleteRequest()); } - public DeleteRequestBuilder(Client client, @Nullable String index) { - super(client, new DeleteRequest(index)); + public DeleteRequestBuilder(ElasticsearchClient client, DeleteAction action, @Nullable String index) { + super(client, action, new DeleteRequest(index)); } /** @@ -98,9 +97,4 @@ public class DeleteRequestBuilder extends ShardReplicationOperationRequestBuilde request.versionType(versionType); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.delete(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/exists/ExistsAction.java b/src/main/java/org/elasticsearch/action/exists/ExistsAction.java index e37f81c5e44..d4463aea0d6 100644 --- a/src/main/java/org/elasticsearch/action/exists/ExistsAction.java +++ b/src/main/java/org/elasticsearch/action/exists/ExistsAction.java @@ -19,10 +19,10 @@ package org.elasticsearch.action.exists; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; -public class ExistsAction extends ClientAction { +public class ExistsAction extends Action { public static final ExistsAction INSTANCE = new ExistsAction(); public static final String NAME = "indices:data/read/exists"; @@ -37,7 +37,7 @@ public class ExistsAction extends ClientAction { - +public class ExistsRequestBuilder extends BroadcastOperationRequestBuilder { private QuerySourceBuilder sourceBuilder; - public ExistsRequestBuilder(Client client) { - super(client, new ExistsRequest()); + public ExistsRequestBuilder(ElasticsearchClient client, ExistsAction action) { + super(client, action, new ExistsRequest()); } /** @@ -104,12 +102,11 @@ public class ExistsRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected ExistsRequest beforeExecute(ExistsRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.exists(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/explain/ExplainAction.java b/src/main/java/org/elasticsearch/action/explain/ExplainAction.java index 3d7645db09b..b48530ce527 100644 --- a/src/main/java/org/elasticsearch/action/explain/ExplainAction.java +++ b/src/main/java/org/elasticsearch/action/explain/ExplainAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.explain; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Entry point for the explain feature. */ -public class ExplainAction extends ClientAction { +public class ExplainAction extends Action { public static final ExplainAction INSTANCE = new ExplainAction(); public static final String NAME = "indices:data/read/explain"; @@ -35,8 +35,8 @@ public class ExplainAction extends ClientAction listener) { + protected ExplainRequest beforeExecute(ExplainRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.explain(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java b/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java index fb4a3f77833..085952c9be6 100644 --- a/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java +++ b/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.fieldstats; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class FieldStatsAction extends ClientAction { +public class FieldStatsAction extends Action { public static final FieldStatsAction INSTANCE = new FieldStatsAction(); public static final String NAME = "indices:data/read/field_stats"; @@ -39,7 +39,7 @@ public class FieldStatsAction extends ClientAction { +public class FieldStatsRequestBuilder extends BroadcastOperationRequestBuilder { - public FieldStatsRequestBuilder(Client client) { - super(client, new FieldStatsRequest()); + public FieldStatsRequestBuilder(ElasticsearchClient client, FieldStatsAction action) { + super(client, action, new FieldStatsRequest()); } public FieldStatsRequestBuilder setFields(String... fields) { @@ -40,9 +39,4 @@ public class FieldStatsRequestBuilder extends BroadcastOperationRequestBuilder listener) { - client.fieldStats(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/get/GetAction.java b/src/main/java/org/elasticsearch/action/get/GetAction.java index 93e4f26e150..eb499ffb8c2 100644 --- a/src/main/java/org/elasticsearch/action/get/GetAction.java +++ b/src/main/java/org/elasticsearch/action/get/GetAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.get; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetAction extends ClientAction { +public class GetAction extends Action { public static final GetAction INSTANCE = new GetAction(); public static final String NAME = "indices:data/read/get"; @@ -39,7 +39,7 @@ public class GetAction extends ClientAction { - public GetRequestBuilder(Client client) { - super(client, new GetRequest()); + public GetRequestBuilder(ElasticsearchClient client, GetAction action) { + super(client, action, new GetRequest()); } - public GetRequestBuilder(Client client, @Nullable String index) { - super(client, new GetRequest(index)); + public GetRequestBuilder(ElasticsearchClient client, GetAction action, @Nullable String index) { + super(client, action, new GetRequest(index)); } /** @@ -96,14 +95,14 @@ public class GetRequestBuilder extends SingleShardOperationRequestBuilder listener) { - client.get(request, listener); - } - - } diff --git a/src/main/java/org/elasticsearch/action/get/MultiGetAction.java b/src/main/java/org/elasticsearch/action/get/MultiGetAction.java index 0a15892a057..38036d391e8 100644 --- a/src/main/java/org/elasticsearch/action/get/MultiGetAction.java +++ b/src/main/java/org/elasticsearch/action/get/MultiGetAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.get; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiGetAction extends ClientAction { +public class MultiGetAction extends Action { public static final MultiGetAction INSTANCE = new MultiGetAction(); public static final String NAME = "indices:data/read/mget"; @@ -39,7 +39,7 @@ public class MultiGetAction extends ClientAction { +public class MultiGetRequestBuilder extends ActionRequestBuilder { - public MultiGetRequestBuilder(Client client) { - super(client, new MultiGetRequest()); + public MultiGetRequestBuilder(ElasticsearchClient client, MultiGetAction action) { + super(client, action, new MultiGetRequest()); } public MultiGetRequestBuilder add(String index, @Nullable String type, String id) { @@ -86,9 +85,4 @@ public class MultiGetRequestBuilder extends ActionRequestBuilder listener) { - client.multiGet(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/index/IndexAction.java b/src/main/java/org/elasticsearch/action/index/IndexAction.java index 1f6e5a5c8ea..ceacbcf2df7 100644 --- a/src/main/java/org/elasticsearch/action/index/IndexAction.java +++ b/src/main/java/org/elasticsearch/action/index/IndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.index; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndexAction extends ClientAction { +public class IndexAction extends Action { public static final IndexAction INSTANCE = new IndexAction(); public static final String NAME = "indices:data/write/index"; @@ -39,7 +39,7 @@ public class IndexAction extends ClientAction { - public IndexRequestBuilder(Client client) { - super(client, new IndexRequest()); + public IndexRequestBuilder(ElasticsearchClient client, IndexAction action) { + super(client, action, new IndexRequest()); } - public IndexRequestBuilder(Client client, @Nullable String index) { - super(client, new IndexRequest(index)); + public IndexRequestBuilder(ElasticsearchClient client, IndexAction action, @Nullable String index) { + super(client, action, new IndexRequest(index)); } /** @@ -180,7 +179,7 @@ public class IndexRequestBuilder extends ShardReplicationOperationRequestBuilder /** * Constructs a simple document with a field name and value pairs. - * Note: the number of objects passed to this method must be an even number. + * Note: the number of objects passed to this method must be an even number. */ public IndexRequestBuilder setSource(Object... source) { request.source(source); @@ -260,9 +259,4 @@ public class IndexRequestBuilder extends ShardReplicationOperationRequestBuilder request.ttl(ttl); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.index(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java b/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java index 94009796b19..4ccbdf7801d 100644 --- a/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.indexedscripts.delete; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class DeleteIndexedScriptAction extends ClientAction { +public class DeleteIndexedScriptAction extends Action { public static final DeleteIndexedScriptAction INSTANCE = new DeleteIndexedScriptAction(); public static final String NAME = "indices:data/write/script/delete"; @@ -39,7 +39,7 @@ public class DeleteIndexedScriptAction extends ClientAction { +public class DeleteIndexedScriptRequestBuilder extends ActionRequestBuilder { - public DeleteIndexedScriptRequestBuilder(Client client) { - super(client, new DeleteIndexedScriptRequest()); + public DeleteIndexedScriptRequestBuilder(ElasticsearchClient client, DeleteIndexedScriptAction action) { + super(client, action, new DeleteIndexedScriptRequest()); } /** @@ -56,9 +55,4 @@ public class DeleteIndexedScriptRequestBuilder extends ActionRequestBuilder listener) { - client.deleteIndexedScript(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java b/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java index a909b78d289..898d33691f6 100644 --- a/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.indexedscripts.get; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetIndexedScriptAction extends ClientAction { +public class GetIndexedScriptAction extends Action { public static final GetIndexedScriptAction INSTANCE = new GetIndexedScriptAction(); public static final String NAME = "indices:data/read/script/get"; @@ -39,8 +39,8 @@ public class GetIndexedScriptAction extends ClientAction { +public class GetIndexedScriptRequestBuilder extends ActionRequestBuilder { - public GetIndexedScriptRequestBuilder(Client client) { - super(client, new GetIndexedScriptRequest()); + public GetIndexedScriptRequestBuilder(ElasticsearchClient client, GetIndexedScriptAction action) { + super(client, action, new GetIndexedScriptRequest()); } /** @@ -68,10 +67,4 @@ public class GetIndexedScriptRequestBuilder extends ActionRequestBuilder listener) { - client.getIndexedScript(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java b/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java index 3949e05af18..e0f364b0ad1 100644 --- a/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.indexedscripts.put; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PutIndexedScriptAction extends ClientAction { +public class PutIndexedScriptAction extends Action { public static final PutIndexedScriptAction INSTANCE = new PutIndexedScriptAction(); public static final String NAME = "indices:data/write/script/put"; @@ -42,7 +42,7 @@ public class PutIndexedScriptAction extends ClientAction { +public class PutIndexedScriptRequestBuilder extends ActionRequestBuilder { - public PutIndexedScriptRequestBuilder(Client client) { - super(client, new PutIndexedScriptRequest()); + public PutIndexedScriptRequestBuilder(ElasticsearchClient client, PutIndexedScriptAction action) { + super(client, action, new PutIndexedScriptRequest()); } /** @@ -126,7 +125,7 @@ public class PutIndexedScriptRequestBuilder extends ActionRequestBuilderNote: the number of objects passed to this method must be an even number. + * Note: the number of objects passed to this method must be an even number. */ public PutIndexedScriptRequestBuilder setSource(Object... source) { request.source(source); @@ -182,27 +181,4 @@ public class PutIndexedScriptRequestBuilder extends ActionRequestBuilder listener) { - client.putIndexedScript(request, listener); - /* - try { - scriptService.putScriptToIndex(client, request.safeSource(), request.id(), request.scriptLang(), null, request.opType().toString(), new ActionListener() { - @Override - public void onResponse(IndexResponse indexResponse) { - listener.onResponse(new PutIndexedScriptResponse(indexResponse.getType(),indexResponse.getId(),indexResponse.getVersion(),indexResponse.isCreated())); - } - - @Override - public void onFailure(Throwable e) { - listener.onFailure(e); - } - }); - } catch (IOException ioe) { - listener.onFailure(ioe); - } - */ - } } diff --git a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java index b2561650d77..83313dfc095 100644 --- a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java +++ b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.mlt; -import org.elasticsearch.action.ClientAction; +import org.elasticsearch.action.Action; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MoreLikeThisAction extends ClientAction { +public class MoreLikeThisAction extends Action { public static final MoreLikeThisAction INSTANCE = new MoreLikeThisAction(); public static final String NAME = "indices:data/read/mlt"; @@ -40,7 +40,7 @@ public class MoreLikeThisAction extends ClientAction { +public class MoreLikeThisRequestBuilder extends ActionRequestBuilder { - public MoreLikeThisRequestBuilder(Client client) { - super(client, new MoreLikeThisRequest()); + public MoreLikeThisRequestBuilder(ElasticsearchClient client, MoreLikeThisAction action) { + super(client, action, new MoreLikeThisRequest()); } - public MoreLikeThisRequestBuilder(Client client, String index, String type, String id) { - super(client, new MoreLikeThisRequest(index).type(type).id(id)); + public MoreLikeThisRequestBuilder(ElasticsearchClient client, MoreLikeThisAction action, String index, String type, String id) { + super(client, action, new MoreLikeThisRequest(index).type(type).id(id)); } /** @@ -63,7 +62,7 @@ public class MoreLikeThisRequestBuilder extends ActionRequestBuilder30%. * - * @see org.elasticsearch.common.lucene.search.Queries#calculateMinShouldMatch(int, String) + * @see org.elasticsearch.common.lucene.search.Queries#calculateMinShouldMatch(int, String) */ public MoreLikeThisRequestBuilder setMinimumShouldMatch(String minimumShouldMatch) { request.minimumShouldMatch(minimumShouldMatch); @@ -259,10 +258,4 @@ public class MoreLikeThisRequestBuilder extends ActionRequestBuilder listener) { - client.moreLikeThis(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java b/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java index fadb290683c..2b9538ae054 100644 --- a/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java +++ b/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java @@ -18,12 +18,12 @@ */ package org.elasticsearch.action.percolate; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiPercolateAction extends ClientAction { +public class MultiPercolateAction extends Action { public static final MultiPercolateAction INSTANCE = new MultiPercolateAction(); public static final String NAME = "indices:data/read/mpercolate"; @@ -38,8 +38,8 @@ public class MultiPercolateAction extends ClientAction { +public class MultiPercolateRequestBuilder extends ActionRequestBuilder { - public MultiPercolateRequestBuilder(Client client) { - super(client, new MultiPercolateRequest()); + public MultiPercolateRequestBuilder(ElasticsearchClient client, MultiPercolateAction action) { + super(client, action, new MultiPercolateRequest()); } /** @@ -50,16 +49,11 @@ public class MultiPercolateRequestBuilder extends ActionRequestBuilder * Invoke this method before invoking {@link #add(PercolateRequestBuilder)}. */ public MultiPercolateRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { request.indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.multiPercolate(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java b/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java index 6d85d207719..412f4e3ed62 100644 --- a/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java +++ b/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.percolate; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PercolateAction extends ClientAction { +public class PercolateAction extends Action { public static final PercolateAction INSTANCE = new PercolateAction(); public static final String NAME = "indices:data/read/percolate"; @@ -39,7 +39,7 @@ public class PercolateAction extends ClientAction { +public class PercolateRequestBuilder extends BroadcastOperationRequestBuilder { private PercolateSourceBuilder sourceBuilder; - public PercolateRequestBuilder(Client client) { - super(client, new PercolateRequest()); + public PercolateRequestBuilder(ElasticsearchClient client, PercolateAction action) { + super(client, action, new PercolateRequest()); } /** @@ -252,11 +249,10 @@ public class PercolateRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected PercolateRequest beforeExecute(PercolateRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - client.percolate(request, listener); + return request; } - } diff --git a/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java b/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java index 769c14fa369..6523378df4d 100644 --- a/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java +++ b/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClearScrollAction extends ClientAction { +public class ClearScrollAction extends Action { public static final ClearScrollAction INSTANCE = new ClearScrollAction(); public static final String NAME = "indices:data/read/scroll/clear"; @@ -39,7 +39,7 @@ public class ClearScrollAction extends ClientAction { +public class ClearScrollRequestBuilder extends ActionRequestBuilder { - public ClearScrollRequestBuilder(Client client) { - super(client, new ClearScrollRequest()); + public ClearScrollRequestBuilder(ElasticsearchClient client, ClearScrollAction action) { + super(client, action, new ClearScrollRequest()); } public ClearScrollRequestBuilder setScrollIds(List cursorIds) { @@ -42,9 +41,4 @@ public class ClearScrollRequestBuilder extends ActionRequestBuilder listener) { - client.clearScroll(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java b/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java index f052a927a16..ffa0a4b63f0 100644 --- a/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java +++ b/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiSearchAction extends ClientAction { +public class MultiSearchAction extends Action { public static final MultiSearchAction INSTANCE = new MultiSearchAction(); public static final String NAME = "indices:data/read/msearch"; @@ -39,7 +39,7 @@ public class MultiSearchAction extends ClientAction { +public class MultiSearchRequestBuilder extends ActionRequestBuilder { - public MultiSearchRequestBuilder(Client client) { - super(client, new MultiSearchRequest()); + public MultiSearchRequestBuilder(ElasticsearchClient client, MultiSearchAction action) { + super(client, action, new MultiSearchRequest()); } /** @@ -65,16 +64,11 @@ public class MultiSearchRequestBuilder extends ActionRequestBuilder * Invoke this method before invoking {@link #add(SearchRequestBuilder)}. */ public MultiSearchRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { request().indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.multiSearch(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/search/SearchAction.java b/src/main/java/org/elasticsearch/action/search/SearchAction.java index 450e65eed19..501fe1afb76 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchAction.java +++ b/src/main/java/org/elasticsearch/action/search/SearchAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class SearchAction extends ClientAction { +public class SearchAction extends Action { public static final SearchAction INSTANCE = new SearchAction(); public static final String NAME = "indices:data/read/search"; @@ -39,7 +39,7 @@ public class SearchAction extends ClientAction { +public class SearchRequestBuilder extends ActionRequestBuilder { private SearchSourceBuilder sourceBuilder; - public SearchRequestBuilder(Client client) { - super(client, new SearchRequest()); + public SearchRequestBuilder(ElasticsearchClient client, SearchAction action) { + super(client, action, new SearchRequest()); } /** @@ -168,7 +166,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder * For example indices that don't exist. */ public SearchRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { @@ -703,6 +701,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder templateParams) { + public SearchRequestBuilder setTemplateParams(Map templateParams) { request.templateParams(templateParams); return this; } @@ -994,7 +1000,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder listener) { + protected SearchRequest beforeExecute(SearchRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder()); } - client.search(request, listener); + return request; } private SearchSourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java b/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java index 0647b2e6554..eccfa0526a1 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java +++ b/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class SearchScrollAction extends ClientAction { +public class SearchScrollAction extends Action { public static final SearchScrollAction INSTANCE = new SearchScrollAction(); public static final String NAME = "indices:data/read/scroll"; @@ -39,7 +39,7 @@ public class SearchScrollAction extends ClientAction { +public class SearchScrollRequestBuilder extends ActionRequestBuilder { - public SearchScrollRequestBuilder(Client client) { - super(client, new SearchScrollRequest()); + public SearchScrollRequestBuilder(ElasticsearchClient client, SearchScrollAction action) { + super(client, action, new SearchScrollRequest()); } - public SearchScrollRequestBuilder(Client client, String scrollId) { - super(client, new SearchScrollRequest(scrollId)); + public SearchScrollRequestBuilder(ElasticsearchClient client, SearchScrollAction action, String scrollId) { + super(client, action, new SearchScrollRequest(scrollId)); } /** @@ -69,9 +68,4 @@ public class SearchScrollRequestBuilder extends ActionRequestBuilder listener) { - client.searchScroll(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java b/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java index 59bfe4e6e19..88d2a92f331 100644 --- a/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java +++ b/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.suggest; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.search.suggest.Suggest; /** */ -public class SuggestAction extends ClientAction { +public class SuggestAction extends Action { public static final SuggestAction INSTANCE = new SuggestAction(); public static final String NAME = "indices:data/read/suggest"; @@ -40,7 +40,7 @@ public class SuggestAction extends ClientAction { +public class SuggestRequestBuilder extends BroadcastOperationRequestBuilder { final SuggestBuilder suggest = new SuggestBuilder(); - public SuggestRequestBuilder(Client client) { - super(client, new SuggestRequest()); + public SuggestRequestBuilder(ElasticsearchClient client, SuggestAction action) { + super(client, action, new SuggestRequest()); } /** @@ -84,7 +83,7 @@ public class SuggestRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected SuggestRequest beforeExecute(SuggestRequest request) { try { XContentBuilder builder = XContentFactory.contentBuilder(Requests.CONTENT_TYPE); suggest.toXContent(builder, ToXContent.EMPTY_PARAMS); @@ -92,7 +91,6 @@ public class SuggestRequestBuilder extends BroadcastOperationRequestBuilder implements ActionListener(logger, threadPool, ThreadPool.Names.LISTENER, listener); } } diff --git a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java index 9a24917222f..50fb7b097f2 100644 --- a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java @@ -19,19 +19,18 @@ package org.elasticsearch.action.support.broadcast; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.client.Client; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.client.IndicesAdminClient; /** */ -public abstract class BroadcastOperationRequestBuilder, Response extends BroadcastOperationResponse, RequestBuilder extends BroadcastOperationRequestBuilder, Client extends ElasticsearchClient> - extends ActionRequestBuilder { +public abstract class BroadcastOperationRequestBuilder, Response extends BroadcastOperationResponse, RequestBuilder extends BroadcastOperationRequestBuilder> + extends ActionRequestBuilder { - protected BroadcastOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected BroadcastOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java index fcc92ed7959..939f47f9acf 100644 --- a/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java @@ -18,19 +18,18 @@ */ package org.elasticsearch.action.support.master; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * Base request builder for master node operations that support acknowledgements */ -public abstract class AcknowledgedRequestBuilder, Response extends AcknowledgedResponse, RequestBuilder extends AcknowledgedRequestBuilder, Client extends ElasticsearchClient> - extends MasterNodeOperationRequestBuilder { +public abstract class AcknowledgedRequestBuilder, Response extends AcknowledgedResponse, RequestBuilder extends AcknowledgedRequestBuilder> + extends MasterNodeOperationRequestBuilder { - protected AcknowledgedRequestBuilder(Client client, Request request) { - super(client, request); + protected AcknowledgedRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** @@ -39,7 +38,7 @@ public abstract class AcknowledgedRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeOperationRequestBuilder, Client extends ElasticsearchClient> - extends ActionRequestBuilder { +public abstract class MasterNodeOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeOperationRequestBuilder> + extends ActionRequestBuilder { - protected MasterNodeOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected MasterNodeOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java index 0b0644cc428..02c83298c25 100644 --- a/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.support.master; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.ElasticsearchClient; @@ -27,11 +28,11 @@ import org.elasticsearch.client.IndicesAdminClient; /** * Base request builder for master node read operations that can be executed on the local node as well */ -public abstract class MasterNodeReadOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeReadOperationRequestBuilder, Client extends ElasticsearchClient> - extends MasterNodeOperationRequestBuilder { +public abstract class MasterNodeReadOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeReadOperationRequestBuilder> + extends MasterNodeOperationRequestBuilder { - protected MasterNodeReadOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected MasterNodeReadOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java index d310a2abe7f..cc12e2836dd 100644 --- a/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java @@ -19,19 +19,21 @@ package org.elasticsearch.action.support.master.info; import com.google.common.collect.ObjectArrays; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.IndicesAdminClient; /** */ -public abstract class ClusterInfoRequestBuilder, Response extends ActionResponse, Builder extends ClusterInfoRequestBuilder> extends MasterNodeReadOperationRequestBuilder { +public abstract class ClusterInfoRequestBuilder, Response extends ActionResponse, Builder extends ClusterInfoRequestBuilder> extends MasterNodeReadOperationRequestBuilder { - protected ClusterInfoRequestBuilder(IndicesAdminClient client, Request request) { - super(client, request); + protected ClusterInfoRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java index e9c38539ede..303671db595 100644 --- a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java @@ -19,17 +19,18 @@ package org.elasticsearch.action.support.nodes; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; /** */ public abstract class NodesOperationRequestBuilder, Response extends NodesOperationResponse, RequestBuilder extends NodesOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected NodesOperationRequestBuilder(ClusterAdminClient client, Request request) { - super(client, request); + protected NodesOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java index 80a0c96bd6a..aa34e249d9d 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java @@ -19,19 +19,21 @@ package org.elasticsearch.action.support.replication; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.WriteConsistencyLevel; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; /** */ public abstract class ShardReplicationOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends ShardReplicationOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected ShardReplicationOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected ShardReplicationOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** 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 index 8b0cc7fbe47..46019916f46 100644 --- a/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java @@ -18,19 +18,21 @@ */ package org.elasticsearch.action.support.single.custom; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.IndicesAdminClient; /** */ public abstract class SingleCustomOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleCustomOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected SingleCustomOperationRequestBuilder(IndicesAdminClient client, Request request) { - super(client, request); + protected SingleCustomOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** 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 index 5d1299c60b1..a40e293f64e 100644 --- a/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java @@ -19,18 +19,20 @@ package org.elasticsearch.action.support.single.instance; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; /** */ public abstract class InstanceShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends InstanceShardOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected InstanceShardOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected InstanceShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") 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 index cca130375ee..e9ce5204aaf 100644 --- a/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java @@ -19,17 +19,19 @@ package org.elasticsearch.action.support.single.shard; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; /** */ public abstract class SingleShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleShardOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected SingleShardOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected SingleShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java b/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java index 99faae076c0..d4451157c4b 100644 --- a/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java +++ b/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java @@ -19,12 +19,13 @@ package org.elasticsearch.action.termvectors; -import org.elasticsearch.action.ClientAction; +import org.elasticsearch.action.Action; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiTermVectorsAction extends ClientAction { +public class MultiTermVectorsAction extends Action { public static final MultiTermVectorsAction INSTANCE = new MultiTermVectorsAction(); public static final String NAME = "indices:data/read/mtv"; @@ -39,7 +40,7 @@ public class MultiTermVectorsAction extends ClientAction { - public MultiTermVectorsRequestBuilder(Client client) { - super(client, new MultiTermVectorsRequest()); +public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder { + + public MultiTermVectorsRequestBuilder(ElasticsearchClient client, MultiTermVectorsAction action) { + super(client, action, new MultiTermVectorsRequest()); } public MultiTermVectorsRequestBuilder add(String index, @Nullable String type, Iterable ids) { @@ -47,9 +47,4 @@ public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder listener) { - client.multiTermVectors(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java index 96269d55f1b..a4c53ee4a2d 100644 --- a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java +++ b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.termvectors; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class TermVectorsAction extends ClientAction { +public class TermVectorsAction extends Action { public static final TermVectorsAction INSTANCE = new TermVectorsAction(); public static final String NAME = "indices:data/read/tv"; @@ -39,7 +39,7 @@ public class TermVectorsAction extends ClientAction { +public class TermVectorsRequestBuilder extends ActionRequestBuilder { - public TermVectorsRequestBuilder(Client client) { - super(client, new TermVectorsRequest()); + public TermVectorsRequestBuilder(ElasticsearchClient client, TermVectorsAction action) { + super(client, action, new TermVectorsRequest()); } /** @@ -45,8 +45,8 @@ public class TermVectorsRequestBuilder extends ActionRequestBuilder listener) { - client.termVectors(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/update/UpdateAction.java b/src/main/java/org/elasticsearch/action/update/UpdateAction.java index c149a8839d2..4ac1002dbc6 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateAction.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.update; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class UpdateAction extends ClientAction { +public class UpdateAction extends Action { public static final UpdateAction INSTANCE = new UpdateAction(); public static final String NAME = "indices:data/write/update"; @@ -39,7 +39,7 @@ public class UpdateAction extends ClientAction { - public UpdateRequestBuilder(Client client) { - super(client, new UpdateRequest()); + public UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action) { + super(client, action, new UpdateRequest()); } - public UpdateRequestBuilder(Client client, String index, String type, String id) { - super(client, new UpdateRequest(index, type, id)); + public UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action, String index, String type, String id) { + super(client, action, new UpdateRequest(index, type, id)); } /** @@ -77,7 +76,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder + *

* The script works with the variable ctx, which is bound to the entry, * e.g. ctx._source.mycounter += 1. * @@ -93,7 +92,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder * Default: groovy - *

+ *

* Ref: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html */ public UpdateRequestBuilder setScriptLang(String scriptLang) { @@ -344,7 +343,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder listener) { - 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 973ebf511c3..e356244db1a 100644 --- a/src/main/java/org/elasticsearch/client/Client.java +++ b/src/main/java/org/elasticsearch/client/Client.java @@ -62,6 +62,7 @@ import org.elasticsearch.action.termvectors.*; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.settings.Settings; @@ -79,7 +80,7 @@ import org.elasticsearch.common.settings.Settings; * @see org.elasticsearch.node.Node#client() * @see org.elasticsearch.client.transport.TransportClient */ -public interface Client extends ElasticsearchClient, Releasable { +public interface Client extends ElasticsearchClient, Releasable { String CLIENT_TYPE_SETTING = "client.type"; @@ -256,18 +257,11 @@ public interface Client extends ElasticsearchClient, Releasable { /** * Put the indexed script - * @param scriptLang - * @param id - * @param source - * @return */ PutIndexedScriptRequestBuilder preparePutIndexedScript(@Nullable String scriptLang, String id, String source); /** * delete an indexed script - * - * @param request - * @param listener */ void deleteIndexedScript(DeleteIndexedScriptRequest request, ActionListener listener); @@ -287,17 +281,11 @@ public interface Client extends ElasticsearchClient, Releasable { /** * Delete an indexed script - * @param scriptLang - * @param id - * @return */ DeleteIndexedScriptRequestBuilder prepareDeleteIndexedScript(@Nullable String scriptLang, String id); /** * Put an indexed script - * - * @param request - * @param listener */ void putIndexedScript(PutIndexedScriptRequest request, ActionListener listener); @@ -317,17 +305,11 @@ public interface Client extends ElasticsearchClient, Releasable { /** * Get the indexed script - * @param scriptLang - * @param id - * @return */ GetIndexedScriptRequestBuilder prepareGetIndexedScript(@Nullable String scriptLang, String id); /** * Get an indexed script - * - * @param request - * @param listener */ void getIndexedScript(GetIndexedScriptRequest request, ActionListener listener); @@ -670,4 +652,5 @@ public interface Client extends ElasticsearchClient, Releasable { */ Settings settings(); + Headers headers(); } diff --git a/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 0169151fc93..c3eb51585c2 100644 --- a/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -83,7 +83,7 @@ import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; * * @see AdminClient#cluster() */ -public interface ClusterAdminClient extends ElasticsearchClient { +public interface ClusterAdminClient extends ElasticsearchClient { /** * The health of the cluster. diff --git a/src/main/java/org/elasticsearch/client/ElasticsearchClient.java b/src/main/java/org/elasticsearch/client/ElasticsearchClient.java index 807dcc84f57..08a95bc71e6 100644 --- a/src/main/java/org/elasticsearch/client/ElasticsearchClient.java +++ b/src/main/java/org/elasticsearch/client/ElasticsearchClient.java @@ -23,7 +23,7 @@ package org.elasticsearch.client; import org.elasticsearch.action.*; import org.elasticsearch.threadpool.ThreadPool; -public interface ElasticsearchClient { +public interface ElasticsearchClient { /** * Executes a generic action, denoted by an {@link org.elasticsearch.action.Action}. @@ -35,7 +35,7 @@ public interface ElasticsearchClient { * @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}. @@ -47,7 +47,7 @@ public interface ElasticsearchClient { * @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}. @@ -58,7 +58,7 @@ public interface ElasticsearchClient { * @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); /** * Returns the threadpool used to execute requests on this client diff --git a/src/main/java/org/elasticsearch/client/FilterClient.java b/src/main/java/org/elasticsearch/client/FilterClient.java index 2fc9f5f9f6a..c0a93f5aa05 100644 --- a/src/main/java/org/elasticsearch/client/FilterClient.java +++ b/src/main/java/org/elasticsearch/client/FilterClient.java @@ -20,10 +20,6 @@ package org.elasticsearch.client; import org.elasticsearch.action.*; import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; /** @@ -31,16 +27,18 @@ import org.elasticsearch.threadpool.ThreadPool; * uses as its basic source, possibly transforming the requests / responses along the * way or providing additional functionality. */ -public abstract class FilterClient extends AbstractClient implements AdminClient { +public abstract class FilterClient extends AbstractClient { protected final Client in; /** * Creates a new FilterClient + * * @param in the client to delegate to * @see #in() */ public FilterClient(Client in) { + super(in.settings(), in.threadPool(), in.headers()); this.in = in; } @@ -50,127 +48,14 @@ public abstract class FilterClient extends AbstractClient implements AdminClient } @Override - public AdminClient admin() { - return this; - } - - @Override - public > ActionFuture execute( - Action action, Request request) { - return in().execute(action, request); - } - - @Override - public > void execute( - Action action, Request request, ActionListener listener) { + protected > void doExecute(Action action, Request request, ActionListener listener) { in().execute(action, request, listener); } - @Override - public Settings settings() { - return in().settings(); - } - - @Override - public ThreadPool threadPool() { - return in().threadPool(); - } - /** * Returns the delegate {@link Client} */ protected Client in() { return in; } - - @Override - public ClusterAdminClient cluster() { - return in().admin().cluster(); - } - - @Override - public IndicesAdminClient indices() { - return in().admin().indices(); - } - - /** - * A {@link IndicesAdminClient} that contains another {@link IndicesAdminClient} which it - * uses as its basic source, possibly transforming the requests / responses along the - * way or providing additional functionality. - */ - public static class IndicesAdmin extends AbstractIndicesAdminClient { - protected final IndicesAdminClient in; - - /** - * Creates a new IndicesAdmin - * @param in the client to delegate to - * @see #in() - */ - public IndicesAdmin(IndicesAdminClient in) { - this.in = in; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return in().execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - in().execute(action, request, listener); - } - - - /** - * Returns the delegate {@link Client} - */ - protected IndicesAdminClient in() { - return in; - } - - @Override - public ThreadPool threadPool() { - return in().threadPool(); - } - } - - /** - * A {@link ClusterAdminClient} that contains another {@link ClusterAdminClient} which it - * uses as its basic source, possibly transforming the requests / responses along the - * way or providing additional functionality. - */ - public static class ClusterAdmin extends AbstractClusterAdminClient { - protected final ClusterAdminClient in; - - /** - * Creates a new ClusterAdmin - * @param in the client to delegate to - * @see #in() - */ - public ClusterAdmin(ClusterAdminClient in) { - this.in = in; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return in().execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - in().execute(action, request, listener); - } - - /** - * Returns the delegate {@link Client} - */ - protected ClusterAdminClient in() { - return in; - } - - @Override - public ThreadPool threadPool() { - return in().threadPool(); - } - } } diff --git a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 0852643444a..bd1af4586a7 100644 --- a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -112,7 +112,7 @@ import org.elasticsearch.common.Nullable; * * @see AdminClient#indices() */ -public interface IndicesAdminClient extends ElasticsearchClient { +public interface IndicesAdminClient extends ElasticsearchClient { /** diff --git a/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java deleted file mode 100644 index 40e25178454..00000000000 --- a/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.node; - -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; - -/** - * - */ -public class NodeAdminClient extends AbstractComponent implements AdminClient { - - private final NodeIndicesAdminClient indicesAdminClient; - - private final NodeClusterAdminClient clusterAdminClient; - - @Inject - public NodeAdminClient(Settings settings, NodeClusterAdminClient clusterAdminClient, NodeIndicesAdminClient indicesAdminClient) { - super(settings); - this.indicesAdminClient = indicesAdminClient; - this.clusterAdminClient = clusterAdminClient; - } - - @Override - public IndicesAdminClient indices() { - return indicesAdminClient; - } - - @Override - public ClusterAdminClient cluster() { - return this.clusterAdminClient; - } -} diff --git a/src/main/java/org/elasticsearch/client/node/NodeClient.java b/src/main/java/org/elasticsearch/client/node/NodeClient.java index 0c7495e3412..2ee07aee55b 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClient.java @@ -26,6 +26,8 @@ import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.MapBuilder; @@ -42,42 +44,12 @@ import java.util.Map; */ public class NodeClient extends AbstractClient { - private final ESLogger logger; - private final Settings settings; - private final ThreadPool threadPool; - - private final NodeAdminClient admin; - - private final ImmutableMap actions; - - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; + private final ImmutableMap actions; @Inject - public NodeClient(Settings settings, ThreadPool threadPool, NodeAdminClient admin, Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.settings = settings; - this.threadPool = threadPool; - this.admin = admin; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (Map.Entry entry : actions.entrySet()) { - if (entry.getKey() instanceof ClientAction) { - actionsBuilder.put((ClientAction) entry.getKey(), entry.getValue()); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public Settings settings() { - return this.settings; - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; + public NodeClient(Settings settings, ThreadPool threadPool, Headers headers, Map actions) { + super(settings, threadPool, headers); + this.actions = ImmutableMap.copyOf(actions); } @Override @@ -85,25 +57,13 @@ public class NodeClient extends AbstractClient { // nothing really to do } - @Override - public AdminClient admin() { - return this.admin; - } - @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(Action action, Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - TransportAction transportAction = actions.get((ClientAction)action); + public > void doExecute(Action action, Request request, ActionListener listener) { + TransportAction transportAction = actions.get(action); + if (transportAction == null) { + throw new IllegalStateException("failed to find action [" + action + "] to execute"); + } transportAction.execute(request, listener); } } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClientModule.java b/src/main/java/org/elasticsearch/client/node/NodeClientModule.java index ea3a81a105f..fb0891da8cc 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClientModule.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClientModule.java @@ -19,10 +19,7 @@ package org.elasticsearch.client.node; -import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.inject.AbstractModule; @@ -34,9 +31,6 @@ public class NodeClientModule extends AbstractModule { @Override protected void configure() { bind(Headers.class).asEagerSingleton(); - bind(ClusterAdminClient.class).to(NodeClusterAdminClient.class).asEagerSingleton(); - bind(IndicesAdminClient.class).to(NodeIndicesAdminClient.class).asEagerSingleton(); - bind(AdminClient.class).to(NodeAdminClient.class).asEagerSingleton(); bind(Client.class).to(NodeClient.class).asEagerSingleton(); } } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java deleted file mode 100644 index 3e5144b5449..00000000000 --- a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.node; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.action.support.TransportAction; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; - -import java.util.Map; - -/** - * - */ -public class NodeClusterAdminClient extends AbstractClusterAdminClient implements ClusterAdminClient { - - private final ESLogger logger; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public NodeClusterAdminClient(Settings settings, ThreadPool threadPool, Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (Map.Entry entry : actions.entrySet()) { - if (entry.getKey() instanceof ClusterAction) { - actionsBuilder.put((ClusterAction) entry.getKey(), entry.getValue()); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(Action action, Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - TransportAction transportAction = actions.get((ClusterAction)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 deleted file mode 100644 index 6db38103f59..00000000000 --- a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.node; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.action.support.TransportAction; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; - -import java.util.Map; - -/** - * - */ -public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { - - private final ESLogger logger; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (Map.Entry entry : actions.entrySet()) { - if (entry.getKey() instanceof IndicesAction) { - actionsBuilder.put((IndicesAction) entry.getKey(), entry.getValue()); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(Action action, Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - TransportAction transportAction = actions.get((IndicesAction)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 7bfdfa14198..6ac9a0202ab 100644 --- a/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -20,6 +20,194 @@ package org.elasticsearch.client.support; import org.elasticsearch.action.*; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequestBuilder; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryAction; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryAction; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteAction; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotAction; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotAction; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse; +import org.elasticsearch.action.admin.cluster.state.ClusterStateAction; +import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; +import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder; +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksAction; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequestBuilder; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; +import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistAction; +import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistRequestBuilder; +import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; +import org.elasticsearch.action.admin.indices.close.CloseIndexAction; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; +import org.elasticsearch.action.admin.indices.create.CreateIndexAction; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsAction; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequestBuilder; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse; +import org.elasticsearch.action.admin.indices.flush.FlushAction; +import org.elasticsearch.action.admin.indices.flush.FlushRequest; +import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder; +import org.elasticsearch.action.admin.indices.flush.FlushResponse; +import org.elasticsearch.action.admin.indices.get.GetIndexAction; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.get.GetIndexResponse; +import org.elasticsearch.action.admin.indices.mapping.get.*; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; +import org.elasticsearch.action.admin.indices.open.OpenIndexAction; +import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; +import org.elasticsearch.action.admin.indices.open.OpenIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; +import org.elasticsearch.action.admin.indices.optimize.OptimizeAction; +import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; +import org.elasticsearch.action.admin.indices.optimize.OptimizeRequestBuilder; +import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; +import org.elasticsearch.action.admin.indices.recovery.RecoveryAction; +import org.elasticsearch.action.admin.indices.recovery.RecoveryRequest; +import org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder; +import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; +import org.elasticsearch.action.admin.indices.refresh.RefreshAction; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequestBuilder; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequestBuilder; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsAction; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateAction; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequestBuilder; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequestBuilder; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerAction; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequest; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequestBuilder; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersAction; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequest; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequestBuilder; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerAction; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequest; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequestBuilder; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse; import org.elasticsearch.action.bulk.BulkAction; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequestBuilder; @@ -70,24 +258,83 @@ import org.elasticsearch.action.suggest.SuggestAction; import org.elasticsearch.action.suggest.SuggestRequest; import org.elasticsearch.action.suggest.SuggestRequestBuilder; import org.elasticsearch.action.suggest.SuggestResponse; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.termvectors.*; import org.elasticsearch.action.update.UpdateAction; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.*; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; /** * */ -public abstract class AbstractClient implements Client { +public abstract class AbstractClient extends AbstractComponent implements Client { + + private final ThreadPool threadPool; + private final Admin admin; + + private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; + + public AbstractClient(Settings settings, ThreadPool threadPool, Headers headers) { + super(settings); + this.threadPool = threadPool; + this.headers = headers; + this.admin = new Admin(this); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); + } @Override - public > RequestBuilder prepareExecute(final Action action) { + public Headers headers() { + return this.headers; + } + + @Override + public final Settings settings() { + return this.settings; + } + + @Override + public final ThreadPool threadPool() { + return this.threadPool; + } + + @Override + public final AdminClient admin() { + return admin; + } + + @Override + public final > RequestBuilder prepareExecute(final Action action) { return action.newRequestBuilder(this); } + @Override + public final > ActionFuture execute(Action action, Request request) { + PlainActionFuture actionFuture = PlainActionFuture.newFuture(); + execute(action, request, actionFuture); + return actionFuture; + } + + /** + * This is the single execution point of *all* clients. + */ + @Override + public final > void execute(Action action, Request request, ActionListener listener) { + headers.applyTo(request); + listener = threadedWrapper.wrap(listener); + doExecute(action, request, listener); + } + + protected abstract > void doExecute(final Action action, final Request request, ActionListener listener); + + @Override public ActionFuture index(final IndexRequest request) { return execute(IndexAction.INSTANCE, request); @@ -100,7 +347,7 @@ public abstract class AbstractClient implements Client { @Override public IndexRequestBuilder prepareIndex() { - return new IndexRequestBuilder(this, null); + return new IndexRequestBuilder(this, IndexAction.INSTANCE, null); } @Override @@ -125,12 +372,12 @@ public abstract class AbstractClient implements Client { @Override public UpdateRequestBuilder prepareUpdate() { - return new UpdateRequestBuilder(this, null, null, null); + return new UpdateRequestBuilder(this, UpdateAction.INSTANCE, null, null, null); } @Override public UpdateRequestBuilder prepareUpdate(String index, String type, String id) { - return new UpdateRequestBuilder(this, index, type, id); + return new UpdateRequestBuilder(this, UpdateAction.INSTANCE, index, type, id); } @Override @@ -145,7 +392,7 @@ public abstract class AbstractClient implements Client { @Override public DeleteRequestBuilder prepareDelete() { - return new DeleteRequestBuilder(this, null); + return new DeleteRequestBuilder(this, DeleteAction.INSTANCE, null); } @Override @@ -165,7 +412,7 @@ public abstract class AbstractClient implements Client { @Override public BulkRequestBuilder prepareBulk() { - return new BulkRequestBuilder(this); + return new BulkRequestBuilder(this, BulkAction.INSTANCE); } @Override @@ -180,7 +427,7 @@ public abstract class AbstractClient implements Client { @Override public GetRequestBuilder prepareGet() { - return new GetRequestBuilder(this, null); + return new GetRequestBuilder(this, GetAction.INSTANCE, null); } @Override @@ -201,7 +448,7 @@ public abstract class AbstractClient implements Client { @Override public GetIndexedScriptRequestBuilder prepareGetIndexedScript() { - return new GetIndexedScriptRequestBuilder(this); + return new GetIndexedScriptRequestBuilder(this, GetIndexedScriptAction.INSTANCE); } @Override @@ -215,15 +462,11 @@ public abstract class AbstractClient implements Client { */ @Override public PutIndexedScriptRequestBuilder preparePutIndexedScript() { - return new PutIndexedScriptRequestBuilder(this); + return new PutIndexedScriptRequestBuilder(this, PutIndexedScriptAction.INSTANCE); } /** * Put the indexed script - * @param scriptLang - * @param id - * @param source - * @return */ @Override public PutIndexedScriptRequestBuilder preparePutIndexedScript(@Nullable String scriptLang, String id, String source){ @@ -232,9 +475,6 @@ public abstract class AbstractClient implements Client { /** * Put an indexed script - * - * @param request - * @param listener */ @Override public void putIndexedScript(final PutIndexedScriptRequest request, ActionListener listener){ @@ -255,9 +495,6 @@ public abstract class AbstractClient implements Client { /** * delete an indexed script - * - * @param request - * @param listener */ @Override public void deleteIndexedScript(DeleteIndexedScriptRequest request, ActionListener listener){ @@ -286,9 +523,6 @@ public abstract class AbstractClient implements Client { /** * Delete an indexed script - * @param scriptLang - * @param id - * @return */ @Override public DeleteIndexedScriptRequestBuilder prepareDeleteIndexedScript(@Nullable String scriptLang, String id){ @@ -309,7 +543,7 @@ public abstract class AbstractClient implements Client { @Override public MultiGetRequestBuilder prepareMultiGet() { - return new MultiGetRequestBuilder(this); + return new MultiGetRequestBuilder(this, MultiGetAction.INSTANCE); } @Override @@ -324,7 +558,7 @@ public abstract class AbstractClient implements Client { @Override public SearchRequestBuilder prepareSearch(String... indices) { - return new SearchRequestBuilder(this).setIndices(indices); + return new SearchRequestBuilder(this, SearchAction.INSTANCE).setIndices(indices); } @Override @@ -339,7 +573,7 @@ public abstract class AbstractClient implements Client { @Override public SearchScrollRequestBuilder prepareSearchScroll(String scrollId) { - return new SearchScrollRequestBuilder(this, scrollId); + return new SearchScrollRequestBuilder(this, SearchScrollAction.INSTANCE, scrollId); } @Override @@ -354,7 +588,7 @@ public abstract class AbstractClient implements Client { @Override public MultiSearchRequestBuilder prepareMultiSearch() { - return new MultiSearchRequestBuilder(this); + return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE); } @Override @@ -369,7 +603,7 @@ public abstract class AbstractClient implements Client { @Override public CountRequestBuilder prepareCount(String... indices) { - return new CountRequestBuilder(this).setIndices(indices); + return new CountRequestBuilder(this, CountAction.INSTANCE).setIndices(indices); } @Override @@ -384,7 +618,7 @@ public abstract class AbstractClient implements Client { @Override public ExistsRequestBuilder prepareExists(String... indices) { - return new ExistsRequestBuilder(this).setIndices(indices); + return new ExistsRequestBuilder(this, ExistsAction.INSTANCE).setIndices(indices); } @Override @@ -399,7 +633,7 @@ public abstract class AbstractClient implements Client { @Override public SuggestRequestBuilder prepareSuggest(String... indices) { - return new SuggestRequestBuilder(this).setIndices(indices); + return new SuggestRequestBuilder(this, SuggestAction.INSTANCE).setIndices(indices); } @Override @@ -414,7 +648,7 @@ public abstract class AbstractClient implements Client { @Override public MoreLikeThisRequestBuilder prepareMoreLikeThis(String index, String type, String id) { - return new MoreLikeThisRequestBuilder(this, index, type, id); + return new MoreLikeThisRequestBuilder(this, MoreLikeThisAction.INSTANCE, index, type, id); } @Override @@ -429,12 +663,12 @@ public abstract class AbstractClient implements Client { @Override public TermVectorsRequestBuilder prepareTermVectors() { - return new TermVectorsRequestBuilder(this); + return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE); } @Override public TermVectorsRequestBuilder prepareTermVectors(String index, String type, String id) { - return new TermVectorsRequestBuilder(this, index, type, id); + return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE, index, type, id); } @Deprecated @@ -473,7 +707,7 @@ public abstract class AbstractClient implements Client { @Override public MultiTermVectorsRequestBuilder prepareMultiTermVectors() { - return new MultiTermVectorsRequestBuilder(this); + return new MultiTermVectorsRequestBuilder(this, MultiTermVectorsAction.INSTANCE); } @Override @@ -488,12 +722,12 @@ public abstract class AbstractClient implements Client { @Override public PercolateRequestBuilder preparePercolate() { - return new PercolateRequestBuilder(this); + return new PercolateRequestBuilder(this, PercolateAction.INSTANCE); } @Override public MultiPercolateRequestBuilder prepareMultiPercolate() { - return new MultiPercolateRequestBuilder(this); + return new MultiPercolateRequestBuilder(this, MultiPercolateAction.INSTANCE); } @Override @@ -508,7 +742,7 @@ public abstract class AbstractClient implements Client { @Override public ExplainRequestBuilder prepareExplain(String index, String type, String id) { - return new ExplainRequestBuilder(this, index, type, id); + return new ExplainRequestBuilder(this, ExplainAction.INSTANCE, index, type, id); } @Override @@ -533,7 +767,7 @@ public abstract class AbstractClient implements Client { @Override public ClearScrollRequestBuilder prepareClearScroll() { - return new ClearScrollRequestBuilder(this); + return new ClearScrollRequestBuilder(this, ClearScrollAction.INSTANCE); } @Override @@ -548,6 +782,838 @@ public abstract class AbstractClient implements Client { @Override public FieldStatsRequestBuilder prepareFieldStats() { - return new FieldStatsRequestBuilder(this); + return new FieldStatsRequestBuilder(this, FieldStatsAction.INSTANCE); + } + + static class Admin implements AdminClient { + + private final ClusterAdmin clusterAdmin; + private final IndicesAdmin indicesAdmin; + + public Admin(ElasticsearchClient client) { + this.clusterAdmin = new ClusterAdmin(client); + this.indicesAdmin = new IndicesAdmin(client); + } + + @Override + public ClusterAdminClient cluster() { + return clusterAdmin; + } + + @Override + public IndicesAdminClient indices() { + return indicesAdmin; + } + } + + static class ClusterAdmin implements ClusterAdminClient { + + private final ElasticsearchClient client; + + public ClusterAdmin(ElasticsearchClient client) { + this.client = client; + } + + @Override + public > ActionFuture execute(Action action, Request request) { + return client.execute(action, request); + } + + @Override + public > void execute(Action action, Request request, ActionListener listener) { + client.execute(action, request, listener); + } + + @Override + public > RequestBuilder prepareExecute(Action action) { + return client.prepareExecute(action); + } + + @Override + public ThreadPool threadPool() { + return client.threadPool(); + } + + @Override + public ActionFuture health(final ClusterHealthRequest request) { + return execute(ClusterHealthAction.INSTANCE, request); + } + + @Override + public void health(final ClusterHealthRequest request, final ActionListener listener) { + execute(ClusterHealthAction.INSTANCE, request, listener); + } + + @Override + public ClusterHealthRequestBuilder prepareHealth(String... indices) { + return new ClusterHealthRequestBuilder(this, ClusterHealthAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture state(final ClusterStateRequest request) { + return execute(ClusterStateAction.INSTANCE, request); + } + + @Override + public void state(final ClusterStateRequest request, final ActionListener listener) { + execute(ClusterStateAction.INSTANCE, request, listener); + } + + @Override + public ClusterStateRequestBuilder prepareState() { + return new ClusterStateRequestBuilder(this, ClusterStateAction.INSTANCE); + } + + @Override + public ActionFuture reroute(final ClusterRerouteRequest request) { + return execute(ClusterRerouteAction.INSTANCE, request); + } + + @Override + public void reroute(final ClusterRerouteRequest request, final ActionListener listener) { + execute(ClusterRerouteAction.INSTANCE, request, listener); + } + + @Override + public ClusterRerouteRequestBuilder prepareReroute() { + return new ClusterRerouteRequestBuilder(this, ClusterRerouteAction.INSTANCE); + } + + @Override + public ActionFuture updateSettings(final ClusterUpdateSettingsRequest request) { + return execute(ClusterUpdateSettingsAction.INSTANCE, request); + } + + @Override + public void updateSettings(final ClusterUpdateSettingsRequest request, final ActionListener listener) { + execute(ClusterUpdateSettingsAction.INSTANCE, request, listener); + } + + @Override + public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { + return new ClusterUpdateSettingsRequestBuilder(this, ClusterUpdateSettingsAction.INSTANCE); + } + + @Override + public ActionFuture nodesInfo(final NodesInfoRequest request) { + return execute(NodesInfoAction.INSTANCE, request); + } + + @Override + public void nodesInfo(final NodesInfoRequest request, final ActionListener listener) { + execute(NodesInfoAction.INSTANCE, request, listener); + } + + @Override + public NodesInfoRequestBuilder prepareNodesInfo(String... nodesIds) { + return new NodesInfoRequestBuilder(this, NodesInfoAction.INSTANCE).setNodesIds(nodesIds); + } + + @Override + public ActionFuture nodesStats(final NodesStatsRequest request) { + return execute(NodesStatsAction.INSTANCE, request); + } + + @Override + public void nodesStats(final NodesStatsRequest request, final ActionListener listener) { + execute(NodesStatsAction.INSTANCE, request, listener); + } + + @Override + public NodesStatsRequestBuilder prepareNodesStats(String... nodesIds) { + return new NodesStatsRequestBuilder(this, NodesStatsAction.INSTANCE).setNodesIds(nodesIds); + } + + @Override + public ActionFuture clusterStats(ClusterStatsRequest request) { + return execute(ClusterStatsAction.INSTANCE, request); + } + + @Override + public void clusterStats(ClusterStatsRequest request, ActionListener listener) { + execute(ClusterStatsAction.INSTANCE, request, listener); + } + + @Override + public ClusterStatsRequestBuilder prepareClusterStats() { + return new ClusterStatsRequestBuilder(this, ClusterStatsAction.INSTANCE); + } + + @Override + public ActionFuture nodesHotThreads(NodesHotThreadsRequest request) { + return execute(NodesHotThreadsAction.INSTANCE, request); + } + + @Override + public void nodesHotThreads(NodesHotThreadsRequest request, ActionListener listener) { + execute(NodesHotThreadsAction.INSTANCE, request, listener); + } + + @Override + public NodesHotThreadsRequestBuilder prepareNodesHotThreads(String... nodesIds) { + return new NodesHotThreadsRequestBuilder(this, NodesHotThreadsAction.INSTANCE).setNodesIds(nodesIds); + } + + @Override + public ActionFuture searchShards(final ClusterSearchShardsRequest request) { + return execute(ClusterSearchShardsAction.INSTANCE, request); + } + + @Override + public void searchShards(final ClusterSearchShardsRequest request, final ActionListener listener) { + execute(ClusterSearchShardsAction.INSTANCE, request, listener); + } + + @Override + public ClusterSearchShardsRequestBuilder prepareSearchShards() { + return new ClusterSearchShardsRequestBuilder(this, ClusterSearchShardsAction.INSTANCE); + } + + @Override + public ClusterSearchShardsRequestBuilder prepareSearchShards(String... indices) { + return new ClusterSearchShardsRequestBuilder(this, ClusterSearchShardsAction.INSTANCE).setIndices(indices); + } + + @Override + public PendingClusterTasksRequestBuilder preparePendingClusterTasks() { + return new PendingClusterTasksRequestBuilder(this, PendingClusterTasksAction.INSTANCE); + } + + @Override + public ActionFuture pendingClusterTasks(PendingClusterTasksRequest request) { + return execute(PendingClusterTasksAction.INSTANCE, request); + } + + @Override + public void pendingClusterTasks(PendingClusterTasksRequest request, ActionListener listener) { + execute(PendingClusterTasksAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture putRepository(PutRepositoryRequest request) { + return execute(PutRepositoryAction.INSTANCE, request); + } + + @Override + public void putRepository(PutRepositoryRequest request, ActionListener listener) { + execute(PutRepositoryAction.INSTANCE, request, listener); + } + + @Override + public PutRepositoryRequestBuilder preparePutRepository(String name) { + return new PutRepositoryRequestBuilder(this, PutRepositoryAction.INSTANCE, name); + } + + @Override + public ActionFuture createSnapshot(CreateSnapshotRequest request) { + return execute(CreateSnapshotAction.INSTANCE, request); + } + + @Override + public void createSnapshot(CreateSnapshotRequest request, ActionListener listener) { + execute(CreateSnapshotAction.INSTANCE, request, listener); + } + + @Override + public CreateSnapshotRequestBuilder prepareCreateSnapshot(String repository, String name) { + return new CreateSnapshotRequestBuilder(this, CreateSnapshotAction.INSTANCE, repository, name); + } + + @Override + public ActionFuture getSnapshots(GetSnapshotsRequest request) { + return execute(GetSnapshotsAction.INSTANCE, request); + } + + @Override + public void getSnapshots(GetSnapshotsRequest request, ActionListener listener) { + execute(GetSnapshotsAction.INSTANCE, request, listener); + } + + @Override + public GetSnapshotsRequestBuilder prepareGetSnapshots(String repository) { + return new GetSnapshotsRequestBuilder(this, GetSnapshotsAction.INSTANCE, repository); + } + + + @Override + public ActionFuture deleteSnapshot(DeleteSnapshotRequest request) { + return execute(DeleteSnapshotAction.INSTANCE, request); + } + + @Override + public void deleteSnapshot(DeleteSnapshotRequest request, ActionListener listener) { + execute(DeleteSnapshotAction.INSTANCE, request, listener); + } + + @Override + public DeleteSnapshotRequestBuilder prepareDeleteSnapshot(String repository, String name) { + return new DeleteSnapshotRequestBuilder(this, DeleteSnapshotAction.INSTANCE, repository, name); + } + + + @Override + public ActionFuture deleteRepository(DeleteRepositoryRequest request) { + return execute(DeleteRepositoryAction.INSTANCE, request); + } + + @Override + public void deleteRepository(DeleteRepositoryRequest request, ActionListener listener) { + execute(DeleteRepositoryAction.INSTANCE, request, listener); + } + + @Override + public DeleteRepositoryRequestBuilder prepareDeleteRepository(String name) { + return new DeleteRepositoryRequestBuilder(this, DeleteRepositoryAction.INSTANCE, name); + } + + @Override + public ActionFuture verifyRepository(VerifyRepositoryRequest request) { + return execute(VerifyRepositoryAction.INSTANCE, request); + } + + @Override + public void verifyRepository(VerifyRepositoryRequest request, ActionListener listener) { + execute(VerifyRepositoryAction.INSTANCE, request, listener); + } + + @Override + public VerifyRepositoryRequestBuilder prepareVerifyRepository(String name) { + return new VerifyRepositoryRequestBuilder(this, VerifyRepositoryAction.INSTANCE, name); + } + + @Override + public ActionFuture getRepositories(GetRepositoriesRequest request) { + return execute(GetRepositoriesAction.INSTANCE, request); + } + + @Override + public void getRepositories(GetRepositoriesRequest request, ActionListener listener) { + execute(GetRepositoriesAction.INSTANCE, request, listener); + } + + @Override + public GetRepositoriesRequestBuilder prepareGetRepositories(String... name) { + return new GetRepositoriesRequestBuilder(this, GetRepositoriesAction.INSTANCE, name); + } + + @Override + public ActionFuture restoreSnapshot(RestoreSnapshotRequest request) { + return execute(RestoreSnapshotAction.INSTANCE, request); + } + + @Override + public void restoreSnapshot(RestoreSnapshotRequest request, ActionListener listener) { + execute(RestoreSnapshotAction.INSTANCE, request, listener); + } + + @Override + public RestoreSnapshotRequestBuilder prepareRestoreSnapshot(String repository, String snapshot) { + return new RestoreSnapshotRequestBuilder(this, RestoreSnapshotAction.INSTANCE, repository, snapshot); + } + + + @Override + public ActionFuture snapshotsStatus(SnapshotsStatusRequest request) { + return execute(SnapshotsStatusAction.INSTANCE, request); + } + + @Override + public void snapshotsStatus(SnapshotsStatusRequest request, ActionListener listener) { + execute(SnapshotsStatusAction.INSTANCE, request, listener); + } + + @Override + public SnapshotsStatusRequestBuilder prepareSnapshotStatus(String repository) { + return new SnapshotsStatusRequestBuilder(this, SnapshotsStatusAction.INSTANCE, repository); + } + + @Override + public SnapshotsStatusRequestBuilder prepareSnapshotStatus() { + return new SnapshotsStatusRequestBuilder(this, SnapshotsStatusAction.INSTANCE); + } + } + + static class IndicesAdmin implements IndicesAdminClient { + + private final ElasticsearchClient client; + + public IndicesAdmin(ElasticsearchClient client) { + this.client = client; + } + + @Override + public > ActionFuture execute(Action action, Request request) { + return client.execute(action, request); + } + + @Override + public > void execute(Action action, Request request, ActionListener listener) { + client.execute(action, request, listener); + } + + @Override + public > RequestBuilder prepareExecute(Action action) { + return client.prepareExecute(action); + } + + @Override + public ThreadPool threadPool() { + return client.threadPool(); + } + + @Override + public ActionFuture exists(final IndicesExistsRequest request) { + return execute(IndicesExistsAction.INSTANCE, request); + } + + @Override + public void exists(final IndicesExistsRequest request, final ActionListener listener) { + execute(IndicesExistsAction.INSTANCE, request, listener); + } + + @Override + public IndicesExistsRequestBuilder prepareExists(String... indices) { + return new IndicesExistsRequestBuilder(this, IndicesExistsAction.INSTANCE, indices); + } + + @Override + public ActionFuture typesExists(TypesExistsRequest request) { + return execute(TypesExistsAction.INSTANCE, request); + } + + @Override + public void typesExists(TypesExistsRequest request, ActionListener listener) { + execute(TypesExistsAction.INSTANCE, request, listener); + } + + @Override + public TypesExistsRequestBuilder prepareTypesExists(String... index) { + return new TypesExistsRequestBuilder(this, TypesExistsAction.INSTANCE, index); + } + + @Override + public ActionFuture aliases(final IndicesAliasesRequest request) { + return execute(IndicesAliasesAction.INSTANCE, request); + } + + @Override + public void aliases(final IndicesAliasesRequest request, final ActionListener listener) { + execute(IndicesAliasesAction.INSTANCE, request, listener); + } + + @Override + public IndicesAliasesRequestBuilder prepareAliases() { + return new IndicesAliasesRequestBuilder(this, IndicesAliasesAction.INSTANCE); + } + + @Override + public ActionFuture getAliases(GetAliasesRequest request) { + return execute(GetAliasesAction.INSTANCE, request); + } + + @Override + public void getAliases(GetAliasesRequest request, ActionListener listener) { + execute(GetAliasesAction.INSTANCE, request, listener); + } + + @Override + public GetAliasesRequestBuilder prepareGetAliases(String... aliases) { + return new GetAliasesRequestBuilder(this, GetAliasesAction.INSTANCE, aliases); + } + + @Override + public ActionFuture clearCache(final ClearIndicesCacheRequest request) { + return execute(ClearIndicesCacheAction.INSTANCE, request); + } + + @Override + public void aliasesExist(GetAliasesRequest request, ActionListener listener) { + execute(AliasesExistAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture aliasesExist(GetAliasesRequest request) { + return execute(AliasesExistAction.INSTANCE, request); + } + + @Override + public AliasesExistRequestBuilder prepareAliasesExist(String... aliases) { + return new AliasesExistRequestBuilder(this, AliasesExistAction.INSTANCE, aliases); + } + + @Override + public ActionFuture getIndex(GetIndexRequest request) { + return execute(GetIndexAction.INSTANCE, request); + } + + @Override + public void getIndex(GetIndexRequest request, ActionListener listener) { + execute(GetIndexAction.INSTANCE, request, listener); + } + + @Override + public GetIndexRequestBuilder prepareGetIndex() { + return new GetIndexRequestBuilder(this, GetIndexAction.INSTANCE); + } + + @Override + public void clearCache(final ClearIndicesCacheRequest request, final ActionListener listener) { + execute(ClearIndicesCacheAction.INSTANCE, request, listener); + } + + @Override + public ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) { + return new ClearIndicesCacheRequestBuilder(this, ClearIndicesCacheAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture create(final CreateIndexRequest request) { + return execute(CreateIndexAction.INSTANCE, request); + } + + @Override + public void create(final CreateIndexRequest request, final ActionListener listener) { + execute(CreateIndexAction.INSTANCE, request, listener); + } + + @Override + public CreateIndexRequestBuilder prepareCreate(String index) { + return new CreateIndexRequestBuilder(this, CreateIndexAction.INSTANCE, index); + } + + @Override + public ActionFuture delete(final DeleteIndexRequest request) { + return execute(DeleteIndexAction.INSTANCE, request); + } + + @Override + public void delete(final DeleteIndexRequest request, final ActionListener listener) { + execute(DeleteIndexAction.INSTANCE, request, listener); + } + + @Override + public DeleteIndexRequestBuilder prepareDelete(String... indices) { + return new DeleteIndexRequestBuilder(this, DeleteIndexAction.INSTANCE, indices); + } + + @Override + public ActionFuture close(final CloseIndexRequest request) { + return execute(CloseIndexAction.INSTANCE, request); + } + + @Override + public void close(final CloseIndexRequest request, final ActionListener listener) { + execute(CloseIndexAction.INSTANCE, request, listener); + } + + @Override + public CloseIndexRequestBuilder prepareClose(String... indices) { + return new CloseIndexRequestBuilder(this, CloseIndexAction.INSTANCE, indices); + } + + @Override + public ActionFuture open(final OpenIndexRequest request) { + return execute(OpenIndexAction.INSTANCE, request); + } + + @Override + public void open(final OpenIndexRequest request, final ActionListener listener) { + execute(OpenIndexAction.INSTANCE, request, listener); + } + + @Override + public OpenIndexRequestBuilder prepareOpen(String... indices) { + return new OpenIndexRequestBuilder(this, OpenIndexAction.INSTANCE, indices); + } + + @Override + public ActionFuture flush(final FlushRequest request) { + return execute(FlushAction.INSTANCE, request); + } + + @Override + public void flush(final FlushRequest request, final ActionListener listener) { + execute(FlushAction.INSTANCE, request, listener); + } + + @Override + public FlushRequestBuilder prepareFlush(String... indices) { + return new FlushRequestBuilder(this, FlushAction.INSTANCE).setIndices(indices); + } + + @Override + public void getMappings(GetMappingsRequest request, ActionListener listener) { + execute(GetMappingsAction.INSTANCE, request, listener); + } + + @Override + public void getFieldMappings(GetFieldMappingsRequest request, ActionListener listener) { + execute(GetFieldMappingsAction.INSTANCE, request, listener); + } + + @Override + public GetMappingsRequestBuilder prepareGetMappings(String... indices) { + return new GetMappingsRequestBuilder(this, GetMappingsAction.INSTANCE, indices); + } + + @Override + public ActionFuture getMappings(GetMappingsRequest request) { + return execute(GetMappingsAction.INSTANCE, request); + } + + @Override + public GetFieldMappingsRequestBuilder prepareGetFieldMappings(String... indices) { + return new GetFieldMappingsRequestBuilder(this, GetFieldMappingsAction.INSTANCE, indices); + } + + @Override + public ActionFuture getFieldMappings(GetFieldMappingsRequest request) { + return execute(GetFieldMappingsAction.INSTANCE, request); + } + + @Override + public ActionFuture putMapping(final PutMappingRequest request) { + return execute(PutMappingAction.INSTANCE, request); + } + + @Override + public void putMapping(final PutMappingRequest request, final ActionListener listener) { + execute(PutMappingAction.INSTANCE, request, listener); + } + + @Override + public PutMappingRequestBuilder preparePutMapping(String... indices) { + return new PutMappingRequestBuilder(this, PutMappingAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture optimize(final OptimizeRequest request) { + return execute(OptimizeAction.INSTANCE, request); + } + + @Override + public void optimize(final OptimizeRequest request, final ActionListener listener) { + execute(OptimizeAction.INSTANCE, request, listener); + } + + @Override + public OptimizeRequestBuilder prepareOptimize(String... indices) { + return new OptimizeRequestBuilder(this, OptimizeAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture refresh(final RefreshRequest request) { + return execute(RefreshAction.INSTANCE, request); + } + + @Override + public void refresh(final RefreshRequest request, final ActionListener listener) { + execute(RefreshAction.INSTANCE, request, listener); + } + + @Override + public RefreshRequestBuilder prepareRefresh(String... indices) { + return new RefreshRequestBuilder(this, RefreshAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture stats(final IndicesStatsRequest request) { + return execute(IndicesStatsAction.INSTANCE, request); + } + + @Override + public void stats(final IndicesStatsRequest request, final ActionListener listener) { + execute(IndicesStatsAction.INSTANCE, request, listener); + } + + @Override + public IndicesStatsRequestBuilder prepareStats(String... indices) { + return new IndicesStatsRequestBuilder(this, IndicesStatsAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture recoveries(final RecoveryRequest request) { + return execute(RecoveryAction.INSTANCE, request); + } + + @Override + public void recoveries(final RecoveryRequest request, final ActionListener listener) { + execute(RecoveryAction.INSTANCE, request, listener); + } + + @Override + public RecoveryRequestBuilder prepareRecoveries(String... indices) { + return new RecoveryRequestBuilder(this, RecoveryAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture segments(final IndicesSegmentsRequest request) { + return execute(IndicesSegmentsAction.INSTANCE, request); + } + + @Override + public void segments(final IndicesSegmentsRequest request, final ActionListener listener) { + execute(IndicesSegmentsAction.INSTANCE, request, listener); + } + + @Override + public IndicesSegmentsRequestBuilder prepareSegments(String... indices) { + return new IndicesSegmentsRequestBuilder(this, IndicesSegmentsAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture updateSettings(final UpdateSettingsRequest request) { + return execute(UpdateSettingsAction.INSTANCE, request); + } + + @Override + public void updateSettings(final UpdateSettingsRequest request, final ActionListener listener) { + execute(UpdateSettingsAction.INSTANCE, request, listener); + } + + @Override + public UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) { + return new UpdateSettingsRequestBuilder(this, UpdateSettingsAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture analyze(final AnalyzeRequest request) { + return execute(AnalyzeAction.INSTANCE, request); + } + + @Override + public void analyze(final AnalyzeRequest request, final ActionListener listener) { + execute(AnalyzeAction.INSTANCE, request, listener); + } + + @Override + public AnalyzeRequestBuilder prepareAnalyze(@Nullable String index, String text) { + return new AnalyzeRequestBuilder(this, AnalyzeAction.INSTANCE, index, text); + } + + @Override + public AnalyzeRequestBuilder prepareAnalyze(String text) { + return new AnalyzeRequestBuilder(this, AnalyzeAction.INSTANCE, null, text); + } + + @Override + public ActionFuture putTemplate(final PutIndexTemplateRequest request) { + return execute(PutIndexTemplateAction.INSTANCE, request); + } + + @Override + public void putTemplate(final PutIndexTemplateRequest request, final ActionListener listener) { + execute(PutIndexTemplateAction.INSTANCE, request, listener); + } + + @Override + public PutIndexTemplateRequestBuilder preparePutTemplate(String name) { + return new PutIndexTemplateRequestBuilder(this, PutIndexTemplateAction.INSTANCE, name); + } + + @Override + public ActionFuture getTemplates(final GetIndexTemplatesRequest request) { + return execute(GetIndexTemplatesAction.INSTANCE, request); + } + + @Override + public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener listener) { + execute(GetIndexTemplatesAction.INSTANCE, request, listener); + } + + @Override + public GetIndexTemplatesRequestBuilder prepareGetTemplates(String... names) { + return new GetIndexTemplatesRequestBuilder(this, GetIndexTemplatesAction.INSTANCE, names); + } + + @Override + public ActionFuture deleteTemplate(final DeleteIndexTemplateRequest request) { + return execute(DeleteIndexTemplateAction.INSTANCE, request); + } + + @Override + public void deleteTemplate(final DeleteIndexTemplateRequest request, final ActionListener listener) { + execute(DeleteIndexTemplateAction.INSTANCE, request, listener); + } + + @Override + public DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) { + return new DeleteIndexTemplateRequestBuilder(this, DeleteIndexTemplateAction.INSTANCE, name); + } + + @Override + public ActionFuture validateQuery(final ValidateQueryRequest request) { + return execute(ValidateQueryAction.INSTANCE, request); + } + + @Override + public void validateQuery(final ValidateQueryRequest request, final ActionListener listener) { + execute(ValidateQueryAction.INSTANCE, request, listener); + } + + @Override + public ValidateQueryRequestBuilder prepareValidateQuery(String... indices) { + return new ValidateQueryRequestBuilder(this, ValidateQueryAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture putWarmer(PutWarmerRequest request) { + return execute(PutWarmerAction.INSTANCE, request); + } + + @Override + public void putWarmer(PutWarmerRequest request, ActionListener listener) { + execute(PutWarmerAction.INSTANCE, request, listener); + } + + @Override + public PutWarmerRequestBuilder preparePutWarmer(String name) { + return new PutWarmerRequestBuilder(this, PutWarmerAction.INSTANCE, name); + } + + @Override + public ActionFuture deleteWarmer(DeleteWarmerRequest request) { + return execute(DeleteWarmerAction.INSTANCE, request); + } + + @Override + public void deleteWarmer(DeleteWarmerRequest request, ActionListener listener) { + execute(DeleteWarmerAction.INSTANCE, request, listener); + } + + @Override + public DeleteWarmerRequestBuilder prepareDeleteWarmer() { + return new DeleteWarmerRequestBuilder(this, DeleteWarmerAction.INSTANCE); + } + + @Override + public GetWarmersRequestBuilder prepareGetWarmers(String... indices) { + return new GetWarmersRequestBuilder(this, GetWarmersAction.INSTANCE, indices); + } + + @Override + public ActionFuture getWarmers(GetWarmersRequest request) { + return execute(GetWarmersAction.INSTANCE, request); + } + + @Override + public void getWarmers(GetWarmersRequest request, ActionListener listener) { + execute(GetWarmersAction.INSTANCE, request, listener); + } + + @Override + public GetSettingsRequestBuilder prepareGetSettings(String... indices) { + return new GetSettingsRequestBuilder(this, GetSettingsAction.INSTANCE, indices); + } + + @Override + public ActionFuture getSettings(GetSettingsRequest request) { + return execute(GetSettingsAction.INSTANCE, request); + } + + @Override + public void getSettings(GetSettingsRequest request, ActionListener listener) { + execute(GetSettingsAction.INSTANCE, request, listener); + } } } diff --git a/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java deleted file mode 100644 index f4a6e58e49a..00000000000 --- a/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequestBuilder; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryAction; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryAction; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteAction; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotAction; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotAction; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse; -import org.elasticsearch.action.admin.cluster.state.ClusterStateAction; -import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; -import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksAction; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequestBuilder; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; -import org.elasticsearch.client.ClusterAdminClient; - -/** - * - */ -public abstract class AbstractClusterAdminClient implements ClusterAdminClient { - - @Override - public > RequestBuilder prepareExecute(Action action) { - return action.newRequestBuilder(this); - } - - @Override - public ActionFuture health(final ClusterHealthRequest request) { - return execute(ClusterHealthAction.INSTANCE, request); - } - - @Override - public void health(final ClusterHealthRequest request, final ActionListener listener) { - execute(ClusterHealthAction.INSTANCE, request, listener); - } - - @Override - public ClusterHealthRequestBuilder prepareHealth(String... indices) { - return new ClusterHealthRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture state(final ClusterStateRequest request) { - return execute(ClusterStateAction.INSTANCE, request); - } - - @Override - public void state(final ClusterStateRequest request, final ActionListener listener) { - execute(ClusterStateAction.INSTANCE, request, listener); - } - - @Override - public ClusterStateRequestBuilder prepareState() { - return new ClusterStateRequestBuilder(this); - } - - @Override - public ActionFuture reroute(final ClusterRerouteRequest request) { - return execute(ClusterRerouteAction.INSTANCE, request); - } - - @Override - public void reroute(final ClusterRerouteRequest request, final ActionListener listener) { - execute(ClusterRerouteAction.INSTANCE, request, listener); - } - - @Override - public ClusterRerouteRequestBuilder prepareReroute() { - return new ClusterRerouteRequestBuilder(this); - } - - @Override - public ActionFuture updateSettings(final ClusterUpdateSettingsRequest request) { - return execute(ClusterUpdateSettingsAction.INSTANCE, request); - } - - @Override - public void updateSettings(final ClusterUpdateSettingsRequest request, final ActionListener listener) { - execute(ClusterUpdateSettingsAction.INSTANCE, request, listener); - } - - @Override - public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { - return new ClusterUpdateSettingsRequestBuilder(this); - } - - @Override - public ActionFuture nodesInfo(final NodesInfoRequest request) { - return execute(NodesInfoAction.INSTANCE, request); - } - - @Override - public void nodesInfo(final NodesInfoRequest request, final ActionListener listener) { - execute(NodesInfoAction.INSTANCE, request, listener); - } - - @Override - public NodesInfoRequestBuilder prepareNodesInfo(String... nodesIds) { - return new NodesInfoRequestBuilder(this).setNodesIds(nodesIds); - } - - @Override - public ActionFuture nodesStats(final NodesStatsRequest request) { - return execute(NodesStatsAction.INSTANCE, request); - } - - @Override - public void nodesStats(final NodesStatsRequest request, final ActionListener listener) { - execute(NodesStatsAction.INSTANCE, request, listener); - } - - @Override - public NodesStatsRequestBuilder prepareNodesStats(String... nodesIds) { - return new NodesStatsRequestBuilder(this).setNodesIds(nodesIds); - } - - @Override - public ActionFuture clusterStats(ClusterStatsRequest request) { - return execute(ClusterStatsAction.INSTANCE, request); - } - - @Override - public void clusterStats(ClusterStatsRequest request, ActionListener listener) { - execute(ClusterStatsAction.INSTANCE, request, listener); - } - - @Override - public ClusterStatsRequestBuilder prepareClusterStats() { - return new ClusterStatsRequestBuilder(this); - } - - @Override - public ActionFuture nodesHotThreads(NodesHotThreadsRequest request) { - return execute(NodesHotThreadsAction.INSTANCE, request); - } - - @Override - public void nodesHotThreads(NodesHotThreadsRequest request, ActionListener listener) { - execute(NodesHotThreadsAction.INSTANCE, request, listener); - } - - @Override - public NodesHotThreadsRequestBuilder prepareNodesHotThreads(String... nodesIds) { - return new NodesHotThreadsRequestBuilder(this).setNodesIds(nodesIds); - } - - @Override - public ActionFuture searchShards(final ClusterSearchShardsRequest request) { - return execute(ClusterSearchShardsAction.INSTANCE, request); - } - - @Override - public void searchShards(final ClusterSearchShardsRequest request, final ActionListener listener) { - execute(ClusterSearchShardsAction.INSTANCE, request, listener); - } - - @Override - public ClusterSearchShardsRequestBuilder prepareSearchShards() { - return new ClusterSearchShardsRequestBuilder(this); - } - - @Override - public ClusterSearchShardsRequestBuilder prepareSearchShards(String... indices) { - return new ClusterSearchShardsRequestBuilder(this).setIndices(indices); - } - - @Override - public PendingClusterTasksRequestBuilder preparePendingClusterTasks() { - return new PendingClusterTasksRequestBuilder(this); - } - - @Override - public ActionFuture pendingClusterTasks(PendingClusterTasksRequest request) { - return execute(PendingClusterTasksAction.INSTANCE, request); - } - - @Override - public void pendingClusterTasks(PendingClusterTasksRequest request, ActionListener listener) { - execute(PendingClusterTasksAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture putRepository(PutRepositoryRequest request) { - return execute(PutRepositoryAction.INSTANCE, request); - } - - @Override - public void putRepository(PutRepositoryRequest request, ActionListener listener) { - execute(PutRepositoryAction.INSTANCE, request, listener); - } - - @Override - public PutRepositoryRequestBuilder preparePutRepository(String name) { - return new PutRepositoryRequestBuilder(this, name); - } - - @Override - public ActionFuture createSnapshot(CreateSnapshotRequest request) { - return execute(CreateSnapshotAction.INSTANCE, request); - } - - @Override - public void createSnapshot(CreateSnapshotRequest request, ActionListener listener) { - execute(CreateSnapshotAction.INSTANCE, request, listener); - } - - @Override - public CreateSnapshotRequestBuilder prepareCreateSnapshot(String repository, String name) { - return new CreateSnapshotRequestBuilder(this, repository, name); - } - - @Override - public ActionFuture getSnapshots(GetSnapshotsRequest request) { - return execute(GetSnapshotsAction.INSTANCE, request); - } - - @Override - public void getSnapshots(GetSnapshotsRequest request, ActionListener listener) { - execute(GetSnapshotsAction.INSTANCE, request, listener); - } - - @Override - public GetSnapshotsRequestBuilder prepareGetSnapshots(String repository) { - return new GetSnapshotsRequestBuilder(this, repository); - } - - - @Override - public ActionFuture deleteSnapshot(DeleteSnapshotRequest request) { - return execute(DeleteSnapshotAction.INSTANCE, request); - } - - @Override - public void deleteSnapshot(DeleteSnapshotRequest request, ActionListener listener) { - execute(DeleteSnapshotAction.INSTANCE, request, listener); - } - - @Override - public DeleteSnapshotRequestBuilder prepareDeleteSnapshot(String repository, String name) { - return new DeleteSnapshotRequestBuilder(this, repository, name); - } - - - @Override - public ActionFuture deleteRepository(DeleteRepositoryRequest request) { - return execute(DeleteRepositoryAction.INSTANCE, request); - } - - @Override - public void deleteRepository(DeleteRepositoryRequest request, ActionListener listener) { - execute(DeleteRepositoryAction.INSTANCE, request, listener); - } - - @Override - public DeleteRepositoryRequestBuilder prepareDeleteRepository(String name) { - return new DeleteRepositoryRequestBuilder(this, name); - } - - @Override - public ActionFuture verifyRepository(VerifyRepositoryRequest request) { - return execute(VerifyRepositoryAction.INSTANCE, request); - } - - @Override - public void verifyRepository(VerifyRepositoryRequest request, ActionListener listener) { - execute(VerifyRepositoryAction.INSTANCE, request, listener); - } - - @Override - public VerifyRepositoryRequestBuilder prepareVerifyRepository(String name) { - return new VerifyRepositoryRequestBuilder(this, name); - } - - @Override - public ActionFuture getRepositories(GetRepositoriesRequest request) { - return execute(GetRepositoriesAction.INSTANCE, request); - } - - @Override - public void getRepositories(GetRepositoriesRequest request, ActionListener listener) { - execute(GetRepositoriesAction.INSTANCE, request, listener); - } - - @Override - public GetRepositoriesRequestBuilder prepareGetRepositories(String... name) { - return new GetRepositoriesRequestBuilder(this, name); - } - - @Override - public ActionFuture restoreSnapshot(RestoreSnapshotRequest request) { - return execute(RestoreSnapshotAction.INSTANCE, request); - } - - @Override - public void restoreSnapshot(RestoreSnapshotRequest request, ActionListener listener) { - execute(RestoreSnapshotAction.INSTANCE, request, listener); - } - - @Override - public RestoreSnapshotRequestBuilder prepareRestoreSnapshot(String repository, String snapshot) { - return new RestoreSnapshotRequestBuilder(this, repository, snapshot); - } - - - @Override - public ActionFuture snapshotsStatus(SnapshotsStatusRequest request) { - return execute(SnapshotsStatusAction.INSTANCE, request); - } - - @Override - public void snapshotsStatus(SnapshotsStatusRequest request, ActionListener listener) { - execute(SnapshotsStatusAction.INSTANCE, request, listener); - } - - @Override - public SnapshotsStatusRequestBuilder prepareSnapshotStatus(String repository) { - return new SnapshotsStatusRequestBuilder(this, repository); - } - - @Override - public SnapshotsStatusRequestBuilder prepareSnapshotStatus() { - return new SnapshotsStatusRequestBuilder(this); - } -} diff --git a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java deleted file mode 100644 index 02f8a015170..00000000000 --- a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java +++ /dev/null @@ -1,602 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; -import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistAction; -import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistRequestBuilder; -import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; -import org.elasticsearch.action.admin.indices.close.CloseIndexAction; -import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; -import org.elasticsearch.action.admin.indices.close.CloseIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; -import org.elasticsearch.action.admin.indices.create.CreateIndexAction; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsAction; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequestBuilder; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse; -import org.elasticsearch.action.admin.indices.flush.FlushAction; -import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder; -import org.elasticsearch.action.admin.indices.flush.FlushResponse; -import org.elasticsearch.action.admin.indices.get.GetIndexAction; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; -import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.get.GetIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.get.*; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; -import org.elasticsearch.action.admin.indices.open.OpenIndexAction; -import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; -import org.elasticsearch.action.admin.indices.open.OpenIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; -import org.elasticsearch.action.admin.indices.optimize.OptimizeAction; -import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; -import org.elasticsearch.action.admin.indices.optimize.OptimizeRequestBuilder; -import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; -import org.elasticsearch.action.admin.indices.recovery.RecoveryAction; -import org.elasticsearch.action.admin.indices.recovery.RecoveryRequest; -import org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder; -import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; -import org.elasticsearch.action.admin.indices.refresh.RefreshAction; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequestBuilder; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequestBuilder; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsAction; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequestBuilder; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequestBuilder; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerAction; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequest; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequestBuilder; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersAction; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequest; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequestBuilder; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerAction; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequest; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequestBuilder; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.Nullable; - -/** - * - */ -public abstract class AbstractIndicesAdminClient implements IndicesAdminClient { - - @Override - public > RequestBuilder prepareExecute(final Action action) { - return action.newRequestBuilder(this); - } - - @Override - public ActionFuture exists(final IndicesExistsRequest request) { - return execute(IndicesExistsAction.INSTANCE, request); - } - - @Override - public void exists(final IndicesExistsRequest request, final ActionListener listener) { - execute(IndicesExistsAction.INSTANCE, request, listener); - } - - @Override - public IndicesExistsRequestBuilder prepareExists(String... indices) { - return new IndicesExistsRequestBuilder(this, indices); - } - - @Override - public ActionFuture typesExists(TypesExistsRequest request) { - return execute(TypesExistsAction.INSTANCE, request); - } - - @Override - public void typesExists(TypesExistsRequest request, ActionListener listener) { - execute(TypesExistsAction.INSTANCE, request, listener); - } - - @Override - public TypesExistsRequestBuilder prepareTypesExists(String... index) { - return new TypesExistsRequestBuilder(this, index); - } - - @Override - public ActionFuture aliases(final IndicesAliasesRequest request) { - return execute(IndicesAliasesAction.INSTANCE, request); - } - - @Override - public void aliases(final IndicesAliasesRequest request, final ActionListener listener) { - execute(IndicesAliasesAction.INSTANCE, request, listener); - } - - @Override - public IndicesAliasesRequestBuilder prepareAliases() { - return new IndicesAliasesRequestBuilder(this); - } - - @Override - public ActionFuture getAliases(GetAliasesRequest request) { - return execute(GetAliasesAction.INSTANCE, request); - } - - @Override - public void getAliases(GetAliasesRequest request, ActionListener listener) { - execute(GetAliasesAction.INSTANCE, request, listener); - } - - @Override - public GetAliasesRequestBuilder prepareGetAliases(String... aliases) { - return new GetAliasesRequestBuilder(this, aliases); - } - - @Override - public ActionFuture clearCache(final ClearIndicesCacheRequest request) { - return execute(ClearIndicesCacheAction.INSTANCE, request); - } - - @Override - public void aliasesExist(GetAliasesRequest request, ActionListener listener) { - execute(AliasesExistAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture aliasesExist(GetAliasesRequest request) { - return execute(AliasesExistAction.INSTANCE, request); - } - - @Override - public AliasesExistRequestBuilder prepareAliasesExist(String... aliases) { - return new AliasesExistRequestBuilder(this, aliases); - } - - @Override - public ActionFuture getIndex(GetIndexRequest request) { - return execute(GetIndexAction.INSTANCE, request); - } - - @Override - public void getIndex(GetIndexRequest request, ActionListener listener) { - execute(GetIndexAction.INSTANCE, request, listener); - } - - @Override - public GetIndexRequestBuilder prepareGetIndex() { - return new GetIndexRequestBuilder(this); - } - - @Override - public void clearCache(final ClearIndicesCacheRequest request, final ActionListener listener) { - execute(ClearIndicesCacheAction.INSTANCE, request, listener); - } - - @Override - public ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) { - return new ClearIndicesCacheRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture create(final CreateIndexRequest request) { - return execute(CreateIndexAction.INSTANCE, request); - } - - @Override - public void create(final CreateIndexRequest request, final ActionListener listener) { - execute(CreateIndexAction.INSTANCE, request, listener); - } - - @Override - public CreateIndexRequestBuilder prepareCreate(String index) { - return new CreateIndexRequestBuilder(this, index); - } - - @Override - public ActionFuture delete(final DeleteIndexRequest request) { - return execute(DeleteIndexAction.INSTANCE, request); - } - - @Override - public void delete(final DeleteIndexRequest request, final ActionListener listener) { - execute(DeleteIndexAction.INSTANCE, request, listener); - } - - @Override - public DeleteIndexRequestBuilder prepareDelete(String... indices) { - return new DeleteIndexRequestBuilder(this, indices); - } - - @Override - public ActionFuture close(final CloseIndexRequest request) { - return execute(CloseIndexAction.INSTANCE, request); - } - - @Override - public void close(final CloseIndexRequest request, final ActionListener listener) { - execute(CloseIndexAction.INSTANCE, request, listener); - } - - @Override - public CloseIndexRequestBuilder prepareClose(String... indices) { - return new CloseIndexRequestBuilder(this, indices); - } - - @Override - public ActionFuture open(final OpenIndexRequest request) { - return execute(OpenIndexAction.INSTANCE, request); - } - - @Override - public void open(final OpenIndexRequest request, final ActionListener listener) { - execute(OpenIndexAction.INSTANCE, request, listener); - } - - @Override - public OpenIndexRequestBuilder prepareOpen(String... indices) { - return new OpenIndexRequestBuilder(this, indices); - } - - @Override - public ActionFuture flush(final FlushRequest request) { - return execute(FlushAction.INSTANCE, request); - } - - @Override - public void flush(final FlushRequest request, final ActionListener listener) { - execute(FlushAction.INSTANCE, request, listener); - } - - @Override - public FlushRequestBuilder prepareFlush(String... indices) { - return new FlushRequestBuilder(this).setIndices(indices); - } - - @Override - public void getMappings(GetMappingsRequest request, ActionListener listener) { - execute(GetMappingsAction.INSTANCE, request, listener); - } - - @Override - public void getFieldMappings(GetFieldMappingsRequest request, ActionListener listener) { - execute(GetFieldMappingsAction.INSTANCE, request, listener); - } - - @Override - public GetMappingsRequestBuilder prepareGetMappings(String... indices) { - return new GetMappingsRequestBuilder(this, indices); - } - - @Override - public ActionFuture getMappings(GetMappingsRequest request) { - return execute(GetMappingsAction.INSTANCE, request); - } - - @Override - public GetFieldMappingsRequestBuilder prepareGetFieldMappings(String... indices) { - return new GetFieldMappingsRequestBuilder(this, indices); - } - - @Override - public ActionFuture getFieldMappings(GetFieldMappingsRequest request) { - return execute(GetFieldMappingsAction.INSTANCE, request); - } - - @Override - public ActionFuture putMapping(final PutMappingRequest request) { - return execute(PutMappingAction.INSTANCE, request); - } - - @Override - public void putMapping(final PutMappingRequest request, final ActionListener listener) { - execute(PutMappingAction.INSTANCE, request, listener); - } - - @Override - public PutMappingRequestBuilder preparePutMapping(String... indices) { - return new PutMappingRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture optimize(final OptimizeRequest request) { - return execute(OptimizeAction.INSTANCE, request); - } - - @Override - public void optimize(final OptimizeRequest request, final ActionListener listener) { - execute(OptimizeAction.INSTANCE, request, listener); - } - - @Override - public OptimizeRequestBuilder prepareOptimize(String... indices) { - return new OptimizeRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture refresh(final RefreshRequest request) { - return execute(RefreshAction.INSTANCE, request); - } - - @Override - public void refresh(final RefreshRequest request, final ActionListener listener) { - execute(RefreshAction.INSTANCE, request, listener); - } - - @Override - public RefreshRequestBuilder prepareRefresh(String... indices) { - return new RefreshRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture stats(final IndicesStatsRequest request) { - return execute(IndicesStatsAction.INSTANCE, request); - } - - @Override - public void stats(final IndicesStatsRequest request, final ActionListener listener) { - execute(IndicesStatsAction.INSTANCE, request, listener); - } - - @Override - public IndicesStatsRequestBuilder prepareStats(String... indices) { - return new IndicesStatsRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture recoveries(final RecoveryRequest request) { - return execute(RecoveryAction.INSTANCE, request); - } - - @Override - public void recoveries(final RecoveryRequest request, final ActionListener listener) { - execute(RecoveryAction.INSTANCE, request, listener); - } - - @Override - public RecoveryRequestBuilder prepareRecoveries(String... indices) { - return new RecoveryRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture segments(final IndicesSegmentsRequest request) { - return execute(IndicesSegmentsAction.INSTANCE, request); - } - - @Override - public void segments(final IndicesSegmentsRequest request, final ActionListener listener) { - execute(IndicesSegmentsAction.INSTANCE, request, listener); - } - - @Override - public IndicesSegmentsRequestBuilder prepareSegments(String... indices) { - return new IndicesSegmentsRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture updateSettings(final UpdateSettingsRequest request) { - return execute(UpdateSettingsAction.INSTANCE, request); - } - - @Override - public void updateSettings(final UpdateSettingsRequest request, final ActionListener listener) { - execute(UpdateSettingsAction.INSTANCE, request, listener); - } - - @Override - public UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) { - return new UpdateSettingsRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture analyze(final AnalyzeRequest request) { - return execute(AnalyzeAction.INSTANCE, request); - } - - @Override - public void analyze(final AnalyzeRequest request, final ActionListener listener) { - execute(AnalyzeAction.INSTANCE, request, listener); - } - - @Override - public AnalyzeRequestBuilder prepareAnalyze(@Nullable String index, String text) { - return new AnalyzeRequestBuilder(this, index, text); - } - - @Override - public AnalyzeRequestBuilder prepareAnalyze(String text) { - return new AnalyzeRequestBuilder(this, null, text); - } - - @Override - public ActionFuture putTemplate(final PutIndexTemplateRequest request) { - return execute(PutIndexTemplateAction.INSTANCE, request); - } - - @Override - public void putTemplate(final PutIndexTemplateRequest request, final ActionListener listener) { - execute(PutIndexTemplateAction.INSTANCE, request, listener); - } - - @Override - public PutIndexTemplateRequestBuilder preparePutTemplate(String name) { - return new PutIndexTemplateRequestBuilder(this, name); - } - - @Override - public ActionFuture getTemplates(final GetIndexTemplatesRequest request) { - return execute(GetIndexTemplatesAction.INSTANCE, request); - } - - @Override - public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener listener) { - execute(GetIndexTemplatesAction.INSTANCE, request, listener); - } - - @Override - public GetIndexTemplatesRequestBuilder prepareGetTemplates(String... names) { - return new GetIndexTemplatesRequestBuilder(this, names); - } - - @Override - public ActionFuture deleteTemplate(final DeleteIndexTemplateRequest request) { - return execute(DeleteIndexTemplateAction.INSTANCE, request); - } - - @Override - public void deleteTemplate(final DeleteIndexTemplateRequest request, final ActionListener listener) { - execute(DeleteIndexTemplateAction.INSTANCE, request, listener); - } - - @Override - public DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) { - return new DeleteIndexTemplateRequestBuilder(this, name); - } - - @Override - public ActionFuture validateQuery(final ValidateQueryRequest request) { - return execute(ValidateQueryAction.INSTANCE, request); - } - - @Override - public void validateQuery(final ValidateQueryRequest request, final ActionListener listener) { - execute(ValidateQueryAction.INSTANCE, request, listener); - } - - @Override - public ValidateQueryRequestBuilder prepareValidateQuery(String... indices) { - return new ValidateQueryRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture putWarmer(PutWarmerRequest request) { - return execute(PutWarmerAction.INSTANCE, request); - } - - @Override - public void putWarmer(PutWarmerRequest request, ActionListener listener) { - execute(PutWarmerAction.INSTANCE, request, listener); - } - - @Override - public PutWarmerRequestBuilder preparePutWarmer(String name) { - return new PutWarmerRequestBuilder(this, name); - } - - @Override - public ActionFuture deleteWarmer(DeleteWarmerRequest request) { - return execute(DeleteWarmerAction.INSTANCE, request); - } - - @Override - public void deleteWarmer(DeleteWarmerRequest request, ActionListener listener) { - execute(DeleteWarmerAction.INSTANCE, request, listener); - } - - @Override - public DeleteWarmerRequestBuilder prepareDeleteWarmer() { - return new DeleteWarmerRequestBuilder(this); - } - - @Override - public GetWarmersRequestBuilder prepareGetWarmers(String... indices) { - return new GetWarmersRequestBuilder(this, indices); - } - - @Override - public ActionFuture getWarmers(GetWarmersRequest request) { - return execute(GetWarmersAction.INSTANCE, request); - } - - @Override - public void getWarmers(GetWarmersRequest request, ActionListener listener) { - execute(GetWarmersAction.INSTANCE, request, listener); - } - - @Override - public GetSettingsRequestBuilder prepareGetSettings(String... indices) { - return new GetSettingsRequestBuilder(this, indices); - } - - @Override - public ActionFuture getSettings(GetSettingsRequest request) { - return execute(GetSettingsAction.INSTANCE, request); - } - - @Override - public void getSettings(GetSettingsRequest request, ActionListener listener) { - execute(GetSettingsAction.INSTANCE, request, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java b/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java index 573715c10f4..895b3d844f6 100644 --- a/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java +++ b/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java @@ -20,10 +20,7 @@ package org.elasticsearch.client.transport; import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.support.InternalTransportAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportClient; -import org.elasticsearch.client.transport.support.InternalTransportClusterAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient; +import org.elasticsearch.client.transport.support.TransportProxyClient; import org.elasticsearch.common.inject.AbstractModule; /** @@ -34,10 +31,7 @@ public class ClientTransportModule extends AbstractModule { @Override protected void configure() { bind(Headers.class).asEagerSingleton(); - bind(InternalTransportClient.class).asEagerSingleton(); - bind(InternalTransportAdminClient.class).asEagerSingleton(); - bind(InternalTransportIndicesAdminClient.class).asEagerSingleton(); - bind(InternalTransportClusterAdminClient.class).asEagerSingleton(); + bind(TransportProxyClient.class).asEagerSingleton(); bind(TransportClientNodesService.class).asEagerSingleton(); } } diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index a39089e9a5a..c7866e6b1f9 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -20,40 +20,12 @@ package org.elasticsearch.client.transport; import com.google.common.collect.ImmutableList; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.*; -import org.elasticsearch.action.bulk.BulkRequest; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.count.CountRequest; -import org.elasticsearch.action.count.CountResponse; -import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.explain.ExplainRequest; -import org.elasticsearch.action.explain.ExplainResponse; -import org.elasticsearch.action.get.GetRequest; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetRequest; -import org.elasticsearch.action.get.MultiGetResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.mlt.MoreLikeThisRequest; -import org.elasticsearch.action.percolate.PercolateRequest; -import org.elasticsearch.action.percolate.PercolateResponse; -import org.elasticsearch.action.search.*; -import org.elasticsearch.action.suggest.SuggestRequest; -import org.elasticsearch.action.suggest.SuggestResponse; -import org.elasticsearch.action.termvectors.MultiTermVectorsRequest; -import org.elasticsearch.action.termvectors.MultiTermVectorsResponse; -import org.elasticsearch.action.termvectors.TermVectorsRequest; -import org.elasticsearch.action.termvectors.TermVectorsResponse; -import org.elasticsearch.action.update.UpdateRequest; -import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.cache.recycler.PageCacheRecycler; -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.Client; import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.transport.support.InternalTransportClient; +import org.elasticsearch.client.support.Headers; +import org.elasticsearch.client.transport.support.TransportProxyClient; import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.Tuple; @@ -93,92 +65,99 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde */ public class TransportClient extends AbstractClient { + /** + * Handy method ot create a {@link org.elasticsearch.client.transport.TransportClient.Builder}. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * A builder used to create an instance of the transport client. + */ + public static class Builder { + + private Settings settings = ImmutableSettings.EMPTY; + private boolean loadConfigSettings = true; + + /** + * The settings to configure the transport client with. + */ + public Builder settings(Settings.Builder settings) { + return settings(settings.build()); + } + + /** + * The settings to configure the transport client with. + */ + public Builder settings(Settings settings) { + this.settings = settings; + return this; + } + + /** + * Should the transport client load file based configuration automatically or not (and rely + * only on the provided settings), defaults to true. + */ + public Builder loadConfigSettings(boolean loadConfigSettings) { + this.loadConfigSettings = loadConfigSettings; + return this; + } + + /** + * Builds a new instance of the transport client. + */ + public TransportClient build() { + Tuple tuple = InternalSettingsPreparer.prepareSettings(settings, loadConfigSettings); + Settings settings = settingsBuilder() + .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval + .put(tuple.v1()) + .put("network.server", false) + .put("node.client", true) + .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) + .build(); + Environment environment = tuple.v2(); + + PluginsService pluginsService = new PluginsService(settings, tuple.v2()); + this.settings = pluginsService.updatedSettings(); + + Version version = Version.CURRENT; + + CompressorFactory.configure(this.settings); + + ModulesBuilder modules = new ModulesBuilder(); + modules.add(new Version.Module(version)); + modules.add(new PluginsModule(this.settings, pluginsService)); + modules.add(new EnvironmentModule(environment)); + modules.add(new SettingsModule(this.settings)); + modules.add(new NetworkModule()); + modules.add(new ClusterNameModule(this.settings)); + modules.add(new ThreadPoolModule(this.settings)); + modules.add(new TransportSearchModule()); + modules.add(new TransportModule(this.settings)); + modules.add(new ActionModule(true)); + modules.add(new ClientTransportModule()); + modules.add(new CircuitBreakerModule(this.settings)); + + Injector injector = modules.createInjector(); + injector.getInstance(TransportService.class).start(); + + return new TransportClient(injector); + } + } + public static final String CLIENT_TYPE = "transport"; final Injector injector; - private final Settings settings; - private final Environment environment; - private final PluginsService pluginsService; private final TransportClientNodesService nodesService; - private final InternalTransportClient internalClient; - - /** - * Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file - * system (the elasticsearch.(yml|json) files optionally prefixed with config/). - */ - public TransportClient(Settings settings) { - this(settings, true); - } - - /** - * Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file - * system (the elasticsearch.(yml|json) files optionally prefixed with config/). - */ - public TransportClient(Settings.Builder settings) { - this(settings.build(), true); - } - - /** - * Constructs a new transport client with the provided settings and the ability to control if settings will - * be loaded from the classpath / file system (the elasticsearch.(yml|json) files optionally prefixed with - * config/). - * - * @param settings The explicit settings. - * @param loadConfigSettings true if settings should be loaded from the classpath/file system. - * @throws org.elasticsearch.ElasticsearchException - */ - public TransportClient(Settings.Builder settings, boolean loadConfigSettings) { - this(settings.build(), loadConfigSettings); - } - - /** - * Constructs a new transport client with the provided settings and the ability to control if settings will - * be loaded from the classpath / file system (the elasticsearch.(yml|json) files optionally prefixed with - * config/). - * - * @param pSettings The explicit settings. - * @param loadConfigSettings true if settings should be loaded from the classpath/file system. - * @throws org.elasticsearch.ElasticsearchException - */ - public TransportClient(Settings pSettings, boolean loadConfigSettings) { - Tuple tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings); - Settings settings = settingsBuilder() - .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval - .put(tuple.v1()) - .put("network.server", false) - .put("node.client", true) - .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) - .build(); - this.environment = tuple.v2(); - - this.pluginsService = new PluginsService(settings, tuple.v2()); - this.settings = pluginsService.updatedSettings(); - - Version version = Version.CURRENT; - - CompressorFactory.configure(this.settings); - - ModulesBuilder modules = new ModulesBuilder(); - modules.add(new Version.Module(version)); - modules.add(new PluginsModule(this.settings, pluginsService)); - modules.add(new EnvironmentModule(environment)); - modules.add(new SettingsModule(this.settings)); - modules.add(new NetworkModule()); - modules.add(new ClusterNameModule(this.settings)); - modules.add(new ThreadPoolModule(this.settings)); - modules.add(new TransportSearchModule()); - modules.add(new TransportModule(this.settings)); - modules.add(new ActionModule(true)); - modules.add(new ClientTransportModule()); - modules.add(new CircuitBreakerModule(this.settings)); - - injector = modules.createInjector(); - - injector.getInstance(TransportService.class).start(); + private final TransportProxyClient proxy; + private TransportClient(Injector injector) { + super(injector.getInstance(Settings.class), injector.getInstance(ThreadPool.class), injector.getInstance(Headers.class)); + this.injector = injector; nodesService = injector.getInstance(TransportClientNodesService.class); - internalClient = injector.getInstance(InternalTransportClient.class); + proxy = injector.getInstance(TransportProxyClient.class); } TransportClientNodesService nodeService() { @@ -265,7 +244,7 @@ public class TransportClient extends AbstractClient { // ignore, might not be bounded } - for (Class plugin : pluginsService.services()) { + for (Class plugin : injector.getInstance(PluginsService.class).services()) { injector.getInstance(plugin).close(); } try { @@ -278,187 +257,7 @@ public class TransportClient extends AbstractClient { } @Override - public Settings settings() { - return this.settings; - } - - @Override - public ThreadPool threadPool() { - return internalClient.threadPool(); - } - - @Override - public AdminClient admin() { - return internalClient.admin(); - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return internalClient.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - internalClient.execute(action, request, listener); - } - - @Override - public ActionFuture index(IndexRequest request) { - return internalClient.index(request); - } - - @Override - public void index(IndexRequest request, ActionListener listener) { - internalClient.index(request, listener); - } - - @Override - public ActionFuture update(UpdateRequest request) { - return internalClient.update(request); - } - - @Override - public void update(UpdateRequest request, ActionListener listener) { - internalClient.update(request, listener); - } - - @Override - public ActionFuture delete(DeleteRequest request) { - return internalClient.delete(request); - } - - @Override - public void delete(DeleteRequest request, ActionListener listener) { - internalClient.delete(request, listener); - } - - @Override - public ActionFuture bulk(BulkRequest request) { - return internalClient.bulk(request); - } - - @Override - public void bulk(BulkRequest request, ActionListener listener) { - internalClient.bulk(request, listener); - } - - @Override - public ActionFuture get(GetRequest request) { - return internalClient.get(request); - } - - @Override - public void get(GetRequest request, ActionListener listener) { - internalClient.get(request, listener); - } - - @Override - public ActionFuture multiGet(MultiGetRequest request) { - return internalClient.multiGet(request); - } - - @Override - public void multiGet(MultiGetRequest request, ActionListener listener) { - internalClient.multiGet(request, listener); - } - - @Override - public ActionFuture count(CountRequest request) { - return internalClient.count(request); - } - - @Override - public void count(CountRequest request, ActionListener listener) { - internalClient.count(request, listener); - } - - @Override - public ActionFuture suggest(SuggestRequest request) { - return internalClient.suggest(request); - } - - @Override - public void suggest(SuggestRequest request, ActionListener listener) { - internalClient.suggest(request, listener); - } - - @Override - public ActionFuture search(SearchRequest request) { - return internalClient.search(request); - } - - @Override - public void search(SearchRequest request, ActionListener listener) { - internalClient.search(request, listener); - } - - @Override - public ActionFuture searchScroll(SearchScrollRequest request) { - return internalClient.searchScroll(request); - } - - @Override - public void searchScroll(SearchScrollRequest request, ActionListener listener) { - internalClient.searchScroll(request, listener); - } - - @Override - public ActionFuture multiSearch(MultiSearchRequest request) { - return internalClient.multiSearch(request); - } - - @Override - public void multiSearch(MultiSearchRequest request, ActionListener listener) { - internalClient.multiSearch(request, listener); - } - - @Override - public ActionFuture moreLikeThis(MoreLikeThisRequest request) { - return internalClient.moreLikeThis(request); - } - - @Override - public void moreLikeThis(MoreLikeThisRequest request, ActionListener listener) { - internalClient.moreLikeThis(request, listener); - } - - @Override - public ActionFuture termVectors(TermVectorsRequest request) { - return internalClient.termVectors(request); - } - - @Override - public void termVectors(TermVectorsRequest request, ActionListener listener) { - internalClient.termVectors(request, listener); - } - - @Override - public ActionFuture multiTermVectors(final MultiTermVectorsRequest request) { - return internalClient.multiTermVectors(request); - } - - @Override - public void multiTermVectors(final MultiTermVectorsRequest request, final ActionListener listener) { - internalClient.multiTermVectors(request, listener); - } - - @Override - public ActionFuture percolate(PercolateRequest request) { - return internalClient.percolate(request); - } - - @Override - public void percolate(PercolateRequest request, ActionListener listener) { - internalClient.percolate(request, listener); - } - - @Override - public ActionFuture explain(ExplainRequest request) { - return internalClient.explain(request); - } - - @Override - public void explain(ExplainRequest request, ActionListener listener) { - internalClient.explain(request, listener); + protected > void doExecute(Action action, Request request, ActionListener listener) { + proxy.execute(action, request, listener); } } diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java deleted file mode 100644 index d2f51160d8b..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.transport.support; - -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; - -/** - * - */ -public class InternalTransportAdminClient extends AbstractComponent implements AdminClient { - - private final InternalTransportIndicesAdminClient indicesAdminClient; - - private final InternalTransportClusterAdminClient clusterAdminClient; - - @Inject - public InternalTransportAdminClient(Settings settings, InternalTransportIndicesAdminClient indicesAdminClient, InternalTransportClusterAdminClient clusterAdminClient) { - super(settings); - this.indicesAdminClient = indicesAdminClient; - this.clusterAdminClient = clusterAdminClient; - } - - @Override - public IndicesAdminClient indices() { - return indicesAdminClient; - } - - @Override - public ClusterAdminClient cluster() { - return clusterAdminClient; - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java deleted file mode 100644 index 0aff540cb9e..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.transport.support; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.Map; - -/** - * - */ -public class InternalTransportClient extends AbstractClient { - - private final ESLogger logger; - private final Settings settings; - private final ThreadPool threadPool; - private final TransportClientNodesService nodesService; - private final InternalTransportAdminClient adminClient; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public InternalTransportClient(Settings settings, ThreadPool threadPool, TransportService transportService, - TransportClientNodesService nodesService, InternalTransportAdminClient adminClient, - Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.settings = settings; - this.threadPool = threadPool; - this.nodesService = nodesService; - this.adminClient = adminClient; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (GenericAction action : actions.values()) { - if (action instanceof Action) { - actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService)); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public void close() { - // nothing to do here - } - - @Override - public Settings settings() { - return this.settings; - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @Override - public AdminClient admin() { - return adminClient; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(final Action action, final Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - final TransportActionNodeProxy proxy = actions.get(action); - nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { - @Override - public void doWithNode(DiscoveryNode node, ActionListener listener) { - proxy.execute(node, request, listener); - } - }, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java deleted file mode 100644 index 5ede20849a3..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.transport.support; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.Map; - -/** - * - */ -@SuppressWarnings("unchecked") -public class InternalTransportClusterAdminClient extends AbstractClusterAdminClient implements ClusterAdminClient { - - private final ESLogger logger; - private final TransportClientNodesService nodesService; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public InternalTransportClusterAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool, TransportService transportService, - Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.nodesService = nodesService; - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (GenericAction action : actions.values()) { - if (action instanceof ClusterAction) { - actionsBuilder.put((ClusterAction) action, new TransportActionNodeProxy(settings, action, transportService)); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(final Action action, final Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - final TransportActionNodeProxy proxy = actions.get(action); - nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { - @Override - public void doWithNode(DiscoveryNode node, ActionListener listener) { - proxy.execute(node, request, listener); - } - }, listener); - } - -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java deleted file mode 100644 index 49295b1c968..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.transport.support; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.Map; - -/** - * - */ -@SuppressWarnings("unchecked") -public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { - - private final ESLogger logger; - private final TransportClientNodesService nodesService; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, TransportService transportService, ThreadPool threadPool, - Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.nodesService = nodesService; - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (GenericAction action : actions.values()) { - if (action instanceof IndicesAction) { - actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService)); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(final Action action, final Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - final TransportActionNodeProxy proxy = actions.get(action); - nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { - @Override - public void doWithNode(DiscoveryNode node, ActionListener listener) { - proxy.execute(node, request, listener); - } - }, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java b/src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java new file mode 100644 index 00000000000..89b3a042450 --- /dev/null +++ b/src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java @@ -0,0 +1,62 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.transport.support; + +import com.google.common.collect.ImmutableMap; +import org.elasticsearch.action.*; +import org.elasticsearch.client.transport.TransportClientNodesService; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.collect.MapBuilder; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.transport.TransportService; + +import java.util.Map; + +/** + * + */ +public class TransportProxyClient { + + private final TransportClientNodesService nodesService; + private final ImmutableMap proxies; + + @Inject + public TransportProxyClient(Settings settings, TransportService transportService, TransportClientNodesService nodesService, Map actions) { + this.nodesService = nodesService; + MapBuilder actionsBuilder = new MapBuilder<>(); + for (GenericAction action : actions.values()) { + if (action instanceof Action) { + actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService)); + } + } + this.proxies = actionsBuilder.immutableMap(); + } + + public > void execute(final Action action, final Request request, ActionListener listener) { + final TransportActionNodeProxy proxy = proxies.get(action); + nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { + @Override + public void doWithNode(DiscoveryNode node, ActionListener listener) { + proxy.execute(node, request, listener); + } + }, listener); + } +} diff --git a/src/main/java/org/elasticsearch/rest/BaseRestHandler.java b/src/main/java/org/elasticsearch/rest/BaseRestHandler.java index 9b83c2648b3..b291c4366de 100644 --- a/src/main/java/org/elasticsearch/rest/BaseRestHandler.java +++ b/src/main/java/org/elasticsearch/rest/BaseRestHandler.java @@ -21,9 +21,8 @@ package org.elasticsearch.rest; import org.elasticsearch.action.*; import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.FilterClient; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.settings.Settings; @@ -31,7 +30,7 @@ import java.util.Set; /** * Base handler for REST requests. - * + *

* This handler makes sure that the headers & context of the handled {@link RestRequest requests} are copied over to * the transport requests executed by the associated client. While the context is fully copied over, not all the headers * are copied, but a selected few. It is possible to control what headers are copied over by registering them using @@ -58,15 +57,11 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH static final class HeadersAndContextCopyClient extends FilterClient { private final RestRequest restRequest; - private final IndicesAdmin indicesAdmin; - private final ClusterAdmin clusterAdmin; private final Set headers; HeadersAndContextCopyClient(Client in, RestRequest restRequest, Set headers) { super(in); this.restRequest = restRequest; - this.indicesAdmin = new IndicesAdmin(in.admin().indices(), restRequest, headers); - this.clusterAdmin = new ClusterAdmin(in.admin().cluster(), restRequest, headers); this.headers = headers; } @@ -81,73 +76,9 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH } @Override - public > ActionFuture execute(Action action, Request request) { + protected > void doExecute(Action action, Request request, ActionListener listener) { copyHeadersAndContext(request, restRequest, headers); - return super.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - copyHeadersAndContext(request, restRequest, headers); - super.execute(action, request, listener); - } - - @Override - public ClusterAdminClient cluster() { - return clusterAdmin; - } - - @Override - public IndicesAdminClient indices() { - return indicesAdmin; - } - - private static final class ClusterAdmin extends FilterClient.ClusterAdmin { - - private final RestRequest restRequest; - private final Set headers; - - private ClusterAdmin(ClusterAdminClient in, RestRequest restRequest, Set headers) { - super(in); - this.restRequest = restRequest; - this.headers = headers; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - copyHeadersAndContext(request, restRequest, headers); - return super.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - copyHeadersAndContext(request, restRequest, headers); - super.execute(action, request, listener); - } - } - - private final class IndicesAdmin extends FilterClient.IndicesAdmin { - - private final RestRequest restRequest; - private final Set headers; - - private IndicesAdmin(IndicesAdminClient in, RestRequest restRequest, Set headers) { - super(in); - this.restRequest = restRequest; - this.headers = headers; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - copyHeadersAndContext(request, restRequest, headers); - return super.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - copyHeadersAndContext(request, restRequest, headers); - super.execute(action, request, listener); - } + super.doExecute(action, request, listener); } } } \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java index bace2472a3c..ea25cfb767f 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java @@ -33,7 +33,7 @@ public class BulkIntegrationTests extends ElasticsearchIntegrationTest { @Test public void testBulkIndexCreatesMapping() throws Exception { String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/bulk-log.json"); - BulkRequestBuilder bulkBuilder = new BulkRequestBuilder(client()); + BulkRequestBuilder bulkBuilder = client().prepareBulk(); bulkBuilder.add(bulkAction.getBytes(Charsets.UTF_8), 0, bulkAction.length(), null, null); bulkBuilder.get(); assertBusy(new Runnable() { diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java index 68a11b0b8e5..920ae42333a 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java @@ -161,7 +161,7 @@ public class BulkProcessorTests extends ElasticsearchIntegrationTest { Settings settings = ImmutableSettings.builder() .put("path.home", createTempDir().toString()) .build(); - Client transportClient = new TransportClient(settings); + Client transportClient = TransportClient.builder().settings(settings).build(); int bulkActions = randomIntBetween(10, 100); int numDocs = randomIntBetween(bulkActions, bulkActions + 100); diff --git a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java index 85bb2a384cc..ceabdd58965 100644 --- a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java @@ -51,7 +51,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.builder() .put("path.home", createTempDir().toString()) .build(); - client = new TransportClient(settings); + client = TransportClient.builder().settings(settings).build(); } @AfterClass @@ -62,20 +62,20 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testEmptySourceToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); assertThat(countRequestBuilder.toString(), equalTo(new QuerySourceBuilder().toString())); } @Test public void testQueryBuilderQueryToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); countRequestBuilder.setQuery(QueryBuilders.matchAllQuery()); assertThat(countRequestBuilder.toString(), equalTo(new QuerySourceBuilder().setQuery(QueryBuilders.matchAllQuery()).toString())); } @Test public void testStringQueryToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); String query = "{ \"match_all\" : {} }"; countRequestBuilder.setQuery(new BytesArray(query)); assertThat(countRequestBuilder.toString(), containsString("\"query\":{ \"match_all\" : {} }")); @@ -83,7 +83,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testXContentBuilderQueryToString() throws IOException { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("match_all"); @@ -95,7 +95,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testStringSourceToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); String query = "{ \"query\": { \"match_all\" : {} } }"; countRequestBuilder.setSource(new BytesArray(query)); assertThat(countRequestBuilder.toString(), equalTo("{ \"query\": { \"match_all\" : {} } }")); @@ -103,7 +103,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testXContentBuilderSourceToString() throws IOException { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("match_all"); @@ -124,7 +124,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { " }\n" + " }\n" + " }"; - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client).setSource(new BytesArray(source)); + CountRequestBuilder countRequestBuilder = client.prepareCount().setSource(new BytesArray(source)); String preToString = countRequestBuilder.request().source().toUtf8(); assertThat(countRequestBuilder.toString(), equalTo(source)); String postToString = countRequestBuilder.request().source().toUtf8(); diff --git a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java index 9b4b8bc77b8..dec0e8238ea 100644 --- a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java @@ -50,7 +50,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.builder() .put("path.home", createTempDir().toString()) .build(); - client = new TransportClient(settings); + client = TransportClient.builder().settings(settings).build(); } @AfterClass @@ -61,20 +61,20 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testEmptySourceToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); assertThat(searchRequestBuilder.toString(), equalTo(new SearchSourceBuilder().toString())); } @Test public void testQueryBuilderQueryToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery()); assertThat(searchRequestBuilder.toString(), equalTo(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).toString())); } @Test public void testXContentBuilderQueryToString() throws IOException { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("match_all"); @@ -86,7 +86,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testStringQueryToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); String query = "{ \"match_all\" : {} }"; searchRequestBuilder.setQuery(query); assertThat(searchRequestBuilder.toString(), containsString("\"query\":{ \"match_all\" : {} }")); @@ -94,7 +94,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testStringSourceToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); String source = "{ \"query\" : { \"match_all\" : {} } }"; searchRequestBuilder.setSource(source); assertThat(searchRequestBuilder.toString(), equalTo(source)); @@ -102,7 +102,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testXContentBuilderSourceToString() throws IOException { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("query"); @@ -125,7 +125,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { " }\n" + " }\n" + " }"; - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client).setSource(source); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch().setSource(source); String preToString = searchRequestBuilder.request().source().toUtf8(); assertThat(searchRequestBuilder.toString(), equalTo(source)); String postToString = searchRequestBuilder.request().source().toUtf8(); diff --git a/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java b/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java index ecc767c3274..58a96aa5e1f 100644 --- a/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java +++ b/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java @@ -74,7 +74,7 @@ public class MultiTermVectorsTests extends AbstractTermVectorsTests { @Test public void testMissingIndexThrowsMissingIndex() throws Exception { TermVectorsRequestBuilder requestBuilder = client().prepareTermVectors("testX", "typeX", Integer.toString(1)); - MultiTermVectorsRequestBuilder mtvBuilder = new MultiTermVectorsRequestBuilder(client()); + MultiTermVectorsRequestBuilder mtvBuilder = client().prepareMultiTermVectors(); mtvBuilder.add(requestBuilder.request()); MultiTermVectorsResponse response = mtvBuilder.execute().actionGet(); assertThat(response.getResponses().length, equalTo(1)); diff --git a/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java index c55681d3fd2..e67890bf030 100644 --- a/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java @@ -104,6 +104,6 @@ public class ClusterStateBackwardsCompatTests extends ElasticsearchBackwardsComp private TransportClient newTransportClient() { Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.ignore_cluster_name", true) .put("node.name", "transport_client_" + getTestName()).build(); - return new TransportClient(settings); + return TransportClient.builder().settings(settings).build(); } } diff --git a/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java index 0f93011a249..63b45909944 100644 --- a/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java @@ -48,7 +48,7 @@ public class NodesStatsBasicBackwardsCompatTests extends ElasticsearchBackwardsC // We explicitly connect to each node with a custom TransportClient for (NodeInfo n : nodesInfo.getNodes()) { - TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address()); + TransportClient tc = TransportClient.builder().settings(settings).build().addTransportAddress(n.getNode().address()); // Just verify that the NS can be sent and serialized/deserialized between nodes with basic indices NodesStatsResponse ns = tc.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet(); tc.close(); @@ -67,7 +67,7 @@ public class NodesStatsBasicBackwardsCompatTests extends ElasticsearchBackwardsC // We explicitly connect to each node with a custom TransportClient for (NodeInfo n : nodesInfo.getNodes()) { - TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address()); + TransportClient tc = TransportClient.builder().settings(settings).build().addTransportAddress(n.getNode().address()); // randomize the combination of flags set // Uses reflection to find methods in an attempt to future-proof this test against newly added flags diff --git a/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java b/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java index a6bd13731f9..195165715aa 100644 --- a/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java +++ b/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java @@ -50,7 +50,7 @@ public class TransportClientBackwardsCompatibilityTest extends ElasticsearchBack CompositeTestCluster compositeTestCluster = backwardsCluster(); TransportAddress transportAddress = compositeTestCluster.externalTransportAddress(); - try(TransportClient client = new TransportClient(settings)) { + try(TransportClient client = TransportClient.builder().settings(settings).build()) { client.addTransportAddress(transportAddress); assertAcked(client.admin().indices().prepareCreate("test")); diff --git a/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java b/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java index ce4cfa43439..9f8dc0cf2f6 100644 --- a/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java @@ -45,14 +45,9 @@ public class NodeClientHeadersTests extends AbstractClientHeadersTests { @Override protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { Settings settings = HEADER_SETTINGS; - Headers headers = new Headers(settings); Actions actions = new Actions(settings, threadPool, testedActions); - - NodeClusterAdminClient clusterClient = new NodeClusterAdminClient(settings, threadPool, actions, headers); - NodeIndicesAdminClient indicesClient = new NodeIndicesAdminClient(settings, threadPool, actions, headers); - NodeAdminClient adminClient = new NodeAdminClient(settings, clusterClient, indicesClient); - return new NodeClient(settings, threadPool, adminClient, actions, headers); + return new NodeClient(settings, threadPool, headers, actions); } private static class Actions extends HashMap { diff --git a/src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java deleted file mode 100644 index bdccf82deb1..00000000000 --- a/src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.transport; - -import org.elasticsearch.Version; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.support.InternalTransportAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportClient; -import org.elasticsearch.client.transport.support.InternalTransportClusterAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.transport.LocalTransportAddress; -import org.elasticsearch.test.ElasticsearchTestCase; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; -import org.junit.Test; - -import java.io.Closeable; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.notNullValue; - -public class InternalTransportClientTests extends ElasticsearchTestCase { - - private static class TestIteration implements Closeable { - private final ThreadPool threadPool; - private final FailAndRetryMockTransport transport; - private final TransportService transportService; - private final TransportClientNodesService transportClientNodesService; - private final InternalTransportClient internalTransportClient; - private final int nodesCount; - - TestIteration() { - threadPool = new ThreadPool("internal-transport-client-tests"); - transport = new FailAndRetryMockTransport(getRandom()) { - @Override - protected TestResponse newResponse() { - return new TestResponse(); - } - }; - transportService = new TransportService(ImmutableSettings.EMPTY, transport, threadPool); - transportService.start(); - transportClientNodesService = new TransportClientNodesService(ImmutableSettings.EMPTY, ClusterName.DEFAULT, transportService, threadPool, Headers.EMPTY, Version.CURRENT); - Map actions = new HashMap<>(); - actions.put(NodesInfoAction.NAME, NodesInfoAction.INSTANCE); - actions.put(TestAction.NAME, TestAction.INSTANCE); - actions.put(IndicesAdminTestAction.NAME, IndicesAdminTestAction.INSTANCE); - actions.put(ClusterAdminTestAction.NAME, ClusterAdminTestAction.INSTANCE); - - InternalTransportIndicesAdminClient indicesAdminClient = new InternalTransportIndicesAdminClient(ImmutableSettings.EMPTY, transportClientNodesService, transportService, threadPool, actions, Headers.EMPTY); - InternalTransportClusterAdminClient clusterAdminClient = new InternalTransportClusterAdminClient(ImmutableSettings.EMPTY, transportClientNodesService, threadPool, transportService, actions, Headers.EMPTY); - InternalTransportAdminClient adminClient = new InternalTransportAdminClient(ImmutableSettings.EMPTY, indicesAdminClient, clusterAdminClient); - internalTransportClient = new InternalTransportClient(ImmutableSettings.EMPTY, threadPool, transportService, transportClientNodesService, adminClient, actions, Headers.EMPTY); - - nodesCount = randomIntBetween(1, 10); - for (int i = 0; i < nodesCount; i++) { - transportClientNodesService.addTransportAddresses(new LocalTransportAddress("node" + i)); - } - transport.endConnectMode(); - } - - @Override - public void close() { - threadPool.shutdown(); - try { - threadPool.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) { - Thread.currentThread().isInterrupted(); - } - transportService.stop(); - transportClientNodesService.close(); - internalTransportClient.close(); - } - } - - @Test - public void testListenerFailures() throws InterruptedException { - - int iters = iterations(10, 100); - for (int i = 0; i < iters; i++) { - try(final TestIteration iteration = new TestIteration()) { - final CountDownLatch latch = new CountDownLatch(1); - final AtomicInteger finalFailures = new AtomicInteger(); - final AtomicReference finalFailure = new AtomicReference<>(); - final AtomicReference response = new AtomicReference<>(); - ActionListener actionListener = new ActionListener() { - @Override - public void onResponse(TestResponse testResponse) { - response.set(testResponse); - latch.countDown(); - } - - @Override - public void onFailure(Throwable e) { - finalFailures.incrementAndGet(); - finalFailure.set(e); - latch.countDown(); - } - }; - - final AtomicInteger preSendFailures = new AtomicInteger(); - - Action action = randomFrom(Action.values()); - action.execute(iteration, actionListener); - - assertThat(latch.await(1, TimeUnit.SECONDS), equalTo(true)); - - //there can be only either one failure that causes the request to fail straightaway or success - assertThat(preSendFailures.get() + iteration.transport.failures() + iteration.transport.successes(), lessThanOrEqualTo(1)); - - if (iteration.transport.successes() == 1) { - assertThat(finalFailures.get(), equalTo(0)); - assertThat(finalFailure.get(), nullValue()); - assertThat(response.get(), notNullValue()); - } else { - assertThat(finalFailures.get(), equalTo(1)); - assertThat(finalFailure.get(), notNullValue()); - assertThat(response.get(), nullValue()); - if (preSendFailures.get() == 0 && iteration.transport.failures() == 0) { - assertThat(finalFailure.get(), instanceOf(NoNodeAvailableException.class)); - } - } - - assertThat(iteration.transport.triedNodes().size(), lessThanOrEqualTo(iteration.nodesCount)); - assertThat(iteration.transport.triedNodes().size(), equalTo(iteration.transport.connectTransportExceptions() + iteration.transport.failures() + iteration.transport.successes())); - } - } - } - - @Test - public void testSyncFailures() throws InterruptedException { - - int iters = iterations(10, 100); - for (int i = 0; i < iters; i++) { - try(final TestIteration iteration = new TestIteration()) { - TestResponse testResponse = null; - Throwable finalFailure = null; - - try { - Action action = randomFrom(Action.values()); - ActionFuture future = action.execute(iteration); - testResponse = future.actionGet(); - } catch (Throwable t) { - finalFailure = t; - } - - //there can be only either one failure that causes the request to fail straightaway or success - assertThat(iteration.transport.failures() + iteration.transport.successes(), lessThanOrEqualTo(1)); - - if (iteration.transport.successes() == 1) { - assertThat(finalFailure, nullValue()); - assertThat(testResponse, notNullValue()); - } else { - assertThat(testResponse, nullValue()); - assertThat(finalFailure, notNullValue()); - if (iteration.transport.failures() == 0) { - assertThat(finalFailure, instanceOf(NoNodeAvailableException.class)); - } - } - - assertThat(iteration.transport.triedNodes().size(), lessThanOrEqualTo(iteration.nodesCount)); - assertThat(iteration.transport.triedNodes().size(), equalTo(iteration.transport.connectTransportExceptions() + iteration.transport.failures() + iteration.transport.successes())); - } - } - } - - private static enum Action { - TEST { - @Override - ActionFuture execute(TestIteration iteration) { - return iteration.internalTransportClient.execute(TestAction.INSTANCE, new TestRequest()); - } - - @Override - void execute(TestIteration iteration, ActionListener listener) { - iteration.internalTransportClient.execute(TestAction.INSTANCE, new TestRequest(), listener); - } - }, - INDICES_ADMIN { - @Override - ActionFuture execute(TestIteration iteration) { - return iteration.internalTransportClient.admin().indices().execute(IndicesAdminTestAction.INSTANCE, new TestRequest()); - } - - @Override - void execute(TestIteration iteration, ActionListener listener) { - iteration.internalTransportClient.admin().indices().execute(IndicesAdminTestAction.INSTANCE, new TestRequest(), listener); - } - }, - CLUSTER_ADMIN { - @Override - ActionFuture execute(TestIteration iteration) { - return iteration.internalTransportClient.admin().cluster().execute(ClusterAdminTestAction.INSTANCE, new TestRequest()); - } - - @Override - void execute(TestIteration iteration, ActionListener listener) { - iteration.internalTransportClient.admin().cluster().execute(ClusterAdminTestAction.INSTANCE, new TestRequest(), listener); - } - }; - - abstract ActionFuture execute(TestIteration iteration); - - abstract void execute(TestIteration iteration, ActionListener listener); - } - - private static class TestRequest extends ActionRequest { - @Override - public ActionRequestValidationException validate() { - return null; - } - } - - private static class TestResponse extends ActionResponse { - - } - - private static class TestAction extends ClientAction { - static final String NAME = "test-action"; - static final TestAction INSTANCE = new TestAction(NAME); - - private TestAction(String name) { - super(name); - } - - @Override - public TestRequestBuilder newRequestBuilder(Client client) { - throw new UnsupportedOperationException(); - } - - @Override - public TestResponse newResponse() { - return new TestResponse(); - } - } - - private static class TestRequestBuilder extends ActionRequestBuilder { - - protected TestRequestBuilder(Client client, TestRequest request) { - super(client, request); - } - - @Override - protected void doExecute(ActionListener listener) { - throw new UnsupportedOperationException(); - } - } - - private static class IndicesAdminTestAction extends IndicesAction { - static final String NAME = "test-indices-action"; - static final IndicesAdminTestAction INSTANCE = new IndicesAdminTestAction(NAME); - - private IndicesAdminTestAction(String name) { - super(name); - } - - @Override - public IndicesAdminTestRequestBuilder newRequestBuilder(IndicesAdminClient client) { - throw new UnsupportedOperationException(); - } - - @Override - public TestResponse newResponse() { - return new TestResponse(); - } - } - - private static class IndicesAdminTestRequestBuilder extends ActionRequestBuilder { - - protected IndicesAdminTestRequestBuilder(IndicesAdminClient client, TestRequest request) { - super(client, request); - } - - @Override - protected void doExecute(ActionListener listener) { - throw new UnsupportedOperationException(); - } - } - - private static class ClusterAdminTestAction extends ClusterAction { - static final String NAME = "test-cluster-action"; - static final ClusterAdminTestAction INSTANCE = new ClusterAdminTestAction(NAME); - - private ClusterAdminTestAction(String name) { - super(name); - } - - @Override - public ClusterAdminTestRequestBuilder newRequestBuilder(ClusterAdminClient client) { - throw new UnsupportedOperationException(); - } - - @Override - public TestResponse newResponse() { - return new TestResponse(); - } - } - - private static class ClusterAdminTestRequestBuilder extends ActionRequestBuilder { - - protected ClusterAdminTestRequestBuilder(ClusterAdminClient client, TestRequest request) { - super(client, request); - } - - @Override - protected void doExecute(ActionListener listener) { - throw new UnsupportedOperationException(); - } - } -} diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index 07dd7f9c73d..8400b490301 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -55,12 +55,12 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { @Override protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { - TransportClient client = new TransportClient(ImmutableSettings.builder() + TransportClient client = TransportClient.builder().settings(ImmutableSettings.builder() .put("client.transport.sniff", false) .put("node.name", "transport_client_" + this.getTestName()) .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(headersSettings) - .build()); + .build()).build(); client.addTransportAddress(address); return client; @@ -68,7 +68,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { @Test public void testWithSniffing() throws Exception { - TransportClient client = new TransportClient(ImmutableSettings.builder() + TransportClient client = TransportClient.builder().settings(ImmutableSettings.builder() .put("client.transport.sniff", true) .put("cluster.name", "cluster1") .put("node.name", "transport_client_" + this.getTestName() + "_1") @@ -76,7 +76,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(HEADER_SETTINGS) .put("path.home", createTempDir().toString()) - .build()); + .build()).build(); try { client.addTransportAddress(address); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java index 3e8c2b09f38..b0090fff142 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java @@ -65,7 +65,7 @@ public class TransportClientRetryTests extends ElasticsearchIntegrationTest { .put("config.ignore_system_properties", true) .put("path.home", createTempDir()); - try (TransportClient transportClient = new TransportClient(builder.build())) { + try (TransportClient transportClient = TransportClient.builder().settings(builder.build()).build()) { transportClient.addTransportAddresses(addresses); assertThat(transportClient.connectedNodes().size(), equalTo(internalCluster().size())); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index b540800c5d1..3abb071d4ee 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -95,7 +95,7 @@ public class TransportClientTests extends ElasticsearchIntegrationTest { @Test public void testThatTransportClientSettingCannotBeChanged() { Settings baseSettings = settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything").put("path.home", createTempDir()).build(); - try (TransportClient client = new TransportClient(baseSettings)) { + try (TransportClient client = TransportClient.builder().settings(baseSettings).build()) { Settings settings = client.injector.getInstance(Settings.class); assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport")); } diff --git a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java index af419cf68a9..d261b0a3b01 100644 --- a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java +++ b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java @@ -161,7 +161,7 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest { client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet(); } - void checkWriteAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder builder) { + void checkWriteAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder builder) { // we clean the metadata when loosing a master, therefore all operations on indices will auto create it, if allowed long now = System.currentTimeMillis(); try { diff --git a/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java b/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java index dc58961cc4b..af07a25f3ae 100644 --- a/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java +++ b/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java @@ -33,8 +33,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.*; import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; +import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -110,31 +109,32 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - SearchRequest searchRequest = Requests.searchRequest(); - putHeaders(searchRequest, transportHeaders); - putContext(searchRequest, transportContext); - assertHeaders(searchRequest, transportHeaders); - client.search(searchRequest); - assertHeaders(searchRequest, expectedHeaders); - assertContext(searchRequest, expectedContext); + SearchRequest searchRequest = Requests.searchRequest(); + putHeaders(searchRequest, transportHeaders); + putContext(searchRequest, transportContext); + assertHeaders(searchRequest, transportHeaders); + client.search(searchRequest); + assertHeaders(searchRequest, expectedHeaders); + assertContext(searchRequest, expectedContext); - GetRequest getRequest = Requests.getRequest("index"); - putHeaders(getRequest, transportHeaders); - putContext(getRequest, transportContext); - assertHeaders(getRequest, transportHeaders); - client.get(getRequest); - assertHeaders(getRequest, expectedHeaders); - assertContext(getRequest, expectedContext); + GetRequest getRequest = Requests.getRequest("index"); + putHeaders(getRequest, transportHeaders); + putContext(getRequest, transportContext); + assertHeaders(getRequest, transportHeaders); + client.get(getRequest); + assertHeaders(getRequest, expectedHeaders); + assertContext(getRequest, expectedContext); - IndexRequest indexRequest = Requests.indexRequest(); - putHeaders(indexRequest, transportHeaders); - putContext(indexRequest, transportContext); - assertHeaders(indexRequest, transportHeaders); - client.index(indexRequest); - assertHeaders(indexRequest, expectedHeaders); - assertContext(indexRequest, expectedContext); + IndexRequest indexRequest = Requests.indexRequest(); + putHeaders(indexRequest, transportHeaders); + putContext(indexRequest, transportContext); + assertHeaders(indexRequest, transportHeaders); + client.index(indexRequest); + assertHeaders(indexRequest, expectedHeaders); + assertContext(indexRequest, expectedContext); + } } @Test @@ -155,31 +155,32 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, expectedContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, expectedContext), usefulRestHeaders)) { - ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); - putHeaders(clusterHealthRequest, transportHeaders); - putContext(clusterHealthRequest, transportContext); - assertHeaders(clusterHealthRequest, transportHeaders); - client.admin().cluster().health(clusterHealthRequest); - assertHeaders(clusterHealthRequest, expectedHeaders); - assertContext(clusterHealthRequest, expectedContext); + ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); + putHeaders(clusterHealthRequest, transportHeaders); + putContext(clusterHealthRequest, transportContext); + assertHeaders(clusterHealthRequest, transportHeaders); + client.admin().cluster().health(clusterHealthRequest); + assertHeaders(clusterHealthRequest, expectedHeaders); + assertContext(clusterHealthRequest, expectedContext); - ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); - putHeaders(clusterStateRequest, transportHeaders); - putContext(clusterStateRequest, transportContext); - assertHeaders(clusterStateRequest, transportHeaders); - client.admin().cluster().state(clusterStateRequest); - assertHeaders(clusterStateRequest, expectedHeaders); - assertContext(clusterStateRequest, expectedContext); + ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); + putHeaders(clusterStateRequest, transportHeaders); + putContext(clusterStateRequest, transportContext); + assertHeaders(clusterStateRequest, transportHeaders); + client.admin().cluster().state(clusterStateRequest); + assertHeaders(clusterStateRequest, expectedHeaders); + assertContext(clusterStateRequest, expectedContext); - ClusterStatsRequest clusterStatsRequest = Requests.clusterStatsRequest(); - putHeaders(clusterStatsRequest, transportHeaders); - putContext(clusterStatsRequest, transportContext); - assertHeaders(clusterStatsRequest, transportHeaders); - client.admin().cluster().clusterStats(clusterStatsRequest); - assertHeaders(clusterStatsRequest, expectedHeaders); - assertContext(clusterStatsRequest, expectedContext); + ClusterStatsRequest clusterStatsRequest = Requests.clusterStatsRequest(); + putHeaders(clusterStatsRequest, transportHeaders); + putContext(clusterStatsRequest, transportContext); + assertHeaders(clusterStatsRequest, transportHeaders); + client.admin().cluster().clusterStats(clusterStatsRequest); + assertHeaders(clusterStatsRequest, expectedHeaders); + assertContext(clusterStatsRequest, expectedContext); + } } @Test @@ -200,31 +201,32 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test"); - putHeaders(createIndexRequest, transportHeaders); - putContext(createIndexRequest, transportContext); - assertHeaders(createIndexRequest, transportHeaders); - client.admin().indices().create(createIndexRequest); - assertHeaders(createIndexRequest, expectedHeaders); - assertContext(createIndexRequest, expectedContext); + CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test"); + putHeaders(createIndexRequest, transportHeaders); + putContext(createIndexRequest, transportContext); + assertHeaders(createIndexRequest, transportHeaders); + client.admin().indices().create(createIndexRequest); + assertHeaders(createIndexRequest, expectedHeaders); + assertContext(createIndexRequest, expectedContext); - CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test"); - putHeaders(closeIndexRequest, transportHeaders); - putContext(closeIndexRequest, transportContext); - assertHeaders(closeIndexRequest, transportHeaders); - client.admin().indices().close(closeIndexRequest); - assertHeaders(closeIndexRequest, expectedHeaders); - assertContext(closeIndexRequest, expectedContext); + CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test"); + putHeaders(closeIndexRequest, transportHeaders); + putContext(closeIndexRequest, transportContext); + assertHeaders(closeIndexRequest, transportHeaders); + client.admin().indices().close(closeIndexRequest); + assertHeaders(closeIndexRequest, expectedHeaders); + assertContext(closeIndexRequest, expectedContext); - FlushRequest flushRequest = Requests.flushRequest(); - putHeaders(flushRequest, transportHeaders); - putContext(flushRequest, transportContext); - assertHeaders(flushRequest, transportHeaders); - client.admin().indices().flush(flushRequest); - assertHeaders(flushRequest, expectedHeaders); - assertContext(flushRequest, expectedContext); + FlushRequest flushRequest = Requests.flushRequest(); + putHeaders(flushRequest, transportHeaders); + putContext(flushRequest, transportContext); + assertHeaders(flushRequest, transportHeaders); + client.admin().indices().flush(flushRequest); + assertHeaders(flushRequest, expectedHeaders); + assertContext(flushRequest, expectedContext); + } } @Test @@ -245,25 +247,26 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] { - client.prepareIndex("index", "type"), - client.prepareGet("index", "type", "id"), - client.prepareBulk(), - client.prepareDelete(), - client.prepareIndex(), - client.prepareClearScroll(), - client.prepareMultiGet(), - }; + ActionRequestBuilder requestBuilders[] = new ActionRequestBuilder[]{ + client.prepareIndex("index", "type"), + client.prepareGet("index", "type", "id"), + client.prepareBulk(), + client.prepareDelete(), + client.prepareIndex(), + client.prepareClearScroll(), + client.prepareMultiGet(), + }; - for (ActionRequestBuilder requestBuilder : requestBuilders) { - putHeaders(requestBuilder.request(), transportHeaders); - putContext(requestBuilder.request(), transportContext); - assertHeaders(requestBuilder.request(), transportHeaders); - requestBuilder.get(); - assertHeaders(requestBuilder.request(), expectedHeaders); - assertContext(requestBuilder.request(), expectedContext); + for (ActionRequestBuilder requestBuilder : requestBuilders) { + putHeaders(requestBuilder.request(), transportHeaders); + putContext(requestBuilder.request(), transportContext); + assertHeaders(requestBuilder.request(), transportHeaders); + requestBuilder.get(); + assertHeaders(requestBuilder.request(), expectedHeaders); + assertContext(requestBuilder.request(), expectedContext); + } } } @@ -285,24 +288,25 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] { - client.admin().cluster().prepareNodesInfo(), - client.admin().cluster().prepareClusterStats(), - client.admin().cluster().prepareState(), - client.admin().cluster().prepareCreateSnapshot("repo", "name"), - client.admin().cluster().prepareHealth(), - client.admin().cluster().prepareReroute() - }; + ActionRequestBuilder requestBuilders[] = new ActionRequestBuilder[]{ + client.admin().cluster().prepareNodesInfo(), + client.admin().cluster().prepareClusterStats(), + client.admin().cluster().prepareState(), + client.admin().cluster().prepareCreateSnapshot("repo", "name"), + client.admin().cluster().prepareHealth(), + client.admin().cluster().prepareReroute() + }; - for (ActionRequestBuilder requestBuilder : requestBuilders) { - putHeaders(requestBuilder.request(), transportHeaders); - putContext(requestBuilder.request(), transportContext); - assertHeaders(requestBuilder.request(), transportHeaders); - requestBuilder.get(); - assertHeaders(requestBuilder.request(), expectedHeaders); - assertContext(requestBuilder.request(), expectedContext); + for (ActionRequestBuilder requestBuilder : requestBuilders) { + putHeaders(requestBuilder.request(), transportHeaders); + putContext(requestBuilder.request(), transportContext); + assertHeaders(requestBuilder.request(), transportHeaders); + requestBuilder.get(); + assertHeaders(requestBuilder.request(), expectedHeaders); + assertContext(requestBuilder.request(), expectedContext); + } } } @@ -324,25 +328,26 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] { - client.admin().indices().prepareValidateQuery(), - client.admin().indices().prepareCreate("test"), - client.admin().indices().prepareAliases(), - client.admin().indices().prepareAnalyze("text"), - client.admin().indices().prepareDeleteWarmer(), - client.admin().indices().prepareTypesExists("type"), - client.admin().indices().prepareClose() - }; + ActionRequestBuilder requestBuilders[] = new ActionRequestBuilder[]{ + client.admin().indices().prepareValidateQuery(), + client.admin().indices().prepareCreate("test"), + client.admin().indices().prepareAliases(), + client.admin().indices().prepareAnalyze("text"), + client.admin().indices().prepareDeleteWarmer(), + client.admin().indices().prepareTypesExists("type"), + client.admin().indices().prepareClose() + }; - for (ActionRequestBuilder requestBuilder : requestBuilders) { - putHeaders(requestBuilder.request(), transportHeaders); - putContext(requestBuilder.request(), transportContext); - assertHeaders(requestBuilder.request(), transportHeaders); - requestBuilder.get(); - assertHeaders(requestBuilder.request(), expectedHeaders); - assertContext(requestBuilder.request(), expectedContext); + for (ActionRequestBuilder requestBuilder : requestBuilders) { + putHeaders(requestBuilder.request(), transportHeaders); + putContext(requestBuilder.request(), transportContext); + assertHeaders(requestBuilder.request(), transportHeaders); + requestBuilder.get(); + assertHeaders(requestBuilder.request(), expectedHeaders); + assertContext(requestBuilder.request(), expectedContext); + } } } @@ -417,76 +422,24 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { } } - private static class NoOpClient extends AbstractClient implements AdminClient { + private class NoOpClient extends AbstractClient { - @Override - public AdminClient admin() { - return this; + public NoOpClient() { + super(ImmutableSettings.EMPTY, new ThreadPool(getTestName()), Headers.EMPTY); } @Override - public Settings settings() { - return null; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return null; - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { + protected > void doExecute(Action action, Request request, ActionListener listener) { listener.onResponse(null); } - @Override - public ThreadPool threadPool() { - return null; - } - @Override public void close() { - - } - - @Override - public ClusterAdminClient cluster() { - return new AbstractClusterAdminClient() { - @Override - public > ActionFuture execute(Action action, Request request) { - return null; - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - listener.onResponse(null); - } - - @Override - public ThreadPool threadPool() { - return null; - } - }; - } - - @Override - public IndicesAdminClient indices() { - return new AbstractIndicesAdminClient() { - @Override - public > ActionFuture execute(Action action, Request request) { - return null; - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - listener.onResponse(null); - } - - @Override - public ThreadPool threadPool() { - return null; - } - }; + try { + terminate(threadPool()); + } catch (Throwable t) { + throw new ElasticsearchException(t.getMessage(), t); + } } } } diff --git a/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java b/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java index 1f04063a42d..2c8a7ddbc0d 100644 --- a/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java +++ b/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.script.expression; -import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -53,7 +52,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { paramsMap.put(params[i].toString(), params[i + 1]); } - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.matchAllQuery()) .addSort(SortBuilders.fieldSort("_uid") .order(SortOrder.ASC)).addScriptField("foo", "expression", script, paramsMap); @@ -86,7 +85,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "doc", "2").setSource("text", "hello hello hello goodbye"), client().prepareIndex("test", "doc", "3").setSource("text", "hello hello goodebye")); ScoreFunctionBuilder score = ScoreFunctionBuilders.scriptFunction("1 / _score", "expression"); - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode("replace")); req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent SearchResponse rsp = req.get(); @@ -274,7 +273,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "doc", "2").setSource("x", 10, "y", 1.4), client().prepareIndex("test", "doc", "3").setSource("x", 13, "y", 1.8)); - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.matchAllQuery()) .addAggregation(AggregationBuilders.stats("int_agg").field("x").script("_value * 3").lang(ExpressionScriptEngineService.NAME)) .addAggregation(AggregationBuilders.stats("double_agg").field("y").script("_value - 1.1").lang(ExpressionScriptEngineService.NAME)); @@ -300,7 +299,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "doc", "2").setSource("text", "goodbye"), client().prepareIndex("test", "doc", "3").setSource("text", "hello")); - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.matchAllQuery()) .addAggregation(AggregationBuilders.terms("term_agg").field("text").script("_value").lang(ExpressionScriptEngineService.NAME)); diff --git a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java index c00ceec27b3..d11cec0ab0a 100644 --- a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java +++ b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java @@ -42,7 +42,7 @@ public class ClientFailover { // TODO: what is this? a public static void main test?!?! - final TransportClient client = new TransportClient(ImmutableSettings.EMPTY) + final TransportClient client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress("localhost", 9300)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9301)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9302)); diff --git a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java index fb113a604b7..0426ab647fd 100644 --- a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java +++ b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java @@ -49,7 +49,7 @@ public class ManyIndicesRemoteStressTest { Node node = null; // TODO: what is this? a public static void main test?!?!?! if (true) { - client = new TransportClient(ImmutableSettings.EMPTY).addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); + client = TransportClient.builder().settings(ImmutableSettings.EMPTY).build().addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); } else { node = NodeBuilder.nodeBuilder().client(true).node(); client = node.client(); diff --git a/src/test/java/org/elasticsearch/test/CompositeTestCluster.java b/src/test/java/org/elasticsearch/test/CompositeTestCluster.java index 1e258abfa2a..03f4590daa5 100644 --- a/src/test/java/org/elasticsearch/test/CompositeTestCluster.java +++ b/src/test/java/org/elasticsearch/test/CompositeTestCluster.java @@ -26,9 +26,7 @@ import org.apache.lucene.util.IOUtils; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.FilterClient; -import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -292,34 +290,7 @@ public class CompositeTestCluster extends TestCluster { private final class ExternalClient extends FilterClient { public ExternalClient() { - super(null); - } - - @Override - protected Client in() { - return internalClient(); - } - - @Override - public ClusterAdminClient cluster() { - return new ClusterAdmin(null) { - - @Override - protected ClusterAdminClient in() { - return internalClient().admin().cluster(); - } - }; - } - - @Override - public IndicesAdminClient indices() { - return new IndicesAdmin(null) { - - @Override - protected IndicesAdminClient in() { - return internalClient().admin().indices(); - } - }; + super(internalClient()); } @Override @@ -327,5 +298,4 @@ public class CompositeTestCluster extends TestCluster { // never close this client } } - } diff --git a/src/test/java/org/elasticsearch/test/ExternalNode.java b/src/test/java/org/elasticsearch/test/ExternalNode.java index f304b71cd4b..bc520988a68 100644 --- a/src/test/java/org/elasticsearch/test/ExternalNode.java +++ b/src/test/java/org/elasticsearch/test/ExternalNode.java @@ -21,7 +21,6 @@ package org.elasticsearch.test; import com.google.common.base.Predicate; import org.apache.lucene.util.Constants; -import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; @@ -200,7 +199,7 @@ final class ExternalNode implements Closeable { .put("client.transport.nodes_sampler_interval", "1s") .put("name", "transport_client_" + nodeInfo.getNode().name()) .put(ClusterName.SETTING, clusterName).put("client.transport.sniff", false).build(); - TransportClient client = new TransportClient(clientSettings); + TransportClient client = TransportClient.builder().settings(clientSettings).build(); client.addTransportAddress(addr); this.client = client; } diff --git a/src/test/java/org/elasticsearch/test/ExternalTestCluster.java b/src/test/java/org/elasticsearch/test/ExternalTestCluster.java index c0052f24044..cd30b9937fb 100644 --- a/src/test/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/ExternalTestCluster.java @@ -72,7 +72,7 @@ public final class ExternalTestCluster extends TestCluster { .put("client.transport.ignore_cluster_name", true) .put("node.mode", "network").build(); // we require network here! - this.client = new TransportClient(clientSettings).addTransportAddresses(transportAddresses); + this.client = TransportClient.builder().settings(clientSettings).build().addTransportAddresses(transportAddresses); NodesInfoResponse nodeInfos = this.client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); httpAddresses = new InetSocketAddress[nodeInfos.getNodes().length]; diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 639b30ede4f..92797894e38 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -864,7 +864,7 @@ public final class InternalTestCluster extends TestCluster { .put("config.ignore_system_properties", true) .put(settings); - TransportClient client = new TransportClient(builder.build()); + TransportClient client = TransportClient.builder().settings(builder.build()).build(); client.addTransportAddress(addr); return client; } diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 7a822e163cb..ab59da837e4 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -90,7 +90,7 @@ import static org.hamcrest.Matchers.*; */ public class ElasticsearchAssertions { - public static void assertAcked(AcknowledgedRequestBuilder builder) { + public static void assertAcked(AcknowledgedRequestBuilder builder) { assertAcked(builder.get()); } @@ -501,14 +501,14 @@ public class ElasticsearchAssertions { /** * Run the request from a given builder and check that it throws an exception of the right type */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass) { assertThrows(builder.execute(), exceptionClass); } /** * Run the request from a given builder and check that it throws an exception of the right type, with a given {@link org.elasticsearch.rest.RestStatus} */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, RestStatus status) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, RestStatus status) { assertThrows(builder.execute(), exceptionClass, status); } @@ -517,7 +517,7 @@ public class ElasticsearchAssertions { * * @param extraInfo extra information to add to the failure message */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, String extraInfo) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, String extraInfo) { assertThrows(builder.execute(), exceptionClass, extraInfo); } @@ -582,11 +582,11 @@ public class ElasticsearchAssertions { } } - public static void assertThrows(ActionRequestBuilder builder, RestStatus status) { + public static void assertThrows(ActionRequestBuilder builder, RestStatus status) { assertThrows(builder.execute(), status); } - public static void assertThrows(ActionRequestBuilder builder, RestStatus status, String extraInfo) { + public static void assertThrows(ActionRequestBuilder builder, RestStatus status, String extraInfo) { assertThrows(builder.execute(), status, extraInfo); } diff --git a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java index 53919f8a718..ac54fb70e07 100644 --- a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java +++ b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java @@ -68,7 +68,7 @@ public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegr .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) .put("path.home", createTempDir().toString()) .build(); - try (TransportClient transportClient = new TransportClient(settings, false)) { + try (TransportClient transportClient = TransportClient.builder().settings(settings).loadConfigSettings(false).build()) { transportClient.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", randomPort)); ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get(); assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));