You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ga...@apache.org on 2015/12/02 09:10:05 UTC

ambari git commit: AMBARI-14094 Remove raise condition in Ranger KMS start if repo creation fails

Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 fa75d9107 -> 9914027b9


AMBARI-14094 Remove raise condition in Ranger KMS start if repo creation fails


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

Branch: refs/heads/branch-2.1
Commit: 9914027b996075b2be2f9c2abcfb8d21611f86c1
Parents: fa75d91
Author: Gautam Borad <ga...@apache.org>
Authored: Wed Dec 2 10:40:36 2015 +0530
Committer: Gautam Borad <ga...@apache.org>
Committed: Wed Dec 2 13:39:57 2015 +0530

----------------------------------------------------------------------
 .../RANGER_KMS/0.5.0.2.3/package/scripts/kms.py | 62 ++++++++++++++------
 .../stacks/HDP/2.2/role_command_order.json      |  2 +-
 .../stacks/HDP/2.3/role_command_order.json      |  1 +
 3 files changed, 47 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9914027b/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py b/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py
index 905ec1d..c683dc1 100755
--- a/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py
+++ b/ambari-server/src/main/resources/common-services/RANGER_KMS/0.5.0.2.3/package/scripts/kms.py
@@ -36,6 +36,7 @@ from resource_management.libraries.functions.ranger_functions import Rangeradmin
 from resource_management.core.utils import PasswordString
 from resource_management.core.shell import as_sudo
 import re
+import time
 
 def password_validation(password, key):
   import params
@@ -276,20 +277,16 @@ def enable_kms_plugin():
   import params
 
   if params.has_ranger_admin:
-    ranger_adm_obj = Rangeradmin(url=params.policymgr_mgr_url)
-    ambari_username_password_for_ranger = format("{ambari_ranger_admin}:{ambari_ranger_password}")
-    response_code = ranger_adm_obj.check_ranger_login_urllib2(params.policymgr_mgr_url)
-    if response_code is not None and response_code == 200:
-      user_resp_code = ranger_adm_obj.create_ambari_admin_user(params.ambari_ranger_admin, params.ambari_ranger_password, params.admin_uname_password)
+    count = 0
+    while count < 5:
+      ranger_flag = check_ranger_service()
+      if ranger_flag:
+        break
+      else:
+        time.sleep(5) # delay for 5 seconds
+        count = count + 1
     else:
-      raise Fail('Ranger service is not started on given host')   
-
-    if user_resp_code is not None and user_resp_code == 200:
-      get_repo_flag = get_repo(params.policymgr_mgr_url, params.repo_name, ambari_username_password_for_ranger)
-      if not get_repo_flag:
-        create_repo(params.policymgr_mgr_url, json.dumps(params.kms_ranger_plugin_repo), ambari_username_password_for_ranger)
-    else:
-      raise Fail('Ambari admin user creation failed')
+      Logger.error("Ranger service is not reachable after {0} tries".format(count))
 
     current_datetime = datetime.now()
 
@@ -353,6 +350,31 @@ def enable_kms_plugin():
       mode = 0640
       )
   
+def check_ranger_service():
+  import params
+
+  ranger_adm_obj = Rangeradmin(url=params.policymgr_mgr_url)
+  ambari_username_password_for_ranger = format("{ambari_ranger_admin}:{ambari_ranger_password}")
+  response_code = ranger_adm_obj.check_ranger_login_urllib2(params.policymgr_mgr_url)
+
+  if response_code is not None and response_code == 200:
+    user_resp_code = ranger_adm_obj.create_ambari_admin_user(params.ambari_ranger_admin, params.ambari_ranger_password, params.admin_uname_password)
+    if user_resp_code is not None and user_resp_code == 200:
+      get_repo_flag = get_repo(params.policymgr_mgr_url, params.repo_name, ambari_username_password_for_ranger)
+      if not get_repo_flag:
+        create_repo_flag = create_repo(params.policymgr_mgr_url, json.dumps(params.kms_ranger_plugin_repo), ambari_username_password_for_ranger)
+        if create_repo_flag:
+          return True
+        else:
+          return False
+      else:
+        return True
+    else:
+      Logger.error('Ambari admin user creation failed')
+      return False
+  else:
+    Logger.error('Ranger service is not reachable host')
+    return False
 
 def create_repo(url, data, usernamepassword):
   try:
@@ -369,13 +391,17 @@ def create_repo(url, data, usernamepassword):
     response = json.loads(json.JSONEncoder().encode(result.read()))
     if response_code == 200:
       Logger.info('Repository created Successfully')
+      return True
     else:
       Logger.info('Repository not created')
+      return False
   except urllib2.URLError, e:
     if isinstance(e, urllib2.HTTPError):
-      raise Fail("Error creating service. Http status code - {0}. \n {1}".format(e.code, e.read()))
+      Logger.error("Error creating service. Http status code - {0}. \n {1}".format(e.code, e.read()))
+      return False
     else:
-      raise Fail("Error creating service. Reason - {0}.".format(e.reason))
+      Logger.error("Error creating service. Reason - {0}.".format(e.reason))
+      return False
 
 def get_repo(url, name, usernamepassword):
   try:
@@ -401,6 +427,8 @@ def get_repo(url, name, usernamepassword):
       return False
   except urllib2.URLError, e:
     if isinstance(e, urllib2.HTTPError):
-      raise Fail("Error getting {0} service. Http status code - {1}. \n {2}".format(name, e.code, e.read()))
+      Logger.error("Error getting {0} service. Http status code - {1}. \n {2}".format(name, e.code, e.read()))
+      return False
     else:
-      raise Fail("Error getting {0} service. Reason - {1}.".format(name, e.reason))
+      Logger.error("Error getting {0} service. Reason - {1}.".format(name, e.reason))
+      return False

http://git-wip-us.apache.org/repos/asf/ambari/blob/9914027b/ambari-server/src/main/resources/stacks/HDP/2.2/role_command_order.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/role_command_order.json b/ambari-server/src/main/resources/stacks/HDP/2.2/role_command_order.json
index 5745c78..465d442 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/role_command_order.json
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/role_command_order.json
@@ -22,7 +22,7 @@
     "SLIDER_SERVICE_CHECK-SERVICE_CHECK" : ["NODEMANAGER-START", "RESOURCEMANAGER-START"],
     "KAFKA_BROKER-START" : ["ZOOKEEPER_SERVER-START", "RANGER_USERSYNC-START"],
     "KAFKA_SERVICE_CHECK-SERVICE_CHECK": ["KAFKA_BROKER-START"],
-    "RANGER_USERSYNC-START" : ["RANGER_ADMIN-START", "RANGER_KMS_SERVER-START"],
+    "RANGER_USERSYNC-START" : ["RANGER_ADMIN-START"],
     "ZOOKEEPER_SERVER-START" : ["RANGER_USERSYNC-START"],
     "KNOX_GATEWAY-START": ["RANGER_USERSYNC-START"],
     "KNOX_SERVICE_CHECK-SERVICE_CHECK" : ["KNOX_GATEWAY-START"],

http://git-wip-us.apache.org/repos/asf/ambari/blob/9914027b/ambari-server/src/main/resources/stacks/HDP/2.3/role_command_order.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/role_command_order.json b/ambari-server/src/main/resources/stacks/HDP/2.3/role_command_order.json
index d634ce1..41e1344 100755
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/role_command_order.json
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/role_command_order.json
@@ -4,6 +4,7 @@
   "general_deps" : {
     "_comment" : "dependencies for all cases",
     "MAHOUT_SERVICE_CHECK-SERVICE_CHECK": ["NODEMANAGER-START", "RESOURCEMANAGER-START"],
+    "RANGER_USERSYNC-START" : ["RANGER_ADMIN-START", "RANGER_KMS_SERVER-START"],
     "RANGER_KMS_SERVER-START" : ["RANGER_ADMIN-START"],
     "RANGER_KMS_SERVICE_CHECK-SERVICE_CHECK" : ["RANGER_KMS_SERVER-START"],
     "PHOENIX_QUERY_SERVER-START": ["HBASE_MASTER-START"],