mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Provide a script-layer equivalent to Supervisor::__init_cluster().
If the script layer is able to access the current node's config via Supervisor::node(), it can handle populating Cluster::nodes. That code is much more straightforward than an equivalent in-core implementation (especially with the upcoming change to the cluster table's implementation). This introduces base/frameworks/cluster/supervisor.zeek and Cluster::Supervisor::__init_cluster_nodes() for that purpose. The @load of the Supervisor API in cluster/main.zeek isn't technically necessary since we already load it explicitly even in init-bare.zeek, but being explicit seems better.
This commit is contained in:
parent
3d6954dfd4
commit
a98ec6b08b
1 changed files with 57 additions and 0 deletions
57
scripts/base/frameworks/cluster/supervisor.zeek
Normal file
57
scripts/base/frameworks/cluster/supervisor.zeek
Normal file
|
@ -0,0 +1,57 @@
|
|||
##! Cluster-related functionality specific to running under the Supervisor
|
||||
##! framework.
|
||||
|
||||
@load base/frameworks/supervisor/api
|
||||
|
||||
module Cluster::Supervisor;
|
||||
|
||||
export {
|
||||
## Populates the current node's :zeek:id:`Cluster::nodes` table from the
|
||||
## supervisor's node configuration in :zeek:id:`Supervisor::NodeConfig`.
|
||||
##
|
||||
## Returns: true if initialization completed, false otherwise.
|
||||
global __init_cluster_nodes: function(): bool;
|
||||
}
|
||||
|
||||
function __init_cluster_nodes(): bool
|
||||
{
|
||||
local config = Supervisor::node();
|
||||
|
||||
if ( |config$cluster| == 0 )
|
||||
return F;
|
||||
|
||||
local rolemap: table[Supervisor::ClusterRole] of Cluster::NodeType = {
|
||||
[Supervisor::LOGGER] = Cluster::LOGGER,
|
||||
[Supervisor::MANAGER] = Cluster::MANAGER,
|
||||
[Supervisor::PROXY] = Cluster::PROXY,
|
||||
[Supervisor::WORKER] = Cluster::WORKER,
|
||||
};
|
||||
|
||||
local manager_name = "";
|
||||
local cnode: Cluster::Node;
|
||||
local typ: Cluster::NodeType = Cluster::NONE;
|
||||
|
||||
for ( node_name, endp in config$cluster )
|
||||
{
|
||||
if ( endp$role == Supervisor::MANAGER )
|
||||
manager_name = node_name;
|
||||
}
|
||||
|
||||
for ( node_name, endp in config$cluster )
|
||||
{
|
||||
if ( endp$role in rolemap )
|
||||
typ = rolemap[endp$role];
|
||||
|
||||
cnode = [$node_type=typ, $ip=endp$host, $p=endp$p];
|
||||
@pragma push ignore-deprecations
|
||||
if ( endp?$interface )
|
||||
cnode$interface = endp$interface;
|
||||
@pragma pop ignore-deprecations
|
||||
if ( |manager_name| > 0 && cnode$node_type != Cluster::MANAGER )
|
||||
cnode$manager = manager_name;
|
||||
|
||||
Cluster::nodes[node_name] = cnode;
|
||||
}
|
||||
|
||||
return T;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue