From fd76651d92c18a14cd46395c7fc7ffe8ec5d9733 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Wed, 16 Aug 2017 07:43:18 +0800 Subject: [PATCH] Expose timeout of acknowledged requests in REST layer (elastic/x-pack-elasticsearch#2259) Companion PR to elastic/elasticsearch#26189 Original commit: elastic/x-pack-elasticsearch@f561e228357f65b3a9fa0b82155dc597100b8142 --- .../license/PutLicenseRequest.java | 2 -- .../license/RestDeleteLicenseAction.java | 9 ++++--- .../license/RestPutLicenseAction.java | 3 +++ .../datafeeds/RestDeleteDatafeedAction.java | 2 ++ .../rest/datafeeds/RestPutDatafeedAction.java | 2 ++ .../datafeeds/RestUpdateDatafeedAction.java | 3 +++ .../rest/filter/RestDeleteFilterAction.java | 2 ++ .../ml/rest/job/RestDeleteJobAction.java | 2 ++ .../ml/rest/job/RestPostJobUpdateAction.java | 3 +++ .../xpack/ml/rest/job/RestPutJobAction.java | 3 +++ .../RestRevertModelSnapshotAction.java | 3 +++ .../action/MonitoringBulkDocTests.java | 24 ------------------- .../execute/ExecuteWatchRequestTests.java | 21 ---------------- 13 files changed, 29 insertions(+), 50 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/license/PutLicenseRequest.java b/plugin/src/main/java/org/elasticsearch/license/PutLicenseRequest.java index 1c82588efe8..6657adee41d 100644 --- a/plugin/src/main/java/org/elasticsearch/license/PutLicenseRequest.java +++ b/plugin/src/main/java/org/elasticsearch/license/PutLicenseRequest.java @@ -66,7 +66,6 @@ public class PutLicenseRequest extends AcknowledgedRequest { super.readFrom(in); license = License.readLicense(in); acknowledge = in.readBoolean(); - readTimeout(in); } @Override @@ -74,6 +73,5 @@ public class PutLicenseRequest extends AcknowledgedRequest { super.writeTo(out); license.writeTo(out); out.writeBoolean(acknowledge); - writeTimeout(out); } } diff --git a/plugin/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java b/plugin/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java index b7ee7e89fe8..9b3757adc16 100644 --- a/plugin/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java +++ b/plugin/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java @@ -29,9 +29,12 @@ public class RestDeleteLicenseAction extends XPackRestHandler { @Override public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException { - return channel -> client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE, - new DeleteLicenseRequest(), - new AcknowledgedRestListener<>(channel)); + DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest(); + deleteLicenseRequest.timeout(request.paramAsTime("timeout", deleteLicenseRequest.timeout())); + deleteLicenseRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteLicenseRequest.masterNodeTimeout())); + + return channel -> client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest, + new AcknowledgedRestListener<>(channel)); } } diff --git a/plugin/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java b/plugin/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java index 8a92e108eb2..2abed32bfa8 100644 --- a/plugin/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java +++ b/plugin/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java @@ -44,6 +44,9 @@ public class RestPutLicenseAction extends XPackRestHandler { PutLicenseRequest putLicenseRequest = new PutLicenseRequest(); putLicenseRequest.license(request.content(), request.getXContentType()); putLicenseRequest.acknowledge(request.paramAsBoolean("acknowledge", false)); + putLicenseRequest.timeout(request.paramAsTime("timeout", putLicenseRequest.timeout())); + putLicenseRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putLicenseRequest.masterNodeTimeout())); + return channel -> client.es().admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest, new RestBuilderListener(channel) { @Override diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java index e385a63751f..6e847af0886 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java @@ -38,6 +38,8 @@ public class RestDeleteDatafeedAction extends BaseRestHandler { if (restRequest.hasParam(DeleteDatafeedAction.Request.FORCE.getPreferredName())) { request.setForce(restRequest.paramAsBoolean(CloseJobAction.Request.FORCE.getPreferredName(), request.isForce())); } + request.timeout(restRequest.paramAsTime("timeout", request.timeout())); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(DeleteDatafeedAction.INSTANCE, request, new AcknowledgedRestListener<>(channel)); } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java index 6a350411e51..e4032da3c35 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java @@ -36,6 +36,8 @@ public class RestPutDatafeedAction extends BaseRestHandler { String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName()); XContentParser parser = restRequest.contentParser(); PutDatafeedAction.Request putDatafeedRequest = PutDatafeedAction.Request.parseRequest(datafeedId, parser); + putDatafeedRequest.timeout(restRequest.paramAsTime("timeout", putDatafeedRequest.timeout())); + putDatafeedRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", putDatafeedRequest.masterNodeTimeout())); return channel -> client.execute(PutDatafeedAction.INSTANCE, putDatafeedRequest, new RestToXContentListener<>(channel)); } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java index cc0cb9c8965..7c36ae1dd62 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java @@ -36,6 +36,9 @@ public class RestUpdateDatafeedAction extends BaseRestHandler { String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName()); XContentParser parser = restRequest.contentParser(); UpdateDatafeedAction.Request updateDatafeedRequest = UpdateDatafeedAction.Request.parseRequest(datafeedId, parser); + updateDatafeedRequest.timeout(restRequest.paramAsTime("timeout", updateDatafeedRequest.timeout())); + updateDatafeedRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", updateDatafeedRequest.masterNodeTimeout())); + return channel -> client.execute(UpdateDatafeedAction.INSTANCE, updateDatafeedRequest, new RestToXContentListener<>(channel)); } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java index 988ddf42a56..bbdcdc7f15f 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java @@ -33,6 +33,8 @@ public class RestDeleteFilterAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { Request request = new Request(restRequest.param(Request.FILTER_ID.getPreferredName())); + request.timeout(restRequest.paramAsTime("timeout", request.timeout())); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(DeleteFilterAction.INSTANCE, request, new AcknowledgedRestListener<>(channel)); } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java index a3b0582c9cc..1f2e499fd46 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java @@ -35,6 +35,8 @@ public class RestDeleteJobAction extends BaseRestHandler { protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { DeleteJobAction.Request deleteJobRequest = new DeleteJobAction.Request(restRequest.param(Job.ID.getPreferredName())); deleteJobRequest.setForce(restRequest.paramAsBoolean(CloseJobAction.Request.FORCE.getPreferredName(), deleteJobRequest.isForce())); + deleteJobRequest.timeout(restRequest.paramAsTime("timeout", deleteJobRequest.timeout())); + deleteJobRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", deleteJobRequest.masterNodeTimeout())); return channel -> client.execute(DeleteJobAction.INSTANCE, deleteJobRequest, new AcknowledgedRestListener<>(channel)); } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java index 52b10ca00a0..9238110c720 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java @@ -35,6 +35,9 @@ public class RestPostJobUpdateAction extends BaseRestHandler { String jobId = restRequest.param(Job.ID.getPreferredName()); XContentParser parser = restRequest.contentParser(); UpdateJobAction.Request updateJobRequest = UpdateJobAction.Request.parseRequest(jobId, parser); + updateJobRequest.timeout(restRequest.paramAsTime("timeout", updateJobRequest.timeout())); + updateJobRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", updateJobRequest.masterNodeTimeout())); + return channel -> client.execute(UpdateJobAction.INSTANCE, updateJobRequest, new RestToXContentListener<>(channel)); } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java index e99afaa4e53..85ed6b5c967 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java @@ -36,6 +36,9 @@ public class RestPutJobAction extends BaseRestHandler { String jobId = restRequest.param(Job.ID.getPreferredName()); XContentParser parser = restRequest.contentParser(); PutJobAction.Request putJobRequest = PutJobAction.Request.parseRequest(jobId, parser); + putJobRequest.timeout(restRequest.paramAsTime("timeout", putJobRequest.timeout())); + putJobRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", putJobRequest.masterNodeTimeout())); + return channel -> client.execute(PutJobAction.INSTANCE, putJobRequest, new RestToXContentListener<>(channel)); } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java index 101179f880b..37867b8b290 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java @@ -47,6 +47,9 @@ public class RestRevertModelSnapshotAction extends BaseRestHandler { request.setDeleteInterveningResults(restRequest .paramAsBoolean(RevertModelSnapshotAction.Request.DELETE_INTERVENING.getPreferredName(), DELETE_INTERVENING_DEFAULT)); } + request.timeout(restRequest.paramAsTime("timeout", request.timeout())); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); + return channel -> client.execute(RevertModelSnapshotAction.INSTANCE, request, new RestStatusToXContentListener<>(channel)); } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java index 25057e5e17a..ee74f47ea44 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.xpack.monitoring.MonitoredSystem; import org.elasticsearch.xpack.monitoring.exporter.MonitoringDoc; import java.io.IOException; -import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -56,29 +55,6 @@ public class MonitoringBulkDocTests extends ESTestCase { } } - public void testSerializationBwc() throws IOException { - final byte[] data = Base64.getDecoder().decode("AQNtSWQBBTUuMS4yAAAAAQEEdHlwZQECaWQNeyJmb28iOiJiYXIifQAAAAAAAAAA"); - final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, - Version.V_5_1_1, Version.V_5_1_2, Version.V_5_2_0); - try (StreamInput in = StreamInput.wrap(data)) { - in.setVersion(version); - MonitoringBulkDoc bulkDoc = MonitoringBulkDoc.readFrom(in); - assertEquals(XContentType.JSON, bulkDoc.getXContentType()); - assertEquals("mId", bulkDoc.getMonitoringId()); - assertEquals("5.1.2", bulkDoc.getMonitoringVersion()); - assertEquals(MonitoringIndex.TIMESTAMPED, bulkDoc.getIndex()); - assertEquals("{\"foo\":\"bar\"}", bulkDoc.getSource().utf8ToString()); - assertEquals("type", bulkDoc.getType()); - assertEquals("id", bulkDoc.getId()); - - try (BytesStreamOutput out = new BytesStreamOutput()) { - out.setVersion(version); - bulkDoc.writeTo(out); - assertArrayEquals(data, out.bytes().toBytesRef().bytes); - } - } - } - public static MonitoringBulkDoc newRandomMonitoringBulkDoc() { String monitoringId = randomFrom(MonitoredSystem.values()).getSystem(); String monitoringVersion = randomVersion(random()).toString(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchRequestTests.java index 325a77cfff1..798b473fc67 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchRequestTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.transport.action.execute; -import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; @@ -15,7 +14,6 @@ import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchReq import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Base64; public class ExecuteWatchRequestTests extends ESTestCase { @@ -32,23 +30,4 @@ public class ExecuteWatchRequestTests extends ESTestCase { assertEquals(XContentType.JSON, serialized.getXContentType()); assertEquals("{}", serialized.getWatchSource().utf8ToString()); } - - public void testSerializationBwc() throws IOException { - final byte[] data = Base64.getDecoder().decode("ADwDAAAAAAAAAAAAAAAAAAABDnsid2F0Y2giOiJtZSJ9AAAAAAAAAA=="); - final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, - Version.V_5_1_1, Version.V_5_1_2, Version.V_5_2_0); - try (StreamInput in = StreamInput.wrap(data)) { - in.setVersion(version); - ExecuteWatchRequest request = new ExecuteWatchRequest(); - request.readFrom(in); - assertEquals(XContentType.JSON, request.getXContentType()); - assertEquals("{\"watch\":\"me\"}", request.getWatchSource().utf8ToString()); - - try (BytesStreamOutput out = new BytesStreamOutput()) { - out.setVersion(version); - request.writeTo(out); - assertArrayEquals(data, out.bytes().toBytesRef().bytes); - } - } - } }