Great! This seems to be the best way of improving the module structure with regard to agent module. +1
Regards, Chamila de Alwis Software Engineer | WSO2 | +94772207163 Blog: code.chamiladealwis.com On Tue, Aug 19, 2014 at 8:01 PM, Rajkumar Rajaratnam <[email protected]> wrote: > Hi Chamila, > > To load custom templates (from a cartridge module), > > *content => template("${module}/agent/${name}.erb")* > > We will be creating a directory (agent) inside a cartridge module's > templates directory (puppet/modules/ruby/templates/agent) and keep all > custom agent extension there. We need to separate out agent extension > templates from a module's own templates. > > To load default templates (from agent module), > > *content => template("agent/${name}.erb")* > > So we can make it as a parameter like below; > > define agent::push_templates ($target, $template_dir) { > file { "${target}/${name}": > ensure => present, > owner => $agent::owner, > group => $agent::group, > mode => '0755', > content => template($template_dir) > } > } > > In agent's init.pp, we can pass $template_dir accordingly for default and > custom extensions. Note that we need to call agent::push_templates twice in > init.pp to apply default extensions and custom extensions. > > Thanks. > > > On Tue, Aug 19, 2014 at 7:12 PM, Rajkumar Rajaratnam <[email protected]> > wrote: > >> Yes. >> >> Plus, we will modify agent's init.pp and add custom templates (if any) in >> each cartridge module. >> >> >> On Tue, Aug 19, 2014 at 7:02 PM, Chamila De Alwis <[email protected]> >> wrote: >> >>> So in the agent's push_templates defined type we'll replace *content => >>> template("agent/${name}.erb")* with *content => >>> template("${module}/${name}.erb")*? >>> >>> >>> Regards, >>> Chamila de Alwis >>> Software Engineer | WSO2 | +94772207163 >>> Blog: code.chamiladealwis.com >>> >>> >>> >>> >>> On Tue, Aug 19, 2014 at 4:54 PM, Rajkumar Rajaratnam <[email protected] >>> > wrote: >>> >>>> Hi, >>>> >>>> Currently we are having an agent puppet module, which includes all >>>> agent extensions (puppet/modules/agent/templates/extensions/*). >>>> >>>> All the cartridges need these extensions, but with different behaviors >>>> (implementation of these extensions could be different from cartridge to >>>> cartridge). For example, if it is a php cartridge, we need to do certain >>>> stuffs when the instance is started. If it is a mysql cartridge, we want to >>>> do something else. With current puppet module structure, we have to >>>> hard-code cartridge types in extensions to achieve specific behavior based >>>> on cartridge. >>>> >>>> For example, in instance-started extension; >>>> >>>> <%- if @type == 'mysql' -%> >>>> <%= scope.function_template(['agent/extensions/addons/_mysql.erb']) -%> >>>> <%- end -%> >>>> >>>> <%- if @type == 'ruby' -%> >>>> <%= scope.function_template(['agent/extensions/addons/_ruby.erb']) -%> >>>> <%- end -%> >>>> >>>> IMO, this is not a proper way. >>>> >>>> I guess the proper way is to have some default extensions in agent >>>> module and allow cartridges to override and/or add more extensions specific >>>> to them. This way, we don't have to hard-code anything in agent extensions. >>>> Modules which need custom extension behavior can override default >>>> extensions and/or add more extensions. If they don't override an extension, >>>> default extension will be copied to the instance. >>>> >>>> I am thinking of implementing it as below; >>>> >>>> We introduce two optional parameters to agent class. >>>> $templates : templates which needs to be overridden >>>> $module : which module to look up for these templates >>>> >>>> node /ruby/ inherits base { >>>> require java >>>> class {'agent': >>>> module => 'ruby', >>>> templates => >>>> ['bin/stratos.sh','extenstions/instance-started.sh'], >>>> } >>>> class {'ruby':} >>>> Class['stratos_base'] -> Class['java'] -> Class['ruby'] ~> >>>> Class['agent'] >>>> } >>>> >>>> We keep these templates in the relevant module (ruby in this case) with >>>> appropriate directory structure (ruby/templates/agent/extensions and >>>> ruby/templates/agent/bin) and pass these to the agent class, which will >>>> copy right extensions (default + custom) to the instance. >>>> >>>> WDYT about this approach? >>>> >>>> Thanks >>>> >>>> -- >>>> Rajkumar Rajaratnam >>>> Software Engineer | WSO2, Inc. >>>> Mobile +94777568639 | +94783498120 >>>> >>> >>> >> >> >> -- >> Rajkumar Rajaratnam >> Software Engineer | WSO2, Inc. >> Mobile +94777568639 | +94783498120 >> > > > > -- > Rajkumar Rajaratnam > Software Engineer | WSO2, Inc. > Mobile +94777568639 | +94783498120 >
