Search in sources :

Example 1 with TaskResult

use of org.elasticsearch.tasks.TaskResult in project elasticsearch by elastic.

the class TasksIT method testNodeNotFoundButTaskFound.

public void testNodeNotFoundButTaskFound() throws Exception {
    // Save a fake task that looks like it is from a node that isn't part of the cluster
    CyclicBarrier b = new CyclicBarrier(2);
    TaskResultsService resultsService = internalCluster().getInstance(TaskResultsService.class);
    resultsService.storeResult(new TaskResult(new TaskInfo(new TaskId("fake", 1), "test", "test", "", null, 0, 0, false, TaskId.EMPTY_TASK_ID), new RuntimeException("test")), new ActionListener<Void>() {

        @Override
        public void onResponse(Void response) {
            try {
                b.await();
            } catch (InterruptedException | BrokenBarrierException e) {
                onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception e) {
            throw new RuntimeException(e);
        }
    });
    b.await();
    // Now we can find it!
    GetTaskResponse response = expectFinishedTask(new TaskId("fake:1"));
    assertEquals("test", response.getTask().getTask().getAction());
    assertNotNull(response.getTask().getError());
    assertNull(response.getTask().getResponse());
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) TaskId(org.elasticsearch.tasks.TaskId) TaskResult(org.elasticsearch.tasks.TaskResult) GetTaskResponse(org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) FailedNodeException(org.elasticsearch.action.FailedNodeException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) ReceiveTimeoutTransportException(org.elasticsearch.transport.ReceiveTimeoutTransportException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 2 with TaskResult

use of org.elasticsearch.tasks.TaskResult in project elasticsearch by elastic.

the class TransportGetTaskAction method getRunningTaskFromNode.

/**
     * Executed on the node that should be running the task to find and return the running task. Falls back to
     * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} if the task isn't still running.
     */
void getRunningTaskFromNode(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
    Task runningTask = taskManager.getTask(request.getTaskId().getId());
    if (runningTask == null) {
        // Task isn't running, go look in the task index
        getFinishedTaskFromIndex(thisTask, request, listener);
    } else {
        if (request.getWaitForCompletion()) {
            // Shift to the generic thread pool and let it wait for the task to complete so we don't block any important threads.
            threadPool.generic().execute(new AbstractRunnable() {

                @Override
                protected void doRun() throws Exception {
                    taskManager.waitForTaskCompletion(runningTask, waitForCompletionTimeout(request.getTimeout()));
                    waitedForCompletion(thisTask, request, runningTask.taskInfo(clusterService.localNode().getId(), true), listener);
                }

                @Override
                public void onFailure(Exception e) {
                    listener.onFailure(e);
                }
            });
        } else {
            TaskInfo info = runningTask.taskInfo(clusterService.localNode().getId(), true);
            listener.onResponse(new GetTaskResponse(new TaskResult(false, info)));
        }
    }
}
Also used : AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) TaskInfo(org.elasticsearch.tasks.TaskInfo) Task(org.elasticsearch.tasks.Task) TaskResult(org.elasticsearch.tasks.TaskResult) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Example 3 with TaskResult

use of org.elasticsearch.tasks.TaskResult in project elasticsearch by elastic.

the class TransportGetTaskAction method onGetFinishedTaskFromIndex.

/**
     * Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if
     * that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster.
     */
void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException {
    if (false == response.isExists()) {
        listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId()));
        return;
    }
    if (response.isSourceEmpty()) {
        listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId()));
        return;
    }
    try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
        TaskResult result = TaskResult.PARSER.apply(parser, null);
        listener.onResponse(new GetTaskResponse(result));
    }
}
Also used : TaskResult(org.elasticsearch.tasks.TaskResult) ElasticsearchException(org.elasticsearch.ElasticsearchException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)3 TaskResult (org.elasticsearch.tasks.TaskResult)3 IOException (java.io.IOException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 TaskInfo (org.elasticsearch.tasks.TaskInfo)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)1 FailedNodeException (org.elasticsearch.action.FailedNodeException)1 GetTaskResponse (org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse)1 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 Task (org.elasticsearch.tasks.Task)1 TaskId (org.elasticsearch.tasks.TaskId)1 TaskResultsService (org.elasticsearch.tasks.TaskResultsService)1 ReceiveTimeoutTransportException (org.elasticsearch.transport.ReceiveTimeoutTransportException)1 TransportException (org.elasticsearch.transport.TransportException)1