diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java index 3b399fa4461..14d92e0dece 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java @@ -20,8 +20,6 @@ package org.elasticsearch.action.admin.indices.analyze; import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.IndicesRequest; -import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -36,9 +34,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; * A request to analyze a text associated with a specific index. Allow to provide * the actual analyzer name to perform the analysis with. */ -public class AnalyzeRequest extends SingleCustomOperationRequest implements IndicesRequest { - - private String index; +public class AnalyzeRequest extends SingleCustomOperationRequest { private String text; @@ -72,7 +68,7 @@ public class AnalyzeRequest extends SingleCustomOperationRequest * @param text The text to analyze */ public AnalyzeRequest(@Nullable String index, String text) { - this.index = index; + this.index(index); this.text = text; } @@ -80,28 +76,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest return this.text; } - public AnalyzeRequest index(String index) { - this.index = index; - return this; - } - - public String index() { - return this.index; - } - - @Override - public String[] indices() { - if (index == null) { - return Strings.EMPTY_ARRAY; - } - return new String[]{index}; - } - - @Override - public IndicesOptions indicesOptions() { - return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); - } - public AnalyzeRequest analyzer(String analyzer) { this.analyzer = analyzer; return this; @@ -165,7 +139,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readOptionalString(); text = in.readString(); analyzer = in.readOptionalString(); tokenizer = in.readOptionalString(); @@ -179,7 +152,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeOptionalString(index); out.writeString(text); out.writeOptionalString(analyzer); out.writeOptionalString(tokenizer); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java index 72e6de3b995..92f911e2205 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java @@ -27,12 +27,12 @@ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.analysis.tokenattributes.TypeAttribute; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchIllegalArgumentException; +import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.single.custom.TransportSingleCustomOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.ImmutableSettings; @@ -44,13 +44,15 @@ import org.elasticsearch.index.service.IndexService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.BaseTransportRequestHandler; +import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import java.io.IOException; import java.util.List; /** - * + * Transport action used to execute analyze requests */ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction { @@ -64,6 +66,7 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction super(settings, AnalyzeAction.NAME, threadPool, clusterService, transportService, actionFilters); this.indicesService = indicesService; this.indicesAnalysisService = indicesAnalysisService; + transportService.registerHandler(AnalyzeAction.NAME, new TransportHandler()); } @Override @@ -81,16 +84,11 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction return new AnalyzeResponse(); } - @Override - protected ClusterBlockException checkGlobalBlock(ClusterState state, AnalyzeRequest request) { - return state.blocks().globalBlockedException(ClusterBlockLevel.READ); - } - @Override protected ClusterBlockException checkRequestBlock(ClusterState state, AnalyzeRequest request) { if (request.index() != null) { request.index(state.metaData().concreteSingleIndex(request.index(), request.indicesOptions())); - return state.blocks().indexBlockedException(ClusterBlockLevel.READ, request.index()); + return super.checkRequestBlock(state, request); } return null; } @@ -253,4 +251,44 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction return new AnalyzeResponse(tokens); } + + private class TransportHandler extends BaseTransportRequestHandler { + + @Override + public AnalyzeRequest newInstance() { + return newRequest(); + } + + @Override + public void messageReceived(AnalyzeRequest request, final TransportChannel channel) throws Exception { + // no need to have a threaded listener since we just send back a response + request.listenerThreaded(false); + // if we have a local operation, execute it on a thread since we don't spawn + request.operationThreaded(true); + execute(request, new ActionListener() { + @Override + public void onResponse(AnalyzeResponse result) { + try { + channel.sendResponse(result); + } catch (Throwable e) { + onFailure(e); + } + } + + @Override + public void onFailure(Throwable e) { + try { + channel.sendResponse(e); + } catch (Exception e1) { + logger.warn("Failed to send response for get", e1); + } + } + }); + } + + @Override + public String executor() { + return ThreadPool.Names.SAME; + } + } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsIndexRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsIndexRequest.java index d25fcb7c10e..98df1dc0c71 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsIndexRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsIndexRequest.java @@ -19,9 +19,6 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.IndicesRequest; -import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -29,9 +26,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; -class GetFieldMappingsIndexRequest extends SingleCustomOperationRequest implements IndicesRequest { - - private String index; +class GetFieldMappingsIndexRequest extends SingleCustomOperationRequest { private boolean probablySingleFieldRequest; private boolean includeDefaults; @@ -48,21 +43,7 @@ class GetFieldMappingsIndexRequest extends SingleCustomOperationRequest { @@ -125,16 +124,6 @@ public class TransportGetFieldMappingsIndexAction extends TransportSingleCustomO return new GetFieldMappingsResponse(); } - @Override - protected ClusterBlockException checkGlobalBlock(ClusterState state, GetFieldMappingsIndexRequest request) { - return state.blocks().globalBlockedException(ClusterBlockLevel.READ); - } - - @Override - protected ClusterBlockException checkRequestBlock(ClusterState state, GetFieldMappingsIndexRequest request) { - return state.blocks().indexBlockedException(ClusterBlockLevel.READ, request.index()); - } - private static final ToXContent.Params includeDefaultsParams = new ToXContent.Params() { final static String INCLUDE_DEFAULTS = "include_defaults"; diff --git a/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequest.java b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequest.java index 9b20f458af3..cc7fb722e65 100644 --- a/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequest.java +++ b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequest.java @@ -20,6 +20,9 @@ package org.elasticsearch.action.support.single.custom; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.IndicesRequest; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -28,10 +31,11 @@ import java.io.IOException; /** * */ -public abstract class SingleCustomOperationRequest extends ActionRequest { +public abstract class SingleCustomOperationRequest extends ActionRequest implements IndicesRequest { private boolean threadedOperation = true; private boolean preferLocal = true; + private String index; protected SingleCustomOperationRequest() { } @@ -67,6 +71,29 @@ public abstract class SingleCustomOperationRequesttrue @@ -83,12 +110,22 @@ public abstract class SingleCustomOperationRequest extends TransportAction { @@ -59,7 +61,6 @@ public abstract class TransportSingleCustomOperationAction { - - @Override - public Request newInstance() { - return newRequest(); - } - - @Override - public void messageReceived(Request request, final TransportChannel channel) throws Exception { - // no need to have a threaded listener since we just send back a response - request.listenerThreaded(false); - // if we have a local operation, execute it on a thread since we don't spawn - request.operationThreaded(true); - execute(request, new ActionListener() { - @Override - public void onResponse(Response result) { - try { - channel.sendResponse(result); - } catch (Throwable e) { - onFailure(e); - } - } - - @Override - public void onFailure(Throwable e) { - try { - channel.sendResponse(e); - } catch (Exception e1) { - logger.warn("Failed to send response for get", e1); - } - } - }); - } - - @Override - public String executor() { - return ThreadPool.Names.SAME; - } - } - private class ShardTransportHandler extends BaseTransportRequestHandler { @Override diff --git a/src/main/java/org/elasticsearch/transport/ActionNames.java b/src/main/java/org/elasticsearch/transport/ActionNames.java index a0f608b16bd..46cca47c29d 100644 --- a/src/main/java/org/elasticsearch/transport/ActionNames.java +++ b/src/main/java/org/elasticsearch/transport/ActionNames.java @@ -205,7 +205,6 @@ final class ActionNames { builder.put(DeleteMappingAction.NAME, "indices/mapping/delete"); builder.put(PutMappingAction.NAME, "indices/mapping/put"); builder.put(GetFieldMappingsAction.NAME, "mappings/fields/get"); - builder.put(GetFieldMappingsAction.NAME + "[index]", "mappings/fields/get/index"); builder.put(GetFieldMappingsAction.NAME + "[index][s]", "mappings/fields/get/index/s"); builder.put(GetMappingsAction.NAME, "mappings/get");