瀏覽代碼

AMBARI-14876. Ambari Agent Creating 100,000 Empty Status Command Files (aonishuk)

Andrew Onishuk 9 年之前
父節點
當前提交
9cc01b45ec

+ 8 - 3
ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py

@@ -56,8 +56,11 @@ class CustomServiceOrchestrator():
   IPV4_ADDRESSES_KEY = "all_ipv4_ips"
 
   AMBARI_SERVER_HOST = "ambari_server_host"
-  DONT_DEBUG_FAILURES_FOR_COMMANDS = [COMMAND_NAME_SECURITY_STATUS, COMMAND_NAME_STATUS]
-  REFLECTIVELY_RUN_COMMANDS = [COMMAND_NAME_SECURITY_STATUS, COMMAND_NAME_STATUS] # -- commands which run a lot and often (this increases their speed)
+
+  FREQUENT_COMMANDS = [COMMAND_NAME_SECURITY_STATUS, COMMAND_NAME_STATUS]
+  DONT_DEBUG_FAILURES_FOR_COMMANDS = FREQUENT_COMMANDS
+  REFLECTIVELY_RUN_COMMANDS = FREQUENT_COMMANDS # -- commands which run a lot and often (this increases their speed)
+  DONT_BACKUP_LOGS_FOR_COMMANDS = FREQUENT_COMMANDS
 
   def __init__(self, config, controller):
     self.config = config
@@ -185,13 +188,15 @@ class CustomServiceOrchestrator():
         raise AgentException("Background commands are supported without hooks only")
 
       python_executor = self.get_py_executor(forced_command_name)
+      backup_log_files = not command_name in self.DONT_BACKUP_LOGS_FOR_COMMANDS
       for py_file, current_base_dir in filtered_py_file_list:
         log_info_on_failure = not command_name in self.DONT_DEBUG_FAILURES_FOR_COMMANDS
         script_params = [command_name, json_path, current_base_dir, tmpstrucoutfile, logger_level, self.exec_tmp_dir]
         ret = python_executor.run_file(py_file, script_params,
                                tmpoutfile, tmperrfile, timeout,
                                tmpstrucoutfile, self.map_task_to_process,
-                               task_id, override_output_files, handle = handle, log_info_on_failure=log_info_on_failure)
+                               task_id, override_output_files, backup_log_files = backup_log_files,
+                               handle = handle, log_info_on_failure=log_info_on_failure)
         # Next run_file() invocations should always append to current output
         override_output_files = False
         if ret['exitcode'] != 0:

+ 8 - 6
ambari-agent/src/main/python/ambari_agent/PythonExecutor.py

@@ -53,11 +53,12 @@ class PythonExecutor(object):
     pass
 
 
-  def open_subprocess_files(self, tmpoutfile, tmperrfile, override_output_files):
-    if override_output_files: # Recreate files, existing files are backed up
-      self.back_up_log_file_if_exists(tmpoutfile)
+  def open_subprocess_files(self, tmpoutfile, tmperrfile, override_output_files, backup_log_files = True):
+    if override_output_files: # Recreate files, existing files are backed up if backup_log_files is True
+      if backup_log_files:
+        self.back_up_log_file_if_exists(tmpoutfile)
+        self.back_up_log_file_if_exists(tmperrfile)
       tmpout =  open(tmpoutfile, 'w')
-      self.back_up_log_file_if_exists(tmperrfile)
       tmperr =  open(tmperrfile, 'w')
     else: # Append to files
       tmpout =  open(tmpoutfile, 'a')
@@ -78,7 +79,8 @@ class PythonExecutor(object):
 
   def run_file(self, script, script_params, tmpoutfile, tmperrfile,
                timeout, tmpstructedoutfile, callback, task_id,
-               override_output_files = True, handle = None, log_info_on_failure=True):
+               override_output_files = True, backup_log_files = True, handle = None,
+               log_info_on_failure = True):
     """
     Executes the specified python file in a separate subprocess.
     Method returns only when the subprocess is finished.
@@ -94,7 +96,7 @@ class PythonExecutor(object):
     logger.debug("Running command " + pprint.pformat(pythonCommand))
     
     if handle is None:
-      tmpout, tmperr = self.open_subprocess_files(tmpoutfile, tmperrfile, override_output_files)
+      tmpout, tmperr = self.open_subprocess_files(tmpoutfile, tmperrfile, override_output_files, backup_log_files)
 
       process = self.launch_python_subprocess(pythonCommand, tmpout, tmperr)
       # map task_id to pid

+ 3 - 2
ambari-agent/src/main/python/ambari_agent/PythonReflectiveExecutor.py

@@ -42,12 +42,13 @@ class PythonReflectiveExecutor(PythonExecutor):
     
   def run_file(self, script, script_params, tmpoutfile, tmperrfile,
                timeout, tmpstructedoutfile, callback, task_id,
-               override_output_files = True, handle = None, log_info_on_failure=True):   
+               override_output_files = True, backup_log_files = True,
+               handle = None, log_info_on_failure=True):
     pythonCommand = self.python_command(script, script_params)
     logger.debug("Running command reflectively " + pprint.pformat(pythonCommand))
     
     script_dir = os.path.dirname(script)
-    self.open_subprocess_files(tmpoutfile, tmperrfile, override_output_files)
+    self.open_subprocess_files(tmpoutfile, tmperrfile, override_output_files, backup_log_files)
     returncode = 1
 
     try: