ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [19/22] ambari git commit: AMBARI-20974: Ambari fails to start due to NPE after installation of HDF mpack (mradhakrishnan)
Date Wed, 10 May 2017 13:37:42 GMT
AMBARI-20974: Ambari fails to start due to NPE after installation of HDF mpack (mradhakrishnan)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 4dd94e17203b5c4a52991a23724cebb45f98852a
Parents: 6e1367d
Author: Madhuvanthi Radhakrishnan <mradhakrishnan@hortonworks.com>
Authored: Tue May 9 22:29:18 2017 -0700
Committer: Madhuvanthi Radhakrishnan <mradhakrishnan@hortonworks.com>
Committed: Tue May 9 22:29:18 2017 -0700

----------------------------------------------------------------------
 .../main/python/ambari_server/setupMpacks.py    | 39 +++++++++++++++++++-
 ambari-server/src/test/python/TestMpacks.py     | 17 ++++++---
 2 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4dd94e17/ambari-server/src/main/python/ambari_server/setupMpacks.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupMpacks.py b/ambari-server/src/main/python/ambari_server/setupMpacks.py
index 04b96f5..1bb7a70 100755
--- a/ambari-server/src/main/python/ambari_server/setupMpacks.py
+++ b/ambari-server/src/main/python/ambari_server/setupMpacks.py
@@ -29,7 +29,7 @@ from ambari_server.serverClassPath import ServerClassPath
 from ambari_commons.exceptions import FatalException
 from ambari_commons.inet_utils import download_file
 from ambari_commons.logging_utils import print_info_msg, print_error_msg, print_warning_msg
-from ambari_commons.os_utils import copy_file, run_os_command
+from ambari_commons.os_utils import copy_file, run_os_command, change_owner, set_file_permissions
 from ambari_server.serverConfiguration import get_ambari_properties, get_ambari_version,
get_stack_location, \
   get_common_services_location, get_mpacks_staging_location, get_server_temp_location, get_extension_location,
\
   get_java_exe_path, read_ambari_user, parse_properties_file, JDBC_DATABASE_PROPERTY, get_dashboard_location
@@ -243,6 +243,7 @@ def create_symlink_using_path(src_path, dest_link, force=False):
   """
   if force and os.path.islink(dest_link):
     sudo.unlink(dest_link)
+
   sudo.symlink(src_path, dest_link)
   print_info_msg("Symlink: " + dest_link)
 
@@ -718,24 +719,39 @@ def _install_mpack(options, replay_mode=False, is_upgrade=False):
     validate_purge(options, purge_resources, tmp_root_dir, mpack_metadata, replay_mode)
     purge_stacks_and_mpacks(purge_resources, replay_mode)
 
+  adjust_ownership_list = []
+  change_ownership_list = []
+
   # Get ambari mpack properties
   stack_location, extension_location, service_definitions_location, mpacks_staging_location,
dashboard_location = get_mpack_properties()
   mpacks_cache_location = os.path.join(mpacks_staging_location, MPACKS_CACHE_DIRNAME)
   # Create directories
   if not os.path.exists(stack_location):
     sudo.makedir(stack_location, 0755)
+  adjust_ownership_list.append((stack_location, "0755", "{0}", True))
+  change_ownership_list.append((stack_location,"{0}",True))
   if not os.path.exists(extension_location):
     sudo.makedir(extension_location, 0755)
+  adjust_ownership_list.append((extension_location, "0755", "{0}", True))
+  change_ownership_list.append((extension_location,"{0}",True))
   if not os.path.exists(service_definitions_location):
     sudo.makedir(service_definitions_location, 0755)
+  adjust_ownership_list.append((service_definitions_location, "0755", "{0}", True))
+  change_ownership_list.append((service_definitions_location,"{0}",True))
   if not os.path.exists(mpacks_staging_location):
     sudo.makedir(mpacks_staging_location, 0755)
+  adjust_ownership_list.append((mpacks_staging_location, "0755", "{0}", True))
+  change_ownership_list.append((mpacks_staging_location,"{0}",True))
   if not os.path.exists(mpacks_cache_location):
     sudo.makedir(mpacks_cache_location, 0755)
+  adjust_ownership_list.append((mpacks_cache_location, "0755", "{0}", True))
+  change_ownership_list.append((mpacks_cache_location,"{0}",True))
   if not os.path.exists(dashboard_location):
     sudo.makedir(dashboard_location, 0755)
     sudo.makedir(os.path.join(dashboard_location, GRAFANA_DASHBOARDS_DIRNAME), 0755)
     sudo.makedir(os.path.join(dashboard_location, SERVICE_METRICS_DIRNAME), 0755)
+  adjust_ownership_list.append((dashboard_location, "0755", "{0}", True))
+  change_ownership_list.append((dashboard_location,"{0}",True))
 
   # Stage management pack (Stage at /var/lib/ambari-server/resources/mpacks/mpack_name-mpack_version)
   mpack_name = mpack_metadata.name
@@ -780,7 +796,26 @@ def _install_mpack(options, replay_mode=False, is_upgrade=False):
     else:
       print_info_msg("Unknown artifact {0} of type {1}".format(artifact_name, artifact_type))
 
-  print_info_msg("Management pack {0}-{1} successfully installed!".format(mpack_name, mpack_version))
+  ambari_user = read_ambari_user()
+
+  # This is required when a non-admin user is configured to setup ambari-server
+  print_info_msg("Adjusting file permissions and ownerships")
+  for pack in adjust_ownership_list:
+      file = pack[0]
+      mod = pack[1]
+      user = pack[2].format(ambari_user)
+      recursive = pack[3]
+      logger.info("Setting file permissions: {0} {1} {2} {3}".format(file, mod, user, recursive))
+      set_file_permissions(file, mod, user, recursive)
+
+  for pack in change_ownership_list:
+      path = pack[0]
+      user = pack[1].format(ambari_user)
+      recursive = pack[2]
+      logger.info("Changing ownership: {0} {1} {2}".format(path, user, recursive))
+      change_owner(path, user, recursive)
+
+  print_info_msg("Management pack {0}-{1} successfully installed! Please restart ambari-server.".format(mpack_name,
mpack_version))
   return mpack_metadata, mpack_name, mpack_version, mpack_staging_dir, mpack_archive_path
 
 def _execute_hook(mpack_metadata, hook_name, base_dir):

http://git-wip-us.apache.org/repos/asf/ambari/blob/4dd94e17/ambari-server/src/test/python/TestMpacks.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestMpacks.py b/ambari-server/src/test/python/TestMpacks.py
index 32db005..f9ae39c 100644
--- a/ambari-server/src/test/python/TestMpacks.py
+++ b/ambari-server/src/test/python/TestMpacks.py
@@ -269,7 +269,8 @@ class TestMpacks(TestCase):
   @patch("ambari_server.setupMpacks.download_mpack")
   @patch("ambari_server.setupMpacks.run_os_command")
   @patch("ambari_server.setupMpacks.validate_purge")
-  def test_install_stack_mpack(self, validate_purge_mock, run_os_command_mock, download_mpack_mock,
expand_mpack_mock, purge_stacks_and_mpacks_mock,
+  @patch("ambari_server.setupMpacks.set_file_permissions")
+  def test_install_stack_mpack(self, set_file_permissions_mock, validate_purge_mock, run_os_command_mock,
download_mpack_mock, expand_mpack_mock, purge_stacks_and_mpacks_mock,
                                      add_replay_log_mock, get_ambari_properties_mock, get_ambari_version_mock,
                                      create_symlink_mock, os_mkdir_mock, shutil_move_mock,
os_path_exists_mock):
     options = self._create_empty_options_mock()
@@ -415,7 +416,9 @@ class TestMpacks(TestCase):
   @patch("ambari_server.setupMpacks.add_replay_log")
   @patch("ambari_server.setupMpacks.expand_mpack")
   @patch("ambari_server.setupMpacks.download_mpack")
-  def test_install_extension_mpack(self, download_mpack_mock, expand_mpack_mock, add_replay_log_mock,
+  @patch("ambari_server.setupMpacks.set_file_permissions")
+
+  def test_install_extension_mpack(self, set_file_permissions_mock, download_mpack_mock,
expand_mpack_mock, add_replay_log_mock,
       purge_stacks_and_mpacks_mock, get_ambari_properties_mock, get_ambari_version_mock,
       create_symlink_mock, os_mkdir_mock, shutil_move_mock, os_path_exists_mock):
     options = self._create_empty_options_mock()
@@ -490,10 +493,11 @@ class TestMpacks(TestCase):
   @patch("ambari_server.setupMpacks.purge_stacks_and_mpacks")
   @patch("ambari_server.setupMpacks.expand_mpack")
   @patch("ambari_server.setupMpacks.download_mpack")
-  def test_install_addon_service_mpack(self, download_mpack_mock, expand_mpack_mock, purge_stacks_and_mpacks_mock,
+  @patch("ambari_server.setupMpacks.set_file_permissions")
+  def test_install_addon_service_mpack(self, set_file_permissions_mock, download_mpack_mock,
expand_mpack_mock, purge_stacks_and_mpacks_mock,
                                        add_replay_log_mock, get_ambari_properties_mock, get_ambari_version_mock,
                                        create_symlink_mock, os_mkdir_mock, shutil_move_mock,os_symlink_mock,
-                                       os_path_isdir_mock, os_path_exists_mock):
+                                       os_path_isdir_mock, os_path_exists_mock ):
     options = self._create_empty_options_mock()
     options.mpack_path = "/path/to/myservice.tar.gz"
     options.purge = False
@@ -580,7 +584,9 @@ class TestMpacks(TestCase):
   @patch("ambari_server.setupMpacks.expand_mpack")
   @patch("ambari_server.setupMpacks.download_mpack")
   @patch("ambari_server.setupMpacks.run_os_command")
-  def test_upgrade_stack_mpack(self, run_os_command_mock, download_mpack_mock, expand_mpack_mock,
purge_stacks_and_mpacks_mock,
+  @patch("ambari_server.setupMpacks.set_file_permissions")
+
+  def test_upgrade_stack_mpack(self, set_file_permissions_mock, run_os_command_mock, download_mpack_mock,
expand_mpack_mock, purge_stacks_and_mpacks_mock,
                                _uninstall_mpack_mock, add_replay_log_mock, get_ambari_properties_mock,
                                get_ambari_version_mock, create_symlink_mock, os_mkdir_mock,
shutil_move_mock,
                                os_path_exists_mock, create_symlink_using_path_mock):
@@ -590,6 +596,7 @@ class TestMpacks(TestCase):
     expand_mpack_mock.side_effect = ["mpacks/mystack-ambari-mpack-1.0.0.1", "mpacks/mystack-ambari-mpack-1.0.0.1"]
     get_ambari_version_mock.return_value = "2.4.0.0"
     run_os_command_mock.return_value = (0, "", "")
+
     mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY]
     os_path_exists_mock.side_effect = [True, True, True, True, True, True, True, True, True,
True,
                                        True, True, True, True, True, True, True, False, False,
True,


Mime
View raw message