You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2015/08/12 03:11:45 UTC

ambari git commit: AMBARI-12727. Ambari agent should support configuration where it does not attempt to download stack scripts from the server (smohanty)

Repository: ambari
Updated Branches:
  refs/heads/trunk 3f607731f -> 38d5eaf0c


AMBARI-12727. Ambari agent should support configuration where it does not attempt to download stack scripts from the server (smohanty)


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

Branch: refs/heads/trunk
Commit: 38d5eaf0c867d0cbd47fe11eca55bb16f7640c52
Parents: 3f60773
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Tue Aug 11 18:11:32 2015 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Tue Aug 11 18:11:32 2015 -0700

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/AmbariConfig.py   |  3 +++
 .../src/main/python/ambari_agent/Controller.py     |  1 +
 .../src/main/python/ambari_agent/FileCache.py      | 17 ++++++++++++++++-
 .../src/test/python/ambari_agent/TestFileCache.py  | 17 +++++++++++++++++
 .../ambari/server/configuration/Configuration.java |  5 +++++
 .../ambari/server/agent/TestHeartbeatHandler.java  |  1 +
 6 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/38d5eaf0/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
index 01a573c..f8f220b 100644
--- a/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
+++ b/ambari-agent/src/main/python/ambari_agent/AmbariConfig.py
@@ -18,6 +18,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
+import logging
 import ConfigParser
 import StringIO
 import hostname
@@ -27,6 +28,7 @@ import os
 
 from ambari_commons import OSConst
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
+logger = logging.getLogger(__name__)
 
 content = """
 
@@ -255,6 +257,7 @@ class AmbariConfig:
         self.add_section(AmbariConfig.AMBARI_PROPERTIES_CATEGORY)
       for k,v in reg_resp[AmbariConfig.AMBARI_PROPERTIES_CATEGORY].items():
         self.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, k, v)
+        logger.info("Updating config property (%s) with value (%s)", k, v)
     pass
 
 def updateConfigServerHostname(configFile, new_host):

http://git-wip-us.apache.org/repos/asf/ambari/blob/38d5eaf0/ambari-agent/src/main/python/ambari_agent/Controller.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Controller.py b/ambari-agent/src/main/python/ambari_agent/Controller.py
index 801b85a..8746172 100644
--- a/ambari-agent/src/main/python/ambari_agent/Controller.py
+++ b/ambari-agent/src/main/python/ambari_agent/Controller.py
@@ -173,6 +173,7 @@ class Controller(threading.Thread):
         self.recovery_manager.update_configuration_from_registration(ret)
         self.config.update_configuration_from_registration(ret)
         logger.debug("Updated config:" + str(self.config))
+
         # always update alert definitions on registration
         self.alert_scheduler_handler.update_definitions(ret)
       except ssl.SSLError:

http://git-wip-us.apache.org/repos/asf/ambari/blob/38d5eaf0/ambari-agent/src/main/python/ambari_agent/FileCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/FileCache.py b/ambari-agent/src/main/python/ambari_agent/FileCache.py
index 5a9318f..fa960e1 100644
--- a/ambari-agent/src/main/python/ambari_agent/FileCache.py
+++ b/ambari-agent/src/main/python/ambari_agent/FileCache.py
@@ -25,6 +25,7 @@ import shutil
 import zipfile
 import urllib2
 import urllib
+from AmbariConfig import AmbariConfig
 
 logger = logging.getLogger()
 
@@ -44,6 +45,7 @@ class FileCache():
   HOST_SCRIPTS_CACHE_DIRECTORY="host_scripts"
   HASH_SUM_FILE=".hash"
   ARCHIVE_NAME="archive.zip"
+  ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY = "agent.auto.cache.update"
 
   BLOCK_SIZE=1024*16
   SOCKET_TIMEOUT=10
@@ -104,6 +106,13 @@ class FileCache():
                                   server_url_prefix)
 
 
+  def auto_cache_update_enabled(self):
+    if self.config and \
+        self.config.has_option(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY) and \
+            self.config.get(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY).lower() == "false":
+      return False
+    return True
+
   def provide_directory(self, cache_path, subdirectory, server_url_prefix):
     """
     Ensures that directory at cache is up-to-date. Throws a CachingException
@@ -113,8 +122,14 @@ class FileCache():
       subdirectory: subpath inside cache
       server_url_prefix: url of "resources" folder at the server
     """
+
     full_path = os.path.join(cache_path, subdirectory)
     logger.debug("Trying to provide directory {0}".format(subdirectory))
+
+    if not self.auto_cache_update_enabled():
+      logger.debug("Auto cache update is disabled.")
+      return full_path
+
     try:
       if full_path not in self.uptodate_paths:
         logger.debug("Checking if update is available for "
@@ -138,7 +153,7 @@ class FileCache():
     except CachingException, e:
       if self.tolerate_download_failures:
         # ignore
-        logger.warn("Error occured during cache update. "
+        logger.warn("Error occurred during cache update. "
                     "Error tolerate setting is set to true, so"
                     " ignoring this error and continuing with current cache. "
                     "Error details: {0}".format(str(e)))

http://git-wip-us.apache.org/repos/asf/ambari/blob/38d5eaf0/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestFileCache.py b/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
index 724124c..d0c987b 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestFileCache.py
@@ -46,9 +46,11 @@ class TestFileCache(TestCase):
     tmpdir = tempfile.gettempdir()
     self.config = ConfigParser.RawConfigParser()
     self.config.add_section('agent')
+    self.config.add_section('agentConfig')
     self.config.set('agent', 'prefix', tmpdir)
     self.config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
     self.config.set('agent', 'tolerate_download_failures', "true")
+    self.config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY, "true")
 
 
   def test_reset(self):
@@ -115,6 +117,21 @@ class TestFileCache(TestCase):
       "('/var/lib/ambari-agent/cache', 'custom_actions', 'server_url_pref')")
     self.assertEquals(res, "dummy value")
 
+  @patch.object(FileCache, "build_download_url")
+  def test_provide_directory_no_update(self, build_download_url_mock):
+    try:
+      self.config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY, "false")
+      fileCache = FileCache(self.config)
+
+      # Test uptodate dirs after start
+      path = os.path.join("cache_path", "subdirectory")
+      res = fileCache.provide_directory("cache_path", "subdirectory",
+                                        "server_url_prefix")
+      self.assertEquals(res, path)
+      self.assertFalse(build_download_url_mock.called)
+    finally:
+      self.config.set(AmbariConfig.AMBARI_PROPERTIES_CATEGORY, FileCache.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY, "true")
+    pass
 
   @patch.object(FileCache, "build_download_url")
   @patch.object(FileCache, "fetch_url")

http://git-wip-us.apache.org/repos/asf/ambari/blob/38d5eaf0/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 87cc7a4..371d5d2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -127,6 +127,8 @@ public class Configuration {
   public static final String CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY = "client.api.ssl.cert_pass_file";
   public static final String CLIENT_API_SSL_CRT_PASS_KEY = "client.api.ssl.crt_pass";
   public static final String CLIENT_API_SSL_KEY_NAME_KEY = "client.api.ssl.key_name";
+  public static final String ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY = "agent.auto.cache.update";
+  public static final String ENABLE_AUTO_AGENT_CACHE_UPDATE_DEFAULT = "true";
   public static final String CHECK_REMOTE_MOUNTS_KEY = "agent.check.remote.mounts";
   public static final String CHECK_REMOTE_MOUNTS_DEFAULT = "true";
   public static final String CHECK_MOUNTS_TIMEOUT_KEY = "agent.check.mounts.timeout";
@@ -530,6 +532,9 @@ public class Configuration {
     agentConfigsMap.put(CHECK_MOUNTS_TIMEOUT_KEY, properties.getProperty(
       CHECK_MOUNTS_TIMEOUT_KEY, CHECK_MOUNTS_TIMEOUT_DEFAULT));
 
+    agentConfigsMap.put(ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY, properties.getProperty(
+        ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY, ENABLE_AUTO_AGENT_CACHE_UPDATE_DEFAULT));
+
     configsMap = new HashMap<String, String>();
     configsMap.putAll(agentConfigsMap);
     configsMap.put(AMBARI_PYTHON_WRAP_KEY, properties.getProperty(

http://git-wip-us.apache.org/repos/asf/ambari/blob/38d5eaf0/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index 15d7904..cb418b4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -914,6 +914,7 @@ public class TestHeartbeatHandler {
     assertTrue("true".equals(config.get(Configuration.CHECK_REMOTE_MOUNTS_KEY)));
     assertTrue(config.containsKey(Configuration.CHECK_MOUNTS_TIMEOUT_KEY));
     assertTrue("0".equals(config.get(Configuration.CHECK_MOUNTS_TIMEOUT_KEY)));
+    assertTrue("true".equals(config.get(Configuration.ENABLE_AUTO_AGENT_CACHE_UPDATE_KEY)));
   }
 
   @Test