java.lang.Object
com.scivicslab.turingworkflow.plugins.inventory.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"));
 
Since:
1.0
Author:
devteam@scivicslab.com
  • Constructor Details

    • NodeGroup

      public NodeGroup()
      Constructs an empty NodeGroup.

      Note: Consider using NodeGroup.Builder for a more fluent API.

  • 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

      public List<String> getParseWarnings()
      Gets the warnings generated during inventory parsing.

      These warnings should be logged by the caller using the appropriate logging mechanism.

      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.

      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
    • createLocalNode

      public List<Node> createLocalNode()
      Creates a single Node for localhost execution.

      This method creates a Node configured for local execution without requiring an inventory file.

      Returns:
      a list containing a single localhost Node
    • getInventory

      public InventoryParser.Inventory 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.
      Parameters:
      password - the SSH password to use for all nodes
    • getSshPassword

      public String 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.
      Parameters:
      limitString - comma-separated list of hosts
    • getHostLimit

      public List<String> getHostLimit()
      Gets the host limit.
      Returns:
      the list of limited hosts, or null if no limit is set
    • toString

      public String toString()
      Returns a string representation of this NodeGroup, including the loaded group names.
      Overrides:
      toString in class Object
      Returns:
      a string in the format NodeGroup{groups=[group1, group2, ...]}