use of org.elasticsearch.tasks.TaskInfo in project elasticsearch by elastic.
the class SearchCancellationIT method cancelSearch.
private void cancelSearch(String action) {
ListTasksResponse listTasksResponse = client().admin().cluster().prepareListTasks().setActions(action).get();
assertThat(listTasksResponse.getTasks(), hasSize(1));
TaskInfo searchTask = listTasksResponse.getTasks().get(0);
logger.info("Cancelling search");
CancelTasksResponse cancelTasksResponse = client().admin().cluster().prepareCancelTasks().setTaskId(searchTask.getTaskId()).get();
assertThat(cancelTasksResponse.getTasks(), hasSize(1));
assertThat(cancelTasksResponse.getTasks().get(0).getTaskId(), equalTo(searchTask.getTaskId()));
}
use of org.elasticsearch.tasks.TaskInfo in project elasticsearch by elastic.
the class TransportRethrottleAction method rethrottle.
static void rethrottle(String localNodeId, Client client, BulkByScrollTask task, float newRequestsPerSecond, ActionListener<TaskInfo> listener) {
int runningSubTasks = task.runningSliceSubTasks();
if (runningSubTasks == 0) {
// Nothing to do, all sub tasks are done
task.rethrottle(newRequestsPerSecond);
listener.onResponse(task.taskInfo(localNodeId, true));
return;
}
RethrottleRequest subRequest = new RethrottleRequest();
subRequest.setRequestsPerSecond(newRequestsPerSecond / runningSubTasks);
subRequest.setParentTaskId(new TaskId(localNodeId, task.getId()));
client.execute(RethrottleAction.INSTANCE, subRequest, ActionListener.wrap(r -> {
r.rethrowFailures("Rethrottle");
listener.onResponse(task.getInfoGivenSliceInfo(localNodeId, r.getTasks()));
}, listener::onFailure));
}
use of org.elasticsearch.tasks.TaskInfo in project elasticsearch by elastic.
the class TransportRethrottleActionTests method testRethrottleSuccessfulResponse.
public void testRethrottleSuccessfulResponse() {
List<TaskInfo> tasks = new ArrayList<>();
List<BulkByScrollTask.StatusOrException> sliceStatuses = new ArrayList<>(slices);
for (int i = 0; i < slices; i++) {
BulkByScrollTask.Status status = believeableInProgressStatus(i);
tasks.add(new TaskInfo(new TaskId("test", 123), "test", "test", "test", status, 0, 0, true, new TaskId("test", task.getId())));
sliceStatuses.add(new BulkByScrollTask.StatusOrException(status));
}
rethrottleTestCase(slices, listener -> listener.onResponse(new ListTasksResponse(tasks, emptyList(), emptyList())), expectSuccessfulRethrottleWithStatuses(sliceStatuses));
}
use of org.elasticsearch.tasks.TaskInfo in project elasticsearch by elastic.
the class TaskTests method testTaskInfoToString.
public void testTaskInfoToString() {
String nodeId = randomAsciiOfLength(10);
long taskId = randomIntBetween(0, 100000);
long startTime = randomNonNegativeLong();
long runningTime = randomNonNegativeLong();
boolean cancellable = randomBoolean();
TaskInfo taskInfo = new TaskInfo(new TaskId(nodeId, taskId), "test_type", "test_action", "test_description", null, startTime, runningTime, cancellable, TaskId.EMPTY_TASK_ID);
String taskInfoString = taskInfo.toString();
Map<String, Object> map = XContentHelper.convertToMap(new BytesArray(taskInfoString.getBytes(StandardCharsets.UTF_8)), true).v2();
assertEquals(((Number) map.get("id")).longValue(), taskId);
assertEquals(map.get("type"), "test_type");
assertEquals(map.get("action"), "test_action");
assertEquals(map.get("description"), "test_description");
assertEquals(((Number) map.get("start_time_in_millis")).longValue(), startTime);
assertEquals(((Number) map.get("running_time_in_nanos")).longValue(), runningTime);
assertEquals(map.get("cancellable"), cancellable);
}
use of org.elasticsearch.tasks.TaskInfo in project elasticsearch by elastic.
the class TasksIT method testNodeNotFoundButTaskFound.
public void testNodeNotFoundButTaskFound() throws Exception {
// Save a fake task that looks like it is from a node that isn't part of the cluster
CyclicBarrier b = new CyclicBarrier(2);
TaskResultsService resultsService = internalCluster().getInstance(TaskResultsService.class);
resultsService.storeResult(new TaskResult(new TaskInfo(new TaskId("fake", 1), "test", "test", "", null, 0, 0, false, TaskId.EMPTY_TASK_ID), new RuntimeException("test")), new ActionListener<Void>() {
@Override
public void onResponse(Void response) {
try {
b.await();
} catch (InterruptedException | BrokenBarrierException e) {
onFailure(e);
}
}
@Override
public void onFailure(Exception e) {
throw new RuntimeException(e);
}
});
b.await();
// Now we can find it!
GetTaskResponse response = expectFinishedTask(new TaskId("fake:1"));
assertEquals("test", response.getTask().getTask().getAction());
assertNotNull(response.getTask().getError());
assertNull(response.getTask().getResponse());
}
Aggregations