This is an automated email from the ASF dual-hosted git repository.

aonishuk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit e5c11fa0d65ef570bf8d619bab7209efb34b2430
Author: Andrew Onishuk <[email protected]>
AuthorDate: Wed Mar 28 10:47:00 2018 +0300

    AMBARI-23376. Create topic handler for small agent actions. Like 
restart_agent, clean_caches etc. (aonishuk)
---
 ambari-agent/src/main/python/ambari_agent/AmbariAgent.py | 3 ++-
 ambari-agent/src/main/python/ambari_agent/ExitHelper.py  | 7 ++++---
 ambari-agent/src/main/python/ambari_agent/Utils.py       | 3 +--
 ambari-agent/src/main/python/ambari_agent/main.py        | 4 +---
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/ambari-agent/src/main/python/ambari_agent/AmbariAgent.py 
b/ambari-agent/src/main/python/ambari_agent/AmbariAgent.py
index ef38491..6f5a14e 100644
--- a/ambari-agent/src/main/python/ambari_agent/AmbariAgent.py
+++ b/ambari-agent/src/main/python/ambari_agent/AmbariAgent.py
@@ -22,7 +22,8 @@ import os
 import sys
 from ambari_commons import subprocess32
 import signal
-from Controller import AGENT_AUTO_RESTART_EXIT_CODE
+
+AGENT_AUTO_RESTART_EXIT_CODE = 77
 
 if os.environ.has_key("PYTHON_BIN"):
   AGENT_SCRIPT = 
os.path.join(os.environ["PYTHON_BIN"],"site-packages/ambari_agent/main.py")
diff --git a/ambari-agent/src/main/python/ambari_agent/ExitHelper.py 
b/ambari-agent/src/main/python/ambari_agent/ExitHelper.py
index 66e29e6..e61ccc4 100644
--- a/ambari-agent/src/main/python/ambari_agent/ExitHelper.py
+++ b/ambari-agent/src/main/python/ambari_agent/ExitHelper.py
@@ -48,6 +48,7 @@ class ExitHelper(object):
   def __init__(self):
     self.exit_functions = []
     self.exit_functions_executed = False
+    self.exitcode = 0
     atexit.register(self.execute_cleanup)
 
   def execute_cleanup(self):
@@ -65,10 +66,10 @@ class ExitHelper(object):
   def register(self, func, *args, **kwargs):
     self.exit_functions.append((func, args, kwargs))
 
-  def exit(self, code):
+  def exit(self):
     self.execute_cleanup()
-    logger.info("Cleanup finished, exiting with code:" + str(code))
-    os._exit(code)
+    logger.info("Cleanup finished, exiting with code:" + str(self.exitcode))
+    os._exit(self.exitcode)
 
 
 if __name__ == '__main__':
diff --git a/ambari-agent/src/main/python/ambari_agent/Utils.py 
b/ambari-agent/src/main/python/ambari_agent/Utils.py
index d4162c4..774e957 100644
--- a/ambari-agent/src/main/python/ambari_agent/Utils.py
+++ b/ambari-agent/src/main/python/ambari_agent/Utils.py
@@ -155,8 +155,7 @@ class Utils(object):
 
   @staticmethod
   def restartAgent(stop_event, graceful_stop_timeout=30):
-    from ambari_agent import main
-    main.EXIT_CODE_ON_STOP = AGENT_AUTO_RESTART_EXIT_CODE
+    ExitHelper().exitcode = AGENT_AUTO_RESTART_EXIT_CODE
     stop_event.set()
 
     t = threading.Timer( graceful_stop_timeout, ExitHelper().exit, 
[AGENT_AUTO_RESTART_EXIT_CODE])
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py 
b/ambari-agent/src/main/python/ambari_agent/main.py
index bfe335f..6280a4c 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -142,8 +142,6 @@ 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)
@@ -518,7 +516,7 @@ def main(initializer_module, heartbeat_stop_callback=None):
       # Clean up if not Windows OS
       #
       if connected or stopped:
-        ExitHelper().exit(EXIT_CODE_ON_STOP)
+        ExitHelper().exit()
         logger.info("finished")
         break
     pass # for server_hostname in server_hostnames

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to