Remove ListTasksResponse#setDiscoveryNodes
This commit is contained in:
parent
a1633d6444
commit
54603903f3
|
@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.cluster.node.tasks.cancel;
|
||||||
import org.elasticsearch.action.FailedNodeException;
|
import org.elasticsearch.action.FailedNodeException;
|
||||||
import org.elasticsearch.action.TaskOperationFailure;
|
import org.elasticsearch.action.TaskOperationFailure;
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||||
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||||
import org.elasticsearch.tasks.TaskInfo;
|
import org.elasticsearch.tasks.TaskInfo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -34,9 +35,13 @@ public class CancelTasksResponse extends ListTasksResponse {
|
||||||
public CancelTasksResponse() {
|
public CancelTasksResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CancelTasksResponse(DiscoveryNodes discoveryNodes) {
|
||||||
|
super(discoveryNodes);
|
||||||
|
}
|
||||||
|
|
||||||
public CancelTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures, List<? extends FailedNodeException>
|
public CancelTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures, List<? extends FailedNodeException>
|
||||||
nodeFailures) {
|
nodeFailures, DiscoveryNodes discoveryNodes) {
|
||||||
super(tasks, taskFailures, nodeFailures);
|
super(tasks, taskFailures, nodeFailures, discoveryNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,8 @@ public class TransportCancelTasksAction extends TransportTasksAction<Cancellable
|
||||||
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver
|
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver
|
||||||
indexNameExpressionResolver) {
|
indexNameExpressionResolver) {
|
||||||
super(settings, CancelTasksAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
super(settings, CancelTasksAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
||||||
indexNameExpressionResolver, CancelTasksRequest::new, CancelTasksResponse::new, ThreadPool.Names.MANAGEMENT);
|
indexNameExpressionResolver, CancelTasksRequest::new, () -> new CancelTasksResponse(clusterService.state().nodes()),
|
||||||
|
ThreadPool.Names.MANAGEMENT);
|
||||||
transportService.registerRequestHandler(BAN_PARENT_ACTION_NAME, BanParentTaskRequest::new, ThreadPool.Names.SAME, new
|
transportService.registerRequestHandler(BAN_PARENT_ACTION_NAME, BanParentTaskRequest::new, ThreadPool.Names.SAME, new
|
||||||
BanParentRequestHandler());
|
BanParentRequestHandler());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ public class TransportCancelTasksAction extends TransportTasksAction<Cancellable
|
||||||
@Override
|
@Override
|
||||||
protected CancelTasksResponse newResponse(CancelTasksRequest request, List<TaskInfo> tasks, List<TaskOperationFailure>
|
protected CancelTasksResponse newResponse(CancelTasksRequest request, List<TaskInfo> tasks, List<TaskOperationFailure>
|
||||||
taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
||||||
return new CancelTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
|
return new CancelTasksResponse(tasks, taskOperationFailures, failedNodeExceptions, clusterService.state().nodes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -56,12 +56,18 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
||||||
private DiscoveryNodes discoveryNodes;
|
private DiscoveryNodes discoveryNodes;
|
||||||
|
|
||||||
public ListTasksResponse() {
|
public ListTasksResponse() {
|
||||||
|
this(null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListTasksResponse(DiscoveryNodes discoveryNodes) {
|
||||||
|
this(null, null, null, discoveryNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures,
|
public ListTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures,
|
||||||
List<? extends FailedNodeException> nodeFailures) {
|
List<? extends FailedNodeException> nodeFailures, DiscoveryNodes discoveryNodes) {
|
||||||
super(taskFailures, nodeFailures);
|
super(taskFailures, nodeFailures);
|
||||||
this.tasks = tasks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(tasks));
|
this.tasks = tasks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(tasks));
|
||||||
|
this.discoveryNodes = discoveryNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,15 +131,6 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a reference to the {@linkplain DiscoveryNodes}. Used for calling {@link #toXContent(XContentBuilder, ToXContent.Params)} with
|
|
||||||
* {@code group_by=nodes}.
|
|
||||||
*/
|
|
||||||
public void setDiscoveryNodes(DiscoveryNodes discoveryNodes) {
|
|
||||||
//WTF is this? Why isn't this set by default;
|
|
||||||
this.discoveryNodes = discoveryNodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
if (getTaskFailures() != null && getTaskFailures().size() > 0) {
|
if (getTaskFailures() != null && getTaskFailures().size() > 0) {
|
||||||
|
@ -157,9 +154,6 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
||||||
}
|
}
|
||||||
String groupBy = params.param("group_by", "nodes");
|
String groupBy = params.param("group_by", "nodes");
|
||||||
if ("nodes".equals(groupBy)) {
|
if ("nodes".equals(groupBy)) {
|
||||||
if (discoveryNodes == null) {
|
|
||||||
throw new IllegalStateException("discoveryNodes must be set before calling toXContent with group_by=nodes");
|
|
||||||
}
|
|
||||||
builder.startObject("nodes");
|
builder.startObject("nodes");
|
||||||
for (Map.Entry<String, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
|
for (Map.Entry<String, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
|
||||||
DiscoveryNode node = discoveryNodes.get(entry.getKey());
|
DiscoveryNode node = discoveryNodes.get(entry.getKey());
|
||||||
|
@ -201,27 +195,12 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
||||||
group.toXContent(builder, params);
|
group.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
} else {
|
|
||||||
builder.startObject("tasks");
|
|
||||||
if (tasks != null) {
|
|
||||||
for(TaskInfo task : tasks) {
|
|
||||||
builder.field(task.getTaskId().toString());
|
|
||||||
task.toXContent(builder, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
return Strings.toString(this);
|
||||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
|
||||||
toXContent(builder, new MapParams(Collections.singletonMap("group_by", "none")));
|
|
||||||
return builder.string();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return "Error building toString out of XContent: " + ExceptionsHelper.stackTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,10 @@ import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
|
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
|
||||||
|
|
||||||
|
@ -57,13 +59,14 @@ public class TransportListTasksAction extends TransportTasksAction<Task, ListTas
|
||||||
public TransportListTasksAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
public TransportListTasksAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
||||||
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||||
super(settings, ListTasksAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
super(settings, ListTasksAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
||||||
indexNameExpressionResolver, ListTasksRequest::new, ListTasksResponse::new, ThreadPool.Names.MANAGEMENT);
|
indexNameExpressionResolver, ListTasksRequest::new, () -> new ListTasksResponse(clusterService.state().nodes()),
|
||||||
|
ThreadPool.Names.MANAGEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListTasksResponse newResponse(ListTasksRequest request, List<TaskInfo> tasks,
|
protected ListTasksResponse newResponse(ListTasksRequest request, List<TaskInfo> tasks,
|
||||||
List<TaskOperationFailure> taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
List<TaskOperationFailure> taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
||||||
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
|
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions, clusterService.state().nodes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -81,7 +81,6 @@ public class RestListTasksAction extends BaseRestHandler {
|
||||||
return new ActionListener<T>() {
|
return new ActionListener<T>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(T response) {
|
public void onResponse(T response) {
|
||||||
response.setDiscoveryNodes(clusterService.state().nodes());
|
|
||||||
channelListener.onResponse(response);
|
channelListener.onResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -736,12 +736,6 @@ public class TransportTasksActionTests extends TaskManagerTestCase {
|
||||||
ListTasksResponse response = testNodes[0].transportListTasksAction.execute(listTasksRequest).get();
|
ListTasksResponse response = testNodes[0].transportListTasksAction.execute(listTasksRequest).get();
|
||||||
assertEquals(testNodes.length + 1, response.getTasks().size());
|
assertEquals(testNodes.length + 1, response.getTasks().size());
|
||||||
|
|
||||||
// First group by node
|
|
||||||
DiscoveryNodes.Builder discoNodes = DiscoveryNodes.builder();
|
|
||||||
for (TestNode testNode : this.testNodes) {
|
|
||||||
discoNodes.put(testNode.discoveryNode);
|
|
||||||
}
|
|
||||||
response.setDiscoveryNodes(discoNodes.build());
|
|
||||||
Map<String, Object> byNodes = serialize(response, new ToXContent.MapParams(Collections.singletonMap("group_by", "nodes")));
|
Map<String, Object> byNodes = serialize(response, new ToXContent.MapParams(Collections.singletonMap("group_by", "nodes")));
|
||||||
byNodes = (Map<String, Object>) byNodes.get("nodes");
|
byNodes = (Map<String, Object>) byNodes.get("nodes");
|
||||||
// One element on the top level
|
// One element on the top level
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.tasks;
|
package org.elasticsearch.tasks;
|
||||||
|
|
||||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||||
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
|
|
||||||
|
@ -27,17 +28,19 @@ import java.util.Collections;
|
||||||
|
|
||||||
public class ListTasksResponseTests extends ESTestCase {
|
public class ListTasksResponseTests extends ESTestCase {
|
||||||
|
|
||||||
public void testToStringWithNoTask() {
|
public void testToStringNoTask() {
|
||||||
ListTasksResponse tasksResponse = new ListTasksResponse();
|
ListTasksResponse tasksResponse = new ListTasksResponse();
|
||||||
String string = tasksResponse.toString();
|
String string = tasksResponse.toString();
|
||||||
assertThat(string, Matchers.containsString("tasks"));
|
assertThat(string, Matchers.containsString("nodes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testToString() {
|
public void testToString() {
|
||||||
TaskInfo info = new TaskInfo(
|
TaskInfo info = new TaskInfo(
|
||||||
new TaskId("node1", 1), "dummy-type", "dummy-action", "dummy-description", null, 0, 1, true, new TaskId("node1", 0));
|
new TaskId("node1", 1), "dummy-type", "dummy-action", "dummy-description", null, 0, 1, true, new TaskId("node1", 0));
|
||||||
|
|
||||||
ListTasksResponse tasksResponse = new ListTasksResponse(Collections.singletonList(info), Collections.emptyList(), Collections.emptyList());
|
DiscoveryNodes nodes = DiscoveryNodes.builder().build();
|
||||||
|
ListTasksResponse tasksResponse = new ListTasksResponse(Collections.singletonList(info), Collections.emptyList(),
|
||||||
|
Collections.emptyList(), nodes);
|
||||||
|
|
||||||
String string = tasksResponse.toString();
|
String string = tasksResponse.toString();
|
||||||
assertThat(string, Matchers.containsString("\"type\":\"dummy-type\""));
|
assertThat(string, Matchers.containsString("\"type\":\"dummy-type\""));
|
||||||
|
|
|
@ -41,7 +41,8 @@ public class TransportRethrottleAction extends TransportTasksAction<BulkByScroll
|
||||||
public TransportRethrottleAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
public TransportRethrottleAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
|
||||||
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||||
super(settings, RethrottleAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
super(settings, RethrottleAction.NAME, threadPool, clusterService, transportService, actionFilters,
|
||||||
indexNameExpressionResolver, RethrottleRequest::new, ListTasksResponse::new, ThreadPool.Names.MANAGEMENT);
|
indexNameExpressionResolver, RethrottleRequest::new, () -> new ListTasksResponse(clusterService.state().nodes()),
|
||||||
|
ThreadPool.Names.MANAGEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +60,7 @@ public class TransportRethrottleAction extends TransportTasksAction<BulkByScroll
|
||||||
@Override
|
@Override
|
||||||
protected ListTasksResponse newResponse(RethrottleRequest request, List<TaskInfo> tasks,
|
protected ListTasksResponse newResponse(RethrottleRequest request, List<TaskInfo> tasks,
|
||||||
List<TaskOperationFailure> taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
List<TaskOperationFailure> taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
||||||
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
|
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions, clusterService.state().nodes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue