Search in sources :

Example 11 with TaskId

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

the class ParentTaskAssigningClientTests method testSetsParentId.

public void testSetsParentId() {
    TaskId[] parentTaskId = new TaskId[] { new TaskId(randomAsciiOfLength(3), randomLong()) };
    // This mock will do nothing but verify that parentTaskId is set on all requests sent to it.
    NoOpClient mock = new NoOpClient(getTestName()) {

        @Override
        protected <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
            assertEquals(parentTaskId[0], request.getParentTask());
            super.doExecute(action, request, listener);
        }
    };
    try (ParentTaskAssigningClient client = new ParentTaskAssigningClient(mock, parentTaskId[0])) {
        // All of these should have the parentTaskId set
        client.bulk(new BulkRequest());
        client.search(new SearchRequest());
        client.clearScroll(new ClearScrollRequest());
        // Now lets verify that unwrapped calls don't have the parentTaskId set
        parentTaskId[0] = TaskId.EMPTY_TASK_ID;
        client.unwrap().bulk(new BulkRequest());
        client.unwrap().search(new SearchRequest());
        client.unwrap().clearScroll(new ClearScrollRequest());
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Action(org.elasticsearch.action.Action) TaskId(org.elasticsearch.tasks.TaskId) ActionRequest(org.elasticsearch.action.ActionRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ActionResponse(org.elasticsearch.action.ActionResponse) ActionRequestBuilder(org.elasticsearch.action.ActionRequestBuilder) ActionListener(org.elasticsearch.action.ActionListener) ActionRequest(org.elasticsearch.action.ActionRequest) NoOpClient(org.elasticsearch.test.client.NoOpClient) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest)

Example 12 with TaskId

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

the class BulkByScrollParallelizationHelper method startSlices.

public static <Request extends AbstractBulkByScrollRequest<Request>> void startSlices(Client client, TaskManager taskManager, Action<Request, BulkByScrollResponse, ?> action, String localNodeId, ParentBulkByScrollTask task, Request request, ActionListener<BulkByScrollResponse> listener) {
    TaskId parentTaskId = new TaskId(localNodeId, task.getId());
    for (final SearchRequest slice : sliceIntoSubRequests(request.getSearchRequest(), UidFieldMapper.NAME, request.getSlices())) {
        // TODO move the request to the correct node. maybe here or somehow do it as part of startup for reindex in general....
        Request requestForSlice = request.forSlice(parentTaskId, slice);
        ActionListener<BulkByScrollResponse> sliceListener = ActionListener.wrap(r -> task.onSliceResponse(listener, slice.source().slice().getId(), r), e -> task.onSliceFailure(listener, slice.source().slice().getId(), e));
        client.execute(action, requestForSlice, sliceListener);
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) TaskId(org.elasticsearch.tasks.TaskId) SearchRequest(org.elasticsearch.action.search.SearchRequest)

Example 13 with TaskId

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

the class TransportGetTaskAction method runOnNodeWithTaskIfPossible.

/**
     * Executed on the coordinating node to forward execution of the remaining work to the node that matches that requested
     * {@link TaskId#getNodeId()}. If the node isn't in the cluster then this will just proceed to
     * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} on this node.
     */
private void runOnNodeWithTaskIfPossible(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
    TransportRequestOptions.Builder builder = TransportRequestOptions.builder();
    if (request.getTimeout() != null) {
        builder.withTimeout(request.getTimeout());
    }
    builder.withCompress(false);
    DiscoveryNode node = clusterService.state().nodes().get(request.getTaskId().getNodeId());
    if (node == null) {
        // Node is no longer part of the cluster! Try and look the task up from the results index.
        getFinishedTaskFromIndex(thisTask, request, ActionListener.wrap(listener::onResponse, e -> {
            if (e instanceof ResourceNotFoundException) {
                e = new ResourceNotFoundException("task [" + request.getTaskId() + "] belongs to the node [" + request.getTaskId().getNodeId() + "] which isn't part of the cluster and there is no record of the task", e);
            }
            listener.onFailure(e);
        }));
        return;
    }
    GetTaskRequest nodeRequest = request.nodeRequest(clusterService.localNode().getId(), thisTask.getId());
    transportService.sendRequest(node, GetTaskAction.NAME, nodeRequest, builder.build(), new TransportResponseHandler<GetTaskResponse>() {

        @Override
        public GetTaskResponse newInstance() {
            return new GetTaskResponse();
        }

        @Override
        public void handleResponse(GetTaskResponse response) {
            listener.onResponse(response);
        }

        @Override
        public void handleException(TransportException exp) {
            listener.onFailure(exp);
        }

        @Override
        public String executor() {
            return ThreadPool.Names.SAME;
        }
    });
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) ClusterService(org.elasticsearch.cluster.service.ClusterService) TaskId(org.elasticsearch.tasks.TaskId) Inject(org.elasticsearch.common.inject.Inject) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) TaskResult(org.elasticsearch.tasks.TaskResult) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) HandledTransportAction(org.elasticsearch.action.support.HandledTransportAction) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) TaskInfo(org.elasticsearch.tasks.TaskInfo) GetRequest(org.elasticsearch.action.get.GetRequest) ActionFilters(org.elasticsearch.action.support.ActionFilters) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) XContentParser(org.elasticsearch.common.xcontent.XContentParser) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportListTasksAction.waitForCompletionTimeout(org.elasticsearch.action.admin.cluster.node.tasks.list.TransportListTasksAction.waitForCompletionTimeout) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Task(org.elasticsearch.tasks.Task) TransportException(org.elasticsearch.transport.TransportException) ActionListener(org.elasticsearch.action.ActionListener) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) TransportException(org.elasticsearch.transport.TransportException)

Example 14 with TaskId

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

the class ListTasksResponse method buildTaskGroups.

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()));
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) TaskId(org.elasticsearch.tasks.TaskId) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ArrayList(java.util.ArrayList)

Example 15 with TaskId

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

the class RestListTasksAction method generateListTasksRequest.

public static ListTasksRequest generateListTasksRequest(RestRequest request) {
    boolean detailed = request.paramAsBoolean("detailed", false);
    String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes"));
    String[] actions = Strings.splitStringByCommaToArray(request.param("actions"));
    TaskId parentTaskId = new TaskId(request.param("parent_task_id"));
    boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false);
    TimeValue timeout = request.paramAsTime("timeout", null);
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setNodes(nodes);
    listTasksRequest.setDetailed(detailed);
    listTasksRequest.setActions(actions);
    listTasksRequest.setParentTaskId(parentTaskId);
    listTasksRequest.setWaitForCompletion(waitForCompletion);
    listTasksRequest.setTimeout(timeout);
    return listTasksRequest;
}
Also used : TaskId(org.elasticsearch.tasks.TaskId) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

TaskId (org.elasticsearch.tasks.TaskId)28 TaskInfo (org.elasticsearch.tasks.TaskInfo)13 IOException (java.io.IOException)10 ListTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 ListTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest)6 Task (org.elasticsearch.tasks.Task)6 CancelTasksRequest (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest)5 Settings (org.elasticsearch.common.settings.Settings)5 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 ActionListener (org.elasticsearch.action.ActionListener)4 CancelTasksResponse (org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse)4 BulkByScrollTask (org.elasticsearch.action.bulk.byscroll.BulkByScrollTask)4 SearchRequest (org.elasticsearch.action.search.SearchRequest)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 HashMap (java.util.HashMap)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 FailedNodeException (org.elasticsearch.action.FailedNodeException)3 GetTaskResponse (org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse)3