Package titan.tasks

Class ScriptExecutorHandler

java.lang.Object
titan.tasks.ScriptExecutorHandler
All Implemented Interfaces:
TaskHandler

public class ScriptExecutorHandler extends Object implements TaskHandler
ScriptExecutorHandler is an implementation of TaskHandler responsible for executing scripts (Python, Shell, or standalone executables) on the worker node. It manages a dedicated workspace for script execution, handles payload parsing, process execution, real-time log streaming, and result reporting back to the master.

This handler supports different execution contexts:

  • Isolated: Each job gets its own subdirectory within the root workspace.
  • Shared: A common 'shared' directory for DAG-related tasks.
  • Archive Mode: Executes scripts directly within their unzipped absolute path.
It also provides robust parsing for job payloads, supporting both new (JOB_ID | FILENAME | ARGS) and legacy formats.
  • Field Details

    • WORKSPACE_DIR

      private static final String WORKSPACE_DIR
      The base directory name for all Titan worker workspaces. All job-specific and shared workspaces will be created under this directory.
      See Also:
    • parentServer

      private final RpcWorkerServer parentServer
      A reference to the parent RpcWorkerServer instance. Used for interacting with the master, specifically for streaming logs.
    • rootWorkspace

      private final File rootWorkspace
      The root File object representing the base directory for all script executions. This is typically titan_workspace.
    • sharedWorkspace

      private final File sharedWorkspace
      The File object representing the shared workspace directory. This directory is used for tasks that require shared resources, such as DAG executions. It is located at titan_workspace/shared.
  • Constructor Details

    • ScriptExecutorHandler

      public ScriptExecutorHandler(RpcWorkerServer parentServer)
      Constructs a new ScriptExecutorHandler. Initializes the root and shared workspace directories, creating them if they do not exist.
      Parameters:
      parentServer - The RpcWorkerServer instance that this handler is associated with.
  • Method Details

    • execute

      public String execute(String payload)
      Executes a script based on the provided payload. The payload is parsed to extract the job ID, script filename, and any arguments. The script is then executed in an appropriate workspace directory (isolated, shared, or archive mode). Standard output and error streams of the script are captured and streamed to the master via a LogBatcher. The method waits for the script to complete or times out after 60 seconds.

      Payload Format (New): JOB_ID | FILENAME | ARGS

      Payload Format (Legacy): FILENAME | ... | JOB_ID (where ARGS are not explicitly passed)

      Specified by:
      execute in interface TaskHandler
      Parameters:
      payload - The string payload containing script execution details.
      Returns:
      A string indicating the execution status and result. Format: COMPLETED|ExitCode|OutputContent or ERROR: [message] if an error occurs or the script times out.