Class LocalCommandExecutor
java.lang.Object
com.scivicslab.turingworkflow.plugins.ssh.mixin.LocalCommandExecutor
- All Implemented Interfaces:
CommandExecutor
Command executor that executes commands on the local machine.
Used by NodeGroupInterpreter to execute commands locally when running on the control node itself.
- Since:
- 2.15.0
- Author:
- devteam@scivicslab.com
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a local command executor that runs commands on the local machine. -
Method Summary
Modifier and TypeMethodDescriptionExecutes a command and returns the result.execute(String command, Node.OutputCallback callback) Executes a command and returns the result with output callback.executeSudo(String command) Executes a command with sudo privileges.executeSudo(String command, Node.OutputCallback callback) Executes a command with sudo privileges and output callback.Gets a short identifier for this executor (e.g., hostname).
-
Constructor Details
-
LocalCommandExecutor
public LocalCommandExecutor()Constructs a local command executor that runs commands on the local machine.Automatically detects the local hostname for use as the executor identifier. Falls back to "localhost" if hostname detection fails.
-
-
Method Details
-
execute
Executes a command and returns the result.- Specified by:
executein interfaceCommandExecutor- Parameters:
command- the command to execute- Returns:
- the result of command execution
- Throws:
IOException- if command execution fails
-
execute
Executes a command and returns the result with output callback.Executes the command via
/bin/sh -cwith a timeout of 300L seconds. Stdout and stderr are read in separate virtual threads (Java 21) to prevent deadlocks.- Specified by:
executein interfaceCommandExecutor- Parameters:
command- the command to executecallback- the callback for real-time output (may be null)- Returns:
- the result of command execution
- Throws:
IOException- if command execution fails
-
executeSudo
Executes a command with sudo privileges.- Specified by:
executeSudoin interfaceCommandExecutor- Parameters:
command- the command to execute with sudo- Returns:
- the result of command execution
- Throws:
IOException- if command execution fails or SUDO_PASSWORD is not set
-
executeSudo
public Node.CommandResult executeSudo(String command, Node.OutputCallback callback) throws IOException Executes a command with sudo privileges and output callback.Executes via
sudo -S bash -c, writing the password from theSUDO_PASSWORDenvironment variable to stdin.- Specified by:
executeSudoin interfaceCommandExecutor- Parameters:
command- the command to execute with sudocallback- the callback for real-time output (may be null)- Returns:
- the result of command execution
- Throws:
IOException- if command execution fails or SUDO_PASSWORD is not set
-
getIdentifier
Gets a short identifier for this executor (e.g., hostname).- Specified by:
getIdentifierin interfaceCommandExecutor- Returns:
- the identifier string
-