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

ambari git commit: AMBARI-13019: Empty package folders on ambari-server causes corresponding component restart to fail (Nahappan Somasundaram via jluniya)

Repository: ambari
Updated Branches:
  refs/heads/trunk 25fd9a627 -> 1065bc515


AMBARI-13019: Empty package folders on ambari-server causes corresponding component restart to fail (Nahappan Somasundaram via jluniya)


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

Branch: refs/heads/trunk
Commit: 1065bc5155629ce5951c370c5cc74ad849ae222d
Parents: 25fd9a6
Author: Jayush Luniya <jl...@hortonworks.com>
Authored: Fri Sep 18 17:25:38 2015 -0700
Committer: Jayush Luniya <jl...@hortonworks.com>
Committed: Fri Sep 18 17:25:38 2015 -0700

----------------------------------------------------------------------
 .../server/stack/StackServiceDirectory.java     | 16 ++++++++++----
 .../python/ambari_server/resourceFilesKeeper.py |  8 +++++--
 .../src/test/python/TestResourceFilesKeeper.py  | 23 +++++++++++++++++++-
 3 files changed, 40 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1065bc51/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
index 92455fe..d27e52a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackServiceDirectory.java
@@ -63,12 +63,20 @@ public class StackServiceDirectory extends ServiceDirectory {
 
     File absPackageDir = new File(getAbsolutePath() + File.separator + PACKAGE_FOLDER_NAME);
     if (absPackageDir.isDirectory()) {
-      packageDir = absPackageDir.getPath().substring(stackDir.getParentFile().getParentFile().getPath().length() + 1);
-      LOG.debug(String.format("Service package folder for service %s for stack %s has been resolved to %s",
-          serviceDir.getName(), stackId, packageDir));
+      String[] files = absPackageDir.list();
+      int fileCount = files.length;
+      if (fileCount > 0) {
+        packageDir = absPackageDir.getPath().substring(stackDir.getParentFile().getParentFile().getPath().length() + 1);
+        LOG.debug(String.format("Service package folder for service %s for stack %s has been resolved to %s",
+                serviceDir.getName(), stackId, packageDir));
+      }
+      else {
+        LOG.debug(String.format("Service package folder %s for service %s for stack %s is empty.",
+                absPackageDir, serviceDir.getName(), stackId));
+      }
     } else {
       LOG.debug(String.format("Service package folder %s for service %s for stack %s does not exist.",
-          absPackageDir, serviceDir.getName(), stackId));
+              absPackageDir, serviceDir.getName(), stackId));
     }
     parseMetaInfoFile();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1065bc51/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py b/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
index c9bca73..fb429d0 100644
--- a/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
+++ b/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
@@ -152,8 +152,12 @@ class ResourceFilesKeeper():
     if cur_hash != saved_hash:
       if not self.nozip:
         self.zip_directory(directory, skip_empty_directory)
-      self.write_hash_sum(directory, cur_hash)
-
+      # Skip generation of .hash file is directory is empty
+      if (skip_empty_directory and not os.listdir(directory)):
+        self.dbg_out("Empty directory. Skipping generation of hash file for {0}".format(directory))
+      else:
+        self.write_hash_sum(directory, cur_hash)
+      pass
 
   def count_hash_sum(self, directory):
     """

http://git-wip-us.apache.org/repos/asf/ambari/blob/1065bc51/ambari-server/src/test/python/TestResourceFilesKeeper.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestResourceFilesKeeper.py b/ambari-server/src/test/python/TestResourceFilesKeeper.py
index 1fefa7a..8a06e07 100644
--- a/ambari-server/src/test/python/TestResourceFilesKeeper.py
+++ b/ambari-server/src/test/python/TestResourceFilesKeeper.py
@@ -165,13 +165,16 @@ class TestResourceFilesKeeper(TestCase):
     except Exception, e:
       self.fail('Unexpected exception thrown:' + str(e))
 
+  @patch("os.listdir")
   @patch.object(ResourceFilesKeeper, "count_hash_sum")
   @patch.object(ResourceFilesKeeper, "read_hash_sum")
   @patch.object(ResourceFilesKeeper, "zip_directory")
   @patch.object(ResourceFilesKeeper, "write_hash_sum")
   def test_update_directory_archive(self, write_hash_sum_mock,
                                     zip_directory_mock, read_hash_sum_mock,
-                                    count_hash_sum_mock):
+                                    count_hash_sum_mock,
+                                    os_listdir_mock):
+    os_listdir_mock.return_value = ['file1', 'dir1']
     # Test situation when there is no saved directory hash
     read_hash_sum_mock.return_value = None
     count_hash_sum_mock.return_value = self.YA_HASH
@@ -245,6 +248,24 @@ class TestResourceFilesKeeper(TestCase):
     self.assertTrue(count_hash_sum_mock.called)
     self.assertFalse(zip_directory_mock.called)
     self.assertTrue(write_hash_sum_mock.called)
+
+    # Test empty directory
+    read_hash_sum_mock.reset_mock()
+    count_hash_sum_mock.reset_mock()
+    zip_directory_mock.reset_mock()
+    write_hash_sum_mock.reset_mock()
+
+    # If the input directory is empty, then write_hash_sum() should not be called
+    os_listdir_mock.return_value = [] # Empty dir
+    zip_directory_mock.side_effect = None
+    read_hash_sum_mock.return_value = None # hash read from .hash file
+    resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.SOME_PATH)
+    resource_files_keeper.update_directory_archive(self.SOME_PATH)
+
+    self.assertTrue(read_hash_sum_mock.called)
+    self.assertTrue(count_hash_sum_mock.called)
+    self.assertTrue(zip_directory_mock.called)
+    self.assertFalse(write_hash_sum_mock.called)
     pass