mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Move supervisor control events into SupervisorControl namespace
This commit is contained in:
parent
68b513a364
commit
bbdf5f8938
9 changed files with 166 additions and 140 deletions
|
@ -1,2 +1,3 @@
|
|||
@load ./api
|
||||
@load ./control
|
||||
@load ./main
|
||||
|
|
|
@ -114,76 +114,4 @@ export {
|
|||
## It's an error to call this function from a process other than
|
||||
## a supervised one.
|
||||
global node: function(): NodeConfig;
|
||||
|
||||
## Send a request to a remote Supervisor process to create a node.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the desired configuration for the new supervised node process.
|
||||
global Supervisor::create_request: event(reqid: string, node: NodeConfig);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`Supervisor::create_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::create`.
|
||||
global Supervisor::create_response: event(reqid: string, result: string);
|
||||
|
||||
## Send a request to a remote Supervisor process to retrieve node status.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the name of the node to get status of or empty string to mean "all
|
||||
## nodes".
|
||||
global Supervisor::status_request: event(reqid: string, node: string);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`Supervisor::status_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::status`.
|
||||
global Supervisor::status_response: event(reqid: string, result: Status);
|
||||
|
||||
## Send a request to a remote Supervisor process to restart a node.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the name of the node to restart or empty string to mean "all
|
||||
## nodes".
|
||||
global Supervisor::restart_request: event(reqid: string, node: string);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`Supervisor::restart_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::restart`.
|
||||
global Supervisor::restart_response: event(reqid: string, result: bool);
|
||||
|
||||
## Send a request to a remote Supervisor process to destroy a node.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the name of the node to destory or empty string to mean "all
|
||||
## nodes".
|
||||
global Supervisor::destroy_request: event(reqid: string, node: string);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`Supervisor::destroy_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::destroy`.
|
||||
global Supervisor::destroy_response: event(reqid: string, result: bool);
|
||||
|
||||
## Send a request to a remote Supervisor to stop and shutdown its
|
||||
## process tree. There is no response to this message as the Supervisor
|
||||
## simply terminates on receipt.
|
||||
global Supervisor::stop_request: event();
|
||||
}
|
||||
|
|
86
scripts/base/frameworks/supervisor/control.zeek
Normal file
86
scripts/base/frameworks/supervisor/control.zeek
Normal file
|
@ -0,0 +1,86 @@
|
|||
##! The Zeek process supervision (remote) control API. This defines a Broker topic
|
||||
##! prefix and events that can be used to control an external Zeek supervisor process.
|
||||
|
||||
@load ./api
|
||||
|
||||
module SupervisorControl;
|
||||
|
||||
export {
|
||||
## The Broker topic prefix to use when subscribing to Supervisor API
|
||||
## requests and when publishing Supervisor API responses. If you are
|
||||
## publishing Supervisor requests, this is also the prefix string to use
|
||||
## for their topic names.
|
||||
const topic_prefix = "zeek/supervisor" &redef;
|
||||
|
||||
## Send a request to a remote Supervisor process to create a node.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the desired configuration for the new supervised node process.
|
||||
global SupervisorControl::create_request: event(reqid: string, node: Supervisor::NodeConfig);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`SupervisorControl::create_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::create`.
|
||||
global SupervisorControl::create_response: event(reqid: string, result: string);
|
||||
|
||||
## Send a request to a remote Supervisor process to retrieve node status.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the name of the node to get status of or empty string to mean "all
|
||||
## nodes".
|
||||
global SupervisorControl::status_request: event(reqid: string, node: string);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`SupervisorControl::status_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::status`.
|
||||
global SupervisorControl::status_response: event(reqid: string, result: Supervisor::Status);
|
||||
|
||||
## Send a request to a remote Supervisor process to restart a node.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the name of the node to restart or empty string to mean "all
|
||||
## nodes".
|
||||
global SupervisorControl::restart_request: event(reqid: string, node: string);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`SupervisorControl::restart_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::restart`.
|
||||
global SupervisorControl::restart_response: event(reqid: string, result: bool);
|
||||
|
||||
## Send a request to a remote Supervisor process to destroy a node.
|
||||
##
|
||||
## reqid: an arbitrary string that will be directly echoed in the response
|
||||
##
|
||||
## node: the name of the node to destory or empty string to mean "all
|
||||
## nodes".
|
||||
global SupervisorControl::destroy_request: event(reqid: string, node: string);
|
||||
|
||||
## Handle a response from a Supervisor process that received
|
||||
## :zeek:see:`SupervisorControl::destroy_request`.
|
||||
##
|
||||
## reqid: an arbitrary string matching the value in the original request.
|
||||
##
|
||||
## result: the return value of the remote call to
|
||||
## :zeek:see:`Supervisor::destroy`.
|
||||
global SupervisorControl::destroy_response: event(reqid: string, result: bool);
|
||||
|
||||
## Send a request to a remote Supervisor to stop and shutdown its
|
||||
## process tree. There is no response to this message as the Supervisor
|
||||
## simply terminates on receipt.
|
||||
global SupervisorControl::stop_request: event();
|
||||
}
|
|
@ -1,63 +1,16 @@
|
|||
##! Implements Zeek process supervision configuration options and default
|
||||
##! behavior.
|
||||
##! Implements Zeek process supervision API and default behavior for its
|
||||
##! associated (remote) control events.
|
||||
|
||||
@load ./api
|
||||
@load ./control
|
||||
@load base/frameworks/broker
|
||||
|
||||
module Supervisor;
|
||||
|
||||
export {
|
||||
## The Broker topic prefix to use when subscribing to Supervisor API
|
||||
## requests and when publishing Supervisor API responses. If you are
|
||||
## publishing Supervisor requests, this is also the prefix string to use
|
||||
## for their topic names.
|
||||
const topic_prefix = "zeek/supervisor" &redef;
|
||||
}
|
||||
|
||||
event zeek_init() &priority=10
|
||||
{
|
||||
Broker::subscribe(Supervisor::topic_prefix);
|
||||
}
|
||||
|
||||
event Supervisor::stop_request()
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event Supervisor::status_request(reqid: string, node: string)
|
||||
{
|
||||
local res = Supervisor::status(node);
|
||||
local topic = Supervisor::topic_prefix + fmt("/status_response/%s", reqid);
|
||||
Broker::publish(topic, Supervisor::status_response, reqid, res);
|
||||
}
|
||||
|
||||
event Supervisor::create_request(reqid: string, node: NodeConfig)
|
||||
{
|
||||
local res = Supervisor::create(node);
|
||||
local topic = Supervisor::topic_prefix + fmt("/create_response/%s", reqid);
|
||||
Broker::publish(topic, Supervisor::create_response, reqid, res);
|
||||
}
|
||||
|
||||
event Supervisor::destroy_request(reqid: string, node: string)
|
||||
{
|
||||
local res = Supervisor::destroy(node);
|
||||
local topic = Supervisor::topic_prefix + fmt("/destroy_response/%s", reqid);
|
||||
Broker::publish(topic, Supervisor::destroy_response, reqid, res);
|
||||
}
|
||||
|
||||
event Supervisor::restart_request(reqid: string, node: string)
|
||||
{
|
||||
local res = Supervisor::restart(node);
|
||||
local topic = Supervisor::topic_prefix + fmt("/restart_response/%s", reqid);
|
||||
Broker::publish(topic, Supervisor::restart_response, reqid, res);
|
||||
}
|
||||
|
||||
function Supervisor::status(node: string): Status
|
||||
function Supervisor::status(node: string): Supervisor::Status
|
||||
{
|
||||
return Supervisor::__status(node);
|
||||
}
|
||||
|
||||
function Supervisor::create(node: NodeConfig): string
|
||||
function Supervisor::create(node: Supervisor::NodeConfig): string
|
||||
{
|
||||
return Supervisor::__create(node);
|
||||
}
|
||||
|
@ -72,17 +25,70 @@ function Supervisor::restart(node: string): bool
|
|||
return Supervisor::__restart(node);
|
||||
}
|
||||
|
||||
function is_supervisor(): bool
|
||||
function Supervisor::is_supervisor(): bool
|
||||
{
|
||||
return Supervisor::__is_supervisor();
|
||||
}
|
||||
|
||||
function is_supervised(): bool
|
||||
function Supervisor::is_supervised(): bool
|
||||
{
|
||||
return Supervisor::__is_supervised();
|
||||
}
|
||||
|
||||
function node(): NodeConfig
|
||||
function Supervisor::node(): Supervisor::NodeConfig
|
||||
{
|
||||
return Supervisor::__node();
|
||||
}
|
||||
|
||||
event zeek_init() &priority=10
|
||||
{
|
||||
Broker::subscribe(SupervisorControl::topic_prefix);
|
||||
}
|
||||
|
||||
event SupervisorControl::stop_request()
|
||||
{
|
||||
if ( ! Supervisor::is_supervisor() )
|
||||
return;
|
||||
|
||||
terminate();
|
||||
}
|
||||
|
||||
event SupervisorControl::status_request(reqid: string, node: string)
|
||||
{
|
||||
if ( ! Supervisor::is_supervisor() )
|
||||
return;
|
||||
|
||||
local res = Supervisor::status(node);
|
||||
local topic = SupervisorControl::topic_prefix + fmt("/status_response/%s", reqid);
|
||||
Broker::publish(topic, SupervisorControl::status_response, reqid, res);
|
||||
}
|
||||
|
||||
event SupervisorControl::create_request(reqid: string, node: Supervisor::NodeConfig)
|
||||
{
|
||||
if ( ! Supervisor::is_supervisor() )
|
||||
return;
|
||||
|
||||
local res = Supervisor::create(node);
|
||||
local topic = SupervisorControl::topic_prefix + fmt("/create_response/%s", reqid);
|
||||
Broker::publish(topic, SupervisorControl::create_response, reqid, res);
|
||||
}
|
||||
|
||||
event SupervisorControl::destroy_request(reqid: string, node: string)
|
||||
{
|
||||
if ( ! Supervisor::is_supervisor() )
|
||||
return;
|
||||
|
||||
local res = Supervisor::destroy(node);
|
||||
local topic = SupervisorControl::topic_prefix + fmt("/destroy_response/%s", reqid);
|
||||
Broker::publish(topic, SupervisorControl::destroy_response, reqid, res);
|
||||
}
|
||||
|
||||
event SupervisorControl::restart_request(reqid: string, node: string)
|
||||
{
|
||||
if ( ! Supervisor::is_supervisor() )
|
||||
return;
|
||||
|
||||
local res = Supervisor::restart(node);
|
||||
local topic = SupervisorControl::topic_prefix + fmt("/restart_response/%s", reqid);
|
||||
Broker::publish(topic, SupervisorControl::restart_response, reqid, res);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue