You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2014/02/21 17:03:05 UTC

git commit: AMBARI-4702. Create hash files on agent rpm creation (dlysnichenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk d6d048d4a -> 54a9df72a


AMBARI-4702. Create hash files on agent rpm creation (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 54a9df72aee7229e411a4f5a39f7a36abc96ae1b
Parents: d6d048d
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Feb 21 17:52:51 2014 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Feb 21 17:52:51 2014 +0200

----------------------------------------------------------------------
 ambari-agent/pom.xml                            | 61 ++++++++++++++++----
 .../python/ambari_server/resourceFilesKeeper.py | 23 +++++++-
 .../src/test/python/TestResourceFilesKeeper.py  | 17 +++++-
 3 files changed, 87 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/54a9df72/ambari-agent/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-agent/pom.xml b/ambari-agent/pom.xml
index cdfabfc..600d17d 100644
--- a/ambari-agent/pom.xml
+++ b/ambari-agent/pom.xml
@@ -45,6 +45,9 @@
     <ruby.tar>http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.15/repos/centos6/ruby-1.8.7-p370.tar.gz</ruby.tar>
     <lib.dir>/usr/lib/ambari-agent/lib</lib.dir>
     <python.ver>python &gt;= 2.6</python.ver>
+    <ambari.server.module>../ambari-server</ambari.server.module>
+    <target.cache.dir>${project.build.directory}/cache/</target.cache.dir>
+    <resource.keeper.script>${ambari.server.module}/src/main/python/ambari_server/resourceFilesKeeper.py</resource.keeper.script>
   </properties>
   <profiles>
     <profile>
@@ -135,6 +138,7 @@
             </goals>
           </execution>
           <execution>
+            <!-- TODO: Looks like section is unused, maybe remove? -->
             <configuration>
               <executable>python2.6</executable>
               <workingDirectory>target/ambari-agent-${project.version}</workingDirectory>
@@ -153,6 +157,24 @@
               <goal>exec</goal>
             </goals>
           </execution>
+          <execution>
+            <configuration>
+              <executable>python2.6</executable>
+              <workingDirectory>${basedir}</workingDirectory>
+              <arguments>
+                <argument>${resource.keeper.script}</argument>
+                <argument>${target.cache.dir}</argument>
+              </arguments>
+              <environmentVariables>
+                <PYTHONPATH>target/ambari-agent-${project.version}:$PYTHONPATH</PYTHONPATH>
+              </environmentVariables>
+            </configuration>
+            <id>generate-hash-files</id>
+            <phase>package</phase>
+            <goals>
+              <goal>exec</goal>
+            </goals>
+          </execution>
         </executions>
       </plugin>
       <plugin>
@@ -336,22 +358,13 @@
               </sources>
             </mapping>
             <mapping>
-              <directory>/var/lib/ambari-agent/cache/stacks</directory>
-              <sources>
-                <source>
-                  <location>../ambari-server/src/main/resources/stacks</location>
-                </source>
-              </sources>
-            </mapping>
-            <mapping>
-              <!-- custom actions root-->
-              <directory>/var/lib/ambari-agent/cache/custom_actions</directory>
+              <directory>/var/lib/ambari-agent/cache</directory>
               <filemode>755</filemode>
               <username>root</username>
               <groupname>root</groupname>
               <sources>
                 <source>
-                  <location>../ambari-server/src/main/resources/custom_actions</location>
+                  <location>${target.cache.dir}</location>
                 </source>
               </sources>
             </mapping>
@@ -392,6 +405,32 @@
         </executions>
       </plugin>
       <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.6</version>
+        <executions>
+          <execution>
+            <id>copy-resources</id>
+            <phase>prepare-package</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${target.cache.dir}</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>${ambari.server.module}/src/main/resources</directory>
+                  <includes>
+                    <include>stacks/**/*</include>
+                    <include>custom_actions/**/*</include>
+                  </includes>
+                  <filtering>false</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
         <configuration>

http://git-wip-us.apache.org/repos/asf/ambari/blob/54a9df72/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 92cab3d..ba2fdf2 100644
--- a/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
+++ b/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
@@ -53,9 +53,13 @@ class ResourceFilesKeeper():
   # Change that to True to see debug output at stderr
   DEBUG=False
 
-  def __init__(self, resources_dir, verbose=False):
+  def __init__(self, resources_dir, verbose=False, nozip=False):
+    """
+      nozip = create only hash files and skip creating zip archives
+    """
     self.resources_dir = resources_dir
     self.verbose = verbose
+    self.nozip = nozip
 
 
   def perform_housekeeping(self):
@@ -116,7 +120,8 @@ class ResourceFilesKeeper():
     cur_hash = self.count_hash_sum(directory)
     saved_hash = self.read_hash_sum(directory)
     if cur_hash != saved_hash:
-      self.zip_directory(directory)
+      if not self.nozip:
+        self.zip_directory(directory)
       self.write_hash_sum(directory, cur_hash)
 
 
@@ -256,3 +261,17 @@ class ResourceFilesKeeper():
     return None
 
 
+def main(argv=None):
+  """
+  This method is called by maven during rpm creation.
+  Params:
+    1: Path to resources root directory
+  """
+  path = argv[1]
+  resource_files_keeper = ResourceFilesKeeper(path, nozip=True)
+  resource_files_keeper.perform_housekeeping()
+
+
+if __name__ == '__main__':
+  main(sys.argv)
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/54a9df72/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 6ec8436..5c9e30f 100644
--- a/ambari-server/src/test/python/TestResourceFilesKeeper.py
+++ b/ambari-server/src/test/python/TestResourceFilesKeeper.py
@@ -178,6 +178,21 @@ class TestResourceFilesKeeper(TestCase):
     self.assertTrue(zip_directory_mock.called)
     self.assertFalse(write_hash_sum_mock.called)
 
+    read_hash_sum_mock.reset_mock()
+    count_hash_sum_mock.reset_mock()
+    zip_directory_mock.reset_mock()
+    write_hash_sum_mock.reset_mock()
+
+    # Test nozip option
+    read_hash_sum_mock.return_value = None
+    count_hash_sum_mock.return_value = self.YA_HASH
+    resource_files_keeper = ResourceFilesKeeper(self.SOME_PATH, nozip=True)
+    resource_files_keeper.update_directory_archive(self.SOME_PATH)
+    self.assertTrue(read_hash_sum_mock.called)
+    self.assertTrue(count_hash_sum_mock.called)
+    self.assertFalse(zip_directory_mock.called)
+    self.assertTrue(write_hash_sum_mock.called)
+
 
   def test_count_hash_sum(self):
     # Test normal flow
@@ -316,4 +331,4 @@ class TestResourceFilesKeeper(TestCase):
 
 
   def keeper_exc_side_effect(self, *a):
-    raise KeeperException("horrible_keeper_exc")
\ No newline at end of file
+    raise KeeperException("horrible_keeper_exc")