Package titan.tasks
Class ScriptExecutorHandler
java.lang.Object
titan.tasks.ScriptExecutorHandler
- All Implemented Interfaces:
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RpcWorkerServerA reference to the parentRpcWorkerServerinstance.private final FileThe rootFileobject representing the base directory for all script executions.private final FileTheFileobject representing the shared workspace directory.private static final StringThe base directory name for all Titan worker workspaces. -
Constructor Summary
ConstructorsConstructorDescriptionScriptExecutorHandler(RpcWorkerServer parentServer) Constructs a newScriptExecutorHandler. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface titan.tasks.TaskHandler
setLogListener
-
Field Details
-
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
A reference to the parentRpcWorkerServerinstance. Used for interacting with the master, specifically for streaming logs. -
rootWorkspace
The rootFileobject representing the base directory for all script executions. This is typicallytitan_workspace.
-
-
Constructor Details
-
ScriptExecutorHandler
Constructs a newScriptExecutorHandler. Initializes the root and shared workspace directories, creating them if they do not exist.- Parameters:
parentServer- TheRpcWorkerServerinstance that this handler is associated with.
-
-
Method Details
-
execute
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 aLogBatcher. The method waits for the script to complete or times out after 60 seconds.Payload Format (New):
JOB_ID | FILENAME | ARGSPayload Format (Legacy):
FILENAME | ... | JOB_ID(where ARGS are not explicitly passed)- Specified by:
executein interfaceTaskHandler- Parameters:
payload- The string payload containing script execution details.- Returns:
- A string indicating the execution status and result. Format:
COMPLETED|ExitCode|OutputContentorERROR: [message]if an error occurs or the script times out.
-