org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.action.admin.cluster.node.tasks.list;
import org.elasticsearch.tasks.TaskInfo;
import org.elasticsearch.xcontent.ToXContent.Params;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* Information about a currently running task and all its subtasks.
*/
public class TaskGroup implements ToXContentObject {
private final TaskInfo task;
private final List childTasks;
public TaskGroup(TaskInfo task, List childTasks) {
this.task = task;
this.childTasks = Collections.unmodifiableList(new ArrayList<>(childTasks));
}
public static Builder builder(TaskInfo taskInfo) {
return new Builder(taskInfo);
}
public static class Builder {
private TaskInfo taskInfo;
private List childTasks;
private Builder(TaskInfo taskInfo) {
this.taskInfo = taskInfo;
childTasks = new ArrayList<>();
}
public void addGroup(Builder builder) {
childTasks.add(builder);
}
public TaskInfo getTaskInfo() {
return taskInfo;
}
public TaskGroup build() {
return new TaskGroup(taskInfo, childTasks.stream().map(Builder::build).collect(Collectors.toList()));
}
}
public TaskInfo getTaskInfo() {
return task;
}
public List getChildTasks() {
return childTasks;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
task.toXContent(builder, params);
if (childTasks.isEmpty() == false) {
builder.startArray("children");
for (TaskGroup taskGroup : childTasks) {
taskGroup.toXContent(builder, params);
}
builder.endArray();
}
return builder.endObject();
}
}