You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/01/26 22:45:37 UTC

[34/50] ambari git commit: AMBARI-14710. Add retry logic for REST calls between Ambari and Ranger - Part 3 (gautam)

AMBARI-14710. Add retry logic for REST calls between Ambari and Ranger - Part 3 (gautam)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: c0b4e5528ca39f2c0d2dcbf70558b0fdc6b7cd0f
Parents: f680b52
Author: Gautam Borad <ga...@apache.org>
Authored: Mon Jan 25 17:05:20 2016 +0530
Committer: Gautam Borad <ga...@apache.org>
Committed: Mon Jan 25 22:46:26 2016 +0530

----------------------------------------------------------------------
 .../libraries/functions/ranger_functions.py     | 27 +++++++-----------
 .../libraries/functions/ranger_functions_v2.py  | 30 +++++++-------------
 2 files changed, 21 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c0b4e552/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions.py b/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions.py
index e302235..84a03a3 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions.py
@@ -85,13 +85,11 @@ class Rangeradmin:
         return None
     except urllib2.URLError, e:
       if isinstance(e, urllib2.HTTPError):
-        Logger.error("Error getting {0} repository for component {1}. Http status code - {2}. \n {3}".format(name, component, e.code, e.read()))
+        raise Fail("Error getting {0} repository for component {1}. Http status code - {2}. \n {3}".format(name, component, e.code, e.read()))
       else:
-        Logger.error("Error getting {0} repository for component {1}. Reason - {2}.".format(name, component, e.reason))
-      return None
+        raise Fail("Error getting {0} repository for component {1}. Reason - {2}.".format(name, component, e.reason))
     except httplib.BadStatusLine:
-      Logger.error("Ranger Admin service is not reachable, please restart the service and then try again")
-      return None
+      raise Fail("Ranger Admin service is not reachable, please restart the service and then try again")
     except TimeoutError:
       raise Fail("Connection to Ranger Admin failed. Reason - timeout")
     
@@ -197,17 +195,15 @@ class Rangeradmin:
         return None
     except urllib2.URLError, e:
       if isinstance(e, urllib2.HTTPError):
-        Logger.error("Error creating repository. Http status code - {0}. \n {1}".format(e.code, e.read()))
+        raise Fail("Error creating repository. Http status code - {0}. \n {1}".format(e.code, e.read()))
       else:
-        Logger.error("Error creating repository. Reason - {0}.".format(e.reason))
-      return None
+        raise Fail("Error creating repository. Reason - {0}.".format(e.reason))
     except httplib.BadStatusLine:
-      Logger.error("Ranger Admin service is not reachable, please restart the service and then try again")
-      return None
+      raise Fail("Ranger Admin service is not reachable, please restart the service and then try again")
     except TimeoutError:
       raise Fail("Connection to Ranger Admin failed. Reason - timeout")
 
-  @safe_retry(times=15, sleep_time=8, backoff_factor=1.5, err_class=Fail, return_on_fail=None)
+  @safe_retry(times=75, sleep_time=8, backoff_factor=1, err_class=Fail, return_on_fail=None)
   def check_ranger_login_urllib2(self, url):
     """
     :param url: ranger admin host url
@@ -390,13 +386,10 @@ class Rangeradmin:
         return None
     except urllib2.URLError, e:
       if isinstance(e, urllib2.HTTPError):
-        Logger.error("Error creating ambari admin user. Http status code - {0}. \n {1}".format(e.code, e.read()))
-        return None
+        raise Fail("Error creating ambari admin user. Http status code - {0}. \n {1}".format(e.code, e.read()))
       else:
-        Logger.error("Error creating ambari admin user. Reason - {0}.".format(e.reason))
-        return None
+        raise Fail("Error creating ambari admin user. Reason - {0}.".format(e.reason))
     except httplib.BadStatusLine:
-      Logger.error("Ranger Admin service is not reachable, please restart the service and then try again")
-      return None
+      raise Fail("Ranger Admin service is not reachable, please restart the service and then try again")
     except TimeoutError:
       raise Fail("Connection to Ranger Admin failed. Reason - timeout")

http://git-wip-us.apache.org/repos/asf/ambari/blob/c0b4e552/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions_v2.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions_v2.py b/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions_v2.py
index 6624c89..3bb0103 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions_v2.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/ranger_functions_v2.py
@@ -84,13 +84,11 @@ class RangeradminV2:
         return None
     except urllib2.URLError, e:
       if isinstance(e, urllib2.HTTPError):
-        Logger.error("Error getting {0} repository for component {1}. Http status code - {2}. \n {3}".format(name, component, e.code, e.read()))
+        raise Fail("Error getting {0} repository for component {1}. Http status code - {2}. \n {3}".format(name, component, e.code, e.read()))
       else:
-        Logger.error("Error getting {0} repository for component {1}. Reason - {2}.".format(name, component, e.reason))
-      return None
+        raise Fail("Error getting {0} repository for component {1}. Reason - {2}.".format(name, component, e.reason))
     except httplib.BadStatusLine:
-      Logger.error("Ranger Admin service is not reachable, please restart the service and then try again")
-      return None
+      raise Fail("Ranger Admin service is not reachable, please restart the service and then try again")
     except TimeoutError:
       raise Fail("Connection to Ranger Admin failed. Reason - timeout")
       
@@ -156,21 +154,18 @@ class RangeradminV2:
         Logger.info('Repository created Successfully')
         return response
       else:
-        Logger.error('Repository creation failed')
-        return None
+        raise Fail('Repository creation failed')
     except urllib2.URLError, e:
       if isinstance(e, urllib2.HTTPError):
-        Logger.error("Error creating repository. Http status code - {0}. \n {1}".format(e.code, e.read()))
+        raise Fail("Error creating repository. Http status code - {0}. \n {1}".format(e.code, e.read()))
       else:
-        Logger.error("Error creating repository. Reason - {0}.".format(e.reason))
-      return None
+        raise Fail("Error creating repository. Reason - {0}.".format(e.reason))
     except httplib.BadStatusLine:
-      Logger.error("Ranger Admin service is not reachable, please restart the service and then try again")
-      return None
+      raise Fail("Ranger Admin service is not reachable, please restart the service and then try again")
     except TimeoutError:
       raise Fail("Connection to Ranger Admin failed. Reason - timeout")
 
-  @safe_retry(times=15, sleep_time=8, backoff_factor=1.5, err_class=Fail, return_on_fail=None)
+  @safe_retry(times=75, sleep_time=8, backoff_factor=1, err_class=Fail, return_on_fail=None)
   def check_ranger_login_urllib2(self, url):
     """
     :param url: ranger admin host url
@@ -255,13 +250,10 @@ class RangeradminV2:
         return None
     except urllib2.URLError, e:
       if isinstance(e, urllib2.HTTPError):
-        Logger.error("Error creating ambari admin user. Http status code - {0}. \n {1}".format(e.code, e.read()))
-        return None
+        raise Fail("Error creating ambari admin user. Http status code - {0}. \n {1}".format(e.code, e.read()))
       else:
-        Logger.error("Error creating ambari admin user. Reason - {0}.".format(e.reason))
-        return None
+        raise Fail("Error creating ambari admin user. Reason - {0}.".format(e.reason))
     except httplib.BadStatusLine:
-      Logger.error("Ranger Admin service is not reachable, please restart the service and then try again")
-      return None
+      raise Fail("Ranger Admin service is not reachable, please restart the service and then try again")
     except TimeoutError:
       raise Fail("Connection to Ranger Admin failed. Reason - timeout")