Example #1
0
def setup_solr_client(config,
                      custom_log4j=True,
                      custom_log_location=None,
                      log4jcontent=None):
    solr_client_dir = '/usr/lib/ambari-infra-solr-client'
    solr_client_log_dir = default_config(
        config,
        '/configurations/infra-solr-client-log4j/infra_solr_client_log_dir',
        '/var/log/ambari-infra-solr-client'
    ) if custom_log_location is None else custom_log_location
    solr_client_log = format("{solr_client_log_dir}/solr-client.log")
    solr_client_log_maxfilesize = default_config(
        config,
        'configurations/infra-solr-client-log4j/infra_client_log_maxfilesize',
        80)
    solr_client_log_maxbackupindex = default_config(
        config,
        'configurations/infra-solr-client-log4j/infra_client_log_maxbackupindex',
        60)

    Directory(solr_client_log_dir,
              mode=0755,
              cd_access='a',
              create_parents=True)
    Directory(solr_client_dir,
              mode=0755,
              cd_access='a',
              create_parents=True,
              recursive_ownership=True)
    solrCliFilename = format("{solr_client_dir}/solrCloudCli.sh")
    File(solrCliFilename, mode=0755, content=StaticFile(solrCliFilename))
    if custom_log4j:
        # use custom log4j content only, when infra is not installed on the cluster
        solr_client_log4j_content = config['configurations'][
            'infra-solr-client-log4j'][
                'content'] if log4jcontent is None else log4jcontent
        context = {
            'solr_client_log': solr_client_log,
            'solr_client_log_maxfilesize': solr_client_log_maxfilesize,
            'solr_client_log_maxbackupindex': solr_client_log_maxbackupindex
        }
        template = JinjaEnvironment(
          line_statement_prefix='%',
          variable_start_string="{{",
          variable_end_string="}}")\
          .from_string(solr_client_log4j_content)

        File(format("{solr_client_dir}/log4j.properties"),
             content=template.render(context),
             mode=0644)
    else:
        File(format("{solr_client_dir}/log4j.properties"), mode=0644)

    File(solr_client_log, mode=0664, content='')
Example #2
0
 def __init__(self, name, extra_imports=[], **kwargs):
   """
   @param kwargs: Additional variables passed to template
   """
   super(Template, self).__init__(name)
   params = self.env.config.params
   variables = checked_unite(params, kwargs)
   self.imports_dict = dict((module.__name__, module) for module in extra_imports)
   self.context = variables.copy() if variables else {}
   if not hasattr(self, 'template_env'):
     self.template_env = JinjaEnvironment(loader=TemplateLoader(self.env),
                                     autoescape=False, undefined=StrictUndefined, trim_blocks=True)
     
   self.template = self.template_env.get_template(self.name)     
Example #3
0
 def __init__(self, name, extra_imports=[], **kwargs):
     self.template_env = JinjaEnvironment(
         loader=FunctionLoader(lambda text: text))
     super(InlineTemplate, self).__init__(name, extra_imports, **kwargs)
Example #4
0
    <title>${page_title|e}</title>
  </head>
  <body>
    <div class="header">
      <h1>${page_title|e}</h1>
    </div>
    <div class="table">
      <table>
      % for row in table
        <tr>
        % for cell in row
          <td>${testmacro(cell)}</td>
        % endfor
        </tr>
      % endfor
      </table>
    </div>
  </body>
</html>\
"""
jinja_template = JinjaEnvironment(line_statement_prefix='%',
                                  variable_start_string="${",
                                  variable_end_string="}").from_string(source)
print jinja_template.environment.compile(source, raw=True)

p = Profile()
p.runcall(lambda: jinja_template.render(context))
stats = Stats(p)
stats.sort_stats('time', 'calls')
stats.print_stats()
Example #5
0
jinja_template = JinjaEnvironment(
    line_statement_prefix='%',
    variable_start_string="${",
    variable_end_string="}"
).from_string("""\
<!doctype html>
<html>
  <head>
    <title>${page_title|e}</title>
  </head>
  <body>
    <div class="header">
      <h1>${page_title|e}</h1>
    </div>
    <ul class="navigation">
    % for href, caption in [
        ('index.html', 'Index'),
        ('downloads.html', 'Downloads'),
        ('products.html', 'Products')
      ]
      <li><a href="${href|e}">${caption|e}</a></li>
    % endfor
    </ul>
    <div class="table">
      <table>
      % for row in table
        <tr>
        % for cell in row
          <td>${cell}</td>
        % endfor
        </tr>
      % endfor
      </table>
    </div>
  </body>
</html>\
""")