Updated Branches:
  refs/heads/trunk 4c14a716e -> 19c00dbd9

AMBARI-3563. Add 'logoutput' attribute (Andrew Onischuk via dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 19c00dbd99f976d4bdeb0594b8e0c1e1b6a4c85c
Parents: 4c14a71
Author: Lisnichenko Dmitro <[email protected]>
Authored: Tue Oct 22 19:25:29 2013 +0300
Committer: Lisnichenko Dmitro <[email protected]>
Committed: Tue Oct 22 19:25:29 2013 +0300

----------------------------------------------------------------------
 .../resource_management/providers/system.py     |  4 +--
 .../resource_management/resources/system.py     |  3 ++-
 .../main/python/resource_management/shell.py    | 26 +++++++++-----------
 3 files changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/19c00dbd/ambari-agent/src/main/python/resource_management/providers/system.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/main/python/resource_management/providers/system.py 
b/ambari-agent/src/main/python/resource_management/providers/system.py
index c5761c1..b1ce3b9 100644
--- a/ambari-agent/src/main/python/resource_management/providers/system.py
+++ b/ambari-agent/src/main/python/resource_management/providers/system.py
@@ -185,12 +185,12 @@ class ExecuteProvider(Provider):
 
     self.log.info("Executing %s" % self.resource)
     
-    if self.resource.path:
+    if self.resource.path != []:
       self.resource.environment['PATH'] = ":".join(self.resource.path) 
     
     for i in range (0, self.resource.tries):
       try:
-        ret, out = shell.checked_call(self.resource.command,
+        shell.checked_call(self.resource.command, 
logoutput=self.resource.logoutput,
                             cwd=self.resource.cwd, 
env=self.resource.environment,
                             preexec_fn=_preexec_fn(self.resource))
         break

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/19c00dbd/ambari-agent/src/main/python/resource_management/resources/system.py
----------------------------------------------------------------------
diff --git 
a/ambari-agent/src/main/python/resource_management/resources/system.py 
b/ambari-agent/src/main/python/resource_management/resources/system.py
index b973a8f..96da5e4 100644
--- a/ambari-agent/src/main/python/resource_management/resources/system.py
+++ b/ambari-agent/src/main/python/resource_management/resources/system.py
@@ -57,8 +57,9 @@ class Execute(Resource):
   returns = ForcedListArgument(default=0)
   tries = ResourceArgument(default=1)
   try_sleep = ResourceArgument(default=0) # seconds
-  path = ForcedListArgument(default=None)
+  path = ForcedListArgument(default=[])
   actions = Resource.actions + ["run"]
+  logoutput = BooleanArgument(default=False)
 
 
 class Script(Resource):

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/19c00dbd/ambari-agent/src/main/python/resource_management/shell.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/shell.py 
b/ambari-agent/src/main/python/resource_management/shell.py
index b09d5e7..8ca9306 100644
--- a/ambari-agent/src/main/python/resource_management/shell.py
+++ b/ambari-agent/src/main/python/resource_management/shell.py
@@ -2,24 +2,25 @@ import logging
 import subprocess
 from exceptions import Fail
 
+log = logging.getLogger("resource_management.provider")
 
-def checked_call(command, log_stdout=False, 
+def checked_call(command, logoutput=False, 
          cwd=None, env=None, preexec_fn=None):
-  return _call(command, log_stdout, True, cwd, env, preexec_fn)
+  return _call(command, logoutput, True, cwd, env, preexec_fn)
 
-def call(command, log_stdout=False, 
+def call(command, logoutput=False, 
          cwd=None, env=None, preexec_fn=None):
-  return _call(command, log_stdout, False, cwd, env, preexec_fn)
+  return _call(command, logoutput, False, cwd, env, preexec_fn)
   
 
-def _call(command, log_stdout=False, throw_on_failure=True, 
+def _call(command, logoutput=False, throw_on_failure=True, 
          cwd=None, env=None, preexec_fn=None):
   """
   Execute shell command
   
   @param command: list/tuple of arguments (recommended as more safe - don't 
need to escape) 
   or string of the command to execute
-  @param log_stdout: boolean, whether command output should be logged of not
+  @param logoutput: boolean, whether command output should be logged of not
   @param throw_on_failure: if true, when return code is not zero exception is 
thrown
   
   @return: retrun_code, stdout, stderr
@@ -30,20 +31,17 @@ def _call(command, log_stdout=False, throw_on_failure=True,
   else:
     shell = True
   
-  proc = subprocess.Popen(command, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE,
+  proc = subprocess.Popen(command, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT,
                           cwd=cwd, env=env, shell=shell,
                           preexec_fn=preexec_fn)
   out = proc.communicate()[0]
   code = proc.wait()
   
+  if logoutput and out and out!="":
+    log.info(out)
+  
   if throw_on_failure and code:
     err_msg = ("Execution of '%s' returned %d. %s") % (command, code, out)
     raise Fail(err_msg)
   
-  if log_stdout:
-    _log().info("%s.\n%s" % (command, out))
-  
-  return code, out
-    
-def _log():
-  return logging.getLogger("resource_management.provider")
\ No newline at end of file
+  return code, out
\ No newline at end of file

Reply via email to