Class LocalCommandExecutor

java.lang.Object
com.scivicslab.turingworkflow.plugins.ssh.mixin.LocalCommandExecutor
All Implemented Interfaces:
CommandExecutor

public class LocalCommandExecutor extends Object implements 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 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

      public Node.CommandResult execute(String command) throws IOException
      Executes a command and returns the result.
      Specified by:
      execute in interface CommandExecutor
      Parameters:
      command - the command to execute
      Returns:
      the result of command execution
      Throws:
      IOException - if command execution fails
    • execute

      public Node.CommandResult execute(String command, Node.OutputCallback callback) throws IOException
      Executes a command and returns the result with output callback.

      Executes the command via /bin/sh -c with a timeout of 300L seconds. Stdout and stderr are read in separate virtual threads (Java 21) to prevent deadlocks.

      Specified by:
      execute in interface CommandExecutor
      Parameters:
      command - the command to execute
      callback - the callback for real-time output (may be null)
      Returns:
      the result of command execution
      Throws:
      IOException - if command execution fails
    • executeSudo

      public Node.CommandResult executeSudo(String command) throws IOException
      Executes a command with sudo privileges.
      Specified by:
      executeSudo in interface CommandExecutor
      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 the SUDO_PASSWORD environment variable to stdin.

      Specified by:
      executeSudo in interface CommandExecutor
      Parameters:
      command - the command to execute with sudo
      callback - 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

      public String getIdentifier()
      Gets a short identifier for this executor (e.g., hostname).
      Specified by:
      getIdentifier in interface CommandExecutor
      Returns:
      the identifier string