@Override public void onResponse(Task task, Response response) { logger.info("{} finished with response {}", task.getId(), response); }
public boolean match(Task task) { if (getActions() != null && getActions().length > 0 && Regex.simpleMatch(getActions(), task.getAction()) == false) { return false; } if (getTaskId().isSet()) { if(getTaskId().getId() != task.getId()) { return false; } } if (parentTaskId.isSet()) { if (parentTaskId.equals(task.getParentTaskId()) == false) { return false; } } return true; } }
/** * Build a version of the task status you can throw over the wire and back * to the user. * * @param localNodeId * the id of the node this task is running on * @param detailed * should the information include detailed, potentially slow to * generate data? */ public final TaskInfo taskInfo(String localNodeId, boolean detailed) { String description = null; Task.Status status = null; if (detailed) { description = getDescription(); status = getStatus(); } return taskInfo(localNodeId, description, status); }
/** * 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); }
private void registerCancellableTask(Task task) { CancellableTask cancellableTask = (CancellableTask) task; CancellableTaskHolder holder = new CancellableTaskHolder(cancellableTask); CancellableTaskHolder oldHolder = cancellableTasks.put(task.getId(), holder); assert oldHolder == null; // Check if this task was banned before we start it if (task.getParentTaskId().isSet() && banedParents.isEmpty() == false) { String reason = banedParents.get(task.getParentTaskId()); if (reason != null) { try { holder.cancel(reason); throw new IllegalStateException("Task cancelled before it started: " + reason); } finally { // let's clean up the registration unregister(task); } } } }
return null; assert task.getParentTaskId().equals(request.getParentTask()) : "Request [ " + request + "] didn't preserve it parentTaskId"; if (logger.isTraceEnabled()) { logger.trace("register {} [{}] [{}] [{}]", task.getId(), type, action, task.getDescription()); registerCancellableTask(task); } else { Task previousTask = tasks.put(task.getId(), task); assert previousTask == null;
/** * Build a version of the task status you can throw over the wire and back * to the user. * * @param node * the node this task is running on * @param detailed * should the information include detailed, potentially slow to * generate data? */ public TaskInfo taskInfo(DiscoveryNode node, boolean detailed) { String description = null; Task.Status status = null; if (detailed) { description = getDescription(); status = getStatus(); } return new TaskInfo(node, getId(), getType(), getAction(), description, status, startTime, System.nanoTime() - startTimeNanos, parentTask); }
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"); } } }
@Override public void accept(Task t) { operation.accept(t); while (System.nanoTime() - timeoutTime < 0) { Task task = taskManager.getTask(t.getId()); if (task == null) { return; } if (task.getAction().startsWith(ListTasksAction.NAME)) { // It doesn't make sense to wait for List Tasks and it can cause an infinite loop of the task waiting // for itself of one of its child tasks return; } try { Thread.sleep(WAIT_FOR_COMPLETION_POLL.millis()); } catch (InterruptedException e) { throw new ElasticsearchException("Interrupted waiting for completion of [{}]", e, t); } } throw new ElasticsearchTimeoutException("Timed out waiting for completion of [{}]", t); } });
getThreadContext().putTransient(ConfigConstants.SG_ACTION_NAME, task.getAction()); && !task.getAction().equals("internal:transport/handshake") && (task.getAction().startsWith("internal:") || task.getAction().contains("["))) { auditLog.logMissingPrivileges(task.getAction(), request, task); log.error("Internal or shard requests ("+task.getAction()+") not allowed from a non-server node for transport type "+transportChannel.getChannelType()); transportChannel.sendResponse(new ElasticsearchSecurityException( "Internal or shard requests not allowed from a non-server node for transport type "+transportChannel.getChannelType())); Exception ex = new ElasticsearchSecurityException( "No SSL client certificates found for transport type "+transportChannel.getChannelType()+". Search Guard needs the Search Guard SSL plugin to be installed"); auditLog.logSSLException(request, ex, task.getAction(), task); log.error("No SSL client certificates found for transport type "+transportChannel.getChannelType()+". Search Guard needs the Search Guard SSL plugin to be installed"); transportChannel.sendResponse(ex); auditLog.logBadHeaders(request, task.getAction(), task); log.error(exception); transportChannel.sendResponse(exception); if((user = backendRegistry.authenticate(request, principal, task, task.getAction())) == null) { org.apache.logging.log4j.ThreadContext.remove("user"); if(task.getAction().equals(WhoAmIAction.NAME)) { super.messageReceivedDecorate(request, handler, transportChannel, task); return; if(task.getAction().equals("cluster:monitor/nodes/liveness") || task.getAction().equals("internal:transport/handshake")) {
/** * Returns the task object that should be used to keep track of the processing of the request. * * A request can override this method and return null to avoid being tracked by the task * manager. */ default Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { return new Task(id, type, action, getDescription(), parentTaskId, headers); }
taskResult = task.result(localNode, response); } catch (IOException ex) { logger.warn(() -> new ParameterizedMessage("couldn't store response {}", response), ex);
/** * Registers a task without parent task * <p> * Returns the task manager tracked task or null if the task doesn't support the task manager */ public Task register(String type, String action, TaskAwareRequest request) { Task task = request.createTask(taskIdGenerator.incrementAndGet(), type, action, request.getParentTask()); if (task == null) { return null; } assert task.getParentTaskId().equals(request.getParentTask()) : "Request [ " + request + "] didn't preserve it parentTaskId"; if (logger.isTraceEnabled()) { logger.trace("register {} [{}] [{}] [{}]", task.getId(), type, action, task.getDescription()); } if (task instanceof CancellableTask) { registerCancellableTask(task); } else { Task previousTask = tasks.put(task.getId(), task); assert previousTask == null; } return task; }
/** * 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); }
private void registerCancellableTask(Task task) { CancellableTask cancellableTask = (CancellableTask) task; CancellableTaskHolder holder = new CancellableTaskHolder(cancellableTask); CancellableTaskHolder oldHolder = cancellableTasks.put(task.getId(), holder); assert oldHolder == null; // Check if this task was banned before we start it if (task.getParentTaskId().isSet() && banedParents.isEmpty() == false) { String reason = banedParents.get(task.getParentTaskId()); if (reason != null) { try { holder.cancel(reason); throw new IllegalStateException("Task cancelled before it started: " + reason); } finally { // let's clean up the registration unregister(task); } } } }
public TaskResult result(DiscoveryNode node, Exception error) throws IOException { return new TaskResult(taskInfo(node.getId(), true), error); }
@Override protected void processTasks(ListTasksRequest request, Consumer<Task> operation) { if (request.getWaitForCompletion()) { long timeoutNanos = waitForCompletionTimeout(request.getTimeout()); operation = operation.andThen(task -> { if (task.getAction().startsWith(ListTasksAction.NAME)) { // It doesn't make sense to wait for List Tasks and it can cause an infinite loop of the task waiting // for itself or one of its child tasks return; } taskManager.waitForTaskCompletion(task, timeoutNanos); }); } super.processTasks(request, operation); }
/** * Returns the task object that should be used to keep track of the processing of the request. * * A request can override this method and return null to avoid being tracked by the task * manager. */ default Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { return new Task(id, type, action, getDescription(), parentTaskId, headers); }
/** * Stores the task failure */ public <Response extends ActionResponse> void storeResult(Task task, Exception error, ActionListener<Response> listener) { DiscoveryNode localNode = lastDiscoveryNodes.getLocalNode(); if (localNode == null) { // too early to store anything, shouldn't really be here - just pass the error along listener.onFailure(error); return; } final TaskResult taskResult; try { taskResult = task.result(localNode, error); } catch (IOException ex) { logger.warn(() -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), ex); listener.onFailure(ex); return; } taskResultsService.storeResult(taskResult, new ActionListener<Void>() { @Override public void onResponse(Void aVoid) { listener.onFailure(error); } @Override public void onFailure(Exception e) { logger.warn(() -> new ParameterizedMessage("couldn't store error {}", ExceptionsHelper.detailedMessage(error)), e); listener.onFailure(e); } }); }
@Override public void onFailure(Task task, Throwable e) { logger.warn(() -> new ParameterizedMessage("{} failed with exception", task.getId()), e); } }