Class Task

Direct Known Subclasses:
CancellableTask, PrimaryReplicaSyncer.ResyncTask, ReplicationTask

public class Task extends Object
Current task information
  • Field Details


      public static final String X_OPAQUE_ID_HTTP_HEADER
      The request header to mark tasks with specific ids
      See Also:

      public static final String TRACE_PARENT_HTTP_HEADER
      The request header which is contained in HTTP request. We parse from it and store it in thread context. TRACE_PARENT once parsed in RestController.tryAllHandler is not preserved has to be declared as a header copied over from http request.
      See Also:

      public static final String X_ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER
      A request header that indicates the origin of the request from Elastic stack. The value will stored in ThreadContext and emitted to ES logs
      See Also:
    • TRACE_ID

      public static final String TRACE_ID
      Parsed part of traceparent. It is stored in thread context and emitted in logs. Has to be declared as a header copied over for tasks.
      See Also:

      public static final Set<String> HEADERS_TO_COPY
  • Constructor Details

  • Method Details

    • taskInfo

      public final TaskInfo taskInfo(String localNodeId, boolean detailed)
      Build a version of the task status you can throw over the wire and back to the user.
      localNodeId - the id of the node this task is running on
      detailed - should the information include detailed, potentially slow to generate data?
    • taskInfo

      protected final TaskInfo taskInfo(String localNodeId, String description, Task.Status status)
      Build a proper TaskInfo for this task.
    • getId

      public long getId()
      Returns task id
    • getType

      public String getType()
      Returns task channel type (netty, transport, direct)
    • getAction

      public String getAction()
      Returns task action
    • getDescription

      public String getDescription()
      Generates task description
    • getStartTime

      public long getStartTime()
      Returns the task's start time as a wall clock time since epoch (System.currentTimeMillis() style).
    • getStartTimeNanos

      public long getStartTimeNanos()
      Returns the task's start time in nanoseconds (System.nanoTime() style).
    • getParentTaskId

      public TaskId getParentTaskId()
      Returns id of the parent task or NO_PARENT_ID if the task doesn't have any parent tasks
    • getStatus

      public Task.Status getStatus()
      Build a status for this task or null if this task doesn't have status. Since most tasks don't have status this defaults to returning null. While this can never perform IO it might be a costly operation, requiring collating lists of results, etc. So only use it if you need the value.
    • getHeader

      public String getHeader(String header)
      Returns stored task header associated with the task
    • headers

      public Map<String,String> headers()
    • result

      public TaskResult result(DiscoveryNode node, Exception error) throws IOException
    • result

      public TaskResult result(DiscoveryNode node, ActionResponse response) throws IOException