You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2013/10/22 18:24:11 UTC

git commit: AMBARI-3562. Add tries, try_sleep to Execute() resource (Andrew Onischuk via dlysnichenko)

Updated Branches:
  refs/heads/trunk 280c15507 -> 4c14a716e


AMBARI-3562. Add tries, try_sleep to Execute() resource (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/4c14a716
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/4c14a716
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/4c14a716

Branch: refs/heads/trunk
Commit: 4c14a716ee80f39dfd5eef18007a5db1ebbd6e4c
Parents: 280c155
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Tue Oct 22 19:23:18 2013 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Tue Oct 22 19:23:18 2013 +0300

----------------------------------------------------------------------
 .../resource_management/providers/system.py       | 18 ++++++++++++++----
 .../resource_management/resources/system.py       |  3 ++-
 .../src/main/python/resource_management/shell.py  |  4 ++--
 3 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4c14a716/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 d9845a4..c5761c1 100644
--- a/ambari-agent/src/main/python/resource_management/providers/system.py
+++ b/ambari-agent/src/main/python/resource_management/providers/system.py
@@ -3,6 +3,7 @@ from __future__ import with_statement
 import grp
 import os
 import pwd
+import time
 from resource_management import shell
 from resource_management.base import Fail
 from resource_management.providers import Provider
@@ -186,10 +187,19 @@ class ExecuteProvider(Provider):
     
     if self.resource.path:
       self.resource.environment['PATH'] = ":".join(self.resource.path) 
-
-    ret, out = shell.checked_call(self.resource.command,
-                          cwd=self.resource.cwd, env=self.resource.environment,
-                          preexec_fn=_preexec_fn(self.resource))
+    
+    for i in range (0, self.resource.tries):
+      try:
+        ret, out = shell.checked_call(self.resource.command,
+                            cwd=self.resource.cwd, env=self.resource.environment,
+                            preexec_fn=_preexec_fn(self.resource))
+        break
+      except Fail as ex:
+        if i == self.resource.tries-1: # last try
+          raise ex
+        else:
+          self.log.info("Retrying after %d seconds. Reason: %s", self.resource.try_sleep, str(ex))
+          time.sleep(self.resource.try_sleep)
 
     self.resource.updated()
        

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4c14a716/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 21d66e0..b973a8f 100644
--- a/ambari-agent/src/main/python/resource_management/resources/system.py
+++ b/ambari-agent/src/main/python/resource_management/resources/system.py
@@ -55,7 +55,8 @@ class Execute(Resource):
   user = ResourceArgument()
   group = ResourceArgument()
   returns = ForcedListArgument(default=0)
-  timeout = ResourceArgument()
+  tries = ResourceArgument(default=1)
+  try_sleep = ResourceArgument(default=0) # seconds
   path = ForcedListArgument(default=None)
   actions = Resource.actions + ["run"]
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4c14a716/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 2b334a0..b09d5e7 100644
--- a/ambari-agent/src/main/python/resource_management/shell.py
+++ b/ambari-agent/src/main/python/resource_management/shell.py
@@ -37,11 +37,11 @@ def _call(command, log_stdout=False, throw_on_failure=True,
   code = proc.wait()
   
   if throw_on_failure and code:
-    err_msg = ("Execution of '%s' returned %d: Error: %s") % (command, code, out)
+    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))
+    _log().info("%s.\n%s" % (command, out))
   
   return code, out