瀏覽代碼

AMBARI-11972. Atlas and Kafka Start fail with non-root agent (aonishuk)

Andrew Onishuk 10 年之前
父節點
當前提交
9ca9a1deb3
共有 16 個文件被更改,包括 45 次插入136 次删除
  1. 1 1
      ambari-common/src/main/python/resource_management/core/source.py
  2. 3 8
      ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/metadata.py
  3. 0 39
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/atlas_plugin_utils.py
  4. 2 3
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hcat_client.py
  5. 4 8
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive.py
  6. 0 3
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_client.py
  7. 0 4
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py
  8. 0 4
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_server.py
  9. 5 2
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
  10. 15 11
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/setup_atlas_hive.py
  11. 2 4
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_server.py
  12. 5 6
      ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/kafka.py
  13. 0 1
      ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/kafka_broker.py
  14. 0 32
      ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/properties_config.py
  15. 3 0
      ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/service_check.py
  16. 5 10
      ambari-server/src/test/python/stacks/2.3/ATLAS/test_metadata_server.py

+ 1 - 1
ambari-common/src/main/python/resource_management/core/source.py

@@ -55,7 +55,7 @@ class Source(object):
   
   def __eq__(self, other):
     return (isinstance(other, self.__class__)
-        and self.get_content() == other.get_content())
+        and ((self.name.startswith(os.sep) and self.name == other.name) or self.get_content() == other.get_content()))
 
 
 class StaticFile(Source):

+ 3 - 8
ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/metadata.py

@@ -17,8 +17,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 """
-import os
-import shutil
 from resource_management import Directory, Fail, Logger, File, \
     InlineTemplate, PropertiesFile, StaticFile
 from resource_management.libraries.functions import format
@@ -67,12 +65,9 @@ def metadata():
               recursive=True
     )
 
-    metadata_war_file = format('{params.metadata_home}/server/webapp/atlas.war')
-    if not os.path.isfile(metadata_war_file):
-        raise Fail("Unable to copy {0} because it does not exist".format(metadata_war_file))
-
-    Logger.info("Copying {0} to {1}".format(metadata_war_file, params.expanded_war_dir))
-    shutil.copy2(metadata_war_file, params.expanded_war_dir)
+    File(format("{expanded_war_dir}/atlas.war"),
+         content = StaticFile(format('{metadata_home}/server/webapp/atlas.war'))
+    )
 
     PropertiesFile(format('{conf_dir}/application.properties'),
          properties = params.application_properties,

+ 0 - 39
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/atlas_plugin_utils.py

@@ -1,39 +0,0 @@
-#!/usr/bin/env python
-"""
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-"""
-from resource_management import Script
-from resource_management.core import Logger
-
-
-def configure_for_plugin(command_data_file):
-    import json
-    savedConfig = Script.get_config()
-    if savedConfig['hostLevelParams'].get('custom_command', '') == 'RESTART':
-        try:
-            with open(command_data_file) as f:
-                pass
-                Script.config = json.load(f)
-                Script.config['hostLevelParams']['package_list'] = \
-                    "[{\"name\":\"atlas-metadata*-hive-plugin\"}]"
-
-        except IOError:
-            Logger.error("Can not read json file with command parameters: ")
-
-    return savedConfig
-

+ 2 - 3
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hcat_client.py

@@ -21,23 +21,22 @@ limitations under the License.
 import sys
 from resource_management import *
 from hcat import hcat
+from setup_atlas_hive import setup_atlas_hive
 from ambari_commons import OSConst
 from ambari_commons.os_family_impl import OsFamilyImpl
-from atlas_plugin_utils import configure_for_plugin
 
 
 class HCatClient(Script):
   def install(self, env):
     import params
-    savedConfig = configure_for_plugin(self.command_data_file)
     self.install_packages(env, exclude_packages=params.hive_exclude_packages)
-    Script.config = savedConfig
     self.configure(env)
 
   def configure(self, env):
     import params
     env.set_params(params)
     hcat()
+    setup_atlas_hive()
 
   def status(self, env):
     raise ClientComponentHasNoStatus()

+ 4 - 8
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive.py

@@ -21,7 +21,6 @@ limitations under the License.
 import os
 import glob
 from urlparse import urlparse
-from resource_management import PropertiesFile
 
 from resource_management.libraries.script.script import Script
 from resource_management.libraries.resources.hdfs_resource import HdfsResource
@@ -39,6 +38,8 @@ from resource_management.core.exceptions import Fail
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
 from ambari_commons import OSConst
 
+from setup_atlas_hive import setup_atlas_hive
+
 
 @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
 def hive(name=None):
@@ -213,13 +214,8 @@ def hive(name=None):
             group=params.user_group,
             mode=0644)
 
-  if params.atlas_hosts:
-      PropertiesFile(format('{hive_config_dir}/client.properties'),
-                     properties = params.atlas_client_props,
-                     owner = params.hive_user,
-                     group = params.user_group,
-                     mode = 0644)
-
+  setup_atlas_hive()
+  
   if params.hive_specific_configs_supported and name == 'hiveserver2':
     XmlConfig("hiveserver2-site.xml",
               conf_dir=params.hive_server_conf_dir,

+ 0 - 3
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_client.py

@@ -24,14 +24,11 @@ from resource_management.libraries.functions import hdp_select
 from hive import hive
 from ambari_commons.os_family_impl import OsFamilyImpl
 from ambari_commons import OSConst
-from atlas_plugin_utils import configure_for_plugin
 
 class HiveClient(Script):
   def install(self, env):
     import params
-    savedConfig = configure_for_plugin(self.command_data_file)
     self.install_packages(env, exclude_packages=params.hive_exclude_packages)
-    Script.config = savedConfig
     self.configure(env)
 
   def status(self, env):

+ 0 - 4
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py

@@ -38,7 +38,6 @@ from hive import jdbc_connector
 from hive_service import hive_service
 from ambari_commons.os_family_impl import OsFamilyImpl
 from ambari_commons import OSConst
-from atlas_plugin_utils import configure_for_plugin
 
 # the legacy conf.server location in HDP 2.2
 LEGACY_HIVE_SERVER_CONF = "/etc/hive/conf.server"
@@ -62,9 +61,6 @@ class HiveMetastore(Script):
   def configure(self, env):
     import params
     env.set_params(params)
-    savedConfig = configure_for_plugin(self.command_data_file)
-    self.install_packages(env, exclude_packages = params.hive_exclude_packages)
-    Script.config = savedConfig
     hive(name = 'metastore')
 
 

+ 0 - 4
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_server.py

@@ -36,7 +36,6 @@ if OSCheck.is_windows_family():
   from resource_management.libraries.functions.windows_service_utils import check_windows_service_status
 from setup_ranger_hive import setup_ranger_hive
 from ambari_commons.os_family_impl import OsFamilyImpl
-from atlas_plugin_utils import configure_for_plugin
 from resource_management.core.logger import Logger
 
 import hive_server_upgrade
@@ -52,9 +51,6 @@ class HiveServer(Script):
   def configure(self, env):
     import params
     env.set_params(params)
-    savedConfig = configure_for_plugin(self.command_data_file)
-    self.install_packages(env, exclude_packages=params.hive_exclude_packages)
-    Script.config = savedConfig
     hive(name='hiveserver2')
 
 

+ 5 - 2
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py

@@ -354,9 +354,12 @@ hive_site_config = dict(config['configurations']['hive-site'])
 ########################################################
 
 atlas_hosts = default('/clusterHostInfo/atlas_server_hosts', [])
+has_atlas = len(atlas_hosts) > 0
 classpath_addition = ""
-if not atlas_hosts:
-  hive_exclude_packages.append('atlas-metadata*-hive-plugin')
+atlas_plugin_package = "atlas-metadata*-hive-plugin"
+
+if not has_atlas:
+  hive_exclude_packages.append(atlas_plugin_package)
 else:
   # hive-site
   hive_site_config['hive.cluster.name'] = config['clusterName']

+ 15 - 11
ambari-server/src/main/resources/common-services/ATLAS/0.1.0.2.3/package/scripts/properties_config.py → ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/setup_atlas_hive.py

@@ -18,16 +18,20 @@ limitations under the License.
 
 """
 
-from resource_management.core import source, File
-from resource_management.libraries.functions import format
+from resource_management.libraries.resources.properties_file import PropertiesFile
+from resource_management.core.resources.packaging import Package
+from resource_management.libraries.functions.format import format
 
+def setup_atlas_hive():
+  import params
+  
+  if params.has_atlas:
+    if not params.host_sys_prepped:
+      Package(params.atlas_plugin_package, # FIXME HACK: install the package during RESTART/START when install_packages is not triggered.
+      )
 
-def properties_inline_template(configurations):
-  return source.InlineTemplate('''{% for key, value in configurations_dict.items() %}{{ key }}={{ value }}
-{% endfor %}''', configurations_dict=configurations)
-
-def properties_config(filename, configurations = None, conf_dir = None,
-                      mode = None, owner = None, group = None):
-    config_content = properties_inline_template(configurations)
-    File (format("{conf_dir}/{filename}"), content = config_content, owner = owner,
-          group = group, mode = mode)
+    PropertiesFile(format('{hive_config_dir}/client.properties'),
+                   properties = params.atlas_client_props,
+                   owner = params.hive_user,
+                   group = params.user_group,
+                   mode = 0644)

+ 2 - 4
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_server.py

@@ -26,9 +26,9 @@ from resource_management.libraries.functions.security_commons import build_expec
   FILE_TYPE_XML
 from webhcat import webhcat
 from webhcat_service import webhcat_service
+from setup_atlas_hive import setup_atlas_hive
 from ambari_commons import OSConst
 from ambari_commons.os_family_impl import OsFamilyImpl
-from atlas_plugin_utils import configure_for_plugin
 
 
 class WebHCatServer(Script):
@@ -50,10 +50,8 @@ class WebHCatServer(Script):
   def configure(self, env):
     import params
     env.set_params(params)
-    savedConfig = configure_for_plugin(self.command_data_file)
-    self.install_packages(env, exclude_packages=params.hive_exclude_packages)
-    Script.config = savedConfig
     webhcat()
+    setup_atlas_hive()
 
 
 @OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY)

+ 5 - 6
ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/kafka.py

@@ -19,7 +19,7 @@ limitations under the License.
 """
 
 from resource_management import *
-from properties_config import properties_config
+from resource_management.libraries.resources.properties_file import PropertiesFile
 from resource_management.libraries.resources.template_config import TemplateConfig
 import sys, os
 from copy import deepcopy
@@ -67,13 +67,12 @@ def kafka():
               group=params.user_group,
               recursive=True)
 
-    conf_dir = params.conf_dir
-    properties_config("server.properties",
-                      conf_dir=params.conf_dir,
-                      configurations=kafka_server_config,
+    PropertiesFile("server.properties",
+                      dir=params.conf_dir,
+                      properties=kafka_server_config,
                       owner=params.kafka_user,
                       group=params.user_group,
-                      brokerid=brokerid)
+    )
 
     File(format("{conf_dir}/kafka-env.sh"),
           owner=params.kafka_user,

+ 0 - 1
ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/kafka_broker.py

@@ -31,7 +31,6 @@ class KafkaBroker(Script):
 
   def install(self, env):
     self.install_packages(env)
-    self.configure(env)
 
   def configure(self, env):
     import params

+ 0 - 32
ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/properties_config.py

@@ -1,32 +0,0 @@
-#!/usr/bin/env python
-"""
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-"""
-
-import re
-from resource_management import *
-
-def properties_inline_template(configurations):
-  return source.InlineTemplate('''{% for key, value in configurations_dict.items() %}{{ key }}={{ value }}
-{% endfor %}''', configurations_dict=configurations)
-
-def properties_config(filename, configurations = None, conf_dir = None,
-                      mode = None, owner = None, group = None, brokerid = None):
-    config_content = properties_inline_template(configurations)
-    File (format("{conf_dir}/{filename}"), content = config_content, owner = owner,
-          group = group, mode = mode)

+ 3 - 0
ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/service_check.py

@@ -47,6 +47,9 @@ class ServiceCheck(Script):
     kafka_config = {}
     with open(params.conf_dir+"/server.properties", "r") as conf_file:
       for line in conf_file:
+        if line.startswith("#") or not line.strip():
+          continue 
+        
         key,value = line.split("=")
         kafka_config[key] = value.replace("\n","")
     

+ 5 - 10
ambari-server/src/test/python/stacks/2.3/ATLAS/test_metadata_server.py

@@ -64,6 +64,9 @@ class TestMetadataServer(RMFTestCase):
                                 cd_access='a',
                                 mode=0644
       )
+      self.assertResourceCalled('File', '/var/lib/atlas/server/webapp/atlas.war',
+          content = StaticFile('/usr/hdp/current/atlas-server/server/webapp/atlas.war'),
+      )
       appprops =  dict(self.getConfig()['configurations'][
           'application-properties'])
       appprops['atlas.http.authentication.kerberos.name.rules'] = ' \\ \n'.join(appprops['atlas.http.authentication.kerberos.name.rules'].splitlines())
@@ -91,11 +94,7 @@ class TestMetadataServer(RMFTestCase):
                                 mode=0644,
       )
 
-  @patch("shutil.copy2", new = MagicMock())
-  @patch("os.path.isfile")
-  def test_configure_default(self, isfile_mock):
-    isfile_mock.return_value = True
-
+  def test_configure_default(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/metadata_server.py",
                        classname = "MetadataServer",
                        command = "configure",
@@ -107,11 +106,7 @@ class TestMetadataServer(RMFTestCase):
     self.configureResourcesCalled()
     self.assertNoMoreResources()
 
-  @patch("shutil.copy2", new = MagicMock())
-  @patch("os.path.isfile")
-  def test_start_default(self, isfile_mock):
-    isfile_mock.return_value = True
-
+  def test_start_default(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/metadata_server.py",
                        classname = "MetadataServer",
                        command = "start",