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 2014/05/13 16:11:19 UTC

git commit: AMBARI-5746. RMF should dump full dictionaries in debug mode (not ...) (aonishuk)

Repository: ambari
Updated Branches:
  refs/heads/trunk c583c9a68 -> 0ddd7686c


AMBARI-5746. RMF should dump full dictionaries in debug mode (not ...) (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0ddd7686
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0ddd7686
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0ddd7686

Branch: refs/heads/trunk
Commit: 0ddd7686c19f9e1e9c9868d35ede7601e709876a
Parents: c583c9a
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Tue May 13 17:11:08 2014 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Tue May 13 17:11:08 2014 +0300

----------------------------------------------------------------------
 .../ambari_agent/CustomServiceOrchestrator.py      |  5 ++++-
 .../src/main/python/ambari_agent/PythonExecutor.py |  4 ++--
 .../main/python/resource_management/core/logger.py |  4 +++-
 .../resource_management/libraries/script/script.py | 17 ++++++++++++-----
 .../ambari_agent/TestCustomServiceOrchestrator.py  |  6 +++---
 .../test/python/ambari_agent/TestPythonExecutor.py |  6 +++---
 6 files changed, 27 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0ddd7686/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
index a1e59a8..c68a953 100644
--- a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
+++ b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
@@ -118,14 +118,17 @@ class CustomServiceOrchestrator():
       py_file_list = [pre_hook_tuple, script_tuple, post_hook_tuple]
       # filter None values
       filtered_py_file_list = [i for i in py_file_list if i]
+      
+      logger_level = logging.getLevelName(logger.level)
 
       # Executing hooks and script
       ret = None
+      
       for py_file, current_base_dir in filtered_py_file_list:
         script_params = [command_name, json_path, current_base_dir]
         ret = self.python_executor.run_file(py_file, script_params,
                                tmpoutfile, tmperrfile, timeout,
-                               tmpstrucoutfile, override_output_files)
+                               tmpstrucoutfile, logger_level, override_output_files)
         # Next run_file() invocations should always append to current output
         override_output_files = False
         if ret['exitcode'] != 0:

http://git-wip-us.apache.org/repos/asf/ambari/blob/0ddd7686/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py b/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
index f6a679d..e7ef967 100644
--- a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
+++ b/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
@@ -48,7 +48,7 @@ class PythonExecutor:
     pass
 
   def run_file(self, script, script_params, tmpoutfile, tmperrfile, timeout,
-               tmpstructedoutfile, override_output_files = True):
+               tmpstructedoutfile, logger_level, override_output_files = True):
     """
     Executes the specified python file in a separate subprocess.
     Method returns only when the subprocess is finished.
@@ -73,7 +73,7 @@ class PythonExecutor:
     except OSError:
       pass # no error
 
-    script_params += [tmpstructedoutfile]
+    script_params += [tmpstructedoutfile, logger_level]
     pythonCommand = self.python_command(script, script_params)
     logger.info("Running command " + pprint.pformat(pythonCommand))
     process = self.launch_python_subprocess(pythonCommand, tmpout, tmperr)

http://git-wip-us.apache.org/repos/asf/ambari/blob/0ddd7686/ambari-agent/src/main/python/resource_management/core/logger.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/logger.py b/ambari-agent/src/main/python/resource_management/core/logger.py
index 3caa78b..da64f6a 100644
--- a/ambari-agent/src/main/python/resource_management/core/logger.py
+++ b/ambari-agent/src/main/python/resource_management/core/logger.py
@@ -59,6 +59,8 @@ class Logger:
   @staticmethod  
   def _get_resource_repr(resource):
     MESSAGE_MAX_LEN = 256
+    logger_level = logging._levelNames[Logger.logger.level]
+    
     arguments_str = ""
     for x,y in resource.arguments.iteritems():
       
@@ -70,7 +72,7 @@ class Logger:
         val = repr(y).lstrip('u')
       # don't show dicts of configurations
       # usually too long  
-      elif isinstance(y, dict):
+      elif logger_level != 'DEBUG' and isinstance(y, dict):
         val = "..."
       # for configs which didn't come
       elif isinstance(y, UnknownConfiguration):

http://git-wip-us.apache.org/repos/asf/ambari/blob/0ddd7686/ambari-agent/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/script.py b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
index 845ed1d..3fbb067 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
@@ -31,12 +31,13 @@ from resource_management.core.resources.packaging import Package
 from resource_management.libraries.script.config_dictionary import ConfigDictionary
 from resource_management.libraries.script.repo_installer import RepoInstaller
 
-USAGE = """Usage: {0} <COMMAND> <JSON_CONFIG> <BASEDIR> <STROUTPUT>
+USAGE = """Usage: {0} <COMMAND> <JSON_CONFIG> <BASEDIR> <STROUTPUT> <LOGGING_LEVEL>
 
 <COMMAND> command type (INSTALL/CONFIGURE/START/STOP/SERVICE_CHECK...)
 <JSON_CONFIG> path to command json file. Ex: /var/lib/ambari-agent/data/command-2.json
 <BASEDIR> path to service metadata dir. Ex: /var/lib/ambari-agent/cache/stacks/HDP/2.0.6/services/HDFS
 <STROUTPUT> path to file with structured command output (file will be created). Ex:/tmp/my.txt
+<LOGGING_LEVEL> log level for stdout. Ex:DEBUG,INFO
 """
 
 class Script(object):
@@ -80,17 +81,23 @@ class Script(object):
     cherr.setFormatter(formatter)
     logger.addHandler(cherr)
     logger.addHandler(chout)
+    
     # parse arguments
-    if len(sys.argv) < 5: 
-     logger.error("Script expects at least 4 arguments")
+    if len(sys.argv) < 6: 
+     logger.error("Script expects at least 5 arguments")
      print USAGE.format(os.path.basename(sys.argv[0])) # print to stdout
      sys.exit(1)
-      
+    
     command_name = str.lower(sys.argv[1])
-    # parse command parameters
     command_data_file = sys.argv[2]
     basedir = sys.argv[3]
     self.stroutfile = sys.argv[4]
+    logging_level = sys.argv[5]
+    
+    logging_level_str = logging._levelNames[logging_level]
+    chout.setLevel(logging_level_str)
+    logger.setLevel(logging_level_str)
+      
     try:
       with open(command_data_file, "r") as f:
         pass

http://git-wip-us.apache.org/repos/asf/ambari/blob/0ddd7686/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
index ac1194e..d972928 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
@@ -207,9 +207,9 @@ class TestCustomServiceOrchestrator(TestCase):
     ret = orchestrator.runCommand(command, "out.txt", "err.txt",
               forsed_command_name=CustomServiceOrchestrator.COMMAND_NAME_STATUS)
     ## Check that override_output_files was true only during first call
-    self.assertEquals(run_file_mock.call_args_list[0][0][6], True)
-    self.assertEquals(run_file_mock.call_args_list[1][0][6], False)
-    self.assertEquals(run_file_mock.call_args_list[2][0][6], False)
+    self.assertEquals(run_file_mock.call_args_list[0][0][7], True)
+    self.assertEquals(run_file_mock.call_args_list[1][0][7], False)
+    self.assertEquals(run_file_mock.call_args_list[2][0][7], False)
     ## Check that forsed_command_name was taken into account
     self.assertEqual(run_file_mock.call_args_list[0][0][1][0],
                                   CustomServiceOrchestrator.COMMAND_NAME_STATUS)

http://git-wip-us.apache.org/repos/asf/ambari/blob/0ddd7686/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
index abfef7c..9889ec0 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
@@ -56,7 +56,7 @@ class TestPythonExecutor(TestCase):
     executor.runShellKillPgrp = runShellKillPgrp_method
     subproc_mock.returncode = None
     thread = Thread(target =  executor.run_file, args = ("fake_puppetFile",
-      ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS, tmpstrucout))
+      ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS, tmpstrucout,"INFO"))
     thread.start()
     time.sleep(0.1)
     subproc_mock.finished_event.wait()
@@ -85,7 +85,7 @@ class TestPythonExecutor(TestCase):
     subproc_mock.returncode = 0
     thread = Thread(target =  executor.run_file, args = ("fake_puppetFile", ["arg1", "arg2"],
                                                       tmpoutfile, tmperrfile,
-                                                      PYTHON_TIMEOUT_SECONDS, tmpstrucout))
+                                                      PYTHON_TIMEOUT_SECONDS, tmpstrucout, "INFO"))
     thread.start()
     time.sleep(0.1)
     subproc_mock.should_finish_event.set()
@@ -112,7 +112,7 @@ class TestPythonExecutor(TestCase):
     executor.runShellKillPgrp = runShellKillPgrp_method
     subproc_mock.returncode = 0
     subproc_mock.should_finish_event.set()
-    result = executor.run_file("file", ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS, tmpstroutfile)
+    result = executor.run_file("file", ["arg1", "arg2"], tmpoutfile, tmperrfile, PYTHON_TIMEOUT_SECONDS, tmpstroutfile, "INFO")
     self.assertEquals(result, {'exitcode': 0, 'stderr': 'Dummy err', 'stdout': 'Dummy output',
                                'structuredOut': {}})