Don't inject TransportPercolateAction into RestPercolateAction

Instead use the client. This will help us build the actions more
easily in the future.
This commit is contained in:
Nik Everett 2016-06-29 18:41:31 -04:00
parent b5bb27cf90
commit e359be7632
3 changed files with 12 additions and 17 deletions

View File

@ -1168,7 +1168,6 @@
<suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]TransportMultiPercolateAction.java" checks="LineLength" /> <suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]TransportMultiPercolateAction.java" checks="LineLength" />
<suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]TransportPercolateAction.java" checks="LineLength" /> <suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]TransportPercolateAction.java" checks="LineLength" />
<suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]TransportShardMultiPercolateAction.java" checks="LineLength" /> <suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]TransportShardMultiPercolateAction.java" checks="LineLength" />
<suppress files="modules[/\\]percolator[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]RestPercolateAction.java" checks="LineLength" />
<suppress files="modules[/\\]percolator[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]MultiPercolatorIT.java" checks="LineLength" /> <suppress files="modules[/\\]percolator[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]MultiPercolatorIT.java" checks="LineLength" />
<suppress files="modules[/\\]percolator[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]PercolatorIT.java" checks="LineLength" /> <suppress files="modules[/\\]percolator[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]PercolatorIT.java" checks="LineLength" />
<suppress files="modules[/\\]percolator[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]MultiPercolatorRequestTests.java" checks="LineLength" /> <suppress files="modules[/\\]percolator[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]percolator[/\\]MultiPercolatorRequestTests.java" checks="LineLength" />

View File

@ -36,13 +36,10 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestMultiPercolateAction extends BaseRestHandler { public class RestMultiPercolateAction extends BaseRestHandler {
private final boolean allowExplicitIndex; private final boolean allowExplicitIndex;
private final TransportMultiPercolateAction action;
@Inject @Inject
public RestMultiPercolateAction(Settings settings, RestController controller, Client client, public RestMultiPercolateAction(Settings settings, RestController controller, Client client) {
TransportMultiPercolateAction action) {
super(settings, client); super(settings, client);
this.action = action;
controller.registerHandler(POST, "/_mpercolate", this); controller.registerHandler(POST, "/_mpercolate", this);
controller.registerHandler(POST, "/{index}/_mpercolate", this); controller.registerHandler(POST, "/{index}/_mpercolate", this);
controller.registerHandler(POST, "/{index}/{type}/_mpercolate", this); controller.registerHandler(POST, "/{index}/{type}/_mpercolate", this);
@ -61,7 +58,8 @@ public class RestMultiPercolateAction extends BaseRestHandler {
multiPercolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("index"))); multiPercolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("index")));
multiPercolateRequest.documentType(restRequest.param("type")); multiPercolateRequest.documentType(restRequest.param("type"));
multiPercolateRequest.add(RestActions.getRestContent(restRequest), allowExplicitIndex); multiPercolateRequest.add(RestActions.getRestContent(restRequest), allowExplicitIndex);
action.execute(multiPercolateRequest, new RestToXContentListener<MultiPercolateResponse>(restChannel)); client.execute(MultiPercolateAction.INSTANCE, multiPercolateRequest,
new RestToXContentListener<MultiPercolateResponse>(restChannel));
} }
} }

View File

@ -36,13 +36,9 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestPercolateAction extends BaseRestHandler { public class RestPercolateAction extends BaseRestHandler {
private final TransportPercolateAction action;
@Inject @Inject
public RestPercolateAction(Settings settings, RestController controller, Client client, TransportPercolateAction action) { public RestPercolateAction(Settings settings, RestController controller, Client client) {
super(settings, client); super(settings, client);
this.action = action;
controller.registerHandler(GET, "/{index}/{type}/_percolate", this); controller.registerHandler(GET, "/{index}/{type}/_percolate", this);
controller.registerHandler(POST, "/{index}/{type}/_percolate", this); controller.registerHandler(POST, "/{index}/{type}/_percolate", this);
@ -54,7 +50,8 @@ public class RestPercolateAction extends BaseRestHandler {
controller.registerHandler(GET, "/{index}/{type}/_percolate/count", countHandler); controller.registerHandler(GET, "/{index}/{type}/_percolate/count", countHandler);
controller.registerHandler(POST, "/{index}/{type}/_percolate/count", countHandler); controller.registerHandler(POST, "/{index}/{type}/_percolate/count", countHandler);
RestCountPercolateExistingDocHandler countExistingDocHandler = new RestCountPercolateExistingDocHandler(settings, controller, client); RestCountPercolateExistingDocHandler countExistingDocHandler = new RestCountPercolateExistingDocHandler(settings, controller,
client);
controller.registerHandler(GET, "/{index}/{type}/{id}/_percolate/count", countExistingDocHandler); controller.registerHandler(GET, "/{index}/{type}/{id}/_percolate/count", countExistingDocHandler);
controller.registerHandler(POST, "/{index}/{type}/{id}/_percolate/count", countExistingDocHandler); controller.registerHandler(POST, "/{index}/{type}/{id}/_percolate/count", countExistingDocHandler);
} }
@ -67,10 +64,11 @@ public class RestPercolateAction extends BaseRestHandler {
percolateRequest.source(RestActions.getRestContent(restRequest)); percolateRequest.source(RestActions.getRestContent(restRequest));
percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions())); percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
executePercolate(percolateRequest, restChannel); executePercolate(client, percolateRequest, restChannel);
} }
void parseExistingDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel, final Client client) { void parseExistingDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel,
final Client client) {
String index = restRequest.param("index"); String index = restRequest.param("index");
String type = restRequest.param("type"); String type = restRequest.param("type");
percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("percolate_index", index))); percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("percolate_index", index)));
@ -91,11 +89,11 @@ public class RestPercolateAction extends BaseRestHandler {
percolateRequest.source(RestActions.getRestContent(restRequest)); percolateRequest.source(RestActions.getRestContent(restRequest));
percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions())); percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
executePercolate(percolateRequest, restChannel); executePercolate(client, percolateRequest, restChannel);
} }
void executePercolate(final PercolateRequest percolateRequest, final RestChannel restChannel) { void executePercolate(final Client client, final PercolateRequest percolateRequest, final RestChannel restChannel) {
action.execute(percolateRequest, new RestToXContentListener<>(restChannel)); client.execute(PercolateAction.INSTANCE, percolateRequest, new RestToXContentListener<>(restChannel));
} }
@Override @Override