@Override public GetTaskRequestBuilder prepareGetTask(String taskId) { return prepareGetTask(new TaskId(taskId)); }
/** * Set a reference to task that created this request. */ void setParentTask(TaskId taskId);
/** * Build a proper {@link TaskInfo} for this task. */ protected final TaskInfo taskInfo(String localNodeId, String description, Status status) { return new TaskInfo(new TaskId(localNodeId, getId()), getType(), getAction(), description, status, startTime, System.nanoTime() - startTimeNanos, this instanceof CancellableTask, parentTask, headers); }
/** * Read a {@linkplain TaskId} from a stream. {@linkplain TaskId} has this rather than the usual constructor that takes a * {@linkplain StreamInput} so we can return the {@link #EMPTY_TASK_ID} without allocating. */ public static TaskId readFromStream(StreamInput in) throws IOException { String nodeId = in.readString(); if (nodeId.isEmpty()) { /* * The only TaskId allowed to have the empty string as its nodeId is the EMPTY_TASK_ID and there is only ever one of it and it * never writes its taskId to save bytes on the wire because it is by far the most common TaskId. */ return EMPTY_TASK_ID; } return new TaskId(nodeId, in.readLong()); }
/** * 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())); }
/** * Convenience constructor for building the TaskId out of what is usually at hand. */ public ParentTaskAssigningClient(Client in, DiscoveryNode localNode, Task parentTask) { this(in, new TaskId(localNode.getId(), parentTask.getId())); }
public static ContextParser<Void, TaskId> parser() { return (p, c) -> { if (p.currentToken() == XContentParser.Token.VALUE_STRING) { return new TaskId(p.text()); } throw new ElasticsearchParseException("Expected a string but found [{}] instead", p.currentToken()); }; }
private void setBanOnNodes(String reason, CancellableTask task, DiscoveryNodes nodes, ActionListener<Void> listener) { sendSetBanRequest(nodes, BanParentTaskRequest.createSetBanParentTaskRequest(new TaskId(clusterService.localNode().getId(), task.getId()), reason), listener); }
private void removeBanOnNodes(CancellableTask task, DiscoveryNodes nodes) { sendRemoveBanRequest(nodes, BanParentTaskRequest.createRemoveBanParentTaskRequest(new TaskId(clusterService.localNode().getId(), task.getId()))); }
/** * Cancels a locally running task using the Task Manager API */ void sendCancelRequest(final long taskId, final String reason, final ActionListener<CancelTasksResponse> listener) { CancelTasksRequest request = new CancelTasksRequest(); request.setTaskId(new TaskId(clusterService.localNode().getId(), taskId)); request.setReason(reason); try { client.admin().cluster().cancelTasks(request, listener); } catch (Exception e) { listener.onFailure(e); } }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodes")); final TaskId taskId = new TaskId(request.param("task_id")); final String[] actions = Strings.splitStringByCommaToArray(request.param("actions")); final TaskId parentTaskId = new TaskId(request.param("parent_task_id")); final String groupBy = request.param("group_by", "nodes"); CancelTasksRequest cancelTasksRequest = new CancelTasksRequest(); cancelTasksRequest.setTaskId(taskId); cancelTasksRequest.setNodes(nodesIds); cancelTasksRequest.setActions(actions); cancelTasksRequest.setParentTaskId(parentTaskId); return channel -> client.admin().cluster().cancelTasks(cancelTasksRequest, listTasksResponseListener(nodesInCluster, groupBy, channel)); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { TaskId taskId = new TaskId(request.param("task_id")); boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false); TimeValue timeout = request.paramAsTime("timeout", null); GetTaskRequest getTaskRequest = new GetTaskRequest(); getTaskRequest.setTaskId(taskId); getTaskRequest.setWaitForCompletion(waitForCompletion); getTaskRequest.setTimeout(timeout); return channel -> client.admin().cluster().getTask(getTaskRequest, new RestToXContentListener<>(channel)); } }
TaskId parentTaskId = new TaskId("cluster", taskInProgress.getAllocationId());
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; }
/** * Build a proper {@link TaskInfo} for this task. */ protected final TaskInfo taskInfo(String localNodeId, String description, Status status) { return new TaskInfo(new TaskId(localNodeId, getId()), getType(), getAction(), description, status, startTime, System.nanoTime() - startTimeNanos, this instanceof CancellableTask, parentTask); }
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { RethrottleRequest internalRequest = new RethrottleRequest(); internalRequest.setTaskId(new TaskId(request.param("taskId"))); Float requestsPerSecond = AbstractBaseReindexRestHandler.parseRequestsPerSecond(request); if (requestsPerSecond == null) { throw new IllegalArgumentException("requests_per_second is a required parameter"); } internalRequest.setRequestsPerSecond(requestsPerSecond); action.execute(internalRequest, new RestToXContentListener<ListTasksResponse>(channel)); } }
private void setBanOnNodes(String reason, CancellableTask task, DiscoveryNodes nodes, ActionListener<Void> listener) { sendSetBanRequest(nodes, BanParentTaskRequest.createSetBanParentTaskRequest(new TaskId(clusterService.localNode().getId(), task.getId()), reason), listener); }
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { RethrottleRequest internalRequest = new RethrottleRequest(); internalRequest.setTaskId(new TaskId(request.param("taskId"))); Float requestsPerSecond = AbstractBaseReindexRestHandler.parseRequestsPerSecond(request); if (requestsPerSecond == null) { throw new IllegalArgumentException("requests_per_second is a required parameter"); } internalRequest.setRequestsPerSecond(requestsPerSecond); action.execute(internalRequest, new RestToXContentListener<ListTasksResponse>(channel)); } }
private void setBanOnNodes(String reason, CancellableTask task, DiscoveryNodes nodes, ActionListener<Void> listener) { sendSetBanRequest(nodes, BanParentTaskRequest.createSetBanParentTaskRequest(new TaskId(clusterService.localNode().getId(), task.getId()), reason), listener); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { TaskId taskId = new TaskId(request.param("task_id")); boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false); TimeValue timeout = request.paramAsTime("timeout", null); GetTaskRequest getTaskRequest = new GetTaskRequest(); getTaskRequest.setTaskId(taskId); getTaskRequest.setWaitForCompletion(waitForCompletion); getTaskRequest.setTimeout(timeout); return channel -> client.admin().cluster().getTask(getTaskRequest, new RestToXContentListener<>(channel)); } }