浏览代码

AMBARI-18143. Alert on Atlas service after making changes to ZK quorum

Sumit Mohanty 9 年之前
父节点
当前提交
c011f5d48f

+ 47 - 0
ambari-common/src/main/python/ambari_commons/str_utils.py

@@ -89,3 +89,50 @@ def split_on_chunks(text, chunk_max_size):
   chunks.append(chunk[:-1])
   return chunks
 
+
+def string_set_intersection(set_a, set_b, ignore_case=True, sep=","):
+  """
+  Return intersection of two coma-separated sets
+
+  :type set_a str
+  :type set_b str
+  :type ignore_case bool
+  :type sep str
+
+  :rtype set
+  """
+  if set_a is None or set_b is None:
+    return set()
+
+  if ignore_case:
+    set_a = set_a.lower()
+    set_b = set_b.lower()
+
+  set_a = set(set_a.split(sep))
+  set_b = set(set_b.split(sep))
+
+  return set_a & set_b
+
+
+def string_set_equals(set_a, set_b, ignore_case=True, sep=","):
+  """
+  Return True or False based on result of comparison of two string sets
+
+  :type set_a str
+  :type set_b str
+  :type ignore_case bool
+  :type sep str
+
+  :rtype bool
+  """
+  if set_a is None or set_b is None:
+    return False
+
+  if ignore_case:
+    set_a = set_a.lower()
+    set_b = set_b.lower()
+
+  set_a = set(set_a.split(sep))
+  set_b = set(set_b.split(sep))
+
+  return len(set_b) == len(set_a) == len(set_a & set_b)

+ 6 - 2
ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/hbase_regionserver.py

@@ -103,11 +103,15 @@ class HbaseRegionServerDefault(HbaseRegionServer):
 
       if can_apply_permissions:
         kinit_cmd = format("{kinit_path_local} -kt {regionserver_keytab_path} {regionserver_jaas_princ}")
-        permissions_cmd = format("echo \"grant '{metadata_user}', 'RWXCA'\" | hbase shell -n")
+        permissions_cmd = [
+          format("echo \"grant '{metadata_user}', 'RWXCA', '{atlas_graph_storage_hbase_table}'\" | hbase shell -n"),
+          format("echo \"grant '{metadata_user}', 'RWXCA', '{atlas_audit_hbase_tablename}'\" | hbase shell -n"),
+        ]
 
         # no additional logging required, as it supported by checked_call itself
         # re-tries needed to suffer fails on Kerberos wizard as RegionServer update security features status over some time
-        shell.checked_call(format("{kinit_cmd}; {permissions_cmd}"), user=params.hbase_user, tries=10, try_sleep=10)
+        for perm_cmd in permissions_cmd:
+          shell.checked_call(format("{kinit_cmd}; {perm_cmd}"), user=params.hbase_user, tries=10, try_sleep=10)
 
   def start(self, env, upgrade_type=None):
     import params

+ 10 - 2
ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py

@@ -24,6 +24,7 @@ from functions import calc_xmn_from_xms, ensure_unit_for_memory
 
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 from ambari_commons.os_check import OSCheck
+from ambari_commons.str_utils import string_set_intersection
 
 from resource_management.libraries.resources.hdfs_resource import HdfsResource
 from resource_management.libraries.functions import conf_select
@@ -406,5 +407,12 @@ atlas_hosts = default('/clusterHostInfo/atlas_server_hosts', [])
 has_atlas = len(atlas_hosts) > 0
 
 metadata_user = default('/configurations/atlas-env/metadata_user', None)
-atlas_graph_storage_hostname = default('/configurations/application-properties/atlas.graph.storage.hostname', None) if has_atlas else None
-atlas_with_managed_hbase = hbase_zookeeper_quorum == atlas_graph_storage_hostname if has_atlas and atlas_graph_storage_hostname is not None else False
+atlas_graph_storage_hostname = default('/configurations/application-properties/atlas.graph.storage.hostname', None)
+atlas_graph_storage_hbase_table = default('/configurations/application-properties/atlas.graph.storage.hbase.table', None)
+atlas_audit_hbase_tablename = default('/configurations/application-properties/atlas.audit.hbase.tablename', None)
+
+if has_atlas:
+  zk_hosts_matches = string_set_intersection(atlas_graph_storage_hostname, hbase_zookeeper_quorum)
+  atlas_with_managed_hbase = len(zk_hosts_matches) > 0
+else:
+  atlas_with_managed_hbase = False

+ 2 - 1
ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py

@@ -20,6 +20,7 @@ limitations under the License.
 import math
 import traceback
 
+from ambari_commons.str_utils import string_set_equals
 from resource_management.core.logger import Logger
 from resource_management.core.exceptions import Fail
 from resource_management.libraries.functions.get_bare_principal import get_bare_principal
@@ -175,7 +176,7 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
         validationItems.append({"config-name": "atlas.graph.storage.hostname",
                                 "item": self.getErrorItem(
                                     "If HBASE is not installed then the hbase zookeeper quorum configuration must be specified.")})
-      elif application_properties['atlas.graph.storage.hostname'] == hbase_zookeeper_quorum:
+      elif string_set_equals(application_properties['atlas.graph.storage.hostname'], hbase_zookeeper_quorum):
         validationItems.append({"config-name": "atlas.graph.storage.hostname",
                                 "item": self.getWarnItem(
                                     "Atlas is configured to use the HBase installed in this cluster. If you would like Atlas to use another HBase instance, please configure this property and HBASE_CONF_DIR variable in atlas-env appropriately.")})

+ 3 - 2
ambari-server/src/test/python/stacks/2.0.6/HBASE/test_hbase_regionserver.py

@@ -115,7 +115,8 @@ class TestHbaseRegionServer(RMFTestCase):
         }
 
     json_content['configurations']['application-properties'] = {
-        "atlas.graph.storage.hostname": json_content['configurations']['hbase-site']['hbase.zookeeper.quorum']
+        "atlas.graph.storage.hostname": json_content['configurations']['hbase-site']['hbase.zookeeper.quorum'],
+        "atlas.graph.storage.hbase.table": "test"
     }
 
     mock_dicts = {}
@@ -129,7 +130,7 @@ class TestHbaseRegionServer(RMFTestCase):
       mocks_dict=mock_dicts
     )
     permission_apply_call_found = False
-    pattern_search = "/usr/bin/kinit -kt /etc/security/keytabs/hbase.service.keytab hbase/c6401.ambari.apache.org@EXAMPLE.COM; echo \"grant 'atlas', 'RWXCA'\" | hbase shell -n"
+    pattern_search = "/usr/bin/kinit -kt /etc/security/keytabs/hbase.service.keytab hbase/c6401.ambari.apache.org@EXAMPLE.COM; echo \"grant 'atlas', 'RWXCA', 'test'\" | hbase shell -n"
     if "checked_call" in mock_dicts:
         for _call in mock_dicts["checked_call"].call_args_list:
             if len(_call) > 0 and isinstance(_call[0], tuple) and len(_call[0]) > 0 and \