Class NodeGroup

java.lang.Object
com.scivicslab.actoriac.NodeGroup

public class NodeGroup extends Object
Manages a group of nodes based on an Ansible inventory file.

This is a pure POJO class that reads Ansible inventory files and creates Node objects for a specific group. It does not depend on ActorSystem - the responsibility of converting Node objects to actors belongs to the caller.

SSH authentication is handled by ssh-agent. Make sure ssh-agent is running and your SSH key is added before creating nodes.

Usage Examples

NodeGroup nodeGroup = new NodeGroup.Builder()
    .withInventory(new FileInputStream("inventory.ini"))
    .build();

Legacy Constructor Pattern

NodeGroup nodeGroup = new NodeGroup();
nodeGroup.loadInventory(new FileInputStream("inventory.ini"));
Author:
devteam@scivics-lab.com
  • Field Details

  • Constructor Details

  • Method Details

    • loadInventory

      public void loadInventory(InputStream inventoryStream) throws IOException
      Loads an inventory file from an input stream.
      Parameters:
      inventoryStream - the input stream containing the inventory file
      Throws:
      IOException - if reading the inventory fails
    • createNodesForGroup

      public List<Node> createNodesForGroup(String groupName)
      Creates Node objects for all hosts in the specified group.

      This method reads the group from the inventory, applies global and group-specific variables, and creates a Node POJO for each host.

      If Vault integration is configured, this method will fetch SSH keys and sudo passwords from Vault based on the vault-config.ini settings.

      Note: This method returns plain Node objects, not actors. The caller is responsible for converting them to actors using ActorSystem.actorOf() if needed.

      Parameters:
      groupName - the name of the group from the inventory file
      Returns:
      the list of created Node objects
      Throws:
      IllegalStateException - if inventory has not been loaded
      RuntimeException - if Vault secret retrieval fails
    • createLocalNode

      Creates a single Node for localhost execution.

      This method creates a Node configured for local execution without requiring an inventory file. Useful for development, testing, or single-host scenarios.

      The node is created with:

      • hostname: "localhost"
      • user: current system user
      • localMode: true (uses ProcessBuilder instead of SSH)
      Returns:
      a list containing a single localhost Node
    • getInventory

      Gets the inventory object.
      Returns:
      the loaded inventory, or null if not loaded
    • setSshPassword

      public void setSshPassword(String password)
      Sets the SSH password for all nodes in this group.

      When set, nodes will use password authentication instead of ssh-agent key authentication.

      Parameters:
      password - the SSH password to use for all nodes
    • getSshPassword

      Gets the SSH password.
      Returns:
      the SSH password, or null if not set
    • setHostLimit

      public void setHostLimit(String limitString)
      Sets the host limit to restrict execution to specific hosts.

      When set, only hosts in this list will be included when creating nodes. This is similar to Ansible's --limit option.

      Parameters:
      limitString - comma-separated list of hosts (e.g., "192.168.5.15,192.168.5.16")
    • getHostLimit

      Gets the host limit.
      Returns:
      the list of limited hosts, or null if no limit is set
    • toString

      public String toString()
      Overrides:
      toString in class Object