From b57be021b79ec6786ce5d67336fe0af433a2074e Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Mon, 29 Nov 2021 11:56:03 -0800 Subject: [PATCH] Make all globals start with a "g_" prefix This makes it easier to spot them in code, and is shorter than using explicit namespacing. --- .../policy/frameworks/cluster/agent/main.zeek | 32 +++++++++---------- .../frameworks/cluster/controller/main.zeek | 18 +++++------ .../cluster/controller/request.zeek | 14 ++++---- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/scripts/policy/frameworks/cluster/agent/main.zeek b/scripts/policy/frameworks/cluster/agent/main.zeek index 7669942585..b139d6677a 100644 --- a/scripts/policy/frameworks/cluster/agent/main.zeek +++ b/scripts/policy/frameworks/cluster/agent/main.zeek @@ -9,18 +9,18 @@ redef ClusterController::role = ClusterController::Types::AGENT; # The global configuration as passed to us by the controller -global global_config: ClusterController::Types::Configuration; +global g_config: ClusterController::Types::Configuration; # A map to make other instance info accessible -global instances: table[string] of ClusterController::Types::Instance; +global g_instances: table[string] of ClusterController::Types::Instance; # A map for the nodes we run on this instance, via this agent. -global nodes: table[string] of ClusterController::Types::Node; +global g_nodes: table[string] of ClusterController::Types::Node; # The node map employed by the supervisor to describe the cluster # topology to newly forked nodes. We refresh it when we receive # new configurations. -global data_cluster: table[string] of Supervisor::ClusterEndpoint; +global g_data_cluster: table[string] of Supervisor::ClusterEndpoint; event SupervisorControl::create_response(reqid: string, result: string) { @@ -86,43 +86,43 @@ event ClusterAgent::API::set_configuration_request(reqid: string, config: Cluste # Adopt the global configuration provided. # XXX this can later handle validation and persistence # XXX should do this transactionally, only set when all else worked - global_config = config; + g_config = config; # Refresh the instances table: - instances = table(); + g_instances = table(); for ( inst in config$instances ) - instances[inst$name] = inst; + g_instances[inst$name] = inst; # Terminate existing nodes - for ( nodename in nodes ) + for ( nodename in g_nodes ) supervisor_destroy(nodename); - nodes = table(); + g_nodes = table(); # Refresh the data cluster and nodes tables - data_cluster = table(); + g_data_cluster = table(); for ( node in config$nodes ) { if ( node$instance == ClusterAgent::name ) - nodes[node$name] = node; + g_nodes[node$name] = node; local cep = Supervisor::ClusterEndpoint( $role = node$role, - $host = instances[node$instance]$host, + $host = g_instances[node$instance]$host, $p = node$p); if ( node?$interface ) cep$interface = node$interface; - data_cluster[node$name] = cep; + g_data_cluster[node$name] = cep; } # Apply the new configuration via the supervisor - for ( nodename in nodes ) + for ( nodename in g_nodes ) { - node = nodes[nodename]; + node = g_nodes[nodename]; nc = Supervisor::NodeConfig($name=nodename); if ( ClusterAgent::cluster_directory != "" ) @@ -140,7 +140,7 @@ event ClusterAgent::API::set_configuration_request(reqid: string, config: Cluste # XXX could use options to enable per-node overrides for # directory, stdout, stderr, others? - nc$cluster = data_cluster; + nc$cluster = g_data_cluster; supervisor_create(nc); } diff --git a/scripts/policy/frameworks/cluster/controller/main.zeek b/scripts/policy/frameworks/cluster/controller/main.zeek index 11e88fe3fd..5c8c57a057 100644 --- a/scripts/policy/frameworks/cluster/controller/main.zeek +++ b/scripts/policy/frameworks/cluster/controller/main.zeek @@ -9,8 +9,8 @@ redef ClusterController::role = ClusterController::Types::CONTROLLER; -global config_current: ClusterController::Types::Configuration; -global config_reqid_pending: string = ""; +global g_config_current: ClusterController::Types::Configuration; +global g_config_reqid_pending: string = ""; function send_config_to_agents(req: ClusterController::Request::Request, config: ClusterController::Types::Configuration) @@ -90,15 +90,15 @@ event ClusterAgent::API::notify_agent_hello(instance: string, host: addr, api_ve # If we have a pending configuration request, check in on it now to see whether # we have all agents required, and finalize the config request. - if ( config_reqid_pending == "" ) + if ( g_config_reqid_pending == "" ) return; - local req = ClusterController::Request::lookup(config_reqid_pending); + local req = ClusterController::Request::lookup(g_config_reqid_pending); if ( ClusterController::Request::is_null(req) || ! req?$set_configuration_state ) { # Odd, just clear out pending state. - config_reqid_pending = ""; + g_config_reqid_pending = ""; return; } @@ -117,7 +117,7 @@ event ClusterAgent::API::notify_agent_hello(instance: string, host: addr, api_ve # update the request state and eventually send the response event # to the client. send_config_to_agents(req, req$set_configuration_state$config); - config_reqid_pending = ""; + g_config_reqid_pending = ""; } @@ -216,11 +216,11 @@ event ClusterController::API::set_configuration_request(reqid: string, config: C req$set_configuration_state = ClusterController::Request::SetConfigurationState($config = config); # At the moment there can only be one pending request. - if ( config_reqid_pending != "" ) + if ( g_config_reqid_pending != "" ) { res = ClusterController::Types::Result($reqid=reqid); res$success = F; - res$error = fmt("request %s still pending", config_reqid_pending); + res$error = fmt("request %s still pending", g_config_reqid_pending); req$results += res; ClusterController::Log::info(fmt("tx ClusterController::API::set_configuration_response %s", @@ -312,7 +312,7 @@ event ClusterController::API::set_configuration_request(reqid: string, config: C ClusterController::connect_retry); } - config_reqid_pending = req$id; + g_config_reqid_pending = req$id; return; } diff --git a/scripts/policy/frameworks/cluster/controller/request.zeek b/scripts/policy/frameworks/cluster/controller/request.zeek index fbd4a0ff6d..21fcad1117 100644 --- a/scripts/policy/frameworks/cluster/controller/request.zeek +++ b/scripts/policy/frameworks/cluster/controller/request.zeek @@ -49,30 +49,30 @@ export { } # XXX this needs a mechanism for expiring stale requests -global requests: table[string] of Request; +global g_requests: table[string] of Request; function create(reqid: string): Request { local ret = Request($id=reqid); - requests[reqid] = ret; + g_requests[reqid] = ret; return ret; } function lookup(reqid: string): Request { - if ( reqid in requests ) - return requests[reqid]; + if ( reqid in g_requests ) + return g_requests[reqid]; return null_req; } function finish(reqid: string): bool { - if ( reqid !in requests ) + if ( reqid !in g_requests ) return F; - local req = requests[reqid]; - delete requests[reqid]; + local req = g_requests[reqid]; + delete g_requests[reqid]; req$finished = T;