Search in sources :

Example 1 with TaskStatusResponse

use of org.apache.druid.client.indexing.TaskStatusResponse in project druid by druid-io.

the class TaskMonitor method start.

public void start(long taskStatusCheckingPeriod) {
    synchronized (startStopLock) {
        running = true;
        log.info("Starting taskMonitor");
        // NOTE: This polling can be improved to event-driven pushing by registering TaskRunnerListener to TaskRunner.
        // That listener should be able to send the events reported to TaskRunner to this TaskMonitor.
        taskStatusChecker.scheduleAtFixedRate(() -> {
            try {
                final Iterator<Entry<String, MonitorEntry>> iterator = runningTasks.entrySet().iterator();
                while (iterator.hasNext()) {
                    final Entry<String, MonitorEntry> entry = iterator.next();
                    final String specId = entry.getKey();
                    final MonitorEntry monitorEntry = entry.getValue();
                    final String taskId = monitorEntry.runningTask.getId();
                    final TaskStatusResponse taskStatusResponse = indexingServiceClient.getTaskStatus(taskId);
                    final TaskStatusPlus taskStatus = taskStatusResponse.getStatus();
                    if (taskStatus != null) {
                        switch(Preconditions.checkNotNull(taskStatus.getStatusCode(), "taskState")) {
                            case SUCCESS:
                                // Succeeded tasks must have sent a report
                                if (!reportsMap.containsKey(taskId)) {
                                    throw new ISE("Missing reports from task[%s]!", taskId);
                                }
                                incrementNumSucceededTasks();
                                // Remote the current entry after updating taskHistories to make sure that task history
                                // exists either runningTasks or taskHistories.
                                monitorEntry.setLastStatus(taskStatus);
                                iterator.remove();
                                break;
                            case FAILED:
                                // We don't need reports from failed tasks
                                reportsMap.remove(taskId);
                                incrementNumFailedTasks();
                                log.warn("task[%s] failed!", taskId);
                                if (monitorEntry.numTries() < maxRetry) {
                                    log.info("We still have more chances[%d/%d] to process the spec[%s].", monitorEntry.numTries(), maxRetry, monitorEntry.spec.getId());
                                    retry(specId, monitorEntry, taskStatus);
                                } else {
                                    log.error("spec[%s] failed after [%d] tries", monitorEntry.spec.getId(), monitorEntry.numTries());
                                    // Remote the current entry after updating taskHistories to make sure that task history
                                    // exists either runningTasks or taskHistories.
                                    monitorEntry.setLastStatus(taskStatus);
                                    iterator.remove();
                                }
                                break;
                            case RUNNING:
                                monitorEntry.updateStatus(taskStatus);
                                break;
                            default:
                                throw new ISE("Unknown taskStatus[%s] for task[%s[", taskStatus.getStatusCode(), taskId);
                        }
                    }
                }
            } catch (Throwable t) {
                // Note that we only log the message here so that task monitoring continues to happen or else
                // the task which created this monitor will keep on waiting endlessly assuming monitored tasks
                // are still running.
                log.error(t, "Error while monitoring");
            }
        }, taskStatusCheckingPeriod, taskStatusCheckingPeriod, TimeUnit.MILLISECONDS);
    }
}
Also used : Entry(java.util.Map.Entry) TaskStatusResponse(org.apache.druid.client.indexing.TaskStatusResponse) TaskStatusPlus(org.apache.druid.indexer.TaskStatusPlus) ISE(org.apache.druid.java.util.common.ISE)

Example 2 with TaskStatusResponse

use of org.apache.druid.client.indexing.TaskStatusResponse in project druid by druid-io.

the class OverlordResourceTestClient method getTaskStatus.

public TaskStatusPlus getTaskStatus(String taskID) {
    try {
        StatusResponseHolder response = makeRequest(HttpMethod.GET, StringUtils.format("%stask/%s/status", getIndexerURL(), StringUtils.urlEncode(taskID)));
        LOG.debug("Index status response" + response.getContent());
        TaskStatusResponse taskStatusResponse = jsonMapper.readValue(response.getContent(), new TypeReference<TaskStatusResponse>() {
        });
        return taskStatusResponse.getStatus();
    } catch (ISE e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TaskStatusResponse(org.apache.druid.client.indexing.TaskStatusResponse) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE)

Aggregations

TaskStatusResponse (org.apache.druid.client.indexing.TaskStatusResponse)2 ISE (org.apache.druid.java.util.common.ISE)2 Entry (java.util.Map.Entry)1 TaskStatusPlus (org.apache.druid.indexer.TaskStatusPlus)1 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)1