|
@@ -10,16 +10,17 @@ package org.elasticsearch.action.admin.cluster.tasks;
|
|
|
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
import org.elasticsearch.action.ActionResponse;
|
|
import org.elasticsearch.cluster.service.PendingClusterTask;
|
|
import org.elasticsearch.cluster.service.PendingClusterTask;
|
|
|
|
+import org.elasticsearch.common.collect.Iterators;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
-import org.elasticsearch.xcontent.ToXContentObject;
|
|
|
|
-import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
|
|
|
+import org.elasticsearch.common.xcontent.ChunkedToXContent;
|
|
|
|
+import org.elasticsearch.xcontent.ToXContent;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-public class PendingClusterTasksResponse extends ActionResponse implements Iterable<PendingClusterTask>, ToXContentObject {
|
|
|
|
|
|
+public class PendingClusterTasksResponse extends ActionResponse implements ChunkedToXContent {
|
|
|
|
|
|
private final List<PendingClusterTask> pendingTasks;
|
|
private final List<PendingClusterTask> pendingTasks;
|
|
|
|
|
|
@@ -36,23 +37,11 @@ public class PendingClusterTasksResponse extends ActionResponse implements Itera
|
|
return pendingTasks;
|
|
return pendingTasks;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * The pending cluster tasks
|
|
|
|
- */
|
|
|
|
- public List<PendingClusterTask> getPendingTasks() {
|
|
|
|
- return pendingTasks();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Iterator<PendingClusterTask> iterator() {
|
|
|
|
- return pendingTasks.iterator();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public String toString() {
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder();
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("tasks: (").append(pendingTasks.size()).append("):\n");
|
|
sb.append("tasks: (").append(pendingTasks.size()).append("):\n");
|
|
- for (PendingClusterTask pendingClusterTask : this) {
|
|
|
|
|
|
+ for (PendingClusterTask pendingClusterTask : pendingTasks) {
|
|
sb.append(pendingClusterTask.getInsertOrder())
|
|
sb.append(pendingClusterTask.getInsertOrder())
|
|
.append("/")
|
|
.append("/")
|
|
.append(pendingClusterTask.getPriority())
|
|
.append(pendingClusterTask.getPriority())
|
|
@@ -66,10 +55,12 @@ public class PendingClusterTasksResponse extends ActionResponse implements Itera
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
|
- builder.startObject();
|
|
|
|
- builder.startArray(Fields.TASKS);
|
|
|
|
- for (PendingClusterTask pendingClusterTask : this) {
|
|
|
|
|
|
+ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
|
|
|
|
+ return Iterators.concat(Iterators.single((builder, p) -> {
|
|
|
|
+ builder.startObject();
|
|
|
|
+ builder.startArray(Fields.TASKS);
|
|
|
|
+ return builder;
|
|
|
|
+ }), pendingTasks.stream().<ToXContent>map(pendingClusterTask -> (builder, p) -> {
|
|
builder.startObject();
|
|
builder.startObject();
|
|
builder.field(Fields.INSERT_ORDER, pendingClusterTask.getInsertOrder());
|
|
builder.field(Fields.INSERT_ORDER, pendingClusterTask.getInsertOrder());
|
|
builder.field(Fields.PRIORITY, pendingClusterTask.getPriority());
|
|
builder.field(Fields.PRIORITY, pendingClusterTask.getPriority());
|
|
@@ -78,10 +69,12 @@ public class PendingClusterTasksResponse extends ActionResponse implements Itera
|
|
builder.field(Fields.TIME_IN_QUEUE_MILLIS, pendingClusterTask.getTimeInQueueInMillis());
|
|
builder.field(Fields.TIME_IN_QUEUE_MILLIS, pendingClusterTask.getTimeInQueueInMillis());
|
|
builder.field(Fields.TIME_IN_QUEUE, pendingClusterTask.getTimeInQueue());
|
|
builder.field(Fields.TIME_IN_QUEUE, pendingClusterTask.getTimeInQueue());
|
|
builder.endObject();
|
|
builder.endObject();
|
|
- }
|
|
|
|
- builder.endArray();
|
|
|
|
- builder.endObject();
|
|
|
|
- return builder;
|
|
|
|
|
|
+ return builder;
|
|
|
|
+ }).iterator(), Iterators.single((builder, p) -> {
|
|
|
|
+ builder.endArray();
|
|
|
|
+ builder.endObject();
|
|
|
|
+ return builder;
|
|
|
|
+ }));
|
|
}
|
|
}
|
|
|
|
|
|
static final class Fields {
|
|
static final class Fields {
|