-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Run TransportGetDataStreamsAction on local node
#122852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db1e3ea
Run `TransportGetDataStreamsAction` on local node
nielsbauman 27b9bfc
Update docs/changelog/122852.yaml
nielsbauman 52dd4a1
Merge branch 'main' into local-get-data-streams
nielsbauman b89d78b
Remove serialization tests
nielsbauman dc8237e
Add verbose cancellation test
nielsbauman eadffcb
Add cancellation check in verbose path
nielsbauman cbf69c2
Merge branch 'main' into local-get-data-streams
nielsbauman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 122852 | ||
| summary: Run `TransportGetDataStreamsAction` on local node | ||
| area: Data streams | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...nalClusterTest/java/org/elasticsearch/datastreams/DataStreamRestActionCancellationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.datastreams; | ||
|
|
||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.client.methods.HttpPost; | ||
| import org.elasticsearch.action.datastreams.GetDataStreamAction; | ||
| import org.elasticsearch.action.support.CancellableActionTestPlugin; | ||
| import org.elasticsearch.action.support.PlainActionFuture; | ||
| import org.elasticsearch.action.support.RefCountingListener; | ||
| import org.elasticsearch.action.support.SubscribableListener; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.network.NetworkModule; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.rest.root.MainRestPlugin; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.test.rest.ObjectPath; | ||
| import org.elasticsearch.transport.netty4.Netty4Plugin; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.concurrent.CancellationException; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.elasticsearch.action.support.ActionTestUtils.wrapAsRestResponseListener; | ||
| import static org.elasticsearch.test.TaskAssertions.assertAllTasksHaveFinished; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
| import static org.hamcrest.Matchers.oneOf; | ||
|
|
||
| public class DataStreamRestActionCancellationIT extends ESIntegTestCase { | ||
|
|
||
| @Override | ||
| protected boolean addMockHttpTransport() { | ||
| return false; // enable http | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) { | ||
| return Settings.builder() | ||
| .put(super.nodeSettings(nodeOrdinal, otherSettings)) | ||
| .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME) | ||
| .put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| return List.of(getTestTransportPlugin(), MainRestPlugin.class, CancellableActionTestPlugin.class, DataStreamsPlugin.class); | ||
| } | ||
|
|
||
| public void testGetDataStreamCancellation() { | ||
| runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_data_stream"), GetDataStreamAction.NAME); | ||
| } | ||
|
|
||
| private void runRestActionCancellationTest(Request request, String actionName) { | ||
| final var node = usually() ? internalCluster().getRandomNodeName() : internalCluster().startCoordinatingOnlyNode(Settings.EMPTY); | ||
|
|
||
| try ( | ||
| var restClient = createRestClient(node); | ||
| var capturingAction = CancellableActionTestPlugin.capturingActionOnNode(actionName, node) | ||
| ) { | ||
| final var responseFuture = new PlainActionFuture<Response>(); | ||
| final var restInvocation = restClient.performRequestAsync(request, wrapAsRestResponseListener(responseFuture)); | ||
|
|
||
| if (randomBoolean()) { | ||
| // cancel by aborting the REST request | ||
| capturingAction.captureAndCancel(restInvocation::cancel); | ||
| expectThrows(ExecutionException.class, CancellationException.class, () -> responseFuture.get(10, TimeUnit.SECONDS)); | ||
| } else { | ||
| // cancel via the task management API | ||
| final var cancelFuture = new PlainActionFuture<Void>(); | ||
| capturingAction.captureAndCancel( | ||
| () -> SubscribableListener | ||
|
|
||
| .<ObjectPath>newForked( | ||
| l -> restClient.performRequestAsync( | ||
| getListTasksRequest(node, actionName), | ||
| wrapAsRestResponseListener(l.map(ObjectPath::createFromResponse)) | ||
| ) | ||
| ) | ||
|
|
||
| .<Void>andThen((l, listTasksResponse) -> { | ||
| final var taskCount = listTasksResponse.evaluateArraySize("tasks"); | ||
| assertThat(taskCount, greaterThan(0)); | ||
| try (var listeners = new RefCountingListener(l)) { | ||
| for (int i = 0; i < taskCount; i++) { | ||
| final var taskPrefix = "tasks." + i + "."; | ||
| assertTrue(listTasksResponse.evaluate(taskPrefix + "cancellable")); | ||
| assertFalse(listTasksResponse.evaluate(taskPrefix + "cancelled")); | ||
| restClient.performRequestAsync( | ||
| getCancelTaskRequest( | ||
| listTasksResponse.evaluate(taskPrefix + "node"), | ||
| listTasksResponse.evaluate(taskPrefix + "id") | ||
| ), | ||
| wrapAsRestResponseListener(listeners.acquire(DataStreamRestActionCancellationIT::assertOK)) | ||
| ); | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| .addListener(cancelFuture) | ||
| ); | ||
| cancelFuture.get(10, TimeUnit.SECONDS); | ||
| expectThrows(Exception.class, () -> responseFuture.get(10, TimeUnit.SECONDS)); | ||
| } | ||
|
|
||
| assertAllTasksHaveFinished(actionName); | ||
| } catch (Exception e) { | ||
| fail(e); | ||
| } | ||
| } | ||
|
|
||
| private static Request getListTasksRequest(String taskNode, String actionName) { | ||
| final var listTasksRequest = new Request(HttpGet.METHOD_NAME, "/_tasks"); | ||
| listTasksRequest.addParameter("nodes", taskNode); | ||
| listTasksRequest.addParameter("actions", actionName); | ||
| listTasksRequest.addParameter("group_by", "none"); | ||
| return listTasksRequest; | ||
| } | ||
|
|
||
| private static Request getCancelTaskRequest(String taskNode, int taskId) { | ||
| final var cancelTaskRequest = new Request(HttpPost.METHOD_NAME, Strings.format("/_tasks/%s:%d/_cancel", taskNode, taskId)); | ||
| cancelTaskRequest.addParameter("wait_for_completion", null); | ||
| return cancelTaskRequest; | ||
| } | ||
|
|
||
| public static void assertOK(Response response) { | ||
| assertThat(response.getStatusLine().getStatusCode(), oneOf(200, 201)); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.