pub struct TreeWorker { /* private fields */ }Expand description
Worker that distributes command execution across a cluster topology.
TreeWorker uses PropagationTreeRouter to determine routing through
gateway nodes, and PropagationChannel to communicate with gateways.
Nodes directly reachable (same hop as root) are executed via direct
workers (SSH or local).
Mirrors ClusterShell’s TreeWorker class.
Implementations§
Source§impl TreeWorker
impl TreeWorker
Sourcepub fn new(nodes: NodeSet, command: String, config: TreeWorkerConfig) -> Self
pub fn new(nodes: NodeSet, command: String, config: TreeWorkerConfig) -> Self
Create a new TreeWorker for command execution.
§Arguments
nodes- Target nodes to execute on.command- Command to execute on each node.config- Tree worker configuration.
Sourcepub fn set_router(&mut self, router: PropagationTreeRouter)
pub fn set_router(&mut self, router: PropagationTreeRouter)
Set the topology router for this worker.
Must be called before start(). The router determines how commands
are distributed across gateway nodes.
Sourcepub fn set_topology(
&mut self,
root: &str,
topology: &TopologyTree,
) -> Result<(), WorkerError>
pub fn set_topology( &mut self, root: &str, topology: &TopologyTree, ) -> Result<(), WorkerError>
Sourcepub fn state(&self) -> WorkerState
pub fn state(&self) -> WorkerState
Get the current state.
Sourcepub fn events(&self) -> &[TreeWorkerEvent]
pub fn events(&self) -> &[TreeWorkerEvent]
Get collected events from remote nodes.
Sourcepub fn drain_events(&mut self) -> Vec<TreeWorkerEvent>
pub fn drain_events(&mut self) -> Vec<TreeWorkerEvent>
Drain collected events.
Sourcepub fn num_timeout(&self) -> usize
pub fn num_timeout(&self) -> usize
Get the number of timed out nodes.
Sourcepub fn timeout_nodes(&self) -> &HashSet<String>
pub fn timeout_nodes(&self) -> &HashSet<String>
Get timed out nodes.
Sourcepub fn has_timeout(&self) -> bool
pub fn has_timeout(&self) -> bool
Whether any node has timed out.
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Check if the worker is done (all targets completed or timed out).
Sourcepub fn start(&mut self) -> Result<Vec<(NodeSet, NodeSet)>, WorkerError>
pub fn start(&mut self) -> Result<Vec<(NodeSet, NodeSet)>, WorkerError>
Start the tree worker — distribute work across gateways.
This sets up propagation channels for gateway nodes and prepares direct execution for leaf nodes.
Sourcepub fn start_gateway(
&mut self,
gateway: &str,
topology_bytes: &[u8],
) -> Result<(), WorkerError>
pub fn start_gateway( &mut self, gateway: &str, topology_bytes: &[u8], ) -> Result<(), WorkerError>
Start a gateway’s propagation channel with topology data.
§Arguments
gateway- The gateway node name.topology_bytes- Serialized topology data to send to gateway.
Sourcepub fn process_result(
&mut self,
gateway: &str,
result: PropagationResult,
) -> Result<bool, WorkerError>
pub fn process_result( &mut self, gateway: &str, result: PropagationResult, ) -> Result<bool, WorkerError>
Process a propagation result from a gateway.
Call this when the gateway channel receives results. Returns true if the worker is now complete.
Sourcepub fn record_direct_close(&mut self, node: &str, rc: i32)
pub fn record_direct_close(&mut self, node: &str, rc: i32)
Record completion of a direct (non-gateway) node.
Called when a direct SSH/local worker reports node completion.
Sourcepub fn record_direct_timeout(&mut self, node: &str)
pub fn record_direct_timeout(&mut self, node: &str)
Record a direct node timeout.
Sourcepub fn write_remote(&mut self, buf: &[u8])
pub fn write_remote(&mut self, buf: &[u8])
Write data to all active gateway channels.
Sourcepub fn set_write_eof_remote(&mut self)
pub fn set_write_eof_remote(&mut self)
Send write EOF to all active gateway channels.
Sourcepub fn abort(&mut self)
pub fn abort(&mut self)
Abort the tree worker.
Marks all remaining gateway targets as failed with EX_PROTOCOL (76).
Sourcepub fn active_gateway_count(&self) -> usize
pub fn active_gateway_count(&self) -> usize
Get the number of active gateways.
Sourcepub fn active_gateways(&self) -> Vec<&str>
pub fn active_gateways(&self) -> Vec<&str>
Get active gateway names.