Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 482C8200D0E for ; Tue, 26 Sep 2017 10:42:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 466CD1609C1; Tue, 26 Sep 2017 08:42:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 374941609B4 for ; Tue, 26 Sep 2017 10:42:48 +0200 (CEST) Received: (qmail 85163 invoked by uid 500); 26 Sep 2017 08:42:47 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 85154 invoked by uid 99); 26 Sep 2017 08:42:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Sep 2017 08:42:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3C994F331A; Tue, 26 Sep 2017 08:42:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aonishuk@apache.org To: commits@ambari.apache.org Message-Id: <8907bdb1787e4893a55a9d439835a9ea@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-21989. Multiple fixes into branch-3.0-perf (aonishuk) Date: Tue, 26 Sep 2017 08:42:47 +0000 (UTC) archived-at: Tue, 26 Sep 2017 08:42:49 -0000 Repository: ambari Updated Branches: refs/heads/branch-3.0-perf 79a37e510 -> a670750c3 AMBARI-21989. Multiple fixes into branch-3.0-perf (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a670750c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a670750c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a670750c Branch: refs/heads/branch-3.0-perf Commit: a670750c39b55178eb9971a24128d5f0e72534c2 Parents: 79a37e5 Author: Andrew Onishuk Authored: Tue Sep 26 11:42:33 2017 +0300 Committer: Andrew Onishuk Committed: Tue Sep 26 11:42:33 2017 +0300 ---------------------------------------------------------------------- .../ambari_agent/AlertSchedulerHandler.py | 10 ++-- .../python/ambari_agent/AlertStatusReporter.py | 2 +- .../main/python/ambari_agent/AmbariConfig.py | 56 +++++++++++++++++++- .../python/ambari_agent/CommandStatusDict.py | 2 +- .../ambari_agent/CommandStatusReporter.py | 2 +- .../ambari_agent/ComponentStatusExecutor.py | 9 +++- .../src/main/python/ambari_agent/Constants.py | 6 +-- .../src/main/python/ambari_agent/FileCache.py | 2 +- .../main/python/ambari_agent/HeartbeatThread.py | 10 ++-- .../python/ambari_agent/HostStatusReporter.py | 2 +- .../python/ambari_agent/InitializerModule.py | 40 +++----------- .../src/main/python/ambari_agent/Utils.py | 10 ++-- .../listeners/AlertDefinitionsEventListener.py | 6 +-- .../src/main/python/ambari_agent/main.py | 4 +- .../ambari_agent/TestAgentStompResponses.py | 6 +-- 15 files changed, 103 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py b/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py index 94e72c2..231cdd1 100644 --- a/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py +++ b/ambari-agent/src/main/python/ambari_agent/AlertSchedulerHandler.py @@ -51,11 +51,11 @@ class AlertSchedulerHandler(): def __init__(self, initializer_module, in_minutes=True): - self.cachedir = initializer_module.alerts_cachedir - self.stacks_dir = initializer_module.stacks_dir - self.common_services_dir = initializer_module.common_services_dir - self.extensions_dir = initializer_module.extensions_dir - self.host_scripts_dir = initializer_module.host_scripts_dir + self.cachedir = initializer_module.config.alerts_cachedir + self.stacks_dir = initializer_module.config.stacks_dir + self.common_services_dir = initializer_module.config.common_services_dir + self.extensions_dir = initializer_module.config.extensions_dir + self.host_scripts_dir = initializer_module.config.host_scripts_dir self._cluster_configuration = initializer_module.configurations_cache self.alert_definitions_cache = initializer_module.alert_definitions_cache http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py b/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py index 2bd2383..3d5a62e 100644 --- a/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py +++ b/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py @@ -30,7 +30,7 @@ class AlertStatusReporter(threading.Thread): self.initializer_module = initializer_module self.collector = initializer_module.alert_scheduler_handler.collector() self.stop_event = initializer_module.stop_event - self.alert_reports_interval = initializer_module.alert_reports_interval + self.alert_reports_interval = initializer_module.config.alert_reports_interval threading.Thread.__init__(self) def run(self): http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py index e1c40c8..604939b 100644 --- a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py +++ b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py @@ -25,7 +25,7 @@ import hostname import ambari_simplejson as json import os -from ambari_commons import OSConst +from ambari_agent.FileCache import FileCache from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl logger = logging.getLogger(__name__) @@ -219,6 +219,60 @@ class AmbariConfig: # home_dir may be an empty string return os.path.join(os.sep, home_dir, "etc", "ambari-agent", "conf", "ambari-agent.ini") + @property + def server_hostname(self): + return self.get('server', 'hostname') + + @property + def secured_url_port(self): + return self.get('server', 'secured_url_port') + + @property + def command_reports_interval(self): + return int(self.get('agent', 'command_reports_interval', default='5')) + + @property + def alert_reports_interval(self): + return int(self.get('agent', 'alert_reports_interval', default='5')) + + @property + def status_commands_run_interval(self): + return int(self.get('agent', 'status_commands_run_interval', default='20')) + + @property + def command_update_output(self): + return bool(int(self.get('agent', 'command_update_output', default='1'))) + + @property + def host_status_report_interval(self): + return int(self.get('heartbeat', 'state_interval_seconds', '60')) + + @property + def cache_dir(self): + return self.get('agent', 'cache_dir', default='/var/lib/ambari-agent/cache') + + @property + def cluster_cache_dir(self): + return os.path.join(self.cache_dir, FileCache.CLUSTER_CACHE_DIRECTORY) + @property + def recovery_cache_dir(self): + return os.path.join(self.cache_dir, FileCache.RECOVERY_CACHE_DIRECTORY) + @property + def alerts_cachedir(self): + return os.path.join(self.cache_dir, FileCache.ALERTS_CACHE_DIRECTORY) + @property + def stacks_dir(self): + return os.path.join(self.cache_dir, FileCache.STACKS_CACHE_DIRECTORY) + @property + def common_services_dir(self): + return os.path.join(self.cache_dir, FileCache.COMMON_SERVICES_DIRECTORY) + @property + def extensions_dir(self): + return os.path.join(self.cache_dir, FileCache.EXTENSIONS_CACHE_DIRECTORY) + @property + def host_scripts_dir(self): + return os.path.join(self.cache_dir, FileCache.HOST_SCRIPTS_CACHE_DIRECTORY) + # TODO AMBARI-18733, change usages of this function to provide the home_dir. @staticmethod def getLogFile(home_dir=""): http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py b/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py index c681550..25d50bf 100644 --- a/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py +++ b/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py @@ -45,7 +45,7 @@ class CommandStatusDict(): self.current_state = {} # Contains all statuses self.lock = threading.RLock() self.initializer_module = initializer_module - self.command_update_output = initializer_module.command_update_output + self.command_update_output = initializer_module.config.command_update_output self.reported_reports = set() http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/CommandStatusReporter.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/CommandStatusReporter.py b/ambari-agent/src/main/python/ambari_agent/CommandStatusReporter.py index 652574f..129cf14 100644 --- a/ambari-agent/src/main/python/ambari_agent/CommandStatusReporter.py +++ b/ambari-agent/src/main/python/ambari_agent/CommandStatusReporter.py @@ -28,7 +28,7 @@ class CommandStatusReporter(threading.Thread): self.initializer_module = initializer_module self.commandStatuses = initializer_module.commandStatuses self.stop_event = initializer_module.stop_event - self.command_reports_interval = initializer_module.command_reports_interval + self.command_reports_interval = initializer_module.config.command_reports_interval threading.Thread.__init__(self) def run(self): http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/ComponentStatusExecutor.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/ComponentStatusExecutor.py b/ambari-agent/src/main/python/ambari_agent/ComponentStatusExecutor.py index f85ba42..0f5591f 100644 --- a/ambari-agent/src/main/python/ambari_agent/ComponentStatusExecutor.py +++ b/ambari-agent/src/main/python/ambari_agent/ComponentStatusExecutor.py @@ -31,7 +31,7 @@ logger = logging.getLogger(__name__) class ComponentStatusExecutor(threading.Thread): def __init__(self, initializer_module): self.initializer_module = initializer_module - self.status_commands_run_interval = initializer_module.status_commands_run_interval + self.status_commands_run_interval = initializer_module.config.status_commands_run_interval self.metadata_cache = initializer_module.metadata_cache self.topology_cache = initializer_module.topology_cache self.customServiceOrchestrator = initializer_module.customServiceOrchestrator @@ -101,9 +101,14 @@ class ComponentStatusExecutor(threading.Thread): } component_status_result = self.customServiceOrchestrator.requestComponentStatus(command_dict) - # TODO STOMP: if status command failed with exception show exception status = LiveStatus.LIVE_STATUS if component_status_result['exitcode'] == 0 else LiveStatus.DEAD_STATUS + # log if status command failed + if status == LiveStatus.DEAD_STATUS: + stderr = component_status_result['stderr'] + if not "ComponentIsNotRunning" in stderr and not "ClientComponentHasNoStatus" in stderr: + logger.info("Status command for {0} failed:\n{1}".format(component_name, stderr)) + result = { 'serviceName': service_name, 'componentName': component_name, http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/Constants.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/Constants.py b/ambari-agent/src/main/python/ambari_agent/Constants.py index 6a258d2..4c0b01b 100644 --- a/ambari-agent/src/main/python/ambari_agent/Constants.py +++ b/ambari-agent/src/main/python/ambari_agent/Constants.py @@ -22,19 +22,19 @@ limitations under the License. COMMANDS_TOPIC = '/user/commands' CONFIGURATIONS_TOPIC = '/user/configs' HOST_LEVEL_PARAMS_TOPIC = '/user/host_level_params' -ALERTS_DEFENITIONS_TOPIC = '/user/alert_defenitions' +ALERTS_DEFINITIONS_TOPIC = '/user/alert_definitions' METADATA_TOPIC = '/events/metadata' TOPOLOGIES_TOPIC = '/events/topologies' SERVER_RESPONSES_TOPIC = '/user/' PRE_REGISTRATION_TOPICS_TO_SUBSCRIBE = [SERVER_RESPONSES_TOPIC] -POST_REGISTRATION_TOPICS_TO_SUBSCRIBE = [COMMANDS_TOPIC, CONFIGURATIONS_TOPIC, METADATA_TOPIC, TOPOLOGIES_TOPIC, HOST_LEVEL_PARAMS_TOPIC, ALERTS_DEFENITIONS_TOPIC] +POST_REGISTRATION_TOPICS_TO_SUBSCRIBE = [COMMANDS_TOPIC, CONFIGURATIONS_TOPIC, METADATA_TOPIC, TOPOLOGIES_TOPIC, HOST_LEVEL_PARAMS_TOPIC, ALERTS_DEFINITIONS_TOPIC] TOPOLOGY_REQUEST_ENDPOINT = '/agents/topologies' METADATA_REQUEST_ENDPOINT = '/agents/metadata' CONFIGURATIONS_REQUEST_ENDPOINT = '/agents/configs' HOST_LEVEL_PARAMS_TOPIC_ENPOINT = '/agents/host_level_params' -ALERTS_DEFENITIONS_REQUEST_ENDPOINT = '/agents/alert_defenitions' +ALERTS_DEFINITIONS_REQUEST_ENDPOINT = '/agents/alert_definitions' COMPONENT_STATUS_REPORTS_ENDPOINT = '/reports/component_status' COMMANDS_STATUS_REPORTS_ENDPOINT = '/reports/commands_status' HOST_STATUS_REPORTS_ENDPOINT = '/reports/host_status' http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/FileCache.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/FileCache.py b/ambari-agent/src/main/python/ambari_agent/FileCache.py index 0e598e9..17235bf 100644 --- a/ambari-agent/src/main/python/ambari_agent/FileCache.py +++ b/ambari-agent/src/main/python/ambari_agent/FileCache.py @@ -25,7 +25,6 @@ import shutil import zipfile import urllib2 import urllib -from AmbariConfig import AmbariConfig logger = logging.getLogger() @@ -125,6 +124,7 @@ class FileCache(): def auto_cache_update_enabled(self): + from AmbariConfig import AmbariConfig if self.config and \ self.config.has_option(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY) and \ self.config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY).lower() == "false": http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py b/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py index b6e1aaf..2d9e5cc 100644 --- a/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py +++ b/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py @@ -54,6 +54,7 @@ class HeartbeatThread(threading.Thread): self.registration_builder = Register(initializer_module.config) self.initializer_module = initializer_module + self.config = initializer_module.config # listeners self.server_responses_listener = ServerResponsesListener() @@ -70,7 +71,7 @@ class HeartbeatThread(threading.Thread): (Constants.METADATA_REQUEST_ENDPOINT, initializer_module.metadata_cache, self.metadata_events_listener), (Constants.CONFIGURATIONS_REQUEST_ENDPOINT, initializer_module.configurations_cache, self.configuration_events_listener), (Constants.HOST_LEVEL_PARAMS_TOPIC_ENPOINT, initializer_module.host_level_params_cache, self.host_level_params_events_listener), - (Constants.ALERTS_DEFENITIONS_REQUEST_ENDPOINT, initializer_module.alert_definitions_cache, self.alert_definitions_events_listener) + (Constants.ALERTS_DEFINITIONS_REQUEST_ENDPOINT, initializer_module.alert_definitions_cache, self.alert_definitions_events_listener) ] self.responseId = 0 self.file_cache = initializer_module.file_cache @@ -179,13 +180,13 @@ class HeartbeatThread(threading.Thread): if serverId != self.responseId + 1: logger.error("Error in responseId sequence - restarting") - Utils.restartAgent() + Utils.restartAgent(self.stop_event) else: self.responseId = serverId if 'restartAgent' in response and response['restartAgent'].lower() == "true": logger.warn("Restarting the agent by the request from server") - Utils.restartAgent() + Utils.restartAgent(self.stop_event) def get_heartbeat_body(self): """ @@ -197,8 +198,7 @@ class HeartbeatThread(threading.Thread): """ Create a stomp connection """ - # TODO STOMP: handle if agent.ssl=false? - connection_url = 'wss://{0}:{1}/agent/stomp/v1'.format(self.initializer_module.server_hostname, self.initializer_module.secured_url_port) + connection_url = 'wss://{0}:{1}/agent/stomp/v1'.format(self.config.server_hostname, self.config.secured_url_port) self.connection = security.establish_connection(connection_url) def add_listeners(self): http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/HostStatusReporter.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/HostStatusReporter.py b/ambari-agent/src/main/python/ambari_agent/HostStatusReporter.py index 09ce016..c27ee55 100644 --- a/ambari-agent/src/main/python/ambari_agent/HostStatusReporter.py +++ b/ambari-agent/src/main/python/ambari_agent/HostStatusReporter.py @@ -33,7 +33,7 @@ class HostStatusReporter(threading.Thread): """ def __init__(self, initializer_module): self.initializer_module = initializer_module - self.report_interval = initializer_module.host_status_report_interval + self.report_interval = initializer_module.config.host_status_report_interval self.stop_event = initializer_module.stop_event self.config = initializer_module.config self.host_info = HostInfo(initializer_module.config) http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/InitializerModule.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/InitializerModule.py b/ambari-agent/src/main/python/ambari_agent/InitializerModule.py index 0126250..2c80218 100644 --- a/ambari-agent/src/main/python/ambari_agent/InitializerModule.py +++ b/ambari-agent/src/main/python/ambari_agent/InitializerModule.py @@ -20,7 +20,6 @@ limitations under the License. import threading import logging -import os from ambari_agent.FileCache import FileCache from ambari_agent.AmbariConfig import AmbariConfig @@ -46,53 +45,28 @@ class InitializerModule: - Provide an easier way to mock some dependencies. """ def __init__(self): - self.initConfigs() self.init() - def initConfigs(self): - """ - Initialize every property got from ambari-agent.ini - """ - self.config = AmbariConfig.get_resolved_config() - - self.server_hostname = self.config.get('server', 'hostname') - self.secured_url_port = self.config.get('server', 'secured_url_port') - - self.cache_dir = self.config.get('agent', 'cache_dir', default='/var/lib/ambari-agent/cache') - self.command_reports_interval = int(self.config.get('agent', 'command_reports_interval', default='5')) - self.alert_reports_interval = int(self.config.get('agent', 'alert_reports_interval', default='5')) - self.status_commands_run_interval = int(self.config.get('agent', 'status_commands_run_interval', default='20')) - self.command_update_output = bool(int(self.config.get('agent', 'command_update_output', default='1'))) - - self.cluster_cache_dir = os.path.join(self.cache_dir, FileCache.CLUSTER_CACHE_DIRECTORY) - self.recovery_cache_dir = os.path.join(self.cache_dir, FileCache.RECOVERY_CACHE_DIRECTORY) - self.alerts_cachedir = os.path.join(self.cache_dir, FileCache.ALERTS_CACHE_DIRECTORY) - self.stacks_dir = os.path.join(self.cache_dir, FileCache.STACKS_CACHE_DIRECTORY) - self.common_services_dir = os.path.join(self.cache_dir, FileCache.COMMON_SERVICES_DIRECTORY) - self.extensions_dir = os.path.join(self.cache_dir, FileCache.EXTENSIONS_CACHE_DIRECTORY) - self.host_scripts_dir = os.path.join(self.cache_dir, FileCache.HOST_SCRIPTS_CACHE_DIRECTORY) - - self.host_status_report_interval = int(self.config.get('heartbeat', 'state_interval_seconds', '60')) - def init(self): """ Initialize properties """ + self.config = AmbariConfig.get_resolved_config() self.stop_event = threading.Event() self.is_registered = False - self.metadata_cache = ClusterMetadataCache(self.cluster_cache_dir) - self.topology_cache = ClusterTopologyCache(self.cluster_cache_dir, self.config) - self.configurations_cache = ClusterConfigurationCache(self.cluster_cache_dir) - self.host_level_params_cache = ClusterHostLevelParamsCache(self.cluster_cache_dir) - self.alert_definitions_cache = ClusterAlertDefinitionsCache(self.cluster_cache_dir) + self.metadata_cache = ClusterMetadataCache(self.config.cluster_cache_dir) + self.topology_cache = ClusterTopologyCache(self.config.cluster_cache_dir, self.config) + self.configurations_cache = ClusterConfigurationCache(self.config.cluster_cache_dir) + self.host_level_params_cache = ClusterHostLevelParamsCache(self.config.cluster_cache_dir) + self.alert_definitions_cache = ClusterAlertDefinitionsCache(self.config.cluster_cache_dir) self.file_cache = FileCache(self.config) self.customServiceOrchestrator = CustomServiceOrchestrator(self) - self.recovery_manager = RecoveryManager(self.recovery_cache_dir) + self.recovery_manager = RecoveryManager(self.config.recovery_cache_dir) self.commandStatuses = CommandStatusDict(self) self.action_queue = ActionQueue(self) self.alert_scheduler_handler = AlertSchedulerHandler(self) http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/Utils.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/Utils.py b/ambari-agent/src/main/python/ambari_agent/Utils.py index af70d77..370597e 100644 --- a/ambari-agent/src/main/python/ambari_agent/Utils.py +++ b/ambari-agent/src/main/python/ambari_agent/Utils.py @@ -153,9 +153,13 @@ class Utils(object): return version @staticmethod - def restartAgent(): - # TODO STOMP: set stop event? - ExitHelper().exit(AGENT_AUTO_RESTART_EXIT_CODE) + def restartAgent(stop_event, graceful_stop_timeout=30): + from ambari_agent import main + main.EXIT_CODE_ON_STOP = AGENT_AUTO_RESTART_EXIT_CODE + stop_event.set() + + t = threading.Timer( graceful_stop_timeout, ExitHelper().exit, [AGENT_AUTO_RESTART_EXIT_CODE]) + t.start() class ImmutableDictionary(dict): def __init__(self, dictionary): http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py b/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py index 91ae5de..494d0f3 100644 --- a/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py +++ b/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py @@ -28,7 +28,7 @@ logger = logging.getLogger(__name__) class AlertDefinitionsEventListener(EventListener): """ - Listener of Constants.ALERTS_DEFENITIONS_TOPIC events from server. + Listener of Constants.ALERTS_DEFINITIONS_TOPIC events from server. """ def __init__(self, alert_definitions_cache, alert_scheduler_handler): self.alert_definitions_cache = alert_definitions_cache @@ -36,7 +36,7 @@ class AlertDefinitionsEventListener(EventListener): def on_event(self, headers, message): """ - Is triggered when an event to Constants.ALERTS_DEFENITIONS_TOPIC topic is received from server. + Is triggered when an event to Constants.ALERTS_DEFINITIONS_TOPIC topic is received from server. @param headers: headers dictionary @param message: message payload dictionary @@ -59,4 +59,4 @@ class AlertDefinitionsEventListener(EventListener): self.alert_scheduler_handler.update_definitions(event_type) def get_handled_path(self): - return Constants.ALERTS_DEFENITIONS_TOPIC \ No newline at end of file + return Constants.ALERTS_DEFINITIONS_TOPIC \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/main/python/ambari_agent/main.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py index 05fc5ce..de23ff6 100644 --- a/ambari-agent/src/main/python/ambari_agent/main.py +++ b/ambari-agent/src/main/python/ambari_agent/main.py @@ -136,6 +136,8 @@ SYSLOG_FORMATTER = logging.Formatter(SYSLOG_FORMAT_STRING) _file_logging_handlers ={} +EXIT_CODE_ON_STOP = 0 + def setup_logging(logger, filename, logging_level): logger.propagate = False formatter = logging.Formatter(formatstr) @@ -505,7 +507,7 @@ def main(initializer_module, heartbeat_stop_callback=None): # Clean up if not Windows OS # if connected or stopped: - ExitHelper().exit(0) + ExitHelper().exit(EXIT_CODE_ON_STOP) logger.info("finished") break pass # for server_hostname in server_hostnames http://git-wip-us.apache.org/repos/asf/ambari/blob/a670750c/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py b/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py index 3c571ab..2154fca 100644 --- a/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py +++ b/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py @@ -331,13 +331,13 @@ class TestAgentStompResponses(BaseStompServerTestCase): while not self.initializer_module.is_registered: time.sleep(0.1) - f = Frame(frames.MESSAGE, headers={'destination': '/user/alert_defenitions'}, body=self.get_json("alert_definitions_add.json")) + f = Frame(frames.MESSAGE, headers={'destination': '/user/alert_definitions'}, body=self.get_json("alert_definitions_add.json")) self.server.topic_manager.send(f) - f = Frame(frames.MESSAGE, headers={'destination': '/user/alert_defenitions'}, body=self.get_json("alert_definitions_edit.json")) + f = Frame(frames.MESSAGE, headers={'destination': '/user/alert_definitions'}, body=self.get_json("alert_definitions_edit.json")) self.server.topic_manager.send(f) - f = Frame(frames.MESSAGE, headers={'destination': '/user/alert_defenitions'}, body=self.get_json("alert_definitions_delete.json")) + f = Frame(frames.MESSAGE, headers={'destination': '/user/alert_definitions'}, body=self.get_json("alert_definitions_delete.json")) self.server.topic_manager.send(f)