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 2015/06/04 16:35:02 UTC

ambari git commit: AMBARI-11689. All status commands fail in non-root agent mode (aonishuk)

Repository: ambari
Updated Branches:
  refs/heads/trunk b3ed80611 -> 4117e4bee


AMBARI-11689. All status commands fail in non-root agent mode (aonishuk)


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

Branch: refs/heads/trunk
Commit: 4117e4beeabe83ab7b9657e8870ed52e43b5ecfd
Parents: b3ed806
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Thu Jun 4 17:34:44 2015 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Thu Jun 4 17:34:44 2015 +0300

----------------------------------------------------------------------
 .../python/resource_management/core/sudo.py     | 38 ++++++++++++--------
 .../libraries/functions/check_process_status.py |  2 +-
 .../libraries/functions/flume_agent_helper.py   |  4 ++-
 3 files changed, 27 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4117e4be/ambari-common/src/main/python/resource_management/core/sudo.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/sudo.py b/ambari-common/src/main/python/resource_management/core/sudo.py
index 4ceaaed..f864d64 100644
--- a/ambari-common/src/main/python/resource_management/core/sudo.py
+++ b/ambari-common/src/main/python/resource_management/core/sudo.py
@@ -19,12 +19,14 @@ Ambari Agent
 
 """
 
+import time
 import os
 import tempfile
 import shutil
 import stat
 from resource_management.core import shell
 from resource_management.core.logger import Logger
+from resource_management.core.exceptions import Fail
 from ambari_commons.os_check import OSCheck
 
 if os.geteuid() == 0:
@@ -101,6 +103,10 @@ if os.geteuid() == 0:
         self.st_uid, self.st_gid, self.st_mode = stat_val.st_uid, stat_val.st_gid, stat_val.st_mode & 07777
     return Stat(path)
   
+  def kill(pid, signal):
+    os.kill(pid, signal)
+    
+    
 else:
 
   # os.chown replacement
@@ -143,28 +149,23 @@ else:
   def rmtree(path):
     shell.checked_call(["rm","-rf", path], sudo=True)
     
-  def stat(path):
-    class Stat:
-      def __init__(self, path):
-        stat_val = os.stat(path)
-        self.st_uid, self.st_gid, self.st_mode = stat_val.st_uid, stat_val.st_gid, stat_val.st_mode & 07777
-        
-    return Stat(path)
-    
   # fp.write replacement
   def create_file(filename, content, encoding=None):
     """
     if content is None, create empty file
     """
-    tmpf = tempfile.NamedTemporaryFile()
+    content = content if content else ""
+    content = content.encode(encoding) if encoding else content
     
-    if content:
-      content = content.encode(encoding) if encoding else content
-      with open(tmpf.name, "wb") as fp:
-        fp.write(content)
+    tmpf_name = tempfile.gettempdir() + os.sep + tempfile.template + str(time.time())
     
-    with tmpf:    
-      shell.checked_call(["cp", "-f", tmpf.name, filename], sudo=True)
+    try:
+      with open(tmpf_name, "wb") as fp:
+        fp.write(content)
+        
+      shell.checked_call(["cp", "-f", tmpf_name, filename], sudo=True)
+    finally:
+      os.unlink(tmpf_name)
       
   # fp.read replacement
   def read_file(filename, encoding=None):
@@ -217,3 +218,10 @@ else:
           stat_val = os.stat(path)
           self.st_uid, self.st_gid, self.st_mode = stat_val.st_uid, stat_val.st_gid, stat_val.st_mode & 07777
     return Stat(path)
+  
+  # os.kill replacement
+  def kill(pid, signal):
+    try:
+      shell.checked_call(["kill", "-"+str(signal), str(pid)], sudo=True)
+    except Fail as ex:
+      raise OSError(str(ex))
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/4117e4be/ambari-common/src/main/python/resource_management/libraries/functions/check_process_status.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/check_process_status.py b/ambari-common/src/main/python/resource_management/libraries/functions/check_process_status.py
index 6f39c28..7961f00 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/check_process_status.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/check_process_status.py
@@ -54,7 +54,7 @@ def check_process_status(pid_file):
     # If sig is 0, then no signal is sent, but error checking is still
     # performed; this can be used to check for the existence of a
     # process ID or process group ID.
-    os.kill(pid, 0)
+    sudo.kill(pid, 0)
   except OSError:
     Logger.info("Process with pid {0} is not running. Stale pid file"
               " at {1}".format(pid, pid_file))

http://git-wip-us.apache.org/repos/asf/ambari/blob/4117e4be/ambari-common/src/main/python/resource_management/libraries/functions/flume_agent_helper.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/flume_agent_helper.py b/ambari-common/src/main/python/resource_management/libraries/functions/flume_agent_helper.py
index d83c06f..bf1481c 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/flume_agent_helper.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/flume_agent_helper.py
@@ -25,6 +25,8 @@ import time
 
 from resource_management.core.exceptions import ComponentIsNotRunning
 from resource_management.libraries.functions import check_process_status
+from resource_management.core.logger import Logger
+from resource_management.libraries.functions import format
 
 
 def get_flume_status(flume_conf_directory, flume_run_directory):
@@ -112,7 +114,7 @@ def get_live_status(pid_file, flume_conf_directory):
       res['sinks_count'] = meta['sinks_count']
       res['channels_count'] = meta['channels_count']
   except:
-    pass
+    Logger.logger.exception(format("Error reading {flume_agent_meta_file}: "))
 
   return res