java.lang.Object
com.scivicslab.turingworkflow.plugins.ssh.Node

public class Node extends Object
Represents a single node in the infrastructure as a pure POJO.

This is a pure POJO class that provides SSH-based command execution capabilities. It has NO dependency on ActorSystem or workflow components.

Uses ssh-agent for SSH key authentication. Make sure ssh-agent is running and your SSH key is added before using this class.

Since:
2.0.0
Author:
devteam@scivicslab.com
  • Constructor Details

    • Node

      public Node(String hostname, String user, int port)
      Constructs a Node with the specified connection parameters.
      Parameters:
      hostname - the hostname or IP address of the node
      user - the SSH username
      port - the SSH port (typically 22)
    • Node

      public Node(String hostname, String user, int port, boolean localMode)
      Constructs a Node with the specified connection parameters and local mode.
      Parameters:
      hostname - the hostname or IP address of the node
      user - the SSH username
      port - the SSH port (typically 22)
      localMode - if true, execute commands locally instead of via SSH
    • Node

      public Node(String hostname, String user, int port, boolean localMode, String password)
      Constructs a Node with all connection parameters including password.
      Parameters:
      hostname - the hostname or IP address of the node
      user - the SSH username
      port - the SSH port (typically 22)
      localMode - if true, execute commands locally instead of via SSH
      password - the SSH password (null to use ssh-agent key authentication)
    • Node

      public Node(String hostname, String user)
      Constructs a Node with default port 22.
      Parameters:
      hostname - the hostname or IP address of the node
      user - the SSH username
  • Method Details

    • isLocalMode

      public boolean isLocalMode()
      Checks if this node is in local execution mode.
      Returns:
      true if commands are executed locally, false for SSH
    • executeCommand

      public Node.CommandResult executeCommand(String command) throws IOException
      Executes a command on the node.
      Parameters:
      command - the command to execute
      Returns:
      the execution result containing stdout, stderr, and exit code
      Throws:
      IOException - if command execution fails
    • executeCommand

      public Node.CommandResult executeCommand(String command, Node.OutputCallback callback) throws IOException
      Executes a command on the node with real-time output callback.
      Parameters:
      command - the command to execute
      callback - the callback for real-time output (may be null)
      Returns:
      the execution result containing stdout, stderr, and exit code
      Throws:
      IOException - if command execution fails
    • executeSudoCommand

      public Node.CommandResult executeSudoCommand(String command) throws IOException
      Executes a command with sudo privileges on the remote node.
      Parameters:
      command - the command to execute with sudo
      Returns:
      the execution result
      Throws:
      IOException - if SSH connection fails or SUDO_PASSWORD is not set
    • executeSudoCommand

      public Node.CommandResult executeSudoCommand(String command, Node.OutputCallback callback) throws IOException
      Executes a command with sudo privileges on the remote node with real-time output callback.
      Parameters:
      command - the command to execute with sudo
      callback - the callback for real-time output (may be null)
      Returns:
      the execution result
      Throws:
      IOException - if SSH connection fails or SUDO_PASSWORD is not set
    • cleanup

      public void cleanup()
      Cleans up resources used by this Node. Disconnects the cached SSH session and any jump host session.
    • getHostname

      public String getHostname()
      Gets the hostname or IP address of this node.
      Returns:
      the hostname
    • getUser

      public String getUser()
      Gets the SSH username.
      Returns:
      the username
    • getPort

      public int getPort()
      Gets the SSH port number.
      Returns:
      the port number
    • toString

      public String toString()
      Returns a string representation of this node including hostname, user, and port.
      Overrides:
      toString in class Object
      Returns:
      a formatted string describing this node