Search in sources :

Example 1 with TaskInfo

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

the class SearchCancellationIT method cancelSearch.

private void cancelSearch(String action) {
    ListTasksResponse listTasksResponse = client().admin().cluster().prepareListTasks().setActions(action).get();
    assertThat(listTasksResponse.getTasks(), hasSize(1));
    TaskInfo searchTask = listTasksResponse.getTasks().get(0);
    logger.info("Cancelling search");
    CancelTasksResponse cancelTasksResponse = client().admin().cluster().prepareCancelTasks().setTaskId(searchTask.getTaskId()).get();
    assertThat(cancelTasksResponse.getTasks(), hasSize(1));
    assertThat(cancelTasksResponse.getTasks().get(0).getTaskId(), equalTo(searchTask.getTaskId()));
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) CancelTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Example 2 with TaskInfo

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

the class TransportRethrottleAction method rethrottle.

static void rethrottle(String localNodeId, Client client, BulkByScrollTask task, float newRequestsPerSecond, ActionListener<TaskInfo> listener) {
    int runningSubTasks = task.runningSliceSubTasks();
    if (runningSubTasks == 0) {
        // Nothing to do, all sub tasks are done
        task.rethrottle(newRequestsPerSecond);
        listener.onResponse(task.taskInfo(localNodeId, true));
        return;
    }
    RethrottleRequest subRequest = new RethrottleRequest();
    subRequest.setRequestsPerSecond(newRequestsPerSecond / runningSubTasks);
    subRequest.setParentTaskId(new TaskId(localNodeId, task.getId()));
    client.execute(RethrottleAction.INSTANCE, subRequest, ActionListener.wrap(r -> {
        r.rethrowFailures("Rethrottle");
        listener.onResponse(task.getInfoGivenSliceInfo(localNodeId, r.getTasks()));
    }, listener::onFailure));
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) ActionFilters(org.elasticsearch.action.support.ActionFilters) FailedNodeException(org.elasticsearch.action.FailedNodeException) Client(org.elasticsearch.client.Client) ClusterService(org.elasticsearch.cluster.service.ClusterService) IOException(java.io.IOException) TaskId(org.elasticsearch.tasks.TaskId) Inject(org.elasticsearch.common.inject.Inject) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) TaskOperationFailure(org.elasticsearch.action.TaskOperationFailure) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TransportTasksAction(org.elasticsearch.action.support.tasks.TransportTasksAction) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) BulkByScrollTask(org.elasticsearch.action.bulk.byscroll.BulkByScrollTask) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ActionListener(org.elasticsearch.action.ActionListener) TaskId(org.elasticsearch.tasks.TaskId)

Example 3 with TaskInfo

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

the class TransportRethrottleActionTests method testRethrottleSuccessfulResponse.

public void testRethrottleSuccessfulResponse() {
    List<TaskInfo> tasks = new ArrayList<>();
    List<BulkByScrollTask.StatusOrException> sliceStatuses = new ArrayList<>(slices);
    for (int i = 0; i < slices; i++) {
        BulkByScrollTask.Status status = believeableInProgressStatus(i);
        tasks.add(new TaskInfo(new TaskId("test", 123), "test", "test", "test", status, 0, 0, true, new TaskId("test", task.getId())));
        sliceStatuses.add(new BulkByScrollTask.StatusOrException(status));
    }
    rethrottleTestCase(slices, listener -> listener.onResponse(new ListTasksResponse(tasks, emptyList(), emptyList())), expectSuccessfulRethrottleWithStatuses(sliceStatuses));
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) TaskId(org.elasticsearch.tasks.TaskId) ArrayList(java.util.ArrayList) ParentBulkByScrollTask(org.elasticsearch.action.bulk.byscroll.ParentBulkByScrollTask) BulkByScrollTask(org.elasticsearch.action.bulk.byscroll.BulkByScrollTask) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Example 4 with TaskInfo

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

the class TaskTests method testTaskInfoToString.

public void testTaskInfoToString() {
    String nodeId = randomAsciiOfLength(10);
    long taskId = randomIntBetween(0, 100000);
    long startTime = randomNonNegativeLong();
    long runningTime = randomNonNegativeLong();
    boolean cancellable = randomBoolean();
    TaskInfo taskInfo = new TaskInfo(new TaskId(nodeId, taskId), "test_type", "test_action", "test_description", null, startTime, runningTime, cancellable, TaskId.EMPTY_TASK_ID);
    String taskInfoString = taskInfo.toString();
    Map<String, Object> map = XContentHelper.convertToMap(new BytesArray(taskInfoString.getBytes(StandardCharsets.UTF_8)), true).v2();
    assertEquals(((Number) map.get("id")).longValue(), taskId);
    assertEquals(map.get("type"), "test_type");
    assertEquals(map.get("action"), "test_action");
    assertEquals(map.get("description"), "test_description");
    assertEquals(((Number) map.get("start_time_in_millis")).longValue(), startTime);
    assertEquals(((Number) map.get("running_time_in_nanos")).longValue(), runningTime);
    assertEquals(map.get("cancellable"), cancellable);
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) BytesArray(org.elasticsearch.common.bytes.BytesArray) TaskId(org.elasticsearch.tasks.TaskId)

Example 5 with TaskInfo

use of org.elasticsearch.tasks.TaskInfo 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)

Aggregations

TaskInfo (org.elasticsearch.tasks.TaskInfo)25 TaskId (org.elasticsearch.tasks.TaskId)13 ListTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)12 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 GetTaskResponse (org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse)6 Map (java.util.Map)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Tuple (org.elasticsearch.common.collect.Tuple)5 Task (org.elasticsearch.tasks.Task)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 List (java.util.List)4 CancelTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse)4 BulkByScrollTask (org.elasticsearch.action.bulk.byscroll.BulkByScrollTask)4 ExecutionException (java.util.concurrent.ExecutionException)3 ActionListener (org.elasticsearch.action.ActionListener)3 FailedNodeException (org.elasticsearch.action.FailedNodeException)3 ListTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest)3 GetResponse (org.elasticsearch.action.get.GetResponse)3