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 2013/11/01 16:28:21 UTC

[10/15] git commit: AMBARI-3660. Resource management. Fix sibstitution doesn't work in Template, StaticFile, InlineTemplate, DownloadSource arguments (Andrew Onischuk via dlysnichenko)

AMBARI-3660. Resource management. Fix sibstitution doesn't work in Template, StaticFile, InlineTemplate, DownloadSource arguments (Andrew Onischuk via dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 87ef3f4adeaa5134cd3bfacb90587630b2b4600b
Parents: 267239e
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Nov 1 17:18:13 2013 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Nov 1 17:18:13 2013 +0200

----------------------------------------------------------------------
 .../python/resource_management/core/source.py   | 32 +++++++++++---------
 1 file changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/87ef3f4a/ambari-agent/src/main/python/resource_management/core/source.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/source.py b/ambari-agent/src/main/python/resource_management/core/source.py
index 84d27b1..2fcd395 100644
--- a/ambari-agent/src/main/python/resource_management/core/source.py
+++ b/ambari-agent/src/main/python/resource_management/core/source.py
@@ -1,5 +1,5 @@
 from __future__ import with_statement
-from resource_management.core import environment
+from resource_management.core.environment import Substitutor, Environment
 
 __all__ = ["Source", "Template", "InlineTemplate", "StaticFile", "DownloadSource"]
 
@@ -10,6 +10,10 @@ import urlparse
 
 
 class Source(object):
+  def __init__(self, name, env=None):
+    self.name = Substitutor.substitute(name)
+    self.env = env or Environment.get_instance()
+    
   def get_content(self):
     raise NotImplementedError()
 
@@ -22,8 +26,7 @@ class Source(object):
 
 class StaticFile(Source):
   def __init__(self, name, env=None):
-    self.name = name
-    self.env = env or environment.Environment.get_instance()
+    super(StaticFile, self).__init__(name, env)
 
   def get_content(self):
     # absolute path
@@ -39,7 +42,7 @@ class StaticFile(Source):
 
 
 try:
-  from jinja2 import Environment, BaseLoader, TemplateNotFound, FunctionLoader
+  from jinja2 import Environment as JinjaEnvironment, BaseLoader, TemplateNotFound, FunctionLoader
 except ImportError:
   class Template(Source):
     def __init__(self, name, variables=None, env=None):
@@ -51,7 +54,7 @@ except ImportError:
 else:
   class TemplateLoader(BaseLoader):
     def __init__(self, env=None):
-      self.env = env or environment.Environment.get_instance()
+      self.env = env or Environment.get_instance()
 
     def get_source(self, environment, template_name):
       # absolute path
@@ -71,13 +74,12 @@ else:
 
   class Template(Source):
     def __init__(self, name, variables=None, env=None):
-      self.name = name
-      self.env = env or environment.Environment.get_instance()
+      super(Template, self).__init__(name, env)
       params = self.env.config.params
       variables = params if params else variables
       self.context = variables.copy() if variables else {}
       if not hasattr(self, 'template_env'):
-        self.template_env = Environment(loader=TemplateLoader(self.env),
+        self.template_env = JinjaEnvironment(loader=TemplateLoader(self.env),
                                         autoescape=False)
       self.template = self.template_env.get_template(self.name)     
 
@@ -93,19 +95,19 @@ else:
     
   class InlineTemplate(Template):
     def __init__(self, name, variables=None, env=None):
-      self.template_env = Environment(loader=FunctionLoader(lambda text: text))
+      self.template_env = JinjaEnvironment(loader=FunctionLoader(lambda text: text))
       super(InlineTemplate, self).__init__(name, variables, env) 
 
 
 class DownloadSource(Source):
-  def __init__(self, url, cache=True, md5sum=None, env=None):
-    self.env = env or environment.Environment.get_instance()
-    self.url = url
+  def __init__(self, name, cache=True, md5sum=None, env=None):
+    super(DownloadSource, self).__init__(name)
+    self.url = self.name
     self.md5sum = md5sum
     self.cache = cache
-    if not 'download_path' in env.config:
-      env.config.download_path = '/var/tmp/downloads'
-    if not os.path.exists(env.config.download_path):
+    if not 'download_path' in self.env.config:
+      self.env.config.download_path = '/var/tmp/downloads'
+    if not os.path.exists(self.env.config.download_path):
       os.makedirs(self.env.config.download_path)
 
   def get_content(self):