diff --git a/docs/changelog/105168.yaml b/docs/changelog/105168.yaml new file mode 100644 index 000000000000..0f3792b832f5 --- /dev/null +++ b/docs/changelog/105168.yaml @@ -0,0 +1,5 @@ +pr: 105168 +summary: Add ?master_timeout query parameter to ccr apis +area: CCR +type: bug +issues: [] diff --git a/docs/reference/ccr/apis/auto-follow/delete-auto-follow-pattern.asciidoc b/docs/reference/ccr/apis/auto-follow/delete-auto-follow-pattern.asciidoc index c53ad7b26802..dffb20715a67 100644 --- a/docs/reference/ccr/apis/auto-follow/delete-auto-follow-pattern.asciidoc +++ b/docs/reference/ccr/apis/auto-follow/delete-auto-follow-pattern.asciidoc @@ -54,6 +54,13 @@ This API deletes a configured collection of ``:: (Required, string) Specifies the auto-follow pattern collection to delete. +[[ccr-delete-auto-follow-pattern-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. [[ccr-delete-auto-follow-pattern-examples]] ==== {api-examples-title} diff --git a/docs/reference/ccr/apis/auto-follow/get-auto-follow-pattern.asciidoc b/docs/reference/ccr/apis/auto-follow/get-auto-follow-pattern.asciidoc index a3169adad1c2..bcb0406fd43b 100644 --- a/docs/reference/ccr/apis/auto-follow/get-auto-follow-pattern.asciidoc +++ b/docs/reference/ccr/apis/auto-follow/get-auto-follow-pattern.asciidoc @@ -72,6 +72,14 @@ This API will return the specified auto-follow pattern collection. to retrieve. If you do not specify a name, the API returns information for all collections. +[[ccr-get-auto-follow-pattern-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [[ccr-get-auto-follow-pattern-examples]] ==== {api-examples-title} diff --git a/docs/reference/ccr/apis/auto-follow/pause-auto-follow-pattern.asciidoc b/docs/reference/ccr/apis/auto-follow/pause-auto-follow-pattern.asciidoc index 875f6626e618..0ca8a8de6e57 100644 --- a/docs/reference/ccr/apis/auto-follow/pause-auto-follow-pattern.asciidoc +++ b/docs/reference/ccr/apis/auto-follow/pause-auto-follow-pattern.asciidoc @@ -40,6 +40,13 @@ meantime. ``:: (Required, string) Name of the auto-follow pattern to pause. +[[ccr-pause-auto-follow-pattern-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. [[ccr-pause-auto-follow-pattern-examples]] ==== {api-examples-title} diff --git a/docs/reference/ccr/apis/auto-follow/put-auto-follow-pattern.asciidoc b/docs/reference/ccr/apis/auto-follow/put-auto-follow-pattern.asciidoc index e6509e024de8..f38454a1ad02 100644 --- a/docs/reference/ccr/apis/auto-follow/put-auto-follow-pattern.asciidoc +++ b/docs/reference/ccr/apis/auto-follow/put-auto-follow-pattern.asciidoc @@ -71,6 +71,14 @@ the new patterns. ``:: (Required, string) The name of the collection of auto-follow patterns. +[[ccr-put-auto-follow-pattern-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [[ccr-put-auto-follow-pattern-request-body]] ==== {api-request-body-title} diff --git a/docs/reference/ccr/apis/auto-follow/resume-auto-follow-pattern.asciidoc b/docs/reference/ccr/apis/auto-follow/resume-auto-follow-pattern.asciidoc index c28fddb766bf..431137a6a9c1 100644 --- a/docs/reference/ccr/apis/auto-follow/resume-auto-follow-pattern.asciidoc +++ b/docs/reference/ccr/apis/auto-follow/resume-auto-follow-pattern.asciidoc @@ -35,6 +35,13 @@ have been deleted or closed in the meantime. ``:: (Required, string) Specifies the name of the auto-follow pattern to resume. +[[ccr-resume-auto-follow-pattern-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. [[ccr-resume-auto-follow-pattern-examples]] ==== {api-examples-title} diff --git a/docs/reference/ccr/apis/follow/get-follow-info.asciidoc b/docs/reference/ccr/apis/follow/get-follow-info.asciidoc index c4562b2000db..26bb9ac50d2e 100644 --- a/docs/reference/ccr/apis/follow/get-follow-info.asciidoc +++ b/docs/reference/ccr/apis/follow/get-follow-info.asciidoc @@ -49,6 +49,14 @@ replication options and whether the follower indices are active or paused. ``:: (Required, string) A comma-delimited list of follower index patterns. +[[ccr-get-follow-info-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [role="child_attributes"] [[ccr-get-follow-info-response-body]] ==== {api-response-body-title} diff --git a/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc b/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc index c910b0431a6e..72224cc7f51f 100644 --- a/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc +++ b/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc @@ -56,6 +56,12 @@ following tasks associated with each shard for the specified indices. ``:: (Required, string) A comma-delimited list of index patterns. +[[ccr-get-follow-stats-query-params]] +==== {api-query-parms-title} + +`timeout`:: +(Optional, time) Controls the amount of time to wait for results. Defaults to unlimited. + [role="child_attributes"] [[ccr-get-follow-stats-response-body]] ==== {api-response-body-title} diff --git a/docs/reference/ccr/apis/follow/post-forget-follower.asciidoc b/docs/reference/ccr/apis/follow/post-forget-follower.asciidoc index 7df4132da91e..ea7e8640056b 100644 --- a/docs/reference/ccr/apis/follow/post-forget-follower.asciidoc +++ b/docs/reference/ccr/apis/follow/post-forget-follower.asciidoc @@ -100,6 +100,12 @@ the <> is invoked. ``:: (Required, string) The name of the leader index. +[[ccr-post-forget-follower-query-params]] +==== {api-query-parms-title} + +`timeout`:: +(Optional, time) Controls the amount of time to wait for results. Defaults to unlimited. + [[ccr-post-forget-follower-request-body]] ==== {api-request-body-title} diff --git a/docs/reference/ccr/apis/follow/post-pause-follow.asciidoc b/docs/reference/ccr/apis/follow/post-pause-follow.asciidoc index 0ccdd4e1b30f..b0a6752358cf 100644 --- a/docs/reference/ccr/apis/follow/post-pause-follow.asciidoc +++ b/docs/reference/ccr/apis/follow/post-pause-follow.asciidoc @@ -53,6 +53,14 @@ following task. ``:: (Required, string) The name of the follower index. +[[ccr-post-pause-follow-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [[ccr-post-pause-follow-examples]] ==== {api-examples-title} diff --git a/docs/reference/ccr/apis/follow/post-resume-follow.asciidoc b/docs/reference/ccr/apis/follow/post-resume-follow.asciidoc index 3d72fa0bff3e..1f1996837cd8 100644 --- a/docs/reference/ccr/apis/follow/post-resume-follow.asciidoc +++ b/docs/reference/ccr/apis/follow/post-resume-follow.asciidoc @@ -66,6 +66,14 @@ returns, the follower index will resume fetching operations from the leader inde ``:: (Required, string) The name of the follower index. +[[ccr-post-resume-follow-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [[ccr-post-resume-follow-request-body]] ==== {api-request-body-title} include::../follow-request-body.asciidoc[tag=ccr-resume-follow-request-body] diff --git a/docs/reference/ccr/apis/follow/post-unfollow.asciidoc b/docs/reference/ccr/apis/follow/post-unfollow.asciidoc index 7bf7dba5fa8d..0851340a4da0 100644 --- a/docs/reference/ccr/apis/follow/post-unfollow.asciidoc +++ b/docs/reference/ccr/apis/follow/post-unfollow.asciidoc @@ -38,9 +38,9 @@ POST //_ccr/unfollow [[ccr-post-unfollow-prereqs]] ==== {api-prereq-title} -* If the {es} {security-features} are enabled, you must have `manage_follow_index` +* If the {es} {security-features} are enabled, you must have `manage_follow_index` index privileges for the follower index. For more information, see -<>. +<>. [[ccr-post-unfollow-desc]] ==== {api-description-title} @@ -60,6 +60,14 @@ irreversible operation. ``:: (Required, string) The name of the follower index. +[[ccr-post-unfollow-query-params]] +==== {api-query-parms-title} + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [[ccr-post-unfollow-examples]] ==== {api-examples-title} diff --git a/docs/reference/ccr/apis/follow/put-follow.asciidoc b/docs/reference/ccr/apis/follow/put-follow.asciidoc index 93e8a710751a..a7fdfc5ae96c 100644 --- a/docs/reference/ccr/apis/follow/put-follow.asciidoc +++ b/docs/reference/ccr/apis/follow/put-follow.asciidoc @@ -65,6 +65,11 @@ referenced leader index. When this API returns, the follower index exists, and follower shard requires transferring all the remote Lucene segment files to the follower index. +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [[ccr-put-follow-request-body]] ==== {api-request-body-title} diff --git a/docs/reference/ccr/apis/get-ccr-stats.asciidoc b/docs/reference/ccr/apis/get-ccr-stats.asciidoc index 02f5cf886049..69836aec910d 100644 --- a/docs/reference/ccr/apis/get-ccr-stats.asciidoc +++ b/docs/reference/ccr/apis/get-ccr-stats.asciidoc @@ -50,6 +50,17 @@ This API gets {ccr} stats. This API will return all stats related to {ccr}. In particular, this API returns stats about auto-following, and returns the same shard-level stats as in the <>. +[[ccr-get-stats-query-params]] +==== {api-query-parms-title} + +`timeout`:: +(Optional, time) Controls the amount of time to wait for results. Defaults to unlimited. + +`master_timeout`:: +(Optional, <>) Specifies the period of time to wait for +a connection to the master node. If no response is received before the timeout +expires, the request fails and returns an error. Defaults to `30s`. + [role="child_attributes"] [[ccr-get-stats-response-body]] ==== {api-response-body-title} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.delete_auto_follow_pattern.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.delete_auto_follow_pattern.json index 52f56ca32136..c316e9fcbd36 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.delete_auto_follow_pattern.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.delete_auto_follow_pattern.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow.json index 6905a53ead48..642477cb45e4 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow.json @@ -31,6 +31,10 @@ "type":"string", "description":"Sets the number of shard copies that must be active before returning. Defaults to 0. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)", "default":"0" + }, + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" } }, "body":{ diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_info.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_info.json index 17ecd57155a9..a2af3f9be77d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_info.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_info.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_stats.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_stats.json index 54de8c4df64f..75d0bafb5083 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_stats.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.follow_stats.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "timeout":{ + "type":"time", + "description":"Explicit operation timeout" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.forget_follower.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.forget_follower.json index 8106a74b9d00..61a132a1f4ac 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.forget_follower.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.forget_follower.json @@ -26,6 +26,12 @@ } ] }, + "params":{ + "timeout":{ + "type":"time", + "description":"Explicit operation timeout" + } + }, "body":{ "description":"the name and UUID of the follower index, the name of the cluster containing the follower index, and the alias from the perspective of that cluster for the remote cluster containing the leader index", "required":true diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.get_auto_follow_pattern.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.get_auto_follow_pattern.json index 8073fd72bba3..663f37fca3a9 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.get_auto_follow_pattern.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.get_auto_follow_pattern.json @@ -30,6 +30,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_auto_follow_pattern.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_auto_follow_pattern.json index 9375673489e1..c766304fc051 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_auto_follow_pattern.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_auto_follow_pattern.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_follow.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_follow.json index a4923df29c56..1c1fcf71d08f 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_follow.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.pause_follow.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.put_auto_follow_pattern.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.put_auto_follow_pattern.json index 6331b4ff0610..6f5f03bc9a3d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.put_auto_follow_pattern.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.put_auto_follow_pattern.json @@ -26,6 +26,12 @@ } ] }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } + }, "body":{ "description":"The specification of the auto follow pattern", "required":true diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_auto_follow_pattern.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_auto_follow_pattern.json index b679155b28a0..a4ea108426ed 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_auto_follow_pattern.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_auto_follow_pattern.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_follow.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_follow.json index d6addce133a6..854ff83291a8 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_follow.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.resume_follow.json @@ -26,6 +26,12 @@ } ] }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } + }, "body":{ "description":"The name of the leader index and other optional ccr related parameters", "required":false diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.stats.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.stats.json index ac47e9c3d0b7..5ebc781109ab 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.stats.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.stats.json @@ -18,6 +18,16 @@ ] } ] + }, + "params":{ + "timeout":{ + "type":"time", + "description":"Explicit operation timeout" + }, + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.unfollow.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.unfollow.json index 7a49b4a10987..096d39fa1648 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.unfollow.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ccr.unfollow.json @@ -24,6 +24,12 @@ } } ] + }, + "params":{ + "master_timeout":{ + "type":"time", + "description":"Explicit operation timeout for connection to master node" + } } } } diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index b0649c942988..e072bfc799e5 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -160,6 +160,7 @@ public class TransportVersions { public static final TransportVersion ADD_PERSISTENT_TASK_EXCEPTIONS = def(8_619_00_0); public static final TransportVersion ESQL_REDUCER_NODE_FRAGMENT = def(8_620_00_0); public static final TransportVersion FAILURE_STORE_ROLLOVER = def(8_621_00_0); + public static final TransportVersion CCR_STATS_API_TIMEOUT_PARAM = def(8_622_00_0); /* * STOP! READ THIS FIRST! No, really, diff --git a/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/auto_follow.yml b/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/auto_follow.yml index 5003ebfdc4d7..66f9d5df3d9d 100644 --- a/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/auto_follow.yml +++ b/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/auto_follow.yml @@ -201,6 +201,7 @@ - do: ccr.put_auto_follow_pattern: name: pattern_test + master_timeout: 10s body: remote_cluster: local leader_index_patterns: ['logs-*'] @@ -224,6 +225,7 @@ - do: ccr.pause_auto_follow_pattern: name: pattern_test + master_timeout: 10s - is_true: acknowledged - do: @@ -243,6 +245,7 @@ - do: ccr.resume_auto_follow_pattern: name: pattern_test + master_timeout: 10s - is_true: acknowledged - do: diff --git a/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml b/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml index 78a0e67f1341..ac3ed826973b 100644 --- a/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml +++ b/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_and_unfollow.yml @@ -40,6 +40,7 @@ ccr.follow: index: bar wait_for_active_shards: 1 + master_timeout: 10s body: remote_cluster: local leader_index: foo diff --git a/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_info.yml b/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_info.yml index f3224482c274..604cbd83a70d 100644 --- a/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_info.yml +++ b/x-pack/plugin/ccr/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ccr/follow_info.yml @@ -34,6 +34,7 @@ ccr.follow: index: bar wait_for_active_shards: 1 + master_timeout: 10s body: remote_cluster: local leader_index: foo diff --git a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java index df8f19ab3888..dc899989eb04 100644 --- a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java +++ b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java @@ -734,17 +734,26 @@ public class AutoFollowIT extends CcrIntegTestCase { request.setLeaderIndexExclusionPatterns(exclusionPatterns); // Need to set this, because following an index in the same cluster request.setFollowIndexNamePattern("copy-{{leader_index}}"); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } assertTrue(followerClient().execute(PutAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); } private void deleteAutoFollowPattern(final String name) { DeleteAutoFollowPatternAction.Request request = new DeleteAutoFollowPatternAction.Request(name); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } assertTrue(followerClient().execute(DeleteAutoFollowPatternAction.INSTANCE, request).actionGet().isAcknowledged()); } private AutoFollowStats getAutoFollowStats() { CcrStatsAction.Request request = new CcrStatsAction.Request(); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } return followerClient().execute(CcrStatsAction.INSTANCE, request).actionGet().getAutoFollowStats(); } @@ -756,17 +765,26 @@ public class AutoFollowIT extends CcrIntegTestCase { private void pauseAutoFollowPattern(final String name) { ActivateAutoFollowPatternAction.Request request = new ActivateAutoFollowPatternAction.Request(name, false); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } assertAcked(followerClient().execute(ActivateAutoFollowPatternAction.INSTANCE, request).actionGet()); } private void resumeAutoFollowPattern(final String name) { ActivateAutoFollowPatternAction.Request request = new ActivateAutoFollowPatternAction.Request(name, true); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } assertAcked(followerClient().execute(ActivateAutoFollowPatternAction.INSTANCE, request).actionGet()); } private AutoFollowMetadata.AutoFollowPattern getAutoFollowPattern(final String name) { GetAutoFollowPatternAction.Request request = new GetAutoFollowPatternAction.Request(); request.setName(name); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } GetAutoFollowPatternAction.Response response = followerClient().execute(GetAutoFollowPatternAction.INSTANCE, request).actionGet(); assertTrue(response.getAutoFollowPatterns().containsKey(name)); return response.getAutoFollowPatterns().get(name); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportCcrStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportCcrStatsAction.java index 6b324ae90137..b089c1a4cb84 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportCcrStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportCcrStatsAction.java @@ -80,6 +80,9 @@ public class TransportCcrStatsAction extends TransportMasterNodeAction { AutoFollowStats stats = autoFollowCoordinator.getStats(); l.onResponse(new CcrStatsAction.Response(stats, statsResponse)); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java index 99c532f3b077..8207228f0d21 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPauseFollowAction.java @@ -98,7 +98,7 @@ public class TransportPauseFollowAction extends AcknowledgedTransportMasterNodeA final ResponseHandler responseHandler = new ResponseHandler(shardFollowTaskIds.size(), listener); for (String taskId : shardFollowTaskIds) { final int taskSlot = i++; - persistentTasksService.sendRemoveRequest(taskId, null, responseHandler.getActionListener(taskSlot)); + persistentTasksService.sendRemoveRequest(taskId, request.masterNodeTimeout(), responseHandler.getActionListener(taskSlot)); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index 0eff80709ccd..446e9abcd3e2 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -297,6 +297,7 @@ public final class TransportPutFollowAction extends TransportMasterNodeAction listener ) { - submitUnbatchedTask("unfollow_action", new ClusterStateUpdateTask() { + submitUnbatchedTask("unfollow_action", new ClusterStateUpdateTask(request.masterNodeTimeout()) { @Override public ClusterState execute(final ClusterState current) { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java index e394f708b07f..139c6e04c32d 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java @@ -38,6 +38,10 @@ public class RestCcrStatsAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { final CcrStatsAction.Request request = new CcrStatsAction.Request(); + if (restRequest.hasParam("timeout")) { + request.setTimeout(restRequest.paramAsTime("timeout", null)); + } + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute( CcrStatsAction.INSTANCE, request, diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java index a931a498b1bb..9e94e27f5581 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java @@ -32,6 +32,7 @@ public class RestDeleteAutoFollowPatternAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { Request request = new Request(restRequest.param("name")); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java index 4b3ac9f605d3..86be9487417f 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java @@ -33,6 +33,7 @@ public class RestFollowInfoAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { final FollowInfoAction.Request request = new FollowInfoAction.Request(); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); request.setFollowerIndices(Strings.splitStringByCommaToArray(restRequest.param("index"))); return channel -> client.execute(FollowInfoAction.INSTANCE, request, new RestRefCountedChunkedToXContentListener<>(channel)); } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java index 7592db0480b9..e7e4d34a8242 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java @@ -40,6 +40,9 @@ public class RestFollowStatsAction extends BaseRestHandler { protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { final FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest(); request.setIndices(Strings.splitStringByCommaToArray(restRequest.param("index"))); + if (restRequest.hasParam("timeout")) { + request.setTimeout(restRequest.param("timeout")); + } return channel -> client.execute( FollowStatsAction.INSTANCE, request, diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java index caa1b08203fb..fc99b4268082 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java @@ -40,7 +40,11 @@ public class RestForgetFollowerAction extends BaseRestHandler { private static Request createRequest(final RestRequest restRequest, final String leaderIndex) throws IOException { try (XContentParser parser = restRequest.contentOrSourceParamParser()) { - return Request.fromXContent(parser, leaderIndex); + Request request = Request.fromXContent(parser, leaderIndex); + if (restRequest.hasParam("timeout")) { + request.timeout(restRequest.paramAsTime("timeout", null)); + } + return request; } } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java index ba59f00e2053..519888a93afd 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java @@ -33,6 +33,7 @@ public class RestGetAutoFollowPatternAction extends BaseRestHandler { protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { Request request = new Request(); request.setName(restRequest.param("name")); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java index 152a6d091d85..6846d96a2f01 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java @@ -32,6 +32,7 @@ public class RestPauseAutoFollowPatternAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { Request request = new Request(restRequest.param("name"), false); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java index 12a208e82a84..b08fbb039cbc 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java @@ -32,6 +32,7 @@ public class RestPauseFollowAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { Request request = new Request(restRequest.param("index")); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java index 9d536966a3ef..dd432411014a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java @@ -39,7 +39,9 @@ public class RestPutAutoFollowPatternAction extends BaseRestHandler { private static Request createRequest(RestRequest restRequest) throws IOException { try (XContentParser parser = restRequest.contentOrSourceParamParser()) { - return Request.fromXContent(parser, restRequest.param("name")); + Request request = Request.fromXContent(parser, restRequest.param("name")); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); + return request; } } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java index c2bd39286711..5ceef134090a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java @@ -40,8 +40,11 @@ public class RestPutFollowAction extends BaseRestHandler { private static Request createRequest(RestRequest restRequest) throws IOException { try (XContentParser parser = restRequest.contentOrSourceParamParser()) { - ActiveShardCount waitForActiveShards = ActiveShardCount.parseString(restRequest.param("wait_for_active_shards")); - return Request.fromXContent(parser, restRequest.param("index"), waitForActiveShards); + final Request request = Request.fromXContent(parser); + request.waitForActiveShards(ActiveShardCount.parseString(restRequest.param("wait_for_active_shards"))); + request.setFollowerIndex(restRequest.param("index")); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); + return request; } } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java index 9602ca339e29..a6ccf9fe1fa0 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java @@ -32,6 +32,7 @@ public class RestResumeAutoFollowPatternAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { Request request = new Request(restRequest.param("name"), true); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java index 66659d19c74d..d3994c487e45 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java @@ -38,14 +38,16 @@ public class RestResumeFollowAction extends BaseRestHandler { } static Request createRequest(RestRequest restRequest) throws IOException { + Request request; if (restRequest.hasContentOrSourceParam()) { try (XContentParser parser = restRequest.contentOrSourceParamParser()) { - return Request.fromXContent(parser, restRequest.param("index")); + request = Request.fromXContent(parser, restRequest.param("index")); } } else { - Request request = new Request(); + request = new Request(); request.setFollowerIndex(restRequest.param("index")); - return request; } + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); + return request; } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java index 2fb0303f69cf..5936fc05cb44 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java @@ -33,6 +33,7 @@ public class RestUnfollowAction extends BaseRestHandler { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { UnfollowAction.Request request = new UnfollowAction.Request(restRequest.param("index")); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(INSTANCE, request, new RestToXContentListener<>(channel)); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 4ce64bc41d6a..4f453a2ad66f 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -594,6 +594,9 @@ public abstract class CcrIntegTestCase extends ESTestCase { request.getParameters().setMaxReadRequestSize(ByteSizeValue.ofBytes(between(1, 32 * 1024 * 1024))); request.getParameters().setMaxReadRequestOperationCount(between(1, 10000)); request.waitForActiveShards(waitForActiveShards); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } return request; } @@ -602,6 +605,9 @@ public abstract class CcrIntegTestCase extends ESTestCase { request.setFollowerIndex(followerIndex); request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(10)); request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(10)); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java index 9b6d81a206f7..da3f29fcef8d 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java @@ -103,6 +103,9 @@ public abstract class CcrSingleNodeTestCase extends ESSingleNodeTestCase { request.setFollowerIndex(followerIndex); request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(1)); request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(1)); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } return request; } @@ -114,6 +117,9 @@ public abstract class CcrSingleNodeTestCase extends ESSingleNodeTestCase { request.getParameters().setMaxRetryDelay(TimeValue.timeValueMillis(1)); request.getParameters().setReadPollTimeout(TimeValue.timeValueMillis(1)); request.waitForActiveShards(ActiveShardCount.ONE); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("10s", "20s", "30s")); + } return request; } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java index 27aaf1dea7db..171727c3e0bc 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/PutFollowActionRequestTests.java @@ -61,7 +61,10 @@ public class PutFollowActionRequestTests extends AbstractXContentSerializingTest @Override protected PutFollowAction.Request doParseInstance(XContentParser parser) throws IOException { - return PutFollowAction.Request.fromXContent(parser, "followerIndex", ActiveShardCount.DEFAULT); + PutFollowAction.Request request = PutFollowAction.Request.fromXContent(parser); + request.waitForActiveShards(ActiveShardCount.DEFAULT); + request.setFollowerIndex("followerIndex"); + return request; } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsAction.java index b6c078134634..a9954005b448 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsAction.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.ccr.action; +import org.elasticsearch.TransportVersions; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; @@ -16,6 +17,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ChunkedToXContentHelper; import org.elasticsearch.common.xcontent.ChunkedToXContentObject; +import org.elasticsearch.core.TimeValue; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xpack.core.ccr.AutoFollowStats; @@ -34,8 +36,13 @@ public class CcrStatsAction extends ActionType { public static class Request extends MasterNodeRequest { + private TimeValue timeout; + public Request(StreamInput in) throws IOException { super(in); + if (in.getTransportVersion().onOrAfter(TransportVersions.CCR_STATS_API_TIMEOUT_PARAM)) { + timeout = in.readOptionalTimeValue(); + } } public Request() {} @@ -48,6 +55,43 @@ public class CcrStatsAction extends ActionType { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); + if (out.getTransportVersion().onOrAfter(TransportVersions.CCR_STATS_API_TIMEOUT_PARAM)) { + out.writeOptionalTimeValue(timeout); + } + } + + public TimeValue getTimeout() { + return this.timeout; + } + + public void setTimeout(TimeValue timeout) { + this.timeout = timeout; + } + + public void setTimeout(String timeout) { + this.timeout = TimeValue.parseTimeValue(timeout, null, getClass().getSimpleName() + ".timeout"); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Request that = (Request) o; + return Objects.equals(this.timeout, that.timeout) && Objects.equals(this.masterNodeTimeout, that.masterNodeTimeout); + } + + @Override + public int hashCode() { + return Objects.hash(this.timeout, this.masterNodeTimeout); + } + + @Override + public String toString() { + return "CcrStatsAction.Request[timeout=" + timeout + ", masterNodeTimeout=" + masterNodeTimeout + "]"; } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java index c2e1048541a4..6570fb66a275 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/PutFollowAction.java @@ -64,13 +64,10 @@ public final class PutFollowAction extends ActionType FollowParameters.initParser(PARSER); } - public static Request fromXContent(final XContentParser parser, final String followerIndex, ActiveShardCount waitForActiveShards) - throws IOException { + public static Request fromXContent(final XContentParser parser) throws IOException { PutFollowParameters parameters = PARSER.parse(parser, null); Request request = new Request(); - request.waitForActiveShards(waitForActiveShards); - request.setFollowerIndex(followerIndex); request.setRemoteCluster(parameters.remoteCluster); request.setLeaderIndex(parameters.leaderIndex); request.setDataStreamName(parameters.dataStreamName); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsActionTests.java new file mode 100644 index 000000000000..e40954b361ef --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ccr/action/CcrStatsActionTests.java @@ -0,0 +1,60 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.core.ccr.action; + +import org.elasticsearch.TransportVersions; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; +import org.elasticsearch.test.TransportVersionUtils; + +import java.io.IOException; + +public class CcrStatsActionTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return CcrStatsAction.Request::new; + } + + @Override + protected CcrStatsAction.Request createTestInstance() { + var request = new CcrStatsAction.Request(); + request.setTimeout(randomFrom("1s", "5s", "10s", "15s")); + request.masterNodeTimeout(randomFrom("1s", "5s", "10s", "15s")); + return request; + } + + @Override + protected CcrStatsAction.Request mutateInstance(CcrStatsAction.Request instance) throws IOException { + return switch (randomInt(1)) { + case 0 -> { + var mutatedInstance = new CcrStatsAction.Request(); + mutatedInstance.setTimeout(instance.getTimeout()); + mutatedInstance.masterNodeTimeout(randomFrom("20s", "25s", "30s")); + yield mutatedInstance; + } + case 1 -> { + var mutatedInstance = new CcrStatsAction.Request(); + mutatedInstance.setTimeout(randomFrom("20s", "25s", "30s")); + mutatedInstance.masterNodeTimeout(instance.masterNodeTimeout()); + yield mutatedInstance; + } + default -> throw new RuntimeException("Cannot happen"); + }; + } + + public void testSerializationBwc() throws IOException { + // In previous version `timeout` is not set + var request = new CcrStatsAction.Request(); + if (randomBoolean()) { + request.masterNodeTimeout(randomFrom("20s", "25s", "30s")); + } + assertSerialization(request, TransportVersionUtils.getPreviousVersion(TransportVersions.CCR_STATS_API_TIMEOUT_PARAM)); + assertSerialization(request, TransportVersions.MINIMUM_CCS_VERSION); + } +}