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@scivicslab.com
  • Field Details

  • Constructor Details

  • Method Details

    • loadInventory

      public void loadInventory(InputStream inventoryStream) throws IOException
      Loads an inventory file from an input stream.

      Any warnings generated during parsing are stored and can be retrieved via getParseWarnings().

      Parameters:
      inventoryStream - the input stream containing the inventory file
      Throws:
      IOException - if reading the inventory fails
    • getParseWarnings

      Gets the warnings generated during inventory parsing.

      These warnings should be logged by the caller using the appropriate logging mechanism (e.g., DistributedLogStore for database logging, or java.util.logging for console/file logging).

      Returns:
      list of warning messages (may be empty)
    • hasParseWarnings

      public boolean hasParseWarnings()
      Checks if there are any parse warnings.
      Returns:
      true if there are warnings
    • 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
    • getVar

      private String getVar(Map<String,String> vars, String suffix, String defaultValue)
      Gets a variable value with support for both actoriac_* and ansible_* prefixes.

      This method checks for the variable in the following order:

      1. actoriac_{suffix} - actor-IaC native naming
      2. ansible_{suffix} - Ansible-compatible naming
      3. defaultValue - if neither is found
      Parameters:
      vars - the variable map to search
      suffix - the variable suffix (e.g., "host", "user", "port", "connection")
      defaultValue - the default value if neither prefix is found
      Returns:
      the variable value, or defaultValue if not found
    • toString

      public String toString()
      Overrides:
      toString in class Object