mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
cluster: Move Broker connect logic into policy package
Place a package into policy/frameworks/cluster/backend/broker and move Broker's connection specific logic there.
This commit is contained in:
parent
2f15f5ce6a
commit
351bd7b81b
5 changed files with 165 additions and 130 deletions
|
@ -3,63 +3,10 @@
|
|||
|
||||
@load ./main
|
||||
@load ./pools
|
||||
@load base/frameworks/broker
|
||||
|
||||
module Cluster;
|
||||
|
||||
export {
|
||||
## This hook is called when the local node connects to other nodes based on
|
||||
## the given cluster layout. Breaking from the hook will prevent connection
|
||||
## establishment.
|
||||
##
|
||||
## connectee: The node to connect to.
|
||||
global connect_node_hook: hook(connectee: NamedNode);
|
||||
}
|
||||
|
||||
function connect_peer(node_type: NodeType, node_name: string)
|
||||
{
|
||||
local nn = nodes_with_type(node_type);
|
||||
|
||||
for ( i in nn )
|
||||
{
|
||||
local n = nn[i];
|
||||
|
||||
if ( n$name != node_name )
|
||||
next;
|
||||
if ( ! hook connect_node_hook(n) )
|
||||
return;
|
||||
|
||||
local status = Broker::peer(cat(n$node$ip), n$node$p,
|
||||
Cluster::retry_interval);
|
||||
Cluster::log(fmt("initiate peering with %s:%s, retry=%s, status=%s",
|
||||
n$node$ip, n$node$p, Cluster::retry_interval,
|
||||
status));
|
||||
return;
|
||||
}
|
||||
|
||||
Reporter::warning(fmt("connect_peer: node '%s' (%s) not found", node_name, node_type));
|
||||
}
|
||||
|
||||
function connect_peers_with_type(node_type: NodeType)
|
||||
{
|
||||
local nn = nodes_with_type(node_type);
|
||||
|
||||
for ( i in nn )
|
||||
{
|
||||
local n = nn[i];
|
||||
|
||||
if ( ! hook connect_node_hook(n) )
|
||||
next;
|
||||
|
||||
local status = Broker::peer(cat(n$node$ip), n$node$p,
|
||||
Cluster::retry_interval);
|
||||
Cluster::log(fmt("initiate peering with %s:%s, retry=%s, status=%s",
|
||||
n$node$ip, n$node$p, Cluster::retry_interval,
|
||||
status));
|
||||
}
|
||||
}
|
||||
|
||||
event zeek_init() &priority=-10
|
||||
event zeek_init() &priority=-5
|
||||
{
|
||||
if ( getenv("ZEEKCTL_CHECK_CONFIG") != "" )
|
||||
return;
|
||||
|
@ -98,59 +45,4 @@ event zeek_init() &priority=-10
|
|||
|
||||
Cluster::subscribe(nodeid_topic(Cluster::node_id()));
|
||||
Cluster::subscribe(node_topic(node));
|
||||
|
||||
|
||||
# Listening and connecting to other peers is broker specific,
|
||||
# short circuit if Zeek is configured with a different
|
||||
# cluster backend.
|
||||
#
|
||||
# In the future, this could move into a policy script, but
|
||||
# for the time being it's easier for backwards compatibility
|
||||
# to keep this here.
|
||||
if ( Cluster::backend != Cluster::CLUSTER_BACKEND_BROKER )
|
||||
return;
|
||||
|
||||
# Logging setup: Anything handling logging additionally subscribes
|
||||
# to Broker::default_log_topic_prefix.
|
||||
switch ( self$node_type ) {
|
||||
case LOGGER:
|
||||
Cluster::subscribe(Broker::default_log_topic_prefix);
|
||||
break;
|
||||
case MANAGER:
|
||||
if ( Cluster::manager_is_logger )
|
||||
Cluster::subscribe(Broker::default_log_topic_prefix);
|
||||
break;
|
||||
}
|
||||
|
||||
if ( self$p != 0/unknown )
|
||||
{
|
||||
Broker::listen(Broker::default_listen_address,
|
||||
self$p,
|
||||
Broker::default_listen_retry);
|
||||
|
||||
Cluster::log(fmt("listening on %s:%s", Broker::default_listen_address, self$p));
|
||||
}
|
||||
|
||||
|
||||
switch ( self$node_type ) {
|
||||
case MANAGER:
|
||||
connect_peers_with_type(LOGGER);
|
||||
|
||||
break;
|
||||
case PROXY:
|
||||
connect_peers_with_type(LOGGER);
|
||||
|
||||
if ( self?$manager )
|
||||
connect_peer(MANAGER, self$manager);
|
||||
|
||||
break;
|
||||
case WORKER:
|
||||
connect_peers_with_type(LOGGER);
|
||||
connect_peers_with_type(PROXY);
|
||||
|
||||
if ( self?$manager )
|
||||
connect_peer(MANAGER, self$manager);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue