public TaskResult result(DiscoveryNode node, ActionResponse response) throws IOException { if (response instanceof ToXContent) { return new TaskResult(taskInfo(node.getId(), true), (ToXContent) response); } else { throw new IllegalStateException("response has to implement ToXContent to be able to store the results"); } } }
/** * Called after waiting for the task to complete. Attempts to load the results of the task from the tasks index. If it isn't in the * index then returns a snapshot of the task taken shortly after completion. */ void waitedForCompletion(Task thisTask, GetTaskRequest request, TaskInfo snapshotOfRunningTask, ActionListener<GetTaskResponse> listener) { getFinishedTaskFromIndex(thisTask, request, new ActionListener<GetTaskResponse>() { @Override public void onResponse(GetTaskResponse response) { // We were able to load the task from the task index. Let's send that back. listener.onResponse(response); } @Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } }); }
@Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } });
public TaskResult result(DiscoveryNode node, Exception error) throws IOException { return new TaskResult(taskInfo(node.getId(), true), error); }
/** * Executed on the node that should be running the task to find and return the running task. Falls back to * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} if the task isn't still running. */ void getRunningTaskFromNode(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) { Task runningTask = taskManager.getTask(request.getTaskId().getId()); if (runningTask == null) { // Task isn't running, go look in the task index getFinishedTaskFromIndex(thisTask, request, listener); } else { if (request.getWaitForCompletion()) { // Shift to the generic thread pool and let it wait for the task to complete so we don't block any important threads. threadPool.generic().execute(new AbstractRunnable() { @Override protected void doRun() throws Exception { taskManager.waitForTaskCompletion(runningTask, waitForCompletionTimeout(request.getTimeout())); waitedForCompletion(thisTask, request, runningTask.taskInfo(clusterService.localNode().getId(), true), listener); } @Override public void onFailure(Exception e) { listener.onFailure(e); } }); } else { TaskInfo info = runningTask.taskInfo(clusterService.localNode().getId(), true); listener.onResponse(new GetTaskResponse(new TaskResult(false, info))); } } }
/** * Called after waiting for the task to complete. Attempts to load the results of the task from the tasks index. If it isn't in the * index then returns a snapshot of the task taken shortly after completion. */ void waitedForCompletion(Task thisTask, GetTaskRequest request, TaskInfo snapshotOfRunningTask, ActionListener<GetTaskResponse> listener) { getFinishedTaskFromIndex(thisTask, request, new ActionListener<GetTaskResponse>() { @Override public void onResponse(GetTaskResponse response) { // We were able to load the task from the task index. Let's send that back. listener.onResponse(response); } @Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } }); }
public TaskResult result(DiscoveryNode node, ActionResponse response) throws IOException { if (response instanceof ToXContent) { return new TaskResult(taskInfo(node.getId(), true), (ToXContent) response); } else { throw new IllegalStateException("response has to implement ToXContent to be able to store the results"); } } }
public TaskResult result(DiscoveryNode node, ActionResponse response) throws IOException { if (response instanceof ToXContent) { return new TaskResult(taskInfo(node.getId(), true), (ToXContent) response); } else { throw new IllegalStateException("response has to implement ToXContent to be able to store the results"); } } }
/** * Called after waiting for the task to complete. Attempts to load the results of the task from the tasks index. If it isn't in the * index then returns a snapshot of the task taken shortly after completion. */ void waitedForCompletion(Task thisTask, GetTaskRequest request, TaskInfo snapshotOfRunningTask, ActionListener<GetTaskResponse> listener) { getFinishedTaskFromIndex(thisTask, request, new ActionListener<GetTaskResponse>() { @Override public void onResponse(GetTaskResponse response) { // We were able to load the task from the task index. Let's send that back. listener.onResponse(response); } @Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } }); }
public TaskResult result(DiscoveryNode node, ActionResponse response) throws IOException { if (response instanceof ToXContent) { return new TaskResult(taskInfo(node.getId(), true), (ToXContent) response); } else { throw new IllegalStateException("response has to implement ToXContent to be able to store the results"); } } }
/** * Called after waiting for the task to complete. Attempts to load the results of the task from the tasks index. If it isn't in the * index then returns a snapshot of the task taken shortly after completion. */ void waitedForCompletion(Task thisTask, GetTaskRequest request, TaskInfo snapshotOfRunningTask, ActionListener<GetTaskResponse> listener) { getFinishedTaskFromIndex(thisTask, request, new ActionListener<GetTaskResponse>() { @Override public void onResponse(GetTaskResponse response) { // We were able to load the task from the task index. Let's send that back. listener.onResponse(response); } @Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } }); }
@Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } });
@Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } });
@Override public void onFailure(Exception e) { /* * We couldn't load the task from the task index. Instead of 404 we should use the snapshot we took after it finished. If * the error isn't a 404 then we'll just throw it back to the user. */ if (ExceptionsHelper.unwrap(e, ResourceNotFoundException.class) != null) { listener.onResponse(new GetTaskResponse(new TaskResult(true, snapshotOfRunningTask))); } else { listener.onFailure(e); } } });
public TaskResult result(DiscoveryNode node, Exception error) throws IOException { return new TaskResult(taskInfo(node.getId(), true), error); }
public TaskResult result(DiscoveryNode node, Exception error) throws IOException { return new TaskResult(taskInfo(node.getId(), true), error); }
/** * Executed on the node that should be running the task to find and return the running task. Falls back to * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} if the task isn't still running. */ void getRunningTaskFromNode(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) { Task runningTask = taskManager.getTask(request.getTaskId().getId()); if (runningTask == null) { // Task isn't running, go look in the task index getFinishedTaskFromIndex(thisTask, request, listener); } else { if (request.getWaitForCompletion()) { // Shift to the generic thread pool and let it wait for the task to complete so we don't block any important threads. threadPool.generic().execute(new AbstractRunnable() { @Override protected void doRun() throws Exception { taskManager.waitForTaskCompletion(runningTask, waitForCompletionTimeout(request.getTimeout())); waitedForCompletion(thisTask, request, runningTask.taskInfo(clusterService.localNode().getId(), true), listener); } @Override public void onFailure(Exception e) { listener.onFailure(e); } }); } else { TaskInfo info = runningTask.taskInfo(clusterService.localNode().getId(), true); listener.onResponse(new GetTaskResponse(new TaskResult(false, info))); } } }
/** * Executed on the node that should be running the task to find and return the running task. Falls back to * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} if the task isn't still running. */ void getRunningTaskFromNode(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) { Task runningTask = taskManager.getTask(request.getTaskId().getId()); if (runningTask == null) { // Task isn't running, go look in the task index getFinishedTaskFromIndex(thisTask, request, listener); } else { if (request.getWaitForCompletion()) { // Shift to the generic thread pool and let it wait for the task to complete so we don't block any important threads. threadPool.generic().execute(new AbstractRunnable() { @Override protected void doRun() throws Exception { taskManager.waitForTaskCompletion(runningTask, waitForCompletionTimeout(request.getTimeout())); waitedForCompletion(thisTask, request, runningTask.taskInfo(clusterService.localNode().getId(), true), listener); } @Override public void onFailure(Exception e) { listener.onFailure(e); } }); } else { TaskInfo info = runningTask.taskInfo(clusterService.localNode().getId(), true); listener.onResponse(new GetTaskResponse(new TaskResult(false, info))); } } }
/** * Executed on the node that should be running the task to find and return the running task. Falls back to * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} if the task isn't still running. */ void getRunningTaskFromNode(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) { Task runningTask = taskManager.getTask(request.getTaskId().getId()); if (runningTask == null) { // Task isn't running, go look in the task index getFinishedTaskFromIndex(thisTask, request, listener); } else { if (request.getWaitForCompletion()) { // Shift to the generic thread pool and let it wait for the task to complete so we don't block any important threads. threadPool.generic().execute(new AbstractRunnable() { @Override protected void doRun() throws Exception { taskManager.waitForTaskCompletion(runningTask, waitForCompletionTimeout(request.getTimeout())); waitedForCompletion(thisTask, request, runningTask.taskInfo(clusterService.localNode().getId(), true), listener); } @Override public void onFailure(Exception e) { listener.onFailure(e); } }); } else { TaskInfo info = runningTask.taskInfo(clusterService.localNode().getId(), true); listener.onResponse(new GetTaskResponse(new TaskResult(false, info))); } } }
BytesReference error = (BytesReference) a[i++]; BytesReference response = (BytesReference) a[i++]; return new TaskResult(completed, task, error, response); }); static {