org.elasticsearch.tasks.TaskId Java Examples

The following examples show how to use org.elasticsearch.tasks.TaskId. 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: TaskInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public TaskInfo(StreamInput in) throws IOException {
    node = DiscoveryNode.readNode(in);
    taskId = new TaskId(node.getId(), in.readLong());
    type = in.readString();
    action = in.readString();
    description = in.readOptionalString();
    if (in.readBoolean()) {
        status = in.readTaskStatus();
    } else {
        status = null;
    }
    startTime = in.readLong();
    runningTimeNanos = in.readLong();
    parentTaskId = new TaskId(in);
}
 
Example #3
Source File: ChildTaskActionRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    if (in.getVersion().onOrAfter(Version.V_2_3_0)) {
        parentTaskId = new TaskId(in);
    }
}
 
Example #4
Source File: BaseTasksRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    taskId = new TaskId(in);
    parentTaskId = new TaskId(in);
    nodesIds = in.readStringArray();
    actions = in.readStringArray();
    if (in.readBoolean()) {
        timeout = TimeValue.readTimeValue(in);
    }
}
 
Example #5
Source File: ChildTaskRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    if (in.getVersion().onOrAfter(Version.V_2_3_0)) {
        parentTaskId = new TaskId(in);
    }
}
 
Example #6
Source File: TaskInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public TaskInfo(DiscoveryNode node, long id, String type, String action, String description, Task.Status status, long startTime,
                long runningTimeNanos, TaskId parentTaskId) {
    this.node = node;
    this.taskId = new TaskId(node.getId(), id);
    this.type = type;
    this.action = action;
    this.description = description;
    this.status = status;
    this.startTime = startTime;
    this.runningTimeNanos = runningTimeNanos;
    this.parentTaskId = parentTaskId;
}
 
Example #7
Source File: TransportCancelTasksAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    parentTaskId = new TaskId(in);
    ban = in.readBoolean();
    if (ban) {
        reason = in.readString();
    }
}
 
Example #8
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 #9
Source File: RestCancelTasksAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    TaskId taskId = new TaskId(request.param("taskId"));
    String[] actions = Strings.splitStringByCommaToArray(request.param("actions"));
    TaskId parentTaskId = new TaskId(request.param("parent_task_id"));

    CancelTasksRequest cancelTasksRequest = new CancelTasksRequest();
    cancelTasksRequest.setTaskId(taskId);
    cancelTasksRequest.setNodesIds(nodesIds);
    cancelTasksRequest.setActions(actions);
    cancelTasksRequest.setParentTaskId(parentTaskId);
    client.admin().cluster().cancelTasks(cancelTasksRequest, new RestToXContentListener<CancelTasksResponse>(channel));
}
 
Example #10
Source File: TransportRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public TransportRequest(StreamInput in) throws IOException {
    parentTaskId = TaskId.readFromStream(in);
}
 
Example #11
Source File: ChildTaskActionRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
    return new Task(id, type, action, getDescription(), parentTaskId);
}
 
Example #12
Source File: ChildTaskRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public void setParentTask(String parentTaskNode, long parentTaskId) {
    this.parentTaskId = new TaskId(parentTaskNode, parentTaskId);
}
 
Example #13
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 #14
Source File: ChildTaskRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
    return new Task(id, type, action, getDescription(), parentTaskId);
}
 
Example #15
Source File: PrimaryReplicaSyncer.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
    return new ResyncTask(id, type, action, getDescription(), parentTaskId);
}
 
Example #16
Source File: PrimaryReplicaSyncer.java    From crate with Apache License 2.0 4 votes vote down vote up
public ResyncTask(long id, String type, String action, String description, TaskId parentTaskId) {
    super(id, type, action, description, parentTaskId);
}
 
Example #17
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public TaskId getParentTask() {
    return request.getParentTask();
}
 
Example #18
Source File: TransportRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Set a reference to task that created this request.
 */
@Override
public void setParentTask(TaskId taskId) {
    this.parentTaskId = taskId;
}
 
Example #19
Source File: TransportRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Get a reference to the task that created this request. Defaults to {@link TaskId#EMPTY_TASK_ID}, meaning "there is no parent".
 */
@Override
public TaskId getParentTask() {
    return parentTaskId;
}
 
Example #20
Source File: TransportRequestDeduplicatorTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testRequestDeduplication() throws Exception {
    AtomicInteger successCount = new AtomicInteger();
    AtomicInteger failureCount = new AtomicInteger();
    Exception failure = randomBoolean() ? new TransportException("simulated") : null;
    final TransportRequest request = new TransportRequest() {
        @Override
        public void setParentTask(final TaskId taskId) {
        }
    };
    final TransportRequestDeduplicator<TransportRequest> deduplicator = new TransportRequestDeduplicator<>();
    final SetOnce<ActionListener<Void>> listenerHolder = new SetOnce<>();
    int iterationsPerThread = scaledRandomIntBetween(100, 1000);
    Thread[] threads = new Thread[between(1, 4)];
    Phaser barrier = new Phaser(threads.length + 1);
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(() -> {
            barrier.arriveAndAwaitAdvance();
            for (int n = 0; n < iterationsPerThread; n++) {
                deduplicator.executeOnce(request, new ActionListener<Void>() {
                    @Override
                    public void onResponse(Void aVoid) {
                        successCount.incrementAndGet();
                    }

                    @Override
                    public void onFailure(Exception e) {
                        assertThat(e, sameInstance(failure));
                        failureCount.incrementAndGet();
                    }
                }, (req, reqListener) -> listenerHolder.set(reqListener));
            }
        });
        threads[i].start();
    }
    barrier.arriveAndAwaitAdvance();
    for (Thread t : threads) {
        t.join();
    }
    final ActionListener<Void> listener = listenerHolder.get();
    assertThat(deduplicator.size(), equalTo(1));
    if (failure != null) {
        listener.onFailure(failure);
    } else {
        listener.onResponse(null);
    }
    assertThat(deduplicator.size(), equalTo(0));
    assertBusy(() -> {
        if (failure != null) {
            assertThat(successCount.get(), equalTo(0));
            assertThat(failureCount.get(), equalTo(threads.length * iterationsPerThread));
        } else {
            assertThat(successCount.get(), equalTo(threads.length * iterationsPerThread));
            assertThat(failureCount.get(), equalTo(0));
        }
    });
}
 
Example #21
Source File: ReplicationTask.java    From crate with Apache License 2.0 4 votes vote down vote up
public ReplicationTask(long id, String type, String action, String description, TaskId parentTaskId) {
    super(id, type, action, description, parentTaskId);
}
 
Example #22
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
    return request.createTask(id, type, action, parentTaskId);
}
 
Example #23
Source File: ReplicationRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
    return new ReplicationTask(id, type, action, getDescription(), parentTaskId);
}
 
Example #24
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setParentTask(TaskId taskId) {
    request.setParentTask(taskId);
}
 
Example #25
Source File: ChildTaskActionRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public void setParentTask(String parentTaskNode, long parentTaskId) {
    this.parentTaskId = new TaskId(parentTaskNode, parentTaskId);
}
 
Example #26
Source File: BaseTasksRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public T setParentTaskId(TaskId parentTaskId) {
    this.parentTaskId = parentTaskId;
    return (T) this;
}
 
Example #27
Source File: BaseTasksRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the parent task id that tasks should be filtered by
 */
public TaskId getParentTaskId() {
    return parentTaskId;
}
 
Example #28
Source File: BaseTasksRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public final T setTaskId(TaskId taskId) {
    this.taskId = taskId;
    return (T) this;
}
 
Example #29
Source File: ReplicationTask.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public ReplicationTask(long id, String type, String action, String description, TaskId parentTaskId) {
    super(id, type, action, description, parentTaskId);
}
 
Example #30
Source File: ReplicationRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
    return new ReplicationTask(id, type, action, getDescription(), parentTaskId);
}