Class Node
java.lang.Object
com.scivicslab.turingworkflow.plugins.ssh.Node
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents the result of a command execution, containing stdout, stderr, and exit code.static interfaceCallback interface for real-time output streaming during command execution. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a Node with default port 22.Constructs a Node with the specified connection parameters.Constructs a Node with the specified connection parameters and local mode.Constructs a Node with all connection parameters including password. -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Cleans up resources used by this Node.executeCommand(String command) Executes a command on the node.executeCommand(String command, Node.OutputCallback callback) Executes a command on the node with real-time output callback.executeSudoCommand(String command) Executes a command with sudo privileges on the remote node.executeSudoCommand(String command, Node.OutputCallback callback) Executes a command with sudo privileges on the remote node with real-time output callback.Gets the hostname or IP address of this node.intgetPort()Gets the SSH port number.getUser()Gets the SSH username.booleanChecks if this node is in local execution mode.toString()Returns a string representation of this node including hostname, user, and port.
-
Constructor Details
-
Node
Constructs a Node with the specified connection parameters.- Parameters:
hostname- the hostname or IP address of the nodeuser- the SSH usernameport- the SSH port (typically 22)
-
Node
Constructs a Node with the specified connection parameters and local mode.- Parameters:
hostname- the hostname or IP address of the nodeuser- the SSH usernameport- the SSH port (typically 22)localMode- if true, execute commands locally instead of via SSH
-
Node
Constructs a Node with all connection parameters including password.- Parameters:
hostname- the hostname or IP address of the nodeuser- the SSH usernameport- the SSH port (typically 22)localMode- if true, execute commands locally instead of via SSHpassword- the SSH password (null to use ssh-agent key authentication)
-
Node
Constructs a Node with default port 22.- Parameters:
hostname- the hostname or IP address of the nodeuser- 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
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 executecallback- 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
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 sudocallback- 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
Gets the hostname or IP address of this node.- Returns:
- the hostname
-
getUser
Gets the SSH username.- Returns:
- the username
-
getPort
public int getPort()Gets the SSH port number.- Returns:
- the port number
-
toString
Returns a string representation of this node including hostname, user, and port.
-