@SuppressWarnings("unchecked") public final RequestBuilder setTimeout(TimeValue timeout) { request.setTimeout(timeout); return (RequestBuilder) this; }
@SuppressWarnings("unchecked") public final RequestBuilder setActions(String... actions) { request.setActions(actions); return (RequestBuilder) this; }
@SuppressWarnings("unchecked") public final RequestBuilder setNodesIds(String... nodesIds) { request.setNodes(nodesIds); return (RequestBuilder) this; }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(reason); }
public boolean match(Task task) { if (getActions() != null && getActions().length > 0 && Regex.simpleMatch(getActions(), task.getAction()) == false) { return false; } if (getTaskId().isSet()) { if(getTaskId().getId() != task.getId()) { return false; } } if (parentTaskId.isSet()) { if (parentTaskId.equals(task.getParentTaskId()) == false) { return false; } } return true; } }
protected void toXContentCommon(XContentBuilder builder, ToXContent.Params params) throws IOException { if (getTaskFailures() != null && getTaskFailures().size() > 0) { builder.startArray(TASK_FAILURES); for (TaskOperationFailure ex : getTaskFailures()){ builder.startObject(); builder.value(ex); builder.endObject(); } builder.endArray(); } if (getNodeFailures() != null && getNodeFailures().size() > 0) { builder.startArray(NODE_FAILURES); for (ElasticsearchException ex : getNodeFailures()) { builder.startObject(); ex.toXContent(builder, params); builder.endObject(); } builder.endArray(); } }
@Override protected void doExecute(Task task, TasksRequest request, ActionListener<TasksResponse> listener) { new AsyncAction(task, request, listener).start(); }
@Override public boolean match(Task task) { return super.match(task) && task instanceof CancellableTask; }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeList(tasks); }
protected TransportTasksAction(Settings settings, String actionName, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Writeable.Reader<TasksRequest> requestSupplier, Supplier<TasksResponse> responseSupplier, String nodeExecutor) { super(settings, actionName, threadPool, transportService, actionFilters, requestSupplier, indexNameExpressionResolver); this.clusterService = clusterService; this.transportService = transportService; this.transportNodeAction = actionName + "[n]"; this.requestSupplier = requestSupplier; this.responseSupplier = responseSupplier; transportService.registerRequestHandler(transportNodeAction, nodeExecutor, NodeTaskRequest::new, new NodeTransportHandler()); }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); tasks = Collections.unmodifiableList(in.readList(TaskInfo::new)); }
@SuppressWarnings("unchecked") protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray responses) { List<TaskResponse> tasks = new ArrayList<>(); List<FailedNodeException> failedNodeExceptions = new ArrayList<>(); List<TaskOperationFailure> taskOperationFailures = new ArrayList<>(); for (int i = 0; i < responses.length(); i++) { Object response = responses.get(i); if (response instanceof FailedNodeException) { failedNodeExceptions.add((FailedNodeException) response); } else { NodeTasksResponse tasksResponse = (NodeTasksResponse) response; if (tasksResponse.results != null) { tasks.addAll(tasksResponse.results); } if (tasksResponse.exceptions != null) { taskOperationFailures.addAll(tasksResponse.exceptions); } } } return newResponse(request, tasks, taskOperationFailures, failedNodeExceptions); }
@Override public void onFailure(Exception e) { responses.setOnce(taskIndex, new Tuple<>(null, e)); respondIfFinished(); }
/** * Match all children of the provided task. */ @SuppressWarnings("unchecked") public final RequestBuilder setParentTaskId(TaskId taskId) { request.setParentTaskId(taskId); return (RequestBuilder) this; } }
/** * Set the task to lookup. */ @SuppressWarnings("unchecked") public final RequestBuilder setTaskId(TaskId taskId) { request.setTaskId(taskId); return (RequestBuilder) this; }
@Override protected void processTasks(ListTasksRequest request, Consumer<Task> operation) { if (request.getWaitForCompletion()) { long timeoutNanos = waitForCompletionTimeout(request.getTimeout()); operation = operation.andThen(task -> { if (task.getAction().startsWith(ListTasksAction.NAME)) { // It doesn't make sense to wait for List Tasks and it can cause an infinite loop of the task waiting // for itself or one of its child tasks return; } taskManager.waitForTaskCompletion(task, timeoutNanos); }); } super.processTasks(request, operation); }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeBoolean(detailed); out.writeBoolean(waitForCompletion); }
/** * Rethrow task failures if there are any. */ public void rethrowFailures(String operationName) { rethrowAndSuppress(Stream.concat( getNodeFailures().stream(), getTaskFailures().stream().map(f -> new ElasticsearchException( "{} of [{}] failed", f.getCause(), operationName, new TaskId(f.getNodeId(), f.getTaskId())))) .collect(toList())); }
@Override public void onResponse(TaskResponse response) { responses.setOnce(taskIndex, response == null ? null : new Tuple<>(response, null)); respondIfFinished(); }