You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2017/11/09 14:01:24 UTC
ambari git commit: AMBARI-22375. Multiple issue with handling
unexcepted situations (aonishuk)
Repository: ambari
Updated Branches:
refs/heads/branch-3.0-perf 1577f2f06 -> eb156a92d
AMBARI-22375. Multiple issue with handling unexcepted situations (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/eb156a92
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/eb156a92
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/eb156a92
Branch: refs/heads/branch-3.0-perf
Commit: eb156a92dd7317609e6a895db9bbd9b56f5a1a3f
Parents: 1577f2f
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Thu Nov 9 16:00:24 2017 +0200
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Thu Nov 9 16:00:24 2017 +0200
----------------------------------------------------------------------
.../src/main/python/ambari_agent/ClusterCache.py | 12 +++++++++---
.../src/main/python/ambari_agent/InitializerModule.py | 2 +-
ambari-agent/src/main/python/ambari_agent/main.py | 3 +++
.../test/python/ambari_agent/TestAgentStompResponses.py | 8 ++++++++
4 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/eb156a92/ambari-agent/src/main/python/ambari_agent/ClusterCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/ClusterCache.py b/ambari-agent/src/main/python/ambari_agent/ClusterCache.py
index 09e01fe..2e13f16 100644
--- a/ambari-agent/src/main/python/ambari_agent/ClusterCache.py
+++ b/ambari-agent/src/main/python/ambari_agent/ClusterCache.py
@@ -69,7 +69,12 @@ class ClusterCache(dict):
self.hash = None
cache_dict = {}
- self.rewrite_cache(cache_dict, self.hash)
+ try:
+ self.rewrite_cache(cache_dict, self.hash)
+ except:
+ # Example: hostname change and restart causes old topology loading to fail with exception
+ logger.exception("Loading saved cache for {0} failed".format(self.__class__.__name__))
+ self.rewrite_cache({}, None)
def get_cluster_indepedent_data(self):
return self[ClusterCache.COMMON_DATA_CLUSTER]
@@ -93,11 +98,12 @@ class ClusterCache(dict):
for cache_id_to_delete in cache_ids_to_delete:
del self[cache_id_to_delete]
- self.hash = cache_hash
-
self.on_cache_update()
self.persist_cache()
+ # if all of above are sucessful finally set the hash
+ self.hash = cache_hash
+
def cache_update(self, update_dict, cache_hash):
"""
Update the current dictionary by other one
http://git-wip-us.apache.org/repos/asf/ambari/blob/eb156a92/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 dadd508..144b780 100644
--- a/ambari-agent/src/main/python/ambari_agent/InitializerModule.py
+++ b/ambari-agent/src/main/python/ambari_agent/InitializerModule.py
@@ -46,6 +46,7 @@ class InitializerModule:
- Provide an easier way to mock some dependencies.
"""
def __init__(self):
+ self.stop_event = threading.Event()
self.init()
def init(self):
@@ -53,7 +54,6 @@ class InitializerModule:
Initialize properties
"""
self.config = AmbariConfig.get_resolved_config()
- self.stop_event = threading.Event()
self.is_registered = False
http://git-wip-us.apache.org/repos/asf/ambari/blob/eb156a92/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 3948290..51e34c7 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -415,6 +415,9 @@ def main(initializer_module, heartbeat_stop_callback=None):
setup_logging(apscheduler_logger_global, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level)
Logger.initialize_logger('resource_management', logging_level=logging_level)
+ # init data, once loggers are setup to see exceptions/errors of initialization.
+ initializer_module.init()
+
if home_dir != "":
# When running multiple Ambari Agents on this host for simulation, each one will use a unique home directory.
Logger.info("Agent is using Home Dir: %s" % str(home_dir))
http://git-wip-us.apache.org/repos/asf/ambari/blob/eb156a92/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 2154fca..162a809 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestAgentStompResponses.py
@@ -56,6 +56,8 @@ class TestAgentStompResponses(BaseStompServerTestCase):
runCommand_mock.return_value = {'stdout':'...', 'stderr':'...', 'structuredOut' : '{}', 'exitcode':1}
self.initializer_module = InitializerModule()
+ self.initializer_module.init()
+
heartbeat_thread = HeartbeatThread.HeartbeatThread(self.initializer_module)
heartbeat_thread.start()
@@ -154,6 +156,8 @@ class TestAgentStompResponses(BaseStompServerTestCase):
self.initializer_module = InitializerModule()
+ self.initializer_module.init()
+
self.server.frames_queue.queue.clear()
heartbeat_thread = HeartbeatThread.HeartbeatThread(self.initializer_module)
@@ -217,6 +221,8 @@ class TestAgentStompResponses(BaseStompServerTestCase):
def test_topology_update_and_delete(self):
self.initializer_module = InitializerModule()
+ self.initializer_module.init()
+
heartbeat_thread = HeartbeatThread.HeartbeatThread(self.initializer_module)
heartbeat_thread.start()
@@ -294,6 +300,8 @@ class TestAgentStompResponses(BaseStompServerTestCase):
def test_alert_definitions_update_and_delete(self):
self.initializer_module = InitializerModule()
+ self.initializer_module.init()
+
heartbeat_thread = HeartbeatThread.HeartbeatThread(self.initializer_module)
heartbeat_thread.start()