Skip to main content

TreeWorker

Struct TreeWorker 

Source
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

Source

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.
Source

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.

Source

pub fn set_topology( &mut self, root: &str, topology: &TopologyTree, ) -> Result<(), WorkerError>

Create a router from a topology tree.

§Arguments
  • root - The root node name (typically the local hostname).
  • topology - The cluster topology tree.
§Errors

Returns WorkerError if the root node is not found in the topology.

Source

pub fn nodes(&self) -> &NodeSet

Get the target nodes.

Source

pub fn command(&self) -> Option<&str>

Get the command being executed.

Source

pub fn state(&self) -> WorkerState

Get the current state.

Source

pub fn retcodes(&self) -> &HashMap<String, i32>

Get collected return codes.

Source

pub fn events(&self) -> &[TreeWorkerEvent]

Get collected events from remote nodes.

Source

pub fn drain_events(&mut self) -> Vec<TreeWorkerEvent>

Drain collected events.

Source

pub fn num_timeout(&self) -> usize

Get the number of timed out nodes.

Source

pub fn timeout_nodes(&self) -> &HashSet<String>

Get timed out nodes.

Source

pub fn has_timeout(&self) -> bool

Whether any node has timed out.

Source

pub fn is_done(&self) -> bool

Check if the worker is done (all targets completed or timed out).

Source

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.

Source

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.
Source

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.

Source

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.

Source

pub fn record_direct_timeout(&mut self, node: &str)

Record a direct node timeout.

Source

pub fn write_remote(&mut self, buf: &[u8])

Write data to all active gateway channels.

Source

pub fn set_write_eof_remote(&mut self)

Send write EOF to all active gateway channels.

Source

pub fn abort(&mut self)

Abort the tree worker.

Marks all remaining gateway targets as failed with EX_PROTOCOL (76).

Source

pub fn active_gateway_count(&self) -> usize

Get the number of active gateways.

Source

pub fn active_gateways(&self) -> Vec<&str>

Get active gateway names.

Source

pub fn num_nodes(&self) -> usize

Get the total number of target nodes.

Source

pub fn worker_id(&self) -> u64

Get the worker ID.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.