org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestListTasksAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    boolean detailed = request.paramAsBoolean("detailed", false);
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("node_id"));
    TaskId taskId = new TaskId(request.param("taskId"));
    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.setTaskId(taskId);
    listTasksRequest.setNodesIds(nodesIds);
    listTasksRequest.setDetailed(detailed);
    listTasksRequest.setActions(actions);
    listTasksRequest.setParentTaskId(parentTaskId);
    listTasksRequest.setWaitForCompletion(waitForCompletion);
    listTasksRequest.setTimeout(timeout);
    client.admin().cluster().listTasks(listTasksRequest, new RestToXContentListener<ListTasksResponse>(channel));
}
 
Example #2
Source File: EsHighLevelRestTest2.java    From java-study with Apache License 2.0 5 votes vote down vote up
/**
	 * 用于更改正在运行的重索引、逐查询更新或逐查询删除任务的当前节流,或完全禁用任务的节流。
	 * @throws IOException
	 */
	private static void rethrottleByQuery() throws IOException {
		TaskId taskId=new TaskId("1");
		//用于更改正在运行的重索引、逐查询更新或逐查询删除任务的当前节流,或完全禁用任务的节流。
		//并且将请求将任务的节流更改为每秒100个请求
		RethrottleRequest request = new RethrottleRequest(taskId,100.0f);

		// 同步设置需要更改的流
//		client.reindexRethrottle(request, RequestOptions.DEFAULT);       
//		client.updateByQueryRethrottle(request, RequestOptions.DEFAULT); 
//		client.deleteByQueryRethrottle(request, RequestOptions.DEFAULT); 
		
		
		ActionListener<ListTasksResponse> listener = new ActionListener<ListTasksResponse>() {
		    @Override
		    public void onResponse(ListTasksResponse response) {
		        System.out.println("===="+response.getTasks().toString());
		    }

		    @Override
		    public void onFailure(Exception e) {
		    	 System.out.println("====---"+e.getMessage());
		    }
		};
		
		// 异步设置要更改的流
		client.reindexRethrottleAsync(request, RequestOptions.DEFAULT, listener);       
		client.updateByQueryRethrottleAsync(request, RequestOptions.DEFAULT, listener); 
		client.deleteByQueryRethrottleAsync(request, RequestOptions.DEFAULT, listener);

		System.out.println("已成功设置!");

	}
 
Example #3
Source File: ClientUtil.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
/**
 * Helper function to handle ListTasksResponse
 * @param listTasksResponse ListTasksResponse
 * @param detectorId Anomaly Detector Id
 * @param LOG Logger
 */
private void onListTaskResponse(ListTasksResponse listTasksResponse, String detectorId, Logger LOG) {
    List<TaskInfo> tasks = listTasksResponse.getTasks();
    TaskId matchedParentTaskId = null;
    TaskId matchedSingleTaskId = null;
    for (TaskInfo task : tasks) {
        if (!task.getHeaders().isEmpty()
            && task.getHeaders().get(Task.X_OPAQUE_ID).equals(CommonName.ANOMALY_DETECTOR + ":" + detectorId)) {
            if (!task.getParentTaskId().equals(TaskId.EMPTY_TASK_ID)) {
                // we found the parent task, don't need to check more
                matchedParentTaskId = task.getParentTaskId();
                break;
            } else {
                // we found one task, keep checking other tasks
                matchedSingleTaskId = task.getTaskId();
            }
        }
    }
    // case 1: given detectorId is not in current task list
    if (matchedParentTaskId == null && matchedSingleTaskId == null) {
        // log and then clear negative cache
        LOG.info("Couldn't find task for detectorId: {}. Clean this entry from Throttler", detectorId);
        throttler.clearFilteredQuery(detectorId);
        return;
    }
    // case 2: we can find the task for given detectorId
    CancelTasksRequest cancelTaskRequest = new CancelTasksRequest();
    if (matchedParentTaskId != null) {
        cancelTaskRequest.setParentTaskId(matchedParentTaskId);
        LOG.info("Start to cancel task for parentTaskId: {}", matchedParentTaskId.toString());
    } else {
        cancelTaskRequest.setTaskId(matchedSingleTaskId);
        LOG.info("Start to cancel task for taskId: {}", matchedSingleTaskId.toString());
    }

    client
        .execute(
            CancelTasksAction.INSTANCE,
            cancelTaskRequest,
            ActionListener.wrap(response -> { onCancelTaskResponse(response, detectorId, LOG); }, exception -> {
                LOG.error("Failed to cancel task for detectorId: " + detectorId, exception);
                throw new InternalFailure(detectorId, "Failed to cancel current tasks", exception);
            })
        );
}
 
Example #4
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<ListTasksResponse> listTasks(final ListTasksRequest request) {
    return execute(ListTasksAction.INSTANCE, request);
}
 
Example #5
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void listTasks(final ListTasksRequest request, final ActionListener<ListTasksResponse> listener) {
    execute(ListTasksAction.INSTANCE, request, listener);
}
 
Example #6
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * List tasks
 *
 * @param request The nodes tasks request
 * @return The result future
 * @see org.elasticsearch.client.Requests#listTasksRequest()
 */
ActionFuture<ListTasksResponse> listTasks(ListTasksRequest request);
 
Example #7
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * List active tasks
 *
 * @param request  The nodes tasks request
 * @param listener A listener to be notified with a result
 * @see org.elasticsearch.client.Requests#listTasksRequest()
 */
void listTasks(ListTasksRequest request, ActionListener<ListTasksResponse> listener);