Search in sources :

Example 1 with SupervisorReport

use of org.apache.druid.indexing.overlord.supervisor.SupervisorReport in project druid by druid-io.

the class SeekableStreamSupervisor method generateReport.

private SupervisorReport<? extends SeekableStreamSupervisorReportPayload<PartitionIdType, SequenceOffsetType>> generateReport(boolean includeOffsets) {
    int numPartitions = partitionGroups.values().stream().mapToInt(Set::size).sum();
    final SeekableStreamSupervisorReportPayload<PartitionIdType, SequenceOffsetType> payload = createReportPayload(numPartitions, includeOffsets);
    SupervisorReport<SeekableStreamSupervisorReportPayload<PartitionIdType, SequenceOffsetType>> report = new SupervisorReport<>(dataSource, DateTimes.nowUtc(), payload);
    List<TaskReportData<PartitionIdType, SequenceOffsetType>> taskReports = new ArrayList<>();
    try {
        for (TaskGroup taskGroup : activelyReadingTaskGroups.values()) {
            for (Entry<String, TaskData> entry : taskGroup.tasks.entrySet()) {
                String taskId = entry.getKey();
                @Nullable DateTime startTime = entry.getValue().startTime;
                Map<PartitionIdType, SequenceOffsetType> currentOffsets = entry.getValue().currentSequences;
                Long remainingSeconds = null;
                if (startTime != null) {
                    long elapsedMillis = System.currentTimeMillis() - startTime.getMillis();
                    long remainingMillis = Math.max(0, ioConfig.getTaskDuration().getMillis() - elapsedMillis);
                    remainingSeconds = TimeUnit.MILLISECONDS.toSeconds(remainingMillis);
                }
                taskReports.add(new TaskReportData<>(taskId, includeOffsets ? taskGroup.startingSequences : null, includeOffsets ? currentOffsets : null, startTime, remainingSeconds, TaskReportData.TaskType.ACTIVE, includeOffsets ? getRecordLagPerPartition(currentOffsets) : null, includeOffsets ? getTimeLagPerPartition(currentOffsets) : null));
            }
        }
        for (List<TaskGroup> taskGroups : pendingCompletionTaskGroups.values()) {
            for (TaskGroup taskGroup : taskGroups) {
                for (Entry<String, TaskData> entry : taskGroup.tasks.entrySet()) {
                    String taskId = entry.getKey();
                    @Nullable DateTime startTime = entry.getValue().startTime;
                    Map<PartitionIdType, SequenceOffsetType> currentOffsets = entry.getValue().currentSequences;
                    Long remainingSeconds = null;
                    if (taskGroup.completionTimeout != null) {
                        remainingSeconds = Math.max(0, taskGroup.completionTimeout.getMillis() - System.currentTimeMillis()) / 1000;
                    }
                    taskReports.add(new TaskReportData<>(taskId, includeOffsets ? taskGroup.startingSequences : null, includeOffsets ? currentOffsets : null, startTime, remainingSeconds, TaskReportData.TaskType.PUBLISHING, null, null));
                }
            }
        }
        taskReports.forEach(payload::addTask);
    } catch (Exception e) {
        log.warn(e, "Failed to generate status report");
    }
    return report;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) EntryExistsException(org.apache.druid.metadata.EntryExistsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) StreamException(org.apache.druid.indexing.seekablestream.common.StreamException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SupervisorReport(org.apache.druid.indexing.overlord.supervisor.SupervisorReport) Nullable(javax.annotation.Nullable)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Nullable (javax.annotation.Nullable)1 SupervisorReport (org.apache.druid.indexing.overlord.supervisor.SupervisorReport)1 StreamException (org.apache.druid.indexing.seekablestream.common.StreamException)1 EntryExistsException (org.apache.druid.metadata.EntryExistsException)1 DateTime (org.joda.time.DateTime)1