ClusterHelper.NodeConfig (ClusterHelper v1.0.1)

Copy Markdown View Source

GenServer that orchestrates cluster role management.

This is the application / orchestration layer in Clean Architecture terms. It coordinates:

What changed (v0.7 → v0.8)

Previously, NodeConfig was a ~1000-line God module mixing ETS, :pg, RPC, config, and business logic. It has been decomposed into focused modules — each with a single responsibility — while keeping the same GenServer client API for full backward compatibility.

Summary

Functions

Adds a single role to the local node and propagates cluster-wide.

Adds multiple roles to the local node and propagates cluster-wide.

Returns all nodes with at least one role. Reads directly from ETS.

Returns a specification to start this module under a supervisor.

Returns all roles for the local node. Reads directly from ETS.

Returns nodes with the given role. Reads directly from ETS.

Returns roles for a node. Reads directly from ETS.

Joins an additional scope.

Leaves a scope, removing all roles and cleaning up.

Lists all scopes the local node is participating in.

Returns true when the node is the local node.

Removes a single role from the local node and propagates cluster-wide.

Removes multiple roles from the local node and propagates cluster-wide.

Functions

add_role(role, scope \\ nil)

@spec add_role(term(), atom() | nil) :: :ok

Adds a single role to the local node and propagates cluster-wide.

add_roles(roles, scope \\ nil)

@spec add_roles([term()], atom() | nil) :: :ok

Adds multiple roles to the local node and propagates cluster-wide.

all_nodes(scope \\ nil)

@spec all_nodes(atom() | nil) :: [node()]

Returns all nodes with at least one role. Reads directly from ETS.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_my_roles(scope \\ nil)

@spec get_my_roles(atom() | nil) :: [term()]

Returns all roles for the local node. Reads directly from ETS.

get_nodes(role, scope \\ nil)

@spec get_nodes(term(), atom() | nil) :: [node()]

Returns nodes with the given role. Reads directly from ETS.

get_roles(node, scope \\ nil)

@spec get_roles(node(), atom() | nil) :: [term()]

Returns roles for a node. Reads directly from ETS.

join_scope(scope)

@spec join_scope(atom()) :: :ok | {:error, :already_joined}

Joins an additional scope.

leave_scope(scope)

@spec leave_scope(atom()) :: :ok | {:error, :not_joined}

Leaves a scope, removing all roles and cleaning up.

list_scopes()

@spec list_scopes() :: [atom()]

Lists all scopes the local node is participating in.

local_node?(node)

@spec local_node?(node()) :: boolean()

Returns true when the node is the local node.

remove_role(role, scope \\ nil)

@spec remove_role(term(), atom() | nil) :: :ok

Removes a single role from the local node and propagates cluster-wide.

remove_roles(roles, scope \\ nil)

@spec remove_roles([term()], atom() | nil) :: :ok

Removes multiple roles from the local node and propagates cluster-wide.

start_link(_)

@spec start_link(any()) :: GenServer.on_start()