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.TaskOperationFailure;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.tasks.TaskInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -34,9 +35,13 @@ public class CancelTasksResponse extends ListTasksResponse {
|
|||
public CancelTasksResponse() {
|
||||
}
|
||||
|
||||
public CancelTasksResponse(DiscoveryNodes discoveryNodes) {
|
||||
super(discoveryNodes);
|
||||
}
|
||||
|
||||
public CancelTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures, List<? extends FailedNodeException>
|
||||
nodeFailures) {
|
||||
super(tasks, taskFailures, nodeFailures);
|
||||
nodeFailures, DiscoveryNodes discoveryNodes) {
|
||||
super(tasks, taskFailures, nodeFailures, discoveryNodes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ public class TransportCancelTasksAction extends TransportTasksAction<Cancellable
|
|||
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver
|
||||
indexNameExpressionResolver) {
|
||||
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
|
||||
BanParentRequestHandler());
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ public class TransportCancelTasksAction extends TransportTasksAction<Cancellable
|
|||
@Override
|
||||
protected CancelTasksResponse newResponse(CancelTasksRequest request, List<TaskInfo> tasks, List<TaskOperationFailure>
|
||||
taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
||||
return new CancelTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
|
||||
return new CancelTasksResponse(tasks, taskOperationFailures, failedNodeExceptions, clusterService.state().nodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,12 +56,18 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
|||
private DiscoveryNodes discoveryNodes;
|
||||
|
||||
public ListTasksResponse() {
|
||||
this(null, null, null, null);
|
||||
}
|
||||
|
||||
public ListTasksResponse(DiscoveryNodes discoveryNodes) {
|
||||
this(null, null, null, discoveryNodes);
|
||||
}
|
||||
|
||||
public ListTasksResponse(List<TaskInfo> tasks, List<TaskOperationFailure> taskFailures,
|
||||
List<? extends FailedNodeException> nodeFailures) {
|
||||
List<? extends FailedNodeException> nodeFailures, DiscoveryNodes discoveryNodes) {
|
||||
super(taskFailures, nodeFailures);
|
||||
this.tasks = tasks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(tasks));
|
||||
this.discoveryNodes = discoveryNodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,15 +131,6 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
|||
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
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
if (getTaskFailures() != null && getTaskFailures().size() > 0) {
|
||||
|
@ -157,9 +154,6 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
|||
}
|
||||
String groupBy = params.param("group_by", "nodes");
|
||||
if ("nodes".equals(groupBy)) {
|
||||
if (discoveryNodes == null) {
|
||||
throw new IllegalStateException("discoveryNodes must be set before calling toXContent with group_by=nodes");
|
||||
}
|
||||
builder.startObject("nodes");
|
||||
for (Map.Entry<String, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
|
||||
DiscoveryNode node = discoveryNodes.get(entry.getKey());
|
||||
|
@ -201,27 +195,12 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent {
|
|||
group.toXContent(builder, params);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,10 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
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,
|
||||
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
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
|
||||
protected ListTasksResponse newResponse(ListTasksRequest request, List<TaskInfo> tasks,
|
||||
List<TaskOperationFailure> taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
||||
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
|
||||
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions, clusterService.state().nodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -81,7 +81,6 @@ public class RestListTasksAction extends BaseRestHandler {
|
|||
return new ActionListener<T>() {
|
||||
@Override
|
||||
public void onResponse(T response) {
|
||||
response.setDiscoveryNodes(clusterService.state().nodes());
|
||||
channelListener.onResponse(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -736,12 +736,6 @@ public class TransportTasksActionTests extends TaskManagerTestCase {
|
|||
ListTasksResponse response = testNodes[0].transportListTasksAction.execute(listTasksRequest).get();
|
||||
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")));
|
||||
byNodes = (Map<String, Object>) byNodes.get("nodes");
|
||||
// One element on the top level
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.tasks;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -27,17 +28,19 @@ import java.util.Collections;
|
|||
|
||||
public class ListTasksResponseTests extends ESTestCase {
|
||||
|
||||
public void testToStringWithNoTask() {
|
||||
public void testToStringNoTask() {
|
||||
ListTasksResponse tasksResponse = new ListTasksResponse();
|
||||
String string = tasksResponse.toString();
|
||||
assertThat(string, Matchers.containsString("tasks"));
|
||||
assertThat(string, Matchers.containsString("nodes"));
|
||||
}
|
||||
|
||||
public void testToString() {
|
||||
TaskInfo info = new TaskInfo(
|
||||
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();
|
||||
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,
|
||||
TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
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
|
||||
|
@ -59,7 +60,7 @@ public class TransportRethrottleAction extends TransportTasksAction<BulkByScroll
|
|||
@Override
|
||||
protected ListTasksResponse newResponse(RethrottleRequest request, List<TaskInfo> tasks,
|
||||
List<TaskOperationFailure> taskOperationFailures, List<FailedNodeException> failedNodeExceptions) {
|
||||
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions);
|
||||
return new ListTasksResponse(tasks, taskOperationFailures, failedNodeExceptions, clusterService.state().nodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue