Merge branch 'master' into index-lifecycle
This commit is contained in:
commit
eee1a451fc
|
@ -19,10 +19,9 @@
|
|||
package org.elasticsearch.plugin.noop.action.bulk;
|
||||
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
|
||||
public class NoopBulkAction extends Action<BulkRequest, BulkResponse> {
|
||||
public class NoopBulkAction extends Action<BulkResponse> {
|
||||
public static final String NAME = "mock:data/write/bulk";
|
||||
|
||||
public static final NoopBulkAction INSTANCE = new NoopBulkAction();
|
||||
|
|
|
@ -19,10 +19,9 @@
|
|||
package org.elasticsearch.plugin.noop.action.search;
|
||||
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
||||
public class NoopSearchAction extends Action<SearchRequest, SearchResponse> {
|
||||
public class NoopSearchAction extends Action<SearchResponse> {
|
||||
public static final NoopSearchAction INSTANCE = new NoopSearchAction();
|
||||
public static final String NAME = "mock:data/read/search";
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRe
|
|||
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
|
||||
|
@ -892,6 +894,23 @@ final class RequestConverters {
|
|||
return request;
|
||||
}
|
||||
|
||||
static Request getScript(GetStoredScriptRequest getStoredScriptRequest) {
|
||||
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(getStoredScriptRequest.id()).build();
|
||||
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
Params params = new Params(request);
|
||||
params.withMasterTimeout(getStoredScriptRequest.masterNodeTimeout());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request deleteScript(DeleteStoredScriptRequest deleteStoredScriptRequest) {
|
||||
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(deleteStoredScriptRequest.id()).build();
|
||||
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
|
||||
Params params = new Params(request);
|
||||
params.withTimeout(deleteStoredScriptRequest.timeout());
|
||||
params.withMasterTimeout(deleteStoredScriptRequest.masterNodeTimeout());
|
||||
return request;
|
||||
}
|
||||
|
||||
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
|
||||
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
|
||||
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));
|
||||
|
|
|
@ -26,6 +26,10 @@ import org.elasticsearch.ElasticsearchStatusException;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptResponse;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
|
@ -652,6 +656,62 @@ public class RestHighLevelClient implements Closeable {
|
|||
FieldCapabilitiesResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored script by id.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
|
||||
* How to use scripts on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public GetStoredScriptResponse getScript(GetStoredScriptRequest request, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(request, RequestConverters::getScript, options,
|
||||
GetStoredScriptResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously get stored script by id.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
|
||||
* How to use scripts on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void getScriptAsync(GetStoredScriptRequest request, RequestOptions options,
|
||||
ActionListener<GetStoredScriptResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(request, RequestConverters::getScript, options,
|
||||
GetStoredScriptResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete stored script by id.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
|
||||
* How to use scripts on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public DeleteStoredScriptResponse deleteScript(DeleteStoredScriptRequest request, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(request, RequestConverters::deleteScript, options,
|
||||
DeleteStoredScriptResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously delete stored script by id.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
|
||||
* How to use scripts on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void deleteScriptAsync(DeleteStoredScriptRequest request, RequestOptions options,
|
||||
ActionListener<DeleteStoredScriptResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(request, RequestConverters::deleteScript, options,
|
||||
DeleteStoredScriptResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a request using the Field Capabilities API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html">Field Capabilities API
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRe
|
|||
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||
|
@ -1948,6 +1950,32 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
assertThat(request.getEntity(), nullValue());
|
||||
}
|
||||
|
||||
public void testGetScriptRequest() {
|
||||
GetStoredScriptRequest getStoredScriptRequest = new GetStoredScriptRequest("x-script");
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(getStoredScriptRequest, expectedParams);
|
||||
|
||||
Request request = RequestConverters.getScript(getStoredScriptRequest);
|
||||
assertThat(request.getEndpoint(), equalTo("/_scripts/" + getStoredScriptRequest.id()));
|
||||
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
assertThat(request.getEntity(), nullValue());
|
||||
}
|
||||
|
||||
public void testDeleteScriptRequest() {
|
||||
DeleteStoredScriptRequest deleteStoredScriptRequest = new DeleteStoredScriptRequest("x-script");
|
||||
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomTimeout(deleteStoredScriptRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
setRandomMasterTimeout(deleteStoredScriptRequest, expectedParams);
|
||||
|
||||
Request request = RequestConverters.deleteScript(deleteStoredScriptRequest);
|
||||
assertThat(request.getEndpoint(), equalTo("/_scripts/" + deleteStoredScriptRequest.id()));
|
||||
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
assertThat(request.getEntity(), nullValue());
|
||||
}
|
||||
|
||||
private static void assertToXContentBody(ToXContent expectedBody, HttpEntity actualEntity) throws IOException {
|
||||
BytesReference expectedBytes = XContentHelper.toXContent(expectedBody, REQUEST_BODY_CONTENT_TYPE, false);
|
||||
assertEquals(XContentType.JSON.mediaTypeWithoutParameters(), actualEntity.getContentType().getValue());
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package org.elasticsearch.client;/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptResponse;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.StoredScriptSource;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class StoredScriptsIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
final String id = "calculate-score";
|
||||
|
||||
public void testGetStoredScript() throws Exception {
|
||||
final StoredScriptSource scriptSource =
|
||||
new StoredScriptSource("painless",
|
||||
"Math.log(_score * 2) + params.my_modifier",
|
||||
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()));
|
||||
|
||||
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
|
||||
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
|
||||
// so far - using low-level REST API
|
||||
Response putResponse =
|
||||
adminClient()
|
||||
.performRequest("PUT", "/_scripts/calculate-score", emptyMap(),
|
||||
new StringEntity("{\"script\":" + script + "}",
|
||||
ContentType.APPLICATION_JSON));
|
||||
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
|
||||
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
|
||||
|
||||
GetStoredScriptRequest getRequest = new GetStoredScriptRequest("calculate-score");
|
||||
getRequest.masterNodeTimeout("50s");
|
||||
|
||||
GetStoredScriptResponse getResponse = execute(getRequest, highLevelClient()::getScript,
|
||||
highLevelClient()::getScriptAsync);
|
||||
|
||||
assertThat(getResponse.getSource(), equalTo(scriptSource));
|
||||
}
|
||||
|
||||
public void testDeleteStoredScript() throws Exception {
|
||||
final StoredScriptSource scriptSource =
|
||||
new StoredScriptSource("painless",
|
||||
"Math.log(_score * 2) + params.my_modifier",
|
||||
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()));
|
||||
|
||||
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
|
||||
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
|
||||
// so far - using low-level REST API
|
||||
Response putResponse =
|
||||
adminClient()
|
||||
.performRequest("PUT", "/_scripts/" + id, emptyMap(),
|
||||
new StringEntity("{\"script\":" + script + "}",
|
||||
ContentType.APPLICATION_JSON));
|
||||
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
|
||||
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
|
||||
|
||||
DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest(id);
|
||||
deleteRequest.masterNodeTimeout("50s");
|
||||
deleteRequest.timeout("50s");
|
||||
|
||||
DeleteStoredScriptResponse deleteResponse = execute(deleteRequest, highLevelClient()::deleteScript,
|
||||
highLevelClient()::deleteScriptAsync);
|
||||
|
||||
assertThat(deleteResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id);
|
||||
|
||||
final ElasticsearchStatusException statusException = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(getRequest, highLevelClient()::getScript,
|
||||
highLevelClient()::getScriptAsync));
|
||||
assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
package org.elasticsearch.client.documentation;/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.LatchedActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptResponse;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.StoredScriptSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* This class is used to generate the Java Stored Scripts API documentation.
|
||||
* You need to wrap your code between two tags like:
|
||||
* // tag::example
|
||||
* // end::example
|
||||
*
|
||||
* Where example is your tag name.
|
||||
*
|
||||
* Then in the documentation, you can extract what is between tag and end tags with
|
||||
* ["source","java",subs="attributes,callouts,macros"]
|
||||
* --------------------------------------------------
|
||||
* include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[example]
|
||||
* --------------------------------------------------
|
||||
*
|
||||
* The column width of the code block is 84. If the code contains a line longer
|
||||
* than 84, the line will be cut and a horizontal scroll bar will be displayed.
|
||||
* (the code indentation of the tag is not included in the width)
|
||||
*/
|
||||
public class StoredScriptsDocumentationIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
public void testGetStoredScript() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
final StoredScriptSource scriptSource =
|
||||
new StoredScriptSource("painless",
|
||||
"Math.log(_score * 2) + params.my_modifier",
|
||||
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()));
|
||||
|
||||
putStoredScript("calculate-score", scriptSource);
|
||||
|
||||
{
|
||||
// tag::get-stored-script-request
|
||||
GetStoredScriptRequest request = new GetStoredScriptRequest("calculate-score"); // <1>
|
||||
// end::get-stored-script-request
|
||||
|
||||
// tag::get-stored-script-request-masterTimeout
|
||||
request.masterNodeTimeout(TimeValue.timeValueSeconds(50)); // <1>
|
||||
request.masterNodeTimeout("50s"); // <2>
|
||||
// end::get-stored-script-request-masterTimeout
|
||||
|
||||
// tag::get-stored-script-execute
|
||||
GetStoredScriptResponse getResponse = client.getScript(request, RequestOptions.DEFAULT);
|
||||
// end::get-stored-script-execute
|
||||
|
||||
// tag::get-stored-script-response
|
||||
StoredScriptSource storedScriptSource = getResponse.getSource(); // <1>
|
||||
|
||||
String lang = storedScriptSource.getLang(); // <2>
|
||||
String source = storedScriptSource.getSource(); // <3>
|
||||
Map<String, String> options = storedScriptSource.getOptions(); // <4>
|
||||
// end::get-stored-script-response
|
||||
|
||||
assertThat(storedScriptSource, equalTo(scriptSource));
|
||||
|
||||
// tag::get-stored-script-execute-listener
|
||||
ActionListener<GetStoredScriptResponse> listener =
|
||||
new ActionListener<GetStoredScriptResponse>() {
|
||||
@Override
|
||||
public void onResponse(GetStoredScriptResponse response) {
|
||||
// <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::get-stored-script-execute-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::get-stored-script-execute-async
|
||||
client.getScriptAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::get-stored-script-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testDeleteStoredScript() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
final StoredScriptSource scriptSource =
|
||||
new StoredScriptSource("painless",
|
||||
"Math.log(_score * 2) + params.my_modifier",
|
||||
Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()));
|
||||
|
||||
putStoredScript("calculate-score", scriptSource);
|
||||
|
||||
// tag::delete-stored-script-request
|
||||
DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest("calculate-score"); // <1>
|
||||
// end::delete-stored-script-request
|
||||
|
||||
// tag::delete-stored-script-request-masterTimeout
|
||||
deleteRequest.masterNodeTimeout(TimeValue.timeValueSeconds(50)); // <1>
|
||||
deleteRequest.masterNodeTimeout("50s"); // <2>
|
||||
// end::delete-stored-script-request-masterTimeout
|
||||
|
||||
// tag::delete-stored-script-request-timeout
|
||||
deleteRequest.timeout(TimeValue.timeValueSeconds(60)); // <1>
|
||||
deleteRequest.timeout("60s"); // <2>
|
||||
// end::delete-stored-script-request-timeout
|
||||
|
||||
// tag::delete-stored-script-execute
|
||||
DeleteStoredScriptResponse deleteResponse = client.deleteScript(deleteRequest, RequestOptions.DEFAULT);
|
||||
// end::delete-stored-script-execute
|
||||
|
||||
// tag::delete-stored-script-response
|
||||
boolean acknowledged = deleteResponse.isAcknowledged();// <1>
|
||||
// end::delete-stored-script-response
|
||||
|
||||
putStoredScript("calculate-score", scriptSource);
|
||||
|
||||
// tag::delete-stored-script-execute-listener
|
||||
ActionListener<DeleteStoredScriptResponse> listener =
|
||||
new ActionListener<DeleteStoredScriptResponse>() {
|
||||
@Override
|
||||
public void onResponse(DeleteStoredScriptResponse response) {
|
||||
// <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::delete-stored-script-execute-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::delete-stored-script-execute-async
|
||||
client.deleteScriptAsync(deleteRequest, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::delete-stored-script-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
private void putStoredScript(String id, StoredScriptSource scriptSource) throws IOException {
|
||||
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
|
||||
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
|
||||
// so far - using low-level REST API
|
||||
Response putResponse =
|
||||
adminClient()
|
||||
.performRequest("PUT", "/_scripts/" + id, emptyMap(),
|
||||
new StringEntity("{\"script\":" + script + "}",
|
||||
ContentType.APPLICATION_JSON));
|
||||
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
|
||||
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ my @Groups = (
|
|||
">enhancement", ">bug", ">regression", ">upgrade"
|
||||
);
|
||||
my %Ignore = map { $_ => 1 }
|
||||
( ">non-issue", ">refactoring", ">docs", ">test", ":Core/Build" );
|
||||
( ">non-issue", ">refactoring", ">docs", ">test", ">test-failure", ":Core/Build" );
|
||||
|
||||
my %Group_Labels = (
|
||||
'>breaking' => 'Breaking changes',
|
||||
|
|
|
@ -99,11 +99,13 @@ Note that you can also add arrays with `startArray(String)` and
|
|||
other XContentBuilder objects.
|
||||
|
||||
If you need to see the generated JSON content, you can use the
|
||||
`string()` method.
|
||||
`Strings.toString()` method.
|
||||
|
||||
[source,java]
|
||||
--------------------------------------------------
|
||||
String json = builder.string();
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
||||
String json = Strings.toString(builder);
|
||||
--------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
[[java-rest-high-delete-stored-script]]
|
||||
|
||||
=== Delete Stored Script API
|
||||
|
||||
[[java-rest-high-delete-stored-script-request]]
|
||||
==== Delete Stored Script Request
|
||||
|
||||
A `DeleteStoredScriptRequest` requires an `id`:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-request]
|
||||
--------------------------------------------------
|
||||
<1> The id of the script
|
||||
|
||||
==== Optional arguments
|
||||
The following arguments can optionally be provided:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-request-timeout]
|
||||
--------------------------------------------------
|
||||
<1> Timeout to wait for the all the nodes to acknowledge the stored script is deleted as a `TimeValue`
|
||||
<2> Timeout to wait for the all the nodes to acknowledge the stored script is deleted as a `String`
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-request-masterTimeout]
|
||||
--------------------------------------------------
|
||||
<1> Timeout to connect to the master node as a `TimeValue`
|
||||
<2> Timeout to connect to the master node as a `String`
|
||||
|
||||
[[java-rest-high-delete-stored-script-sync]]
|
||||
==== Synchronous Execution
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-execute]
|
||||
--------------------------------------------------
|
||||
|
||||
[[java-rest-high-delete-stored-script-async]]
|
||||
==== Asynchronous Execution
|
||||
|
||||
The asynchronous execution of a delete stored script request requires both the `DeleteStoredScriptRequest`
|
||||
instance and an `ActionListener` instance to be passed to the asynchronous method:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-execute-async]
|
||||
--------------------------------------------------
|
||||
<1> The `DeleteStoredScriptRequest` to execute and the `ActionListener` to use when
|
||||
the execution completes
|
||||
|
||||
[[java-rest-high-delete-stored-script-listener]]
|
||||
===== Action Listener
|
||||
|
||||
The asynchronous method does not block and returns immediately. Once it is
|
||||
completed the `ActionListener` is called back using the `onResponse` method
|
||||
if the execution successfully completed or using the `onFailure` method if
|
||||
it failed.
|
||||
|
||||
A typical listener for `DeleteStoredScriptResponse` looks like:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-execute-listener]
|
||||
--------------------------------------------------
|
||||
<1> Called when the execution is successfully completed. The response is
|
||||
provided as an argument
|
||||
<2> Called in case of failure. The raised exception is provided as an argument
|
||||
|
||||
[[java-rest-high-delete-stored-script-response]]
|
||||
==== Delete Stored Script Response
|
||||
|
||||
The returned `DeleteStoredScriptResponse` allows to retrieve information about the
|
||||
executed operation as follows:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[delete-stored-script-response]
|
||||
--------------------------------------------------
|
||||
<1> Indicates whether all of the nodes have acknowledged the request
|
|
@ -0,0 +1,77 @@
|
|||
[[java-rest-high-get-stored-script]]
|
||||
|
||||
=== Get Stored Script API
|
||||
|
||||
[[java-rest-high-get-stored-script-request]]
|
||||
==== Get Stored Script Request
|
||||
|
||||
A `GetStoredScriptRequest` requires an `id`:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-request]
|
||||
--------------------------------------------------
|
||||
<1> The id of the script
|
||||
|
||||
==== Optional arguments
|
||||
The following arguments can optionally be provided:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-request-masterTimeout]
|
||||
--------------------------------------------------
|
||||
<1> Timeout to connect to the master node as a `TimeValue`
|
||||
<2> Timeout to connect to the master node as a `String`
|
||||
|
||||
[[java-rest-high-get-stored-script-sync]]
|
||||
==== Synchronous Execution
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute]
|
||||
--------------------------------------------------
|
||||
|
||||
[[java-rest-high-get-stored-script-async]]
|
||||
==== Asynchronous Execution
|
||||
|
||||
The asynchronous execution of a get stored script request requires both the `GetStoredScriptRequest`
|
||||
instance and an `ActionListener` instance to be passed to the asynchronous method:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute-async]
|
||||
--------------------------------------------------
|
||||
<1> The `GetStoredScriptRequest` to execute and the `ActionListener` to use when
|
||||
the execution completes
|
||||
|
||||
[[java-rest-high-get-stored-script-listener]]
|
||||
===== Action Listener
|
||||
|
||||
The asynchronous method does not block and returns immediately. Once it is
|
||||
completed the `ActionListener` is called back using the `onResponse` method
|
||||
if the execution successfully completed or using the `onFailure` method if
|
||||
it failed.
|
||||
|
||||
A typical listener for `GetStoredScriptResponse` looks like:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute-listener]
|
||||
--------------------------------------------------
|
||||
<1> Called when the execution is successfully completed. The response is
|
||||
provided as an argument
|
||||
<2> Called in case of failure. The raised exception is provided as an argument
|
||||
|
||||
[[java-rest-high-get-stored-script-response]]
|
||||
==== Get Stored Script Response
|
||||
|
||||
The returned `GetStoredScriptResponse` allows to retrieve information about the
|
||||
executed operation as follows:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-response]
|
||||
--------------------------------------------------
|
||||
<1> The script object consists of a content and a metadata
|
||||
<2> The language the script is written in, which defaults to `painless`.
|
||||
<3> The content of the script
|
||||
<4> Any named options that should be passed into the script.
|
|
@ -151,3 +151,14 @@ The Java High Level REST Client supports the following Tasks APIs:
|
|||
|
||||
include::tasks/list_tasks.asciidoc[]
|
||||
include::tasks/cancel_tasks.asciidoc[]
|
||||
|
||||
== Script APIs
|
||||
|
||||
The Java High Level REST Client supports the following Scripts APIs:
|
||||
|
||||
* <<java-rest-high-get-stored-script>>
|
||||
* <<java-rest-high-delete-stored-script>>
|
||||
|
||||
include::script/get_script.asciidoc[]
|
||||
include::script/delete_script.asciidoc[]
|
||||
|
||||
|
|
|
@ -1028,11 +1028,38 @@ number of slices.
|
|||
Whether query or indexing performance dominates the runtime depends on the
|
||||
documents being reindexed and cluster resources.
|
||||
|
||||
[float]
|
||||
=== Reindexing many indices
|
||||
If you have many indices to reindex it is generally better to reindex them
|
||||
one at a time rather than using a glob pattern to pick up many indices. That
|
||||
way you can resume the process if there are any errors by removing the
|
||||
partially completed index and starting over at that index. It also makes
|
||||
parallelizing the process fairly simple: split the list of indices to reindex
|
||||
and run each list in parallel.
|
||||
|
||||
One off bash scripts seem to work nicely for this:
|
||||
|
||||
[source,bash]
|
||||
----------------------------------------------------------------
|
||||
for index in i1 i2 i3 i4 i5; do
|
||||
curl -HContent-Type:application/json -XPOST localhost:9200/_reindex?pretty -d'{
|
||||
"source": {
|
||||
"index": "'$index'"
|
||||
},
|
||||
"dest": {
|
||||
"index": "'$index'-reindexed"
|
||||
}
|
||||
}'
|
||||
done
|
||||
----------------------------------------------------------------
|
||||
// NOTCONSOLE
|
||||
|
||||
[float]
|
||||
=== Reindex daily indices
|
||||
|
||||
You can use `_reindex` in combination with <<modules-scripting-painless, Painless>>
|
||||
to reindex daily indices to apply a new template to the existing documents.
|
||||
Notwithstanding the above advice, you can use `_reindex` in combination with
|
||||
<<modules-scripting-painless, Painless>> to reindex daily indices to apply
|
||||
a new template to the existing documents.
|
||||
|
||||
Assuming you have indices consisting of documents as follows:
|
||||
|
||||
|
|
|
@ -5,4 +5,10 @@
|
|||
|
||||
`isShardsAcked` has been replaced by `isShardsAcknowledged` in
|
||||
`CreateIndexResponse`, `RolloverResponse` and
|
||||
`CreateIndexClusterStateUpdateResponse`.
|
||||
`CreateIndexClusterStateUpdateResponse`.
|
||||
|
||||
==== `prepareExecute` removed from the client api
|
||||
|
||||
The `prepareExecute` method which created a request builder has been
|
||||
removed from the client api. Instead, construct a builder for the
|
||||
appropriate request directly.
|
||||
|
|
|
@ -18,7 +18,7 @@ directly to configure and access {xpack} features.
|
|||
--
|
||||
|
||||
|
||||
include::{xes-repo-dir}/rest-api/info.asciidoc[]
|
||||
include::info.asciidoc[]
|
||||
include::{xes-repo-dir}/rest-api/graph/explore.asciidoc[]
|
||||
include::{xes-repo-dir}/rest-api/licensing.asciidoc[]
|
||||
include::{xes-repo-dir}/rest-api/migration.asciidoc[]
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
[role="xpack"]
|
||||
[testenv="basic"]
|
||||
[[info-api]]
|
||||
== Info API
|
||||
|
||||
The info API provides general information about the installed {xpack}.
|
||||
The info API provides general information about the installed {xpack} features.
|
||||
|
||||
[float]
|
||||
=== Request
|
||||
|
@ -55,16 +56,15 @@ Example response:
|
|||
"date" : "2015-04-07T13:34:42Z"
|
||||
},
|
||||
"license" : {
|
||||
"uid" : "893361dc-9749-4997-93cb-802e3dofh7aa",
|
||||
"type" : "trial",
|
||||
"mode" : "trial",
|
||||
"status" : "active",
|
||||
"expiry_date_in_millis" : 1914278399999
|
||||
"uid" : "893361dc-9749-4997-93cb-xxx",
|
||||
"type" : "basic",
|
||||
"mode" : "basic",
|
||||
"status" : "active"
|
||||
},
|
||||
"features" : {
|
||||
"graph" : {
|
||||
"description" : "Graph Data Exploration for the Elastic Stack",
|
||||
"available" : true,
|
||||
"available" : false,
|
||||
"enabled" : true
|
||||
},
|
||||
"index_lifecycle" : {
|
||||
|
@ -74,16 +74,16 @@ Example response:
|
|||
},
|
||||
"logstash" : {
|
||||
"description" : "Logstash management component for X-Pack",
|
||||
"available" : true,
|
||||
"available" : false,
|
||||
"enabled" : true
|
||||
},
|
||||
"ml" : {
|
||||
"description" : "Machine Learning for the Elastic Stack",
|
||||
"available" : true,
|
||||
"available" : false,
|
||||
"enabled" : true,
|
||||
"native_code_info" : {
|
||||
"version" : "6.0.0-alpha1-SNAPSHOT",
|
||||
"build_hash" : "d081461967d61a"
|
||||
"version" : "7.0.0-alpha1-SNAPSHOT",
|
||||
"build_hash" : "99a07c016d5a73"
|
||||
}
|
||||
},
|
||||
"monitoring" : {
|
||||
|
@ -98,12 +98,12 @@ Example response:
|
|||
},
|
||||
"security" : {
|
||||
"description" : "Security for the Elastic Stack",
|
||||
"available" : true,
|
||||
"available" : false,
|
||||
"enabled" : true
|
||||
},
|
||||
"watcher" : {
|
||||
"description" : "Alerting, Notification and Automation for the Elastic Stack",
|
||||
"available" : true,
|
||||
"available" : false,
|
||||
"enabled" : true
|
||||
}
|
||||
},
|
||||
|
@ -112,10 +112,10 @@ Example response:
|
|||
------------------------------------------------------------
|
||||
// TESTRESPONSE[s/"hash" : "2798b1a3ce779b3611bb53a0082d4d741e4d3168",/"hash" : "$body.build.hash",/]
|
||||
// TESTRESPONSE[s/"date" : "2015-04-07T13:34:42Z"/"date" : "$body.build.date"/]
|
||||
// TESTRESPONSE[s/"uid" : "893361dc-9749-4997-93cb-802e3dofh7aa",/"uid": "$body.license.uid",/]
|
||||
// TESTRESPONSE[s/"uid" : "893361dc-9749-4997-93cb-xxx",/"uid": "$body.license.uid",/]
|
||||
// TESTRESPONSE[s/"expiry_date_in_millis" : 1914278399999/"expiry_date_in_millis" : "$body.license.expiry_date_in_millis"/]
|
||||
// TESTRESPONSE[s/"version" : "6.0.0-alpha1-SNAPSHOT",/"version": "$body.features.ml.native_code_info.version",/]
|
||||
// TESTRESPONSE[s/"build_hash" : "d081461967d61a"/"build_hash": "$body.features.ml.native_code_info.build_hash"/]
|
||||
// TESTRESPONSE[s/"version" : "7.0.0-alpha1-SNAPSHOT",/"version": "$body.features.ml.native_code_info.version",/]
|
||||
// TESTRESPONSE[s/"build_hash" : "99a07c016d5a73"/"build_hash": "$body.features.ml.native_code_info.build_hash"/]
|
||||
// So much s/// but at least we test that the layout is close to matching....
|
||||
|
||||
The following example only returns the build and features information:
|
|
@ -58,7 +58,6 @@ public final class InboundChannelBuffer implements AutoCloseable {
|
|||
this.pageSupplier = pageSupplier;
|
||||
this.pages = new ArrayDeque<>();
|
||||
this.capacity = PAGE_SIZE * pages.size();
|
||||
ensureCapacity(PAGE_SIZE);
|
||||
}
|
||||
|
||||
public static InboundChannelBuffer allocatingInstance() {
|
||||
|
|
|
@ -34,16 +34,20 @@ public class InboundChannelBufferTests extends ESTestCase {
|
|||
new InboundChannelBuffer.Page(ByteBuffer.allocate(BigArrays.BYTE_PAGE_SIZE), () -> {
|
||||
});
|
||||
|
||||
public void testNewBufferHasSinglePage() {
|
||||
public void testNewBufferNoPages() {
|
||||
InboundChannelBuffer channelBuffer = new InboundChannelBuffer(defaultPageSupplier);
|
||||
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getCapacity());
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getRemaining());
|
||||
assertEquals(0, channelBuffer.getCapacity());
|
||||
assertEquals(0, channelBuffer.getRemaining());
|
||||
assertEquals(0, channelBuffer.getIndex());
|
||||
}
|
||||
|
||||
public void testExpandCapacity() {
|
||||
InboundChannelBuffer channelBuffer = new InboundChannelBuffer(defaultPageSupplier);
|
||||
assertEquals(0, channelBuffer.getCapacity());
|
||||
assertEquals(0, channelBuffer.getRemaining());
|
||||
|
||||
channelBuffer.ensureCapacity(PAGE_SIZE);
|
||||
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getCapacity());
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getRemaining());
|
||||
|
@ -56,6 +60,7 @@ public class InboundChannelBufferTests extends ESTestCase {
|
|||
|
||||
public void testExpandCapacityMultiplePages() {
|
||||
InboundChannelBuffer channelBuffer = new InboundChannelBuffer(defaultPageSupplier);
|
||||
channelBuffer.ensureCapacity(PAGE_SIZE);
|
||||
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getCapacity());
|
||||
|
||||
|
@ -68,6 +73,7 @@ public class InboundChannelBufferTests extends ESTestCase {
|
|||
|
||||
public void testExpandCapacityRespectsOffset() {
|
||||
InboundChannelBuffer channelBuffer = new InboundChannelBuffer(defaultPageSupplier);
|
||||
channelBuffer.ensureCapacity(PAGE_SIZE);
|
||||
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getCapacity());
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getRemaining());
|
||||
|
@ -87,6 +93,7 @@ public class InboundChannelBufferTests extends ESTestCase {
|
|||
|
||||
public void testIncrementIndex() {
|
||||
InboundChannelBuffer channelBuffer = new InboundChannelBuffer(defaultPageSupplier);
|
||||
channelBuffer.ensureCapacity(PAGE_SIZE);
|
||||
|
||||
assertEquals(0, channelBuffer.getIndex());
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getRemaining());
|
||||
|
@ -99,6 +106,7 @@ public class InboundChannelBufferTests extends ESTestCase {
|
|||
|
||||
public void testIncrementIndexWithOffset() {
|
||||
InboundChannelBuffer channelBuffer = new InboundChannelBuffer(defaultPageSupplier);
|
||||
channelBuffer.ensureCapacity(PAGE_SIZE);
|
||||
|
||||
assertEquals(0, channelBuffer.getIndex());
|
||||
assertEquals(PAGE_SIZE, channelBuffer.getRemaining());
|
||||
|
|
|
@ -52,7 +52,7 @@ import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
|
|||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class GrokProcessorGetAction extends Action<GrokProcessorGetAction.Request, GrokProcessorGetAction.Response> {
|
||||
public class GrokProcessorGetAction extends Action<GrokProcessorGetAction.Response> {
|
||||
|
||||
public static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction();
|
||||
public static final String NAME = "cluster:admin/ingest/processor/grok/get";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.script.mustache;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class MultiSearchTemplateAction extends Action<MultiSearchTemplateRequest, MultiSearchTemplateResponse> {
|
||||
public class MultiSearchTemplateAction extends Action<MultiSearchTemplateResponse> {
|
||||
|
||||
public static final MultiSearchTemplateAction INSTANCE = new MultiSearchTemplateAction();
|
||||
public static final String NAME = "indices:data/read/msearch/template";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.script.mustache;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class SearchTemplateAction extends Action<SearchTemplateRequest, SearchTemplateResponse> {
|
||||
public class SearchTemplateAction extends Action<SearchTemplateResponse> {
|
||||
|
||||
public static final SearchTemplateAction INSTANCE = new SearchTemplateAction();
|
||||
public static final String NAME = "indices:data/read/search/template";
|
||||
|
|
|
@ -62,7 +62,7 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
|
|||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class PainlessExecuteAction extends Action<PainlessExecuteAction.Request, PainlessExecuteAction.Response> {
|
||||
public class PainlessExecuteAction extends Action<PainlessExecuteAction.Response> {
|
||||
|
||||
static final PainlessExecuteAction INSTANCE = new PainlessExecuteAction();
|
||||
private static final String NAME = "cluster:admin/scripts/painless/execute";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Action for explaining evaluating search ranking results.
|
||||
*/
|
||||
public class RankEvalAction extends Action<RankEvalRequest, RankEvalResponse> {
|
||||
public class RankEvalAction extends Action<RankEvalResponse> {
|
||||
|
||||
public static final RankEvalAction INSTANCE = new RankEvalAction();
|
||||
public static final String NAME = "indices:data/read/rank_eval";
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.client.ElasticsearchClient;
|
|||
|
||||
public class RankEvalRequestBuilder extends ActionRequestBuilder<RankEvalRequest, RankEvalResponse> {
|
||||
|
||||
public RankEvalRequestBuilder(ElasticsearchClient client, Action<RankEvalRequest, RankEvalResponse> action,
|
||||
public RankEvalRequestBuilder(ElasticsearchClient client, Action<RankEvalResponse> action,
|
||||
RankEvalRequest request) {
|
||||
super(client, action, request);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.elasticsearch.index.reindex;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.GenericAction;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -38,7 +38,7 @@ import java.util.Map;
|
|||
|
||||
public abstract class AbstractBaseReindexRestHandler<
|
||||
Request extends AbstractBulkByScrollRequest<Request>,
|
||||
A extends GenericAction<Request, BulkByScrollResponse>
|
||||
A extends Action<BulkByScrollResponse>
|
||||
> extends BaseRestHandler {
|
||||
|
||||
private final A action;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.elasticsearch.index.reindex;
|
||||
|
||||
import org.elasticsearch.action.GenericAction;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -38,7 +38,7 @@ import java.util.function.Consumer;
|
|||
*/
|
||||
public abstract class AbstractBulkByQueryRestHandler<
|
||||
Request extends AbstractBulkByScrollRequest<Request>,
|
||||
A extends GenericAction<Request, BulkByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {
|
||||
A extends Action<BulkByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {
|
||||
|
||||
protected AbstractBulkByQueryRestHandler(Settings settings, A action) {
|
||||
super(settings, action);
|
||||
|
|
|
@ -61,7 +61,7 @@ class BulkByScrollParallelizationHelper {
|
|||
static <Request extends AbstractBulkByScrollRequest<Request>> void startSlicedAction(
|
||||
Request request,
|
||||
BulkByScrollTask task,
|
||||
Action<Request, BulkByScrollResponse> action,
|
||||
Action<BulkByScrollResponse> action,
|
||||
ActionListener<BulkByScrollResponse> listener,
|
||||
Client client,
|
||||
DiscoveryNode node,
|
||||
|
@ -85,7 +85,7 @@ class BulkByScrollParallelizationHelper {
|
|||
private static <Request extends AbstractBulkByScrollRequest<Request>> void sliceConditionally(
|
||||
Request request,
|
||||
BulkByScrollTask task,
|
||||
Action<Request, BulkByScrollResponse> action,
|
||||
Action<BulkByScrollResponse> action,
|
||||
ActionListener<BulkByScrollResponse> listener,
|
||||
Client client,
|
||||
DiscoveryNode node,
|
||||
|
@ -118,7 +118,7 @@ class BulkByScrollParallelizationHelper {
|
|||
|
||||
private static <Request extends AbstractBulkByScrollRequest<Request>> void sendSubRequests(
|
||||
Client client,
|
||||
Action<Request, BulkByScrollResponse> action,
|
||||
Action<BulkByScrollResponse> action,
|
||||
String localNodeId,
|
||||
BulkByScrollTask task,
|
||||
Request request,
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.index.reindex;
|
|||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||
|
||||
public class RethrottleAction extends Action<RethrottleRequest, ListTasksResponse> {
|
||||
public class RethrottleAction extends Action<ListTasksResponse> {
|
||||
public static final RethrottleAction INSTANCE = new RethrottleAction();
|
||||
public static final String NAME = "cluster:admin/reindex/rethrottle";
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.client.ElasticsearchClient;
|
|||
*/
|
||||
public class RethrottleRequestBuilder extends TasksRequestBuilder<RethrottleRequest, ListTasksResponse, RethrottleRequestBuilder> {
|
||||
public RethrottleRequestBuilder(ElasticsearchClient client,
|
||||
Action<RethrottleRequest, ListTasksResponse> action) {
|
||||
Action<ListTasksResponse> action) {
|
||||
super(client, action, new RethrottleRequest());
|
||||
}
|
||||
|
||||
|
|
|
@ -745,7 +745,7 @@ public class AsyncBulkByScrollActionTests extends ESTestCase {
|
|||
@SuppressWarnings("unchecked")
|
||||
protected <Request extends ActionRequest, Response extends ActionResponse,
|
||||
RequestBuilder extends ActionRequestBuilder<Request, Response>> void doExecute(
|
||||
Action<Request, Response> action, Request request, ActionListener<Response> listener) {
|
||||
Action<Response> action, Request request, ActionListener<Response> listener) {
|
||||
if (false == expectedHeaders.equals(threadPool().getThreadContext().getHeaders())) {
|
||||
listener.onFailure(
|
||||
new RuntimeException("Expected " + expectedHeaders + " but got " + threadPool().getThreadContext().getHeaders()));
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.http.netty4;
|
|||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.common.concurrent.CompletableContext;
|
||||
import org.elasticsearch.http.HttpChannel;
|
||||
import org.elasticsearch.http.HttpResponse;
|
||||
import org.elasticsearch.transport.netty4.Netty4Utils;
|
||||
|
@ -31,9 +32,23 @@ import java.net.InetSocketAddress;
|
|||
public class Netty4HttpChannel implements HttpChannel {
|
||||
|
||||
private final Channel channel;
|
||||
private final CompletableContext<Void> closeContext = new CompletableContext<>();
|
||||
|
||||
Netty4HttpChannel(Channel channel) {
|
||||
this.channel = channel;
|
||||
this.channel.closeFuture().addListener(f -> {
|
||||
if (f.isSuccess()) {
|
||||
closeContext.complete(null);
|
||||
} else {
|
||||
Throwable cause = f.cause();
|
||||
if (cause instanceof Error) {
|
||||
Netty4Utils.maybeDie(cause);
|
||||
closeContext.completeExceptionally(new Exception(cause));
|
||||
} else {
|
||||
closeContext.completeExceptionally((Exception) cause);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +80,16 @@ public class Netty4HttpChannel implements HttpChannel {
|
|||
return (InetSocketAddress) channel.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseListener(ActionListener<Void> listener) {
|
||||
closeContext.addListener(ActionListener.toBiConsumer(listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return channel.isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
channel.close();
|
||||
|
@ -73,4 +98,12 @@ public class Netty4HttpChannel implements HttpChannel {
|
|||
public Channel getNettyChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Netty4HttpChannel{" +
|
||||
"localAddress=" + getLocalAddress() +
|
||||
", remoteAddress=" + getRemoteAddress() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.ExceptionsHelper;
|
|||
import org.elasticsearch.http.HttpPipelinedRequest;
|
||||
import org.elasticsearch.transport.netty4.Netty4Utils;
|
||||
|
||||
import static org.elasticsearch.http.netty4.Netty4HttpServerTransport.HTTP_CHANNEL_KEY;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<HttpPipelinedRequest<FullHttpRequest>> {
|
||||
|
||||
|
@ -40,7 +42,7 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<HttpPipelined
|
|||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, HttpPipelinedRequest<FullHttpRequest> msg) throws Exception {
|
||||
Netty4HttpChannel channel = ctx.channel().attr(Netty4HttpServerTransport.HTTP_CHANNEL_KEY).get();
|
||||
Netty4HttpChannel channel = ctx.channel().attr(HTTP_CHANNEL_KEY).get();
|
||||
FullHttpRequest request = msg.getRequest();
|
||||
|
||||
try {
|
||||
|
@ -75,7 +77,12 @@ class Netty4HttpRequestHandler extends SimpleChannelInboundHandler<HttpPipelined
|
|||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
Netty4Utils.maybeDie(cause);
|
||||
serverTransport.exceptionCaught(ctx, cause);
|
||||
Netty4HttpChannel httpChannel = ctx.channel().attr(HTTP_CHANNEL_KEY).get();
|
||||
if (cause instanceof Error) {
|
||||
serverTransport.onException(httpChannel, new Exception(cause));
|
||||
} else {
|
||||
serverTransport.onException(httpChannel, (Exception) cause);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,15 +40,13 @@ import io.netty.handler.codec.http.HttpResponseEncoder;
|
|||
import io.netty.handler.timeout.ReadTimeoutException;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.logging.log4j.util.Supplier;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.network.CloseableChannel;
|
||||
import org.elasticsearch.common.network.NetworkAddress;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.NetworkExceptionHelper;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
|
@ -57,6 +55,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors;
|
|||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.http.AbstractHttpServerTransport;
|
||||
import org.elasticsearch.http.BindHttpException;
|
||||
import org.elasticsearch.http.HttpChannel;
|
||||
import org.elasticsearch.http.HttpHandlingSettings;
|
||||
import org.elasticsearch.http.HttpStats;
|
||||
import org.elasticsearch.http.netty4.cors.Netty4CorsConfig;
|
||||
|
@ -64,7 +63,6 @@ import org.elasticsearch.http.netty4.cors.Netty4CorsConfigBuilder;
|
|||
import org.elasticsearch.http.netty4.cors.Netty4CorsHandler;
|
||||
import org.elasticsearch.rest.RestUtils;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.netty4.Netty4OpenChannelsHandler;
|
||||
import org.elasticsearch.transport.netty4.Netty4Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -171,10 +169,6 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
|
||||
protected final List<Channel> serverChannels = new ArrayList<>();
|
||||
|
||||
// package private for testing
|
||||
Netty4OpenChannelsHandler serverOpenChannels;
|
||||
|
||||
|
||||
private final Netty4CorsConfig corsConfig;
|
||||
|
||||
public Netty4HttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, ThreadPool threadPool,
|
||||
|
@ -216,8 +210,6 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
protected void doStart() {
|
||||
boolean success = false;
|
||||
try {
|
||||
this.serverOpenChannels = new Netty4OpenChannelsHandler(logger);
|
||||
|
||||
serverBootstrap = new ServerBootstrap();
|
||||
|
||||
serverBootstrap.group(new NioEventLoopGroup(workerCount, daemonThreadFactory(settings,
|
||||
|
@ -281,10 +273,9 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
builder.allowCredentials();
|
||||
}
|
||||
String[] strMethods = Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_METHODS.get(settings), ",");
|
||||
HttpMethod[] methods = Arrays.asList(strMethods)
|
||||
.stream()
|
||||
HttpMethod[] methods = Arrays.stream(strMethods)
|
||||
.map(HttpMethod::valueOf)
|
||||
.toArray(size -> new HttpMethod[size]);
|
||||
.toArray(HttpMethod[]::new);
|
||||
return builder.allowedRequestMethods(methods)
|
||||
.maxAge(SETTING_CORS_MAX_AGE.get(settings))
|
||||
.allowedRequestHeaders(Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_HEADERS.get(settings), ","))
|
||||
|
@ -327,15 +318,21 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
Netty4Utils.closeChannels(serverChannels);
|
||||
} catch (IOException e) {
|
||||
logger.trace("exception while closing channels", e);
|
||||
} finally {
|
||||
serverChannels.clear();
|
||||
}
|
||||
serverChannels.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (serverOpenChannels != null) {
|
||||
serverOpenChannels.close();
|
||||
serverOpenChannels = null;
|
||||
// TODO: Move all of channel closing to abstract class once server channels are handled
|
||||
try {
|
||||
CloseableChannel.closeChannels(new ArrayList<>(httpChannels), true);
|
||||
} catch (Exception e) {
|
||||
logger.warn("unexpected exception while closing http channels", e);
|
||||
}
|
||||
httpChannels.clear();
|
||||
|
||||
|
||||
|
||||
if (serverBootstrap != null) {
|
||||
serverBootstrap.config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS).awaitUninterruptibly();
|
||||
|
@ -349,38 +346,18 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
|
||||
@Override
|
||||
public HttpStats stats() {
|
||||
Netty4OpenChannelsHandler channels = serverOpenChannels;
|
||||
return new HttpStats(channels == null ? 0 : channels.numberOfOpenChannels(), channels == null ? 0 : channels.totalChannels());
|
||||
return new HttpStats(httpChannels.size(), totalChannelsAccepted.get());
|
||||
}
|
||||
|
||||
public Netty4CorsConfig getCorsConfig() {
|
||||
return corsConfig;
|
||||
}
|
||||
|
||||
protected void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
@Override
|
||||
protected void onException(HttpChannel channel, Exception cause) {
|
||||
if (cause instanceof ReadTimeoutException) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Read timeout [{}]", ctx.channel().remoteAddress());
|
||||
logger.trace("Http read timeout {}", channel);
|
||||
}
|
||||
ctx.channel().close();
|
||||
CloseableChannel.closeChannel(channel);;
|
||||
} else {
|
||||
if (!lifecycle.started()) {
|
||||
// ignore
|
||||
return;
|
||||
}
|
||||
if (!NetworkExceptionHelper.isCloseConnectionException(cause)) {
|
||||
logger.warn(
|
||||
(Supplier<?>) () -> new ParameterizedMessage(
|
||||
"caught exception while handling client http traffic, closing connection {}", ctx.channel()),
|
||||
cause);
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
logger.debug(
|
||||
(Supplier<?>) () -> new ParameterizedMessage(
|
||||
"caught exception while handling client http traffic, closing connection {}", ctx.channel()),
|
||||
cause);
|
||||
ctx.channel().close();
|
||||
}
|
||||
super.onException(channel, cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,9 +381,8 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
Netty4HttpChannel nettyTcpChannel = new Netty4HttpChannel(ch);
|
||||
ch.attr(HTTP_CHANNEL_KEY).set(nettyTcpChannel);
|
||||
ch.pipeline().addLast("openChannels", transport.serverOpenChannels);
|
||||
Netty4HttpChannel nettyHttpChannel = new Netty4HttpChannel(ch);
|
||||
ch.attr(HTTP_CHANNEL_KEY).set(nettyHttpChannel);
|
||||
ch.pipeline().addLast("read_timeout", new ReadTimeoutHandler(transport.readTimeoutMillis, TimeUnit.MILLISECONDS));
|
||||
final HttpRequestDecoder decoder = new HttpRequestDecoder(
|
||||
handlingSettings.getMaxInitialLineLength(),
|
||||
|
@ -423,10 +399,11 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
|
|||
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(handlingSettings.getCompressionLevel()));
|
||||
}
|
||||
if (handlingSettings.isCorsEnabled()) {
|
||||
ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.getCorsConfig()));
|
||||
ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.corsConfig));
|
||||
}
|
||||
ch.pipeline().addLast("pipelining", new Netty4HttpPipeliningHandler(transport.logger, transport.pipeliningMaxEvents));
|
||||
ch.pipeline().addLast("handler", requestHandler);
|
||||
transport.serverAcceptedChannel(nettyHttpChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,96 +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.transport.netty4;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
import org.elasticsearch.common.metrics.CounterMetric;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class Netty4OpenChannelsHandler extends ChannelInboundHandlerAdapter implements Releasable {
|
||||
|
||||
final Set<Channel> openChannels = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
final CounterMetric openChannelsMetric = new CounterMetric();
|
||||
final CounterMetric totalChannelsMetric = new CounterMetric();
|
||||
|
||||
final Logger logger;
|
||||
|
||||
public Netty4OpenChannelsHandler(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
final ChannelFutureListener remover = new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
boolean removed = openChannels.remove(future.channel());
|
||||
if (removed) {
|
||||
openChannelsMetric.dec();
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("channel closed: {}", future.channel());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("channel opened: {}", ctx.channel());
|
||||
}
|
||||
final boolean added = openChannels.add(ctx.channel());
|
||||
if (added) {
|
||||
openChannelsMetric.inc();
|
||||
totalChannelsMetric.inc();
|
||||
ctx.channel().closeFuture().addListener(remover);
|
||||
}
|
||||
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
public long numberOfOpenChannels() {
|
||||
return openChannelsMetric.count();
|
||||
}
|
||||
|
||||
public long totalChannels() {
|
||||
return totalChannelsMetric.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
Netty4Utils.closeChannels(openChannels);
|
||||
} catch (IOException e) {
|
||||
logger.trace("exception while closing channels", e);
|
||||
}
|
||||
openChannels.clear();
|
||||
}
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.transport.netty4;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.network.CloseableChannel;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
import org.elasticsearch.common.settings.ClusterSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -91,7 +92,7 @@ public class SimpleNetty4TransportTests extends AbstractSimpleTransportTestCase
|
|||
final Netty4Transport t = (Netty4Transport) transport;
|
||||
@SuppressWarnings("unchecked")
|
||||
final TcpTransport.NodeChannels channels = (TcpTransport.NodeChannels) connection;
|
||||
TcpChannel.closeChannels(channels.getChannels().subList(0, randomIntBetween(1, channels.getChannels().size())), true);
|
||||
CloseableChannel.closeChannels(channels.getChannels().subList(0, randomIntBetween(1, channels.getChannels().size())), true);
|
||||
}
|
||||
|
||||
public void testConnectException() throws UnknownHostException {
|
||||
|
|
|
@ -36,4 +36,17 @@ public class NioHttpChannel extends NioSocketChannel implements HttpChannel {
|
|||
public void sendResponse(HttpResponse response, ActionListener<Void> listener) {
|
||||
getContext().sendMessage(response, ActionListener.toBiConsumer(listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseListener(ActionListener<Void> listener) {
|
||||
addCloseListener(ActionListener.toBiConsumer(listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NioHttpChannel{" +
|
||||
"localAddress=" + getLocalAddress() +
|
||||
", remoteAddress=" + getRemoteAddress() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,22 +20,20 @@
|
|||
package org.elasticsearch.http.nio;
|
||||
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import io.netty.handler.timeout.ReadTimeoutException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.logging.log4j.util.Supplier;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.PlainActionFuture;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.network.CloseableChannel;
|
||||
import org.elasticsearch.common.network.NetworkAddress;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
import org.elasticsearch.common.recycler.Recycler;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.NetworkExceptionHelper;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.util.BigArrays;
|
||||
|
@ -44,6 +42,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors;
|
|||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.http.AbstractHttpServerTransport;
|
||||
import org.elasticsearch.http.BindHttpException;
|
||||
import org.elasticsearch.http.HttpChannel;
|
||||
import org.elasticsearch.http.HttpServerTransport;
|
||||
import org.elasticsearch.http.HttpStats;
|
||||
import org.elasticsearch.http.nio.cors.NioCorsConfig;
|
||||
|
@ -115,7 +114,6 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
|
|||
private final int tcpReceiveBufferSize;
|
||||
|
||||
private final Set<NioServerSocketChannel> serverChannels = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
private final Set<NioSocketChannel> socketChannels = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
private NioGroup nioGroup;
|
||||
private HttpChannelFactory channelFactory;
|
||||
private final NioCorsConfig corsConfig;
|
||||
|
@ -156,7 +154,7 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
|
|||
int workerCount = NIO_HTTP_WORKER_COUNT.get(settings);
|
||||
nioGroup = new NioGroup(daemonThreadFactory(this.settings, HTTP_SERVER_ACCEPTOR_THREAD_NAME_PREFIX), acceptorCount,
|
||||
daemonThreadFactory(this.settings, HTTP_SERVER_WORKER_THREAD_NAME_PREFIX), workerCount,
|
||||
(s) -> new EventHandler(this::nonChannelExceptionCaught, s));
|
||||
(s) -> new EventHandler(this::onNonChannelException, s));
|
||||
channelFactory = new HttpChannelFactory();
|
||||
this.boundAddress = createBoundHttpAddress();
|
||||
|
||||
|
@ -187,12 +185,13 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Move all of channel closing to abstract class once server channels are handled
|
||||
try {
|
||||
closeChannels(new ArrayList<>(socketChannels));
|
||||
CloseableChannel.closeChannels(new ArrayList<>(httpChannels), true);
|
||||
} catch (Exception e) {
|
||||
logger.warn("unexpected exception while closing http channels", e);
|
||||
}
|
||||
socketChannels.clear();
|
||||
httpChannels.clear();
|
||||
|
||||
try {
|
||||
nioGroup.close();
|
||||
|
@ -235,38 +234,7 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
|
|||
|
||||
@Override
|
||||
public HttpStats stats() {
|
||||
return new HttpStats(serverChannels.size(), socketChannels.size());
|
||||
}
|
||||
|
||||
protected void exceptionCaught(NioSocketChannel channel, Exception cause) {
|
||||
if (cause instanceof ReadTimeoutException) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Read timeout [{}]", channel.getRemoteAddress());
|
||||
}
|
||||
channel.close();
|
||||
} else {
|
||||
if (lifecycle.started() == false) {
|
||||
// ignore
|
||||
return;
|
||||
}
|
||||
if (NetworkExceptionHelper.isCloseConnectionException(cause) == false) {
|
||||
logger.warn(
|
||||
(Supplier<?>) () -> new ParameterizedMessage(
|
||||
"caught exception while handling client http traffic, closing connection {}", channel),
|
||||
cause);
|
||||
channel.close();
|
||||
} else {
|
||||
logger.debug(
|
||||
(Supplier<?>) () -> new ParameterizedMessage(
|
||||
"caught exception while handling client http traffic, closing connection {}", channel),
|
||||
cause);
|
||||
channel.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void nonChannelExceptionCaught(Exception ex) {
|
||||
logger.warn(new ParameterizedMessage("exception caught on transport layer [thread={}]", Thread.currentThread().getName()), ex);
|
||||
return new HttpStats(serverChannels.size(), totalChannelsAccepted.get());
|
||||
}
|
||||
|
||||
static NioCorsConfig buildCorsConfig(Settings settings) {
|
||||
|
@ -324,7 +292,7 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
|
|||
}
|
||||
|
||||
private void acceptChannel(NioSocketChannel socketChannel) {
|
||||
socketChannels.add(socketChannel);
|
||||
super.serverAcceptedChannel((HttpChannel) socketChannel);
|
||||
}
|
||||
|
||||
private class HttpChannelFactory extends ChannelFactory<NioServerSocketChannel, NioHttpChannel> {
|
||||
|
@ -342,7 +310,7 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport {
|
|||
};
|
||||
HttpReadWriteHandler httpReadWritePipeline = new HttpReadWriteHandler(nioChannel,NioHttpServerTransport.this,
|
||||
handlingSettings, corsConfig);
|
||||
Consumer<Exception> exceptionHandler = (e) -> exceptionCaught(nioChannel, e);
|
||||
Consumer<Exception> exceptionHandler = (e) -> onException(nioChannel, e);
|
||||
SocketChannelContext context = new BytesChannelContext(nioChannel, selector, exceptionHandler, httpReadWritePipeline,
|
||||
new InboundChannelBuffer(pageSupplier));
|
||||
nioChannel.setContext(context);
|
||||
|
|
|
@ -28,11 +28,11 @@ import java.io.IOException;
|
|||
import java.net.StandardSocketOptions;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
public class TcpNioSocketChannel extends NioSocketChannel implements TcpChannel {
|
||||
public class NioTcpChannel extends NioSocketChannel implements TcpChannel {
|
||||
|
||||
private final String profile;
|
||||
|
||||
public TcpNioSocketChannel(String profile, SocketChannel socketChannel) throws IOException {
|
||||
public NioTcpChannel(String profile, SocketChannel socketChannel) throws IOException {
|
||||
super(socketChannel);
|
||||
this.profile = profile;
|
||||
}
|
|
@ -32,11 +32,11 @@ import java.nio.channels.ServerSocketChannel;
|
|||
* This is an implementation of {@link NioServerSocketChannel} that adheres to the {@link TcpChannel}
|
||||
* interface. As it is a server socket, setting SO_LINGER and sending messages is not supported.
|
||||
*/
|
||||
public class TcpNioServerSocketChannel extends NioServerSocketChannel implements TcpChannel {
|
||||
public class NioTcpServerChannel extends NioServerSocketChannel implements TcpChannel {
|
||||
|
||||
private final String profile;
|
||||
|
||||
public TcpNioServerSocketChannel(String profile, ServerSocketChannel socketChannel) throws IOException {
|
||||
public NioTcpServerChannel(String profile, ServerSocketChannel socketChannel) throws IOException {
|
||||
super(socketChannel);
|
||||
this.profile = profile;
|
||||
}
|
|
@ -40,7 +40,6 @@ import org.elasticsearch.nio.NioSelector;
|
|||
import org.elasticsearch.nio.NioSocketChannel;
|
||||
import org.elasticsearch.nio.ServerChannelContext;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
import org.elasticsearch.transport.TcpTransport;
|
||||
import org.elasticsearch.transport.Transports;
|
||||
|
||||
|
@ -78,14 +77,14 @@ public class NioTransport extends TcpTransport {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected TcpNioServerSocketChannel bind(String name, InetSocketAddress address) throws IOException {
|
||||
protected NioTcpServerChannel bind(String name, InetSocketAddress address) throws IOException {
|
||||
TcpChannelFactory channelFactory = this.profileToChannelFactory.get(name);
|
||||
return nioGroup.bindServerChannel(address, channelFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TcpNioSocketChannel initiateChannel(InetSocketAddress address, ActionListener<Void> connectListener) throws IOException {
|
||||
TcpNioSocketChannel channel = nioGroup.openChannel(address, clientChannelFactory);
|
||||
protected NioTcpChannel initiateChannel(InetSocketAddress address, ActionListener<Void> connectListener) throws IOException {
|
||||
NioTcpChannel channel = nioGroup.openChannel(address, clientChannelFactory);
|
||||
channel.addConnectListener(ActionListener.toBiConsumer(connectListener));
|
||||
return channel;
|
||||
}
|
||||
|
@ -131,19 +130,15 @@ public class NioTransport extends TcpTransport {
|
|||
profileToChannelFactory.clear();
|
||||
}
|
||||
|
||||
protected void exceptionCaught(NioSocketChannel channel, Exception exception) {
|
||||
onException((TcpChannel) channel, exception);
|
||||
}
|
||||
|
||||
protected void acceptChannel(NioSocketChannel channel) {
|
||||
serverAcceptedChannel((TcpNioSocketChannel) channel);
|
||||
serverAcceptedChannel((NioTcpChannel) channel);
|
||||
}
|
||||
|
||||
protected TcpChannelFactory channelFactory(ProfileSettings settings, boolean isClient) {
|
||||
return new TcpChannelFactoryImpl(settings);
|
||||
}
|
||||
|
||||
protected abstract class TcpChannelFactory extends ChannelFactory<TcpNioServerSocketChannel, TcpNioSocketChannel> {
|
||||
protected abstract class TcpChannelFactory extends ChannelFactory<NioTcpServerChannel, NioTcpChannel> {
|
||||
|
||||
protected TcpChannelFactory(RawChannelFactory rawChannelFactory) {
|
||||
super(rawChannelFactory);
|
||||
|
@ -164,14 +159,14 @@ public class NioTransport extends TcpTransport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TcpNioSocketChannel createChannel(NioSelector selector, SocketChannel channel) throws IOException {
|
||||
TcpNioSocketChannel nioChannel = new TcpNioSocketChannel(profileName, channel);
|
||||
public NioTcpChannel createChannel(NioSelector selector, SocketChannel channel) throws IOException {
|
||||
NioTcpChannel nioChannel = new NioTcpChannel(profileName, channel);
|
||||
Supplier<InboundChannelBuffer.Page> pageSupplier = () -> {
|
||||
Recycler.V<byte[]> bytes = pageCacheRecycler.bytePage(false);
|
||||
return new InboundChannelBuffer.Page(ByteBuffer.wrap(bytes.v()), bytes::close);
|
||||
};
|
||||
TcpReadWriteHandler readWriteHandler = new TcpReadWriteHandler(nioChannel, NioTransport.this);
|
||||
Consumer<Exception> exceptionHandler = (e) -> exceptionCaught(nioChannel, e);
|
||||
Consumer<Exception> exceptionHandler = (e) -> onException(nioChannel, e);
|
||||
BytesChannelContext context = new BytesChannelContext(nioChannel, selector, exceptionHandler, readWriteHandler,
|
||||
new InboundChannelBuffer(pageSupplier));
|
||||
nioChannel.setContext(context);
|
||||
|
@ -179,8 +174,8 @@ public class NioTransport extends TcpTransport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TcpNioServerSocketChannel createServerChannel(NioSelector selector, ServerSocketChannel channel) throws IOException {
|
||||
TcpNioServerSocketChannel nioChannel = new TcpNioServerSocketChannel(profileName, channel);
|
||||
public NioTcpServerChannel createServerChannel(NioSelector selector, ServerSocketChannel channel) throws IOException {
|
||||
NioTcpServerChannel nioChannel = new NioTcpServerChannel(profileName, channel);
|
||||
Consumer<Exception> exceptionHandler = (e) -> logger.error(() ->
|
||||
new ParameterizedMessage("exception from server channel caught on transport layer [{}]", channel), e);
|
||||
Consumer<NioSocketChannel> acceptor = NioTransport.this::acceptChannel;
|
||||
|
|
|
@ -28,10 +28,10 @@ import java.io.IOException;
|
|||
|
||||
public class TcpReadWriteHandler extends BytesWriteHandler {
|
||||
|
||||
private final TcpNioSocketChannel channel;
|
||||
private final NioTcpChannel channel;
|
||||
private final TcpTransport transport;
|
||||
|
||||
public TcpReadWriteHandler(TcpNioSocketChannel channel, TcpTransport transport) {
|
||||
public TcpReadWriteHandler(NioTcpChannel channel, TcpTransport transport) {
|
||||
this.channel = channel;
|
||||
this.transport = transport;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.transport.nio;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.network.CloseableChannel;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
import org.elasticsearch.common.settings.ClusterSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -96,7 +97,7 @@ public class SimpleNioTransportTests extends AbstractSimpleTransportTestCase {
|
|||
protected void closeConnectionChannel(Transport transport, Transport.Connection connection) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
TcpTransport.NodeChannels channels = (TcpTransport.NodeChannels) connection;
|
||||
TcpChannel.closeChannels(channels.getChannels().subList(0, randomIntBetween(1, channels.getChannels().size())), true);
|
||||
CloseableChannel.closeChannels(channels.getChannels().subList(0, randomIntBetween(1, channels.getChannels().size())), true);
|
||||
}
|
||||
|
||||
public void testConnectException() throws UnknownHostException {
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
}
|
||||
},
|
||||
"params" : {
|
||||
"master_timeout": {
|
||||
"type" : "time",
|
||||
"description" : "Specify timeout for connection to master"
|
||||
}
|
||||
}
|
||||
},
|
||||
"body": null
|
||||
|
|
|
@ -19,13 +19,49 @@
|
|||
|
||||
package org.elasticsearch.action;
|
||||
|
||||
/**
|
||||
* Base action. Supports building the <code>Request</code> through a <code>RequestBuilder</code>.
|
||||
*/
|
||||
public abstract class Action<Request extends ActionRequest, Response extends ActionResponse>
|
||||
extends GenericAction<Request, Response> {
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.transport.TransportRequestOptions;
|
||||
|
||||
/**
|
||||
* A generic action. Should strive to make it a singleton.
|
||||
*/
|
||||
public abstract class Action<Response extends ActionResponse> {
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* @param name The name of the action, must be unique across actions.
|
||||
*/
|
||||
protected Action(String name) {
|
||||
super(name);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the action. Must be unique across actions.
|
||||
*/
|
||||
public String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new response instance.
|
||||
*/
|
||||
public abstract Response newResponse();
|
||||
|
||||
/**
|
||||
* Optional request options for the action.
|
||||
*/
|
||||
public TransportRequestOptions transportOptions(Settings settings) {
|
||||
return TransportRequestOptions.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Action && name.equals(((Action) o).name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -406,8 +406,8 @@ public class ActionModule extends AbstractModule {
|
|||
}
|
||||
|
||||
public <Request extends ActionRequest, Response extends ActionResponse> void register(
|
||||
GenericAction<Request, Response> action, Class<? extends TransportAction<Request, Response>> transportAction,
|
||||
Class<?>... supportTransportActions) {
|
||||
Action<Response> action, Class<? extends TransportAction<Request, Response>> transportAction,
|
||||
Class<?>... supportTransportActions) {
|
||||
register(new ActionHandler<>(action, transportAction, supportTransportActions));
|
||||
}
|
||||
}
|
||||
|
@ -675,10 +675,10 @@ public class ActionModule extends AbstractModule {
|
|||
bind(AutoCreateIndex.class).toInstance(autoCreateIndex);
|
||||
bind(TransportLivenessAction.class).asEagerSingleton();
|
||||
|
||||
// register GenericAction -> transportAction Map used by NodeClient
|
||||
// register Action -> transportAction Map used by NodeClient
|
||||
@SuppressWarnings("rawtypes")
|
||||
MapBinder<GenericAction, TransportAction> transportActionsBinder
|
||||
= MapBinder.newMapBinder(binder(), GenericAction.class, TransportAction.class);
|
||||
MapBinder<Action, TransportAction> transportActionsBinder
|
||||
= MapBinder.newMapBinder(binder(), Action.class, TransportAction.class);
|
||||
for (ActionHandler<?, ?> action : actions.values()) {
|
||||
// bind the action as eager singleton, so the map binder one will reuse it
|
||||
bind(action.getTransportAction()).asEagerSingleton();
|
||||
|
|
|
@ -26,11 +26,11 @@ import java.util.Objects;
|
|||
|
||||
public abstract class ActionRequestBuilder<Request extends ActionRequest, Response extends ActionResponse> {
|
||||
|
||||
protected final Action<Request, Response> action;
|
||||
protected final Action<Response> action;
|
||||
protected final Request request;
|
||||
protected final ElasticsearchClient client;
|
||||
|
||||
protected ActionRequestBuilder(ElasticsearchClient client, Action<Request, Response> action, Request request) {
|
||||
protected ActionRequestBuilder(ElasticsearchClient client, Action<Response> action, Request request) {
|
||||
Objects.requireNonNull(action, "action must not be null");
|
||||
this.action = action;
|
||||
this.request = request;
|
||||
|
|
|
@ -1,67 +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.common.settings.Settings;
|
||||
import org.elasticsearch.transport.TransportRequestOptions;
|
||||
|
||||
/**
|
||||
* A generic action. Should strive to make it a singleton.
|
||||
*/
|
||||
public abstract class GenericAction<Request extends ActionRequest, Response extends ActionResponse> {
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* @param name The name of the action, must be unique across actions.
|
||||
*/
|
||||
protected GenericAction(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the action. Must be unique across actions.
|
||||
*/
|
||||
public String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new response instance.
|
||||
*/
|
||||
public abstract Response newResponse();
|
||||
|
||||
/**
|
||||
* Optional request options for the action.
|
||||
*/
|
||||
public TransportRequestOptions transportOptions(Settings settings) {
|
||||
return TransportRequestOptions.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GenericAction && name.equals(((GenericAction) o).name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
}
|
|
@ -31,10 +31,10 @@ import org.elasticsearch.transport.TransportService;
|
|||
public class TransportActionNodeProxy<Request extends ActionRequest, Response extends ActionResponse> extends AbstractComponent {
|
||||
|
||||
private final TransportService transportService;
|
||||
private final GenericAction<Request, Response> action;
|
||||
private final Action<Response> action;
|
||||
private final TransportRequestOptions transportOptions;
|
||||
|
||||
public TransportActionNodeProxy(Settings settings, GenericAction<Request, Response> action, TransportService transportService) {
|
||||
public TransportActionNodeProxy(Settings settings, Action<Response> action, TransportService transportService) {
|
||||
super(settings);
|
||||
this.action = action;
|
||||
this.transportService = transportService;
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Action for explaining shard allocation for a shard in the cluster
|
||||
*/
|
||||
public class ClusterAllocationExplainAction extends Action<ClusterAllocationExplainRequest, ClusterAllocationExplainResponse> {
|
||||
public class ClusterAllocationExplainAction extends Action<ClusterAllocationExplainResponse> {
|
||||
|
||||
public static final ClusterAllocationExplainAction INSTANCE = new ClusterAllocationExplainAction();
|
||||
public static final String NAME = "cluster:monitor/allocation/explain";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.health;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClusterHealthAction extends Action<ClusterHealthRequest, ClusterHealthResponse> {
|
||||
public class ClusterHealthAction extends Action<ClusterHealthResponse> {
|
||||
|
||||
public static final ClusterHealthAction INSTANCE = new ClusterHealthAction();
|
||||
public static final String NAME = "cluster:monitor/health";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.node.hotthreads;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class NodesHotThreadsAction extends Action<NodesHotThreadsRequest, NodesHotThreadsResponse> {
|
||||
public class NodesHotThreadsAction extends Action<NodesHotThreadsResponse> {
|
||||
|
||||
public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction();
|
||||
public static final String NAME = "cluster:monitor/nodes/hot_threads";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.node.info;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class NodesInfoAction extends Action<NodesInfoRequest, NodesInfoResponse> {
|
||||
public class NodesInfoAction extends Action<NodesInfoResponse> {
|
||||
|
||||
public static final NodesInfoAction INSTANCE = new NodesInfoAction();
|
||||
public static final String NAME = "cluster:monitor/nodes/info";
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.action.admin.cluster.node.reload;
|
|||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class NodesReloadSecureSettingsAction
|
||||
extends Action<NodesReloadSecureSettingsRequest, NodesReloadSecureSettingsResponse> {
|
||||
extends Action<NodesReloadSecureSettingsResponse> {
|
||||
|
||||
public static final NodesReloadSecureSettingsAction INSTANCE = new NodesReloadSecureSettingsAction();
|
||||
public static final String NAME = "cluster:admin/nodes/reload_secure_settings";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.node.stats;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class NodesStatsAction extends Action<NodesStatsRequest, NodesStatsResponse> {
|
||||
public class NodesStatsAction extends Action<NodesStatsResponse> {
|
||||
|
||||
public static final NodesStatsAction INSTANCE = new NodesStatsAction();
|
||||
public static final String NAME = "cluster:monitor/nodes/stats";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Action for cancelling running tasks
|
||||
*/
|
||||
public class CancelTasksAction extends Action<CancelTasksRequest, CancelTasksResponse> {
|
||||
public class CancelTasksAction extends Action<CancelTasksResponse> {
|
||||
|
||||
public static final CancelTasksAction INSTANCE = new CancelTasksAction();
|
||||
public static final String NAME = "cluster:admin/tasks/cancel";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Action for retrieving a list of currently running tasks
|
||||
*/
|
||||
public class GetTaskAction extends Action<GetTaskRequest, GetTaskResponse> {
|
||||
public class GetTaskAction extends Action<GetTaskResponse> {
|
||||
|
||||
public static final GetTaskAction INSTANCE = new GetTaskAction();
|
||||
public static final String NAME = "cluster:monitor/task/get";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Action for retrieving a list of currently running tasks
|
||||
*/
|
||||
public class ListTasksAction extends Action<ListTasksRequest, ListTasksResponse> {
|
||||
public class ListTasksAction extends Action<ListTasksResponse> {
|
||||
|
||||
public static final ListTasksAction INSTANCE = new ListTasksAction();
|
||||
public static final String NAME = "cluster:monitor/tasks/lists";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.node.usage;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class NodesUsageAction extends Action<NodesUsageRequest, NodesUsageResponse> {
|
||||
public class NodesUsageAction extends Action<NodesUsageResponse> {
|
||||
|
||||
public static final NodesUsageAction INSTANCE = new NodesUsageAction();
|
||||
public static final String NAME = "cluster:monitor/nodes/usage";
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.client.ElasticsearchClient;
|
|||
public class NodesUsageRequestBuilder
|
||||
extends NodesOperationRequestBuilder<NodesUsageRequest, NodesUsageResponse, NodesUsageRequestBuilder> {
|
||||
|
||||
public NodesUsageRequestBuilder(ElasticsearchClient client, Action<NodesUsageRequest, NodesUsageResponse> action) {
|
||||
public NodesUsageRequestBuilder(ElasticsearchClient client, Action<NodesUsageResponse> action) {
|
||||
super(client, action, new NodesUsageRequest());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.remote;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public final class RemoteInfoAction extends Action<RemoteInfoRequest, RemoteInfoResponse> {
|
||||
public final class RemoteInfoAction extends Action<RemoteInfoResponse> {
|
||||
|
||||
public static final String NAME = "cluster:monitor/remote/info";
|
||||
public static final RemoteInfoAction INSTANCE = new RemoteInfoAction();
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Unregister repository action
|
||||
*/
|
||||
public class DeleteRepositoryAction extends Action<DeleteRepositoryRequest, DeleteRepositoryResponse> {
|
||||
public class DeleteRepositoryAction extends Action<DeleteRepositoryResponse> {
|
||||
|
||||
public static final DeleteRepositoryAction INSTANCE = new DeleteRepositoryAction();
|
||||
public static final String NAME = "cluster:admin/repository/delete";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Get repositories action
|
||||
*/
|
||||
public class GetRepositoriesAction extends Action<GetRepositoriesRequest, GetRepositoriesResponse> {
|
||||
public class GetRepositoriesAction extends Action<GetRepositoriesResponse> {
|
||||
|
||||
public static final GetRepositoriesAction INSTANCE = new GetRepositoriesAction();
|
||||
public static final String NAME = "cluster:admin/repository/get";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Register repository action
|
||||
*/
|
||||
public class PutRepositoryAction extends Action<PutRepositoryRequest, PutRepositoryResponse> {
|
||||
public class PutRepositoryAction extends Action<PutRepositoryResponse> {
|
||||
|
||||
public static final PutRepositoryAction INSTANCE = new PutRepositoryAction();
|
||||
public static final String NAME = "cluster:admin/repository/put";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Unregister repository action
|
||||
*/
|
||||
public class VerifyRepositoryAction extends Action<VerifyRepositoryRequest, VerifyRepositoryResponse> {
|
||||
public class VerifyRepositoryAction extends Action<VerifyRepositoryResponse> {
|
||||
|
||||
public static final VerifyRepositoryAction INSTANCE = new VerifyRepositoryAction();
|
||||
public static final String NAME = "cluster:admin/repository/verify";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.reroute;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClusterRerouteAction extends Action<ClusterRerouteRequest, ClusterRerouteResponse> {
|
||||
public class ClusterRerouteAction extends Action<ClusterRerouteResponse> {
|
||||
|
||||
public static final ClusterRerouteAction INSTANCE = new ClusterRerouteAction();
|
||||
public static final String NAME = "cluster:admin/reroute";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.settings;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClusterUpdateSettingsAction extends Action<ClusterUpdateSettingsRequest, ClusterUpdateSettingsResponse> {
|
||||
public class ClusterUpdateSettingsAction extends Action<ClusterUpdateSettingsResponse> {
|
||||
|
||||
public static final ClusterUpdateSettingsAction INSTANCE = new ClusterUpdateSettingsAction();
|
||||
public static final String NAME = "cluster:admin/settings/update";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.shards;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClusterSearchShardsAction extends Action<ClusterSearchShardsRequest, ClusterSearchShardsResponse> {
|
||||
public class ClusterSearchShardsAction extends Action<ClusterSearchShardsResponse> {
|
||||
|
||||
public static final ClusterSearchShardsAction INSTANCE = new ClusterSearchShardsAction();
|
||||
public static final String NAME = "indices:admin/shards/search_shards";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Create snapshot action
|
||||
*/
|
||||
public class CreateSnapshotAction extends Action<CreateSnapshotRequest, CreateSnapshotResponse> {
|
||||
public class CreateSnapshotAction extends Action<CreateSnapshotResponse> {
|
||||
|
||||
public static final CreateSnapshotAction INSTANCE = new CreateSnapshotAction();
|
||||
public static final String NAME = "cluster:admin/snapshot/create";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Delete snapshot action
|
||||
*/
|
||||
public class DeleteSnapshotAction extends Action<DeleteSnapshotRequest, DeleteSnapshotResponse> {
|
||||
public class DeleteSnapshotAction extends Action<DeleteSnapshotResponse> {
|
||||
|
||||
public static final DeleteSnapshotAction INSTANCE = new DeleteSnapshotAction();
|
||||
public static final String NAME = "cluster:admin/snapshot/delete";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Get snapshots action
|
||||
*/
|
||||
public class GetSnapshotsAction extends Action<GetSnapshotsRequest, GetSnapshotsResponse> {
|
||||
public class GetSnapshotsAction extends Action<GetSnapshotsResponse> {
|
||||
|
||||
public static final GetSnapshotsAction INSTANCE = new GetSnapshotsAction();
|
||||
public static final String NAME = "cluster:admin/snapshot/get";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Restore snapshot action
|
||||
*/
|
||||
public class RestoreSnapshotAction extends Action<RestoreSnapshotRequest, RestoreSnapshotResponse> {
|
||||
public class RestoreSnapshotAction extends Action<RestoreSnapshotResponse> {
|
||||
|
||||
public static final RestoreSnapshotAction INSTANCE = new RestoreSnapshotAction();
|
||||
public static final String NAME = "cluster:admin/snapshot/restore";
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.Action;
|
|||
/**
|
||||
* Snapshots status action
|
||||
*/
|
||||
public class SnapshotsStatusAction extends Action<SnapshotsStatusRequest, SnapshotsStatusResponse> {
|
||||
public class SnapshotsStatusAction extends Action<SnapshotsStatusResponse> {
|
||||
|
||||
public static final SnapshotsStatusAction INSTANCE = new SnapshotsStatusAction();
|
||||
public static final String NAME = "cluster:admin/snapshot/status";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.state;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClusterStateAction extends Action<ClusterStateRequest, ClusterStateResponse> {
|
||||
public class ClusterStateAction extends Action<ClusterStateResponse> {
|
||||
|
||||
public static final ClusterStateAction INSTANCE = new ClusterStateAction();
|
||||
public static final String NAME = "cluster:monitor/state";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.stats;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClusterStatsAction extends Action<ClusterStatsRequest, ClusterStatsResponse> {
|
||||
public class ClusterStatsAction extends Action<ClusterStatsResponse> {
|
||||
|
||||
public static final ClusterStatsAction INSTANCE = new ClusterStatsAction();
|
||||
public static final String NAME = "cluster:monitor/stats";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class DeleteStoredScriptAction extends Action<DeleteStoredScriptRequest, DeleteStoredScriptResponse> {
|
||||
public class DeleteStoredScriptAction extends Action<DeleteStoredScriptResponse> {
|
||||
|
||||
public static final DeleteStoredScriptAction INSTANCE = new DeleteStoredScriptAction();
|
||||
public static final String NAME = "cluster:admin/script/delete";
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.action.admin.cluster.storedscripts;
|
||||
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
public class DeleteStoredScriptResponse extends AcknowledgedResponse {
|
||||
|
||||
|
@ -29,4 +30,8 @@ public class DeleteStoredScriptResponse extends AcknowledgedResponse {
|
|||
public DeleteStoredScriptResponse(boolean acknowledged) {
|
||||
super(acknowledged);
|
||||
}
|
||||
|
||||
public static DeleteStoredScriptResponse fromXContent(XContentParser parser) {
|
||||
return new DeleteStoredScriptResponse(parseAcknowledged(parser));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class GetStoredScriptAction extends Action<GetStoredScriptRequest, GetStoredScriptResponse> {
|
||||
public class GetStoredScriptAction extends Action<GetStoredScriptResponse> {
|
||||
|
||||
public static final GetStoredScriptAction INSTANCE = new GetStoredScriptAction();
|
||||
public static final String NAME = "cluster:admin/script/get";
|
||||
|
|
|
@ -21,25 +21,63 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.StatusToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.script.StoredScriptSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GetStoredScriptResponse extends ActionResponse implements ToXContentObject {
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
||||
|
||||
public class GetStoredScriptResponse extends ActionResponse implements StatusToXContentObject {
|
||||
|
||||
public static final ParseField _ID_PARSE_FIELD = new ParseField("_id");
|
||||
public static final ParseField FOUND_PARSE_FIELD = new ParseField("found");
|
||||
public static final ParseField SCRIPT = new ParseField("script");
|
||||
|
||||
private static final ConstructingObjectParser<GetStoredScriptResponse, String> PARSER =
|
||||
new ConstructingObjectParser<>("GetStoredScriptResponse",
|
||||
true,
|
||||
(a, c) -> {
|
||||
String id = (String) a[0];
|
||||
boolean found = (Boolean)a[1];
|
||||
StoredScriptSource scriptSource = (StoredScriptSource)a[2];
|
||||
return found ? new GetStoredScriptResponse(id, scriptSource) : new GetStoredScriptResponse(id, null);
|
||||
});
|
||||
|
||||
static {
|
||||
PARSER.declareField(constructorArg(), (p, c) -> p.text(),
|
||||
_ID_PARSE_FIELD, ObjectParser.ValueType.STRING);
|
||||
PARSER.declareField(constructorArg(), (p, c) -> p.booleanValue(),
|
||||
FOUND_PARSE_FIELD, ObjectParser.ValueType.BOOLEAN);
|
||||
PARSER.declareField(optionalConstructorArg(), (p, c) -> StoredScriptSource.fromXContent(p, true),
|
||||
SCRIPT, ObjectParser.ValueType.OBJECT);
|
||||
}
|
||||
|
||||
private String id;
|
||||
private StoredScriptSource source;
|
||||
|
||||
GetStoredScriptResponse() {
|
||||
}
|
||||
|
||||
GetStoredScriptResponse(StoredScriptSource source) {
|
||||
GetStoredScriptResponse(String id, StoredScriptSource source) {
|
||||
this.id = id;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if a stored script and if not found <code>null</code>
|
||||
*/
|
||||
|
@ -48,12 +86,29 @@ public class GetStoredScriptResponse extends ActionResponse implements ToXConten
|
|||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
source.toXContent(builder, params);
|
||||
public RestStatus status() {
|
||||
return source != null ? RestStatus.OK : RestStatus.NOT_FOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
||||
builder.field(_ID_PARSE_FIELD.getPreferredName(), id);
|
||||
builder.field(FOUND_PARSE_FIELD.getPreferredName(), source != null);
|
||||
if (source != null) {
|
||||
builder.field(StoredScriptSource.SCRIPT_PARSE_FIELD.getPreferredName());
|
||||
source.toXContent(builder, params);
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static GetStoredScriptResponse fromXContent(XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
|
@ -67,6 +122,10 @@ public class GetStoredScriptResponse extends ActionResponse implements ToXConten
|
|||
} else {
|
||||
source = null;
|
||||
}
|
||||
|
||||
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
|
||||
id = in.readString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,5 +143,22 @@ public class GetStoredScriptResponse extends ActionResponse implements ToXConten
|
|||
out.writeString(source.getSource());
|
||||
}
|
||||
}
|
||||
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
|
||||
out.writeString(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GetStoredScriptResponse that = (GetStoredScriptResponse) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(source, that.source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
|
|||
import org.elasticsearch.action.Action;
|
||||
|
||||
|
||||
public class PutStoredScriptAction extends Action<PutStoredScriptRequest, PutStoredScriptResponse> {
|
||||
public class PutStoredScriptAction extends Action<PutStoredScriptResponse> {
|
||||
|
||||
public static final PutStoredScriptAction INSTANCE = new PutStoredScriptAction();
|
||||
public static final String NAME = "cluster:admin/script/put";
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TransportGetStoredScriptAction extends TransportMasterNodeReadActio
|
|||
@Override
|
||||
protected void masterOperation(GetStoredScriptRequest request, ClusterState state,
|
||||
ActionListener<GetStoredScriptResponse> listener) throws Exception {
|
||||
listener.onResponse(new GetStoredScriptResponse(scriptService.getStoredScript(state, request)));
|
||||
listener.onResponse(new GetStoredScriptResponse(request.id(), scriptService.getStoredScript(state, request)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.cluster.tasks;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class PendingClusterTasksAction extends Action<PendingClusterTasksRequest, PendingClusterTasksResponse> {
|
||||
public class PendingClusterTasksAction extends Action<PendingClusterTasksResponse> {
|
||||
|
||||
public static final PendingClusterTasksAction INSTANCE = new PendingClusterTasksAction();
|
||||
public static final String NAME = "cluster:monitor/task";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.alias;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class IndicesAliasesAction extends Action<IndicesAliasesRequest, IndicesAliasesResponse> {
|
||||
public class IndicesAliasesAction extends Action<IndicesAliasesResponse> {
|
||||
|
||||
public static final IndicesAliasesAction INSTANCE = new IndicesAliasesAction();
|
||||
public static final String NAME = "indices:admin/aliases";
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
package org.elasticsearch.action.admin.indices.alias.exists;
|
||||
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||
|
||||
public class AliasesExistAction extends Action<GetAliasesRequest, AliasesExistResponse> {
|
||||
public class AliasesExistAction extends Action<AliasesExistResponse> {
|
||||
|
||||
public static final AliasesExistAction INSTANCE = new AliasesExistAction();
|
||||
public static final String NAME = "indices:admin/aliases/exists";
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.elasticsearch.common.util.ArrayUtils;
|
|||
|
||||
public abstract class BaseAliasesRequestBuilder<Response extends ActionResponse, Builder extends BaseAliasesRequestBuilder<Response, Builder>> extends MasterNodeReadOperationRequestBuilder<GetAliasesRequest, Response, Builder> {
|
||||
|
||||
public BaseAliasesRequestBuilder(ElasticsearchClient client, Action<GetAliasesRequest, Response> action, String... aliases) {
|
||||
public BaseAliasesRequestBuilder(ElasticsearchClient client, Action<Response> action, String... aliases) {
|
||||
super(client, action, new GetAliasesRequest(aliases));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.alias.get;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class GetAliasesAction extends Action<GetAliasesRequest, GetAliasesResponse> {
|
||||
public class GetAliasesAction extends Action<GetAliasesResponse> {
|
||||
|
||||
public static final GetAliasesAction INSTANCE = new GetAliasesAction();
|
||||
public static final String NAME = "indices:admin/aliases/get";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.analyze;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class AnalyzeAction extends Action<AnalyzeRequest, AnalyzeResponse> {
|
||||
public class AnalyzeAction extends Action<AnalyzeResponse> {
|
||||
|
||||
public static final AnalyzeAction INSTANCE = new AnalyzeAction();
|
||||
public static final String NAME = "indices:admin/analyze";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.cache.clear;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ClearIndicesCacheAction extends Action<ClearIndicesCacheRequest, ClearIndicesCacheResponse> {
|
||||
public class ClearIndicesCacheAction extends Action<ClearIndicesCacheResponse> {
|
||||
|
||||
public static final ClearIndicesCacheAction INSTANCE = new ClearIndicesCacheAction();
|
||||
public static final String NAME = "indices:admin/cache/clear";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.close;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class CloseIndexAction extends Action<CloseIndexRequest, CloseIndexResponse> {
|
||||
public class CloseIndexAction extends Action<CloseIndexResponse> {
|
||||
|
||||
public static final CloseIndexAction INSTANCE = new CloseIndexAction();
|
||||
public static final String NAME = "indices:admin/close";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.create;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class CreateIndexAction extends Action<CreateIndexRequest, CreateIndexResponse> {
|
||||
public class CreateIndexAction extends Action<CreateIndexResponse> {
|
||||
|
||||
public static final CreateIndexAction INSTANCE = new CreateIndexAction();
|
||||
public static final String NAME = "indices:admin/create";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.delete;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class DeleteIndexAction extends Action<DeleteIndexRequest, DeleteIndexResponse> {
|
||||
public class DeleteIndexAction extends Action<DeleteIndexResponse> {
|
||||
|
||||
public static final DeleteIndexAction INSTANCE = new DeleteIndexAction();
|
||||
public static final String NAME = "indices:admin/delete";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.exists.indices;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class IndicesExistsAction extends Action<IndicesExistsRequest, IndicesExistsResponse> {
|
||||
public class IndicesExistsAction extends Action<IndicesExistsResponse> {
|
||||
|
||||
public static final IndicesExistsAction INSTANCE = new IndicesExistsAction();
|
||||
public static final String NAME = "indices:admin/exists";
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.elasticsearch.action.admin.indices.exists.types;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class TypesExistsAction extends Action<TypesExistsRequest, TypesExistsResponse> {
|
||||
public class TypesExistsAction extends Action<TypesExistsResponse> {
|
||||
|
||||
public static final TypesExistsAction INSTANCE = new TypesExistsAction();
|
||||
public static final String NAME = "indices:admin/types/exists";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.flush;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class FlushAction extends Action<FlushRequest, FlushResponse> {
|
||||
public class FlushAction extends Action<FlushResponse> {
|
||||
|
||||
public static final FlushAction INSTANCE = new FlushAction();
|
||||
public static final String NAME = "indices:admin/flush";
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.action.admin.indices.flush;
|
|||
import org.elasticsearch.action.Action;
|
||||
|
||||
|
||||
public class SyncedFlushAction extends Action<SyncedFlushRequest, SyncedFlushResponse> {
|
||||
public class SyncedFlushAction extends Action<SyncedFlushResponse> {
|
||||
|
||||
public static final SyncedFlushAction INSTANCE = new SyncedFlushAction();
|
||||
public static final String NAME = "indices:admin/synced_flush";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.forcemerge;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class ForceMergeAction extends Action<ForceMergeRequest, ForceMergeResponse> {
|
||||
public class ForceMergeAction extends Action<ForceMergeResponse> {
|
||||
|
||||
public static final ForceMergeAction INSTANCE = new ForceMergeAction();
|
||||
public static final String NAME = "indices:admin/forcemerge";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.get;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class GetIndexAction extends Action<GetIndexRequest, GetIndexResponse> {
|
||||
public class GetIndexAction extends Action<GetIndexResponse> {
|
||||
|
||||
public static final GetIndexAction INSTANCE = new GetIndexAction();
|
||||
public static final String NAME = "indices:admin/get";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.mapping.get;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class GetFieldMappingsAction extends Action<GetFieldMappingsRequest, GetFieldMappingsResponse> {
|
||||
public class GetFieldMappingsAction extends Action<GetFieldMappingsResponse> {
|
||||
|
||||
public static final GetFieldMappingsAction INSTANCE = new GetFieldMappingsAction();
|
||||
public static final String NAME = "indices:admin/mappings/fields/get";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.mapping.get;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class GetMappingsAction extends Action<GetMappingsRequest, GetMappingsResponse> {
|
||||
public class GetMappingsAction extends Action<GetMappingsResponse> {
|
||||
|
||||
public static final GetMappingsAction INSTANCE = new GetMappingsAction();
|
||||
public static final String NAME = "indices:admin/mappings/get";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.mapping.put;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class PutMappingAction extends Action<PutMappingRequest, PutMappingResponse> {
|
||||
public class PutMappingAction extends Action<PutMappingResponse> {
|
||||
|
||||
public static final PutMappingAction INSTANCE = new PutMappingAction();
|
||||
public static final String NAME = "indices:admin/mapping/put";
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.action.admin.indices.open;
|
|||
|
||||
import org.elasticsearch.action.Action;
|
||||
|
||||
public class OpenIndexAction extends Action<OpenIndexRequest, OpenIndexResponse> {
|
||||
public class OpenIndexAction extends Action<OpenIndexResponse> {
|
||||
|
||||
public static final OpenIndexAction INSTANCE = new OpenIndexAction();
|
||||
public static final String NAME = "indices:admin/open";
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue