mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Management framework: consistency fixes to the Result record
The instance and error fields are now optional instead of defaulting to empty strings, which caused minor output deviations in the client. Agents now ensure that any Result record they create has the instance field filled in.
This commit is contained in:
parent
3ac5fdfc59
commit
f353ac22a5
2 changed files with 16 additions and 8 deletions
|
@ -637,9 +637,11 @@ event Management::Agent::API::node_dispatch_request(reqid: string, action: vecto
|
|||
add req$node_dispatch_state_agent$requests[node];
|
||||
else
|
||||
{
|
||||
res = Management::Result($reqid=reqid, $node=node);
|
||||
res$success = F;
|
||||
res$error = fmt("cluster node %s not in runnning state", node);
|
||||
res = Management::Result($reqid=reqid,
|
||||
$instance = Management::Agent::get_name(),
|
||||
$success = F,
|
||||
$error = fmt("cluster node %s not in runnning state", node),
|
||||
$node=node);
|
||||
req$results += res;
|
||||
}
|
||||
}
|
||||
|
@ -730,6 +732,7 @@ event Management::Node::API::notify_node_hello(node: string)
|
|||
event Management::Request::request_expired(req: Management::Request::Request)
|
||||
{
|
||||
local res = Management::Result($reqid=req$id,
|
||||
$instance = Management::Agent::get_name(),
|
||||
$success = F,
|
||||
$error = "request timed out");
|
||||
|
||||
|
|
|
@ -92,13 +92,18 @@ export {
|
|||
|
||||
type NodeStatusVec: vector of NodeStatus;
|
||||
|
||||
## Return value for request-response API event pairs
|
||||
## Return value for request-response API event pairs. Some responses
|
||||
## contain one, others multiple of these. The request ID allows clients
|
||||
## to string requests and responses together. Agents and the controller
|
||||
## fill in the instance and node fields whenever there's sufficient
|
||||
## context to define them. Any result produced by an agent will carry an
|
||||
## instance value, for example.
|
||||
type Result: record {
|
||||
reqid: string; ##< Request ID of operation this result refers to
|
||||
instance: string &default=""; ##< Name of associated instance (for context)
|
||||
success: bool &default=T; ##< True if successful
|
||||
instance: string &optional; ##< Name of associated instance (for context)
|
||||
data: any &optional; ##< Addl data returned for successful operation
|
||||
error: string &default=""; ##< Descriptive error on failure
|
||||
error: string &optional; ##< Descriptive error on failure
|
||||
node: string &optional; ##< Name of associated node (for context)
|
||||
};
|
||||
|
||||
|
@ -127,7 +132,7 @@ function result_to_string(res: Result): string
|
|||
|
||||
if ( res$success )
|
||||
result = "success";
|
||||
else if ( res$error != "" )
|
||||
else if ( res?$error )
|
||||
result = fmt("error (%s)", res$error);
|
||||
else
|
||||
result = "error";
|
||||
|
@ -136,7 +141,7 @@ function result_to_string(res: Result): string
|
|||
|
||||
if ( res$reqid != "" )
|
||||
details[|details|] = fmt("reqid %s", res$reqid);
|
||||
if ( res$instance != "" )
|
||||
if ( res?$instance )
|
||||
details[|details|] = fmt("instance %s", res$instance);
|
||||
if ( res?$node && res$node != "" )
|
||||
details[|details|] = fmt("node %s", res$node);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue