@Override protected TaskInfo readTaskResponse(StreamInput in) throws IOException { return new TaskInfo(in); }
private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) { table.startRow(); String nodeId = taskInfo.getTaskId().getNodeId(); DiscoveryNode node = discoveryNodes.get(nodeId); table.addCell(taskInfo.getId()); table.addCell(taskInfo.getAction()); table.addCell(taskInfo.getTaskId().toString()); if (taskInfo.getParentTaskId().isSet()) { table.addCell(taskInfo.getParentTaskId().toString()); } else { table.addCell("-"); } table.addCell(taskInfo.getType()); table.addCell(taskInfo.getStartTime()); table.addCell(FORMATTER.format(Instant.ofEpochMilli(taskInfo.getStartTime()))); table.addCell(taskInfo.getRunningTimeNanos()); table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString()); // Node information. Note that the node may be null because it has left the cluster between when we got this response and now. table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4)); table.addCell(node == null ? "-" : node.getHostAddress()); table.addCell(node.getAddress().address().getPort()); table.addCell(node == null ? "-" : node.getName()); table.addCell(node == null ? "-" : node.getVersion().toString()); if (detailed) { table.addCell(taskInfo.getDescription()); } table.endRow(); }
/** * Build the status for this task given a snapshot of the information of running slices. This is only supported if the task is * set as a leader for slice subtasks */ public TaskInfo taskInfoGivenSubtaskInfo(String localNodeId, List<TaskInfo> sliceInfo) { if (isLeader() == false) { throw new IllegalStateException("This task is not set to be a leader of other slice subtasks"); } List<BulkByScrollTask.StatusOrException> sliceStatuses = Arrays.asList( new BulkByScrollTask.StatusOrException[leaderState.getSlices()]); for (TaskInfo t : sliceInfo) { BulkByScrollTask.Status status = (BulkByScrollTask.Status) t.getStatus(); sliceStatuses.set(status.getSliceId(), new BulkByScrollTask.StatusOrException(status)); } Status status = leaderState.getStatus(sliceStatuses); return taskInfo(localNodeId, getDescription(), status); }
private void buildTaskGroups() { Map<TaskId, TaskGroup.Builder> taskGroups = new HashMap<>(); List<TaskGroup.Builder> topLevelTasks = new ArrayList<>(); // First populate all tasks for (TaskInfo taskInfo : this.tasks) { taskGroups.put(taskInfo.getTaskId(), TaskGroup.builder(taskInfo)); } // Now go through all task group builders and add children to their parents for (TaskGroup.Builder taskGroup : taskGroups.values()) { TaskId parentTaskId = taskGroup.getTaskInfo().getParentTaskId(); if (parentTaskId.isSet()) { TaskGroup.Builder parentTask = taskGroups.get(parentTaskId); if (parentTask != null) { // we found parent in the list of tasks - add it to the parent list parentTask.addGroup(taskGroup); } else { // we got zombie or the parent was filtered out - add it to the top task list topLevelTasks.add(taskGroup); } } else { // top level task - add it to the top task list topLevelTasks.add(taskGroup); } } this.groups = Collections.unmodifiableList(topLevelTasks.stream().map(TaskGroup.Builder::build).collect(Collectors.toList())); }
builder.startObject(task.getTaskId().toString()); task.toXContent(builder, params); builder.endObject();
/** * Returns the list of tasks by node */ public Map<String, List<TaskInfo>> getPerNodeTasks() { if (perNodeTasks == null) { perNodeTasks = tasks.stream().collect(Collectors.groupingBy(t -> t.getTaskId().getNodeId())); } return perNodeTasks; }
private void buildGroups(Table table, boolean fullId, boolean detailed, List<TaskGroup> taskGroups) { DiscoveryNodes discoveryNodes = nodesInCluster.get(); List<TaskGroup> sortedGroups = new ArrayList<>(taskGroups); sortedGroups.sort((o1, o2) -> Long.compare(o1.getTaskInfo().getStartTime(), o2.getTaskInfo().getStartTime())); for (TaskGroup taskGroup : sortedGroups) { buildRow(table, fullId, detailed, discoveryNodes, taskGroup.getTaskInfo()); buildGroups(table, fullId, detailed, taskGroup.getChildTasks()); } }
private void buildTaskGroups() { Map<TaskId, TaskGroup.Builder> taskGroups = new HashMap<>(); List<TaskGroup.Builder> topLevelTasks = new ArrayList<>(); // First populate all tasks for (TaskInfo taskInfo : this.tasks) { taskGroups.put(taskInfo.getTaskId(), TaskGroup.builder(taskInfo)); } // Now go through all task group builders and add children to their parents for (TaskGroup.Builder taskGroup : taskGroups.values()) { TaskId parentTaskId = taskGroup.getTaskInfo().getParentTaskId(); if (parentTaskId.isSet()) { TaskGroup.Builder parentTask = taskGroups.get(parentTaskId); if (parentTask != null) { // we found parent in the list of tasks - add it to the parent list parentTask.addGroup(taskGroup); } else { // we got zombie or the parent was filtered out - add it to the top task list topLevelTasks.add(taskGroup); } } else { // top level task - add it to the top task list topLevelTasks.add(taskGroup); } } this.groups = Collections.unmodifiableList(topLevelTasks.stream().map(TaskGroup.Builder::build).collect(Collectors.toList())); }
builder.startObject(task.getTaskId().toString()); task.toXContent(builder, params); builder.endObject();
/** * Convert this response to XContent grouping by parent tasks. */ public XContentBuilder toXContentGroupedByParents(XContentBuilder builder, Params params) throws IOException { toXContentCommon(builder, params); builder.startObject(TASKS); for (TaskGroup group : getTaskGroups()) { builder.field(group.getTaskInfo().getTaskId().toString()); group.toXContent(builder, params); } builder.endObject(); return builder; }
private void buildGroups(Table table, boolean fullId, boolean detailed, List<TaskGroup> taskGroups) { DiscoveryNodes discoveryNodes = nodesInCluster.get(); List<TaskGroup> sortedGroups = new ArrayList<>(taskGroups); sortedGroups.sort((o1, o2) -> Long.compare(o1.getTaskInfo().getStartTime(), o2.getTaskInfo().getStartTime())); for (TaskGroup taskGroup : sortedGroups) { buildRow(table, fullId, detailed, discoveryNodes, taskGroup.getTaskInfo()); buildGroups(table, fullId, detailed, taskGroup.getChildTasks()); } }
private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) { table.startRow(); String nodeId = taskInfo.getTaskId().getNodeId(); DiscoveryNode node = discoveryNodes.get(nodeId); table.addCell(taskInfo.getId()); table.addCell(taskInfo.getAction()); table.addCell(taskInfo.getTaskId().toString()); if (taskInfo.getParentTaskId().isSet()) { table.addCell(taskInfo.getParentTaskId().toString()); } else { table.addCell("-"); } table.addCell(taskInfo.getType()); table.addCell(taskInfo.getStartTime()); table.addCell(FORMATTER.format(Instant.ofEpochMilli(taskInfo.getStartTime()))); table.addCell(taskInfo.getRunningTimeNanos()); table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString()); // Node information. Note that the node may be null because it has left the cluster between when we got this response and now. table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4)); table.addCell(node == null ? "-" : node.getHostAddress()); table.addCell(node.getAddress().address().getPort()); table.addCell(node == null ? "-" : node.getName()); table.addCell(node == null ? "-" : node.getVersion().toString()); if (detailed) { table.addCell(taskInfo.getDescription()); } table.endRow(); }
@Override protected TaskInfo readTaskResponse(StreamInput in) throws IOException { return new TaskInfo(in); }
private void buildTaskGroups() { Map<TaskId, TaskGroup.Builder> taskGroups = new HashMap<>(); List<TaskGroup.Builder> topLevelTasks = new ArrayList<>(); // First populate all tasks for (TaskInfo taskInfo : this.tasks) { taskGroups.put(taskInfo.getTaskId(), TaskGroup.builder(taskInfo)); } // Now go through all task group builders and add children to their parents for (TaskGroup.Builder taskGroup : taskGroups.values()) { TaskId parentTaskId = taskGroup.getTaskInfo().getParentTaskId(); if (parentTaskId.isSet()) { TaskGroup.Builder parentTask = taskGroups.get(parentTaskId); if (parentTask != null) { // we found parent in the list of tasks - add it to the parent list parentTask.addGroup(taskGroup); } else { // we got zombie or the parent was filtered out - add it to the the top task list topLevelTasks.add(taskGroup); } } else { // top level task - add it to the top task list topLevelTasks.add(taskGroup); } } this.groups = Collections.unmodifiableList(topLevelTasks.stream().map(TaskGroup.Builder::build).collect(Collectors.toList())); }
builder.startObject(task.getTaskId().toString()); task.toXContent(builder, params); builder.endObject();
private void doStoreResult(TaskResult taskResult, ActionListener<Void> listener) { IndexRequestBuilder index = client.prepareIndex(TASK_INDEX, TASK_TYPE, taskResult.getTask().getTaskId().toString()); try (XContentBuilder builder = XContentFactory.contentBuilder(Requests.INDEX_CONTENT_TYPE)) { taskResult.toXContent(builder, ToXContent.EMPTY_PARAMS); index.setSource(builder); } catch (IOException e) { throw new ElasticsearchException("Couldn't convert task result to XContent for [{}]", e, taskResult.getTask()); } doStoreResult(STORE_BACKOFF_POLICY.iterator(), index, listener); }
private void buildGroups(Table table, boolean fullId, boolean detailed, List<TaskGroup> taskGroups) { DiscoveryNodes discoveryNodes = nodesInCluster.get(); List<TaskGroup> sortedGroups = new ArrayList<>(taskGroups); sortedGroups.sort((o1, o2) -> Long.compare(o1.getTaskInfo().getStartTime(), o2.getTaskInfo().getStartTime())); for (TaskGroup taskGroup : sortedGroups) { buildRow(table, fullId, detailed, discoveryNodes, taskGroup.getTaskInfo()); buildGroups(table, fullId, detailed, taskGroup.getChildTasks()); } }
/** * Build the status for this task given a snapshot of the information of running slices. This is only supported if the task is * set as a leader for slice subtasks */ public TaskInfo taskInfoGivenSubtaskInfo(String localNodeId, List<TaskInfo> sliceInfo) { if (isLeader() == false) { throw new IllegalStateException("This task is not set to be a leader of other slice subtasks"); } List<BulkByScrollTask.StatusOrException> sliceStatuses = Arrays.asList( new BulkByScrollTask.StatusOrException[leaderState.getSlices()]); for (TaskInfo t : sliceInfo) { BulkByScrollTask.Status status = (BulkByScrollTask.Status) t.getStatus(); sliceStatuses.set(status.getSliceId(), new BulkByScrollTask.StatusOrException(status)); } Status status = leaderState.getStatus(sliceStatuses); return taskInfo(localNodeId, getDescription(), status); }
private void buildRow(Table table, boolean fullId, boolean detailed, DiscoveryNodes discoveryNodes, TaskInfo taskInfo) { table.startRow(); String nodeId = taskInfo.getTaskId().getNodeId(); DiscoveryNode node = discoveryNodes.get(nodeId); table.addCell(taskInfo.getId()); table.addCell(taskInfo.getAction()); table.addCell(taskInfo.getTaskId().toString()); if (taskInfo.getParentTaskId().isSet()) { table.addCell(taskInfo.getParentTaskId().toString()); } else { table.addCell("-"); } table.addCell(taskInfo.getType()); table.addCell(taskInfo.getStartTime()); table.addCell(dateFormat.print(taskInfo.getStartTime())); table.addCell(taskInfo.getRunningTimeNanos()); table.addCell(TimeValue.timeValueNanos(taskInfo.getRunningTimeNanos()).toString()); // Node information. Note that the node may be null because it has left the cluster between when we got this response and now. table.addCell(fullId ? nodeId : Strings.substring(nodeId, 0, 4)); table.addCell(node == null ? "-" : node.getHostAddress()); table.addCell(node.getAddress().address().getPort()); table.addCell(node == null ? "-" : node.getName()); table.addCell(node == null ? "-" : node.getVersion().toString()); if (detailed) { table.addCell(taskInfo.getDescription()); } table.endRow(); }
/** * Read from a stream. */ public TaskResult(StreamInput in) throws IOException { completed = in.readBoolean(); task = new TaskInfo(in); error = in.readOptionalBytesReference(); response = in.readOptionalBytesReference(); }