Anonymous avatar Anonymous committed f910efe

refactoring

Comments (0)

Files changed (29)

manifests/site.pp

 node 'base' {
-  include stdlib
 
   $artifactory_username = 'yumclient'
   $artifactory_password = 'p%4055w0rd'  # must (currently) be pre-urlencoded
   }
 
   Yumrepo <| |> -> Package <| provider == yum |>
-
 }
 
 
 node 'tcserver_machine' inherits 'base' {
-  
-  class {'tcserver::params': }
 
-  class { 'tcserver::install':
-    package_name => $tcserver::params::package_name,
-    version      => $tcserver::params::version,
-    require      => Class['tcserver::params'],
+  class { 'tcserver':
+    instance_name => 'sysdata',
+    owner         => 'tc-server',
+    group         => 'tc-server',
+    service_name  => "tcserver-sysdata",
   }
 
 }
     datasource_url       => 'jdbc:oracle:thin:@10.13.18.67:1522:caasit02',
     datasource_username  => 'sysdata',
     datasource_password  => 'secret',
-    
-    require              => Class['tcserver::install'],
+
+    owner                => $tcserver::owner,
+    group                => $tcserver::group,
+
+    require              => Class['tcserver'],
   }
 
 }

modules/sun_jdk/manifests/init.pp

 #  class {'sun_jdk': }
 #
 class sun_jdk(
-  $jdk_package_name = '',
-  $jdk_version = ''
+  $jdk_package_name = 'UNSET',
+  $jdk_version = 'UNSET'
 ) {
 
   if !defined(Class['sun_jdk::params']) {
   }
 
   $the_package_name = $jdk_package_name ? {
-    '' => $sun_jdk::params::jdk_package_name, default => $jdk_package_name}
+    'UNSET' => $sun_jdk::params::jdk_package_name, default => $jdk_package_name}
   $the_version = $jdk_version ? {
-    '' => $sun_jdk::params::jdk_version, default => $jdk_version}
+    'UNSET' => $sun_jdk::params::jdk_version, default => $jdk_version}
 
   $java_home = "/usr/java/jdk${the_version}"
 

modules/sun_jdk/tests/install.pp

-class {'sun_jdk::install': }

modules/sysdata_web/manifests/application.pp

-class sysdata_web::application (
-  $version,
-  $artifactory_username,
-  $artifactory_password,
-  $crowd_username,
-  $crowd_password,
-  $crowd_server_url,
-  $logout_url,
-  $my_account_url,
-  $sysdata_url,
-  $webportal_url,
-  $datasource_url,
-  $datasource_username,
-  $datasource_password,
-  $grails_server_url,
-  $webservice_base_url,
-  $conf_dir,
-  $release = true
-) {
-
-  Class['sysdata_web::server'] -> Class['sysdata_web::application']
-
-  webapp::install { 'sysdata':
-    group_name           => 'com.canoeventures.sysdata',
-    version              => $version,
-    release              => $release,
-    artifactory_username => $artifactory_username,
-    artifactory_password => $artifactory_password,
-    conf_dir             => $conf_dir,
-    server_dir           => $sysdata_web::server::sysdata_instance_dir,
-    require              => Class['sysdata_web::server'],
-  }
-
-  file { '/var/conf':
-    ensure  => directory,
-    owner   => 'tc-server',
-    group   => 'tc-server',
-  }
-
-  webapp::ext_conf { 'sysdata_web':
-    sysproperty_name => 'SYSDATACONF',
-    conf_dir         => $conf_dir,
-    server_dir       => $sysdata_web::server::sysdata_instance_dir,
-    template_files   => [
-      'sysdata_web/crowd-ehcache.xml.erb',
-      'sysdata_web/crowd.properties.erb',
-      'sysdata_web/log4j.groovy.erb',
-      'sysdata_web/navigation.groovy.erb',
-      'sysdata_web/sysdata.properties.erb',
-    ],
-    require          => Class['sysdata_web::server'],
-  }
-
-}

modules/sysdata_web/manifests/init.pp

   $version,
   $artifactory_username,
   $artifactory_password,
+  $conf_dir,
+  $owner,
+  $group,
+
+  # template values
   $crowd_username,
   $crowd_password,
   $crowd_server_url,
   $datasource_password,
   $grails_server_url,
   $webservice_base_url,
-  $conf_dir,
+
   $release = true
 ) {
 
-  if !defined(Class['tcserver::install']) {
-    if !defined(Class['tcserver::params']) {
-      include 'tcserver::params'
-    }
-
-    class { 'tcserver::install':
-      package_name => $tcserver::params::package_name,
-      version      => $tcserver::params::version,
+  if !defined(Class['tcserver']) {
+    class { 'tcserver':
+      instance_name => 'sysdata',
+      owner         => $owner,
+      group         => $group,
+      service_name  => "tcserver-sysdata",
     }
   }
 
-  class { 'sysdata_web::server': }
-
-  class { 'sysdata_web::application':
+  class { 'webapp':
+    app_name             => 'sysdata',
+    group_name           => 'com.canoeventures.sysdata',
     version              => $version,
     release              => $release,
     artifactory_username => $artifactory_username,
     artifactory_password => $artifactory_password,
-    crowd_username       => $crowd_username,
-    crowd_password       => $crowd_password,
-    crowd_server_url     => $crowd_server_url,
-    logout_url           => $logout_url,
-    my_account_url       => $my_account_url,
-    sysdata_url          => $sysdata_url,
-    webportal_url        => $webportal_url,
-    datasource_url       => $datasource_url,
-    datasource_username  => $datasource_username,
-    datasource_password  => $datasource_password,
-    grails_server_url    => $grails_server_url,
-    webservice_base_url  => $webservice_base_url,
+    owner                => $owner,
+    group                => $group,
     conf_dir             => $conf_dir,
-    require              => Class['sysdata_web::server'],
+    server_dir           => $tcserver::instance_dir_real,
+    sysproperty_name     => 'SYSDATACONF',
+    template_files       => [
+      'sysdata_web/crowd-ehcache.xml.erb',
+      'sysdata_web/crowd.properties.erb',
+      'sysdata_web/log4j.groovy.erb',
+      'sysdata_web/navigation.groovy.erb',
+      'sysdata_web/sysdata.properties.erb',
+    ],
+    require              => Class['tcserver'],
   }
 
-  Class['sysdata_web::server'] -> Class['sysdata_web::application']
-
 }

modules/sysdata_web/manifests/server.pp

-class sysdata_web::server (
-  $tcserver_version = 'UNSET'
-) {
-  
-  Class['tcserver::install'] -> Class['sysdata_web::server']
-
-  if !defined(Class['tcserver::install']) {
-    if !defined(Class['tcserver::params']) {
-      require 'tcserver::params'
-    }
-
-    $tcs_version = $tcserver_version ? {
-      'UNSET' => $tcserver::params::version,
-      default => $tcserver_version,
-    }
-
-    class { 'tcserver::install':
-      version => $tcs_version,
-    }
-  }
-
-  $sysdata_instance_dir = "${tcserver::install::tcserver_home}/sysdata"
-
-  class {'tcserver::instance':
-    name         => 'sysdata',
-    instance_dir => $sysdata_instance_dir,
-    require      => Class['tcserver::install'],
-  }
-
-  class {'tcserver::service':
-    instance_name => 'sysdata',
-    instance_dir  => $sysdata_instance_dir,
-    service_name  => 'tcserver-sysdata',
-    require       => Class['tcserver::instance'],
-  }
-
-}

modules/sysdata_web/spec/classes/init_spec.rb

       datasource_password:  'ds_pw',
       grails_server_url:    'http://server/',
       webservice_base_url:  'http://server/rest/',
+      owner:                'test-user',
+      group:                'test-group',
       conf_dir:             '/the_conf_dir',
     }
   end

modules/sysdata_web/templates/crowd.properties.erb

-application.name=<%= scope.lookupvar('sysdata_web::application::crowd_username') %>
-application.password=<%= scope.lookupvar('sysdata_web::application::crowd_password') %>
+application.name=<%= scope.lookupvar('sysdata_web::crowd_username') %>
+application.password=<%= scope.lookupvar('sysdata_web::crowd_password') %>
 
-crowd.server.url=<%= scope.lookupvar('sysdata_web::application::crowd_server_url') %>
+crowd.server.url=<%= scope.lookupvar('sysdata_web::crowd_server_url') %>
 session.isauthenticated=session.isauthenticated
 session.tokenkey=session.tokenkey
 session.validationinterval=1

modules/sysdata_web/templates/navigation.groovy.erb

 canoeux = [
-  logoutUrl:    "<%= scope.lookupvar('sysdata_web::application::logout_url') %>",
-  myAccountUrl: "<%= scope.lookupvar('sysdata_web::application::my_account_url') %>",
+  logoutUrl:    "<%= scope.lookupvar('sysdata_web::logout_url') %>",
+  myAccountUrl: "<%= scope.lookupvar('sysdata_web::my_account_url') %>",
   applications: [
     [
       name:'System Data',
       roles:'ROLE_sysdata_admin,ROLE_sysdata_company_admin,ROLE_sysdata_app_admin',
-      url:'<%= scope.lookupvar('sysdata_web::application::sysdata_url') %>'],
+      url:'<%= scope.lookupvar('sysdata_web::sysdata_url') %>'],
     [
        name:'Web Portal',
        roles:'ROLE_canoe_ad_ops,ROLE_canoe_admin,ROLE_canoe_marketing,ROLE_canoe_sales,ROLE_network_sales',
-       url:'<%= scope.lookupvar('sysdata_web::application::webportal_url') %>'
+       url:'<%= scope.lookupvar('sysdata_web::webportal_url') %>'
     ]
   ]
 ]

modules/sysdata_web/templates/sysdata.properties.erb

 dataSource.driverClassName=oracle.jdbc.OracleDriver
-dataSource.url=<%= scope.lookupvar('sysdata_web::application::datasource_url') %>
-dataSource.username=<%= scope.lookupvar('sysdata_web::application::datasource_username') %>
-dataSource.password=<%= scope.lookupvar('sysdata_web::application::datasource_password') %>
+dataSource.url=<%= scope.lookupvar('sysdata_web::datasource_url') %>
+dataSource.username=<%= scope.lookupvar('sysdata_web::datasource_username') %>
+dataSource.password=<%= scope.lookupvar('sysdata_web::datasource_password') %>
 
 #Set the following for 11g
 dataSource.dialect=org.hibernate.dialect.Oracle10gDialect
 # The following line should be commented out or deleted in Production or QA environments
 # grails.plugin.databasemigration.updateOnStart=true
 
-grails.serverURL=<%= scope.lookupvar('sysdata_web::application::grails_server_url') %>
-webservice.baseURL=<%= scope.lookupvar('sysdata_web::application::webservice_base_url') %>
-canoe.webportalURL=<%= scope.lookupvar('sysdata_web::application::webportal_url') %>
+grails.serverURL=<%= scope.lookupvar('sysdata_web::grails_server_url') %>
+webservice.baseURL=<%= scope.lookupvar('sysdata_web::webservice_base_url') %>
+canoe.webportalURL=<%= scope.lookupvar('sysdata_web::webportal_url') %>

modules/sysdata_web/tests/init.pp

-$crowd_username = 'web_portal'
-$crowd_password = 'admin'
-$crowd_server_url = 'http://10.13.18.56:9095/crowd/'
+Package {
+  provider => 'yum',
+}
 
-$logout_url = 'https://qa.accesscanoe.com/portal/logout/index'
-$my_account_url = 'https://qa.accesscanoe.com/portal/account/profile'
-$sysdata_url = 'https://qa.accesscanoe.com/sysdata'
-$webportal_url = 'https://qa.accesscanoe.com/portal/'
-$grails_server_url = 'http://localhost:8080/sysdata'
-$webservice_base_url = 'http://localhost:8080/sysdata'
+class {"sysdata_web": 
+  version              => "1.4.2_7",
+  conf_dir             => '/tmp',
+  owner                => 'test-user',
+  group                => 'test-group',
+  crowd_username       => 'web_portal',
+  crowd_password       => 'admin',
+  crowd_server_url     => 'http://10.13.18.56:9095/crowd/',
 
-$datasource_url = 'jdbc:oracle:thin:@10.13.18.67:1522:caasit02'
-$datasource_username = 'sysdata'
-$datasource_password = 'secret'
+  logout_url           => 'https://qa.accesscanoe.com/portal/logout/index',
+  my_account_url       => 'https://qa.accesscanoe.com/portal/account/profile',
+  sysdata_url          => 'https://qa.accesscanoe.com/sysdata',
+  webportal_url        => 'https://qa.accesscanoe.com/portal/',
+  grails_server_url    => 'http://localhost:8080/sysdata',
+  webservice_base_url  => 'http://localhost:8080/sysdata',
 
-$artifactory_username = 'yumclient'
-$artifactory_password = 'p%4055w0rd'  # must (currently) be pre-urlencoded
-# $artifactory_username = 'testclient'
-# $artifactory_password = 'testpw'
+  datasource_url       => 'jdbc:oracle:thin:@10.13.18.67:1522:caasit02',
+  datasource_username  => 'sysdata',
+  datasource_password  => 'secret',
 
-class {"sysdata_web": 
-  version => "1.4.2_7",
-  conf_dir => '/tmp',
-  server_dir => '/Users/JimMoore/Downloads/vfabric-tc-server-developer-2.6.2.RELEASE/myserver',
+  artifactory_username => 'testclient',
+  artifactory_password => 'testpw',
 }

modules/tcserver/manifests/init.pp

 # == Class: tcServer
 #
-# The Sun/Oracle JDK
+# Installs SpringSource tc Server from Yum.
 #
 # === Parameters
 #
-# [*top_java_dirname*]
-#   The top-level directory to contain the Java installation.
-#   (e.g., /usr/java)  Defaults to $sun_jdk::params::top_java_dirname
-#
-# [*jdk_dirname*]
-#   The relative name of the directory under $top_java_dirname that gets
-#   created by the installer. The full path is what gets put into
-#   JAVA_HOME and PATH.  Defaults to $sun_jdk::params::jdk_dirname
 #
 # === Examples
 #
 #  class {'tcserver': }
 #
 class tcserver(
+  $instance_name,
+  $owner,
+  $group,
+  $service_name = "tcserver-${instance_name}",
+  $tomcat_version = 'UNSET',
+  $instance_dir = 'UNSET'
 ) {
 
+  anchor {'tcserver::begin': }
+  -> class { 'tcserver::params':}
+
+
+  class { 'tcserver::install':
+    owner        => $owner,
+    group        => $group,
+    package_name => $package_name,
+    version      => $version,
+    require      => Class['tcserver::params'],
+  }
+
+  $tomcat_version_real = $tomcat_version ? {
+    'UNSET' => $tcserver::params::tomcat_version,
+    default => $tomcat_version,
+  }
+  $tcserver_home = $tcserver::install::tcserver_home
+  $instance_dir_real = $instance_dir ? {
+    'UNSET' => "${tcserver_home}/${instance_name}",
+    default => $instance_dir,
+  }
+
+  class { 'tcserver::instance':
+    instance_name  => $instance_name,
+    owner          => $owner,
+    group          => $group,
+    service_name   => $service_name,
+    tomcat_version => $tomcat_version_real,
+    instance_dir   => $instance_dir_real,
+    require        => Class['tcserver::install'],
+  }
+
+
+  anchor {'tcserver::end':
+    require => Class['tcserver::service'],
+  }
 
 }

modules/tcserver/manifests/install.pp

 # === Actions
 #
 # * Makes sure the Sun/Oracle JDK is installed. (see Class[sun_jdk])
-# * Creates the 'tc-server' user and group.
-# * Installs the tc Server RPM from Yum and makes sure it's owned by 'tc-server'
+# * Creates the user and group to run as
+# * Installs the tc Server RPM from Yum and makes sure ownership is set
 #
 class tcserver::install(
-  $package_name = '',
-  $version = ''
+  $owner,
+  $group,
+  $package_name = 'UNSET',
+  $version = 'UNSET'
 ) {
 
+  Class['tcserver::params'] -> Class['tcserver::install']
+
   if !defined(Class['tcserver::params']) {
-    include 'tcserver::params'
+    class {'tcserver::params': }
   }
 
   $the_package_name = $package_name ? {
-    '' => $tcserver::params::package_name, default => $package_name}
+    'UNSET' => $tcserver::params::package_name, default => $package_name}
   $the_version = $version ? {
-    '' => $tcserver::params::version, default => $version}
+    'UNSET' => $tcserver::params::version, default => $version}
 
   $tcserver_home = "/opt/${the_package_name}-${the_version}"
 
     }
   }
 
+  anchor {'tcserver::install::begin':
+    before => Group[$group],
+  }
+
   package { 'tc-server':
     name    => $the_package_name,
     ensure  => "${the_version}-1",
-    require => [Class['sun_jdk'], User['tc-server']],
+    require => [Class['sun_jdk'], User[$owner]],
   }
 
-  group { 'tc-server':
+  group { $group:
     ensure => present,
   }
 
-  user { 'tc-server':
+  user { $owner:
     ensure           => present,
     comment          => 'SpringSource tc-Server',
-    gid              => 'tc-server',
+    gid              => $group,
     home             => $tcserver_home,
     password         => '!!',
     password_max_age => '-1',
     password_min_age => '-1',
     shell            => '',
-    require          => Group['tc-server'],
+    require          => Group[$group],
   }
   
   exec { "set_tcserver_dir_ownership":
-    command => "chown -R tc-server.tc-server ${tcserver_home}",
+    command => "chown -R ${owner}.${$group} ${tcserver_home}",
     path    => "/usr/bin:/bin",
-    unless  => "test `stat -c %U ${tcserver_home}` = tc-server",
-    require => [Package['tc-server'], User['tc-server']],
-    before  => Class['tcserver::instance'],
+    unless  => "test `stat -c %U ${tcserver_home}` = ${owner}",
+    require => [Package['tc-server'], User[$owner]],
   }
 
   file { "set_tcserver_dir_ownership":
-    path => $tcserver_home,
-    owner => 'tc-server',
-    group => 'tc-server',
+    path    => $tcserver_home,
+    owner   => $owner,
+    group   => $group,
     recurse => false,
-    mode => '2600',
+    mode    => '2600',
     require => Package['tc-server'],
   }
 
+  anchor {'tcserver::install::end':
+    require => Exec["set_tcserver_dir_ownership"],
+  }
+
 }

modules/tcserver/manifests/instance.pp

 # == Examples:
 # tcserver::instance{'a_server_instance': }
 #
-
 class tcserver::instance (
-  $name,
-  $service_name = "tcserver-${name}",
-  $instance_dir = "${tcserver::install::tcserver_home}/${name}"
-) {
+  $instance_name,
+  $owner,
+  $group,
+  $service_name = "tcserver-${instance_name}",
+  $tomcat_version = 'UNSET',
+  $instance_dir = 'UNSET'
+) inherits tcserver::params {
 
   Class['tcserver::params'] -> Class['tcserver::install']
+  Class['tcserver::params'] -> Class['tcserver::instance']
+  Class['tcserver::install'] -> Class['tcserver::instance']
 
   if !defined(Class['tcserver::params']) {
     class {'tcserver::params': }
   }
 
+  if !defined(Class['sun_jdk']) {
+    class {'sun_jdk': }
+  }
+
   if !defined(Class['tcserver::install']) {
-    class { 'tcserver::install':
-      version => $tcserver::params::version,
+    class {'tcserver::install':
+      owner => $owner,
+      group => $group,
     }
   }
-  
+
   $java_home = $sun_jdk::java_home
   $tcserver_home = $tcserver::install::tcserver_home
-  $tomcat_version = $tcserver::params::tomcat_version
-  info("tc-Server instance '${name}': java_home='${java_home}' tcserver_home='${tcserver_home}' tomcat_version='${tomcat_version}'")
+  $tomcat_version_real = $tomcat_version ? {
+    'UNSET' => $tcserver::params::tomcat_version,
+    default => $tomcat_version,
+  }
+  $instance_dir_real = $instance_dir ? {
+    'UNSET' => "${tcserver_home}/${instance_name}",
+    default => $instance_dir,
+  }
+
+  info("tc-Server instance '${name}': java_home='${java_home}' tcserver_home='${tcserver_home}' tomcat_version='${tomcat_version_real}'")
 
   # Create instance
-  exec { "create_tcserver_${name}":
-    command  => "export JAVA_HOME=${java_home} ; ${tcserver_home}/tcruntime-instance.sh create --java-home ${java_home} --version ${tomcat_version} --instance-directory ${tcserver_home} ${name}",
-    cwd      => $tcserver::install::tcserver_home,
+  exec { "create_tcserver_${instance_name}":
+    command  => "export JAVA_HOME=${java_home} ; ${tcserver_home}/tcruntime-instance.sh create --java-home ${java_home} --version ${tomcat_version} --instance-directory ${tcserver_home} ${instance_name}",
+    cwd      => $tcserver_home,
     creates  => "${instance_dir}/webapps",
     provider => shell,
-    user     => 'tc-server',
-    group    => 'tc-server',
+    user     => $owner,
+    group    => $group,
     require  => [Class["tcserver::install"], Package['tc-server']],
   }
 
-  Package['tc-server'] -> Exec["create_tcserver_${name}"]
+  class { 'tcserver::service':
+    instance_name => $instance_name,
+    service_name  => $service_name,
+    owner         => $owner,
+    group         => $group,
+    instance_dir  => $instance_dir,
+    require       => Exec["create_tcserver_${instance_name}"],
+  }
+
+
+  Package['tc-server'] -> Exec["create_tcserver_${instance_name}"]
 }

modules/tcserver/manifests/params.pp

 class tcserver::params {
 
-  $package_name = 'vfabric-tc-server-developer'
-  $version = '2.6.2.RELEASE'
+  $package_name   = 'vfabric-tc-server-developer'
+  $version        = '2.6.2.RELEASE'
   $tomcat_version = '7.0.22.A.RELEASE'
+  info("params::tomcat_version='${tomcat_version}'")
+  $owner          = 'tc-server'
+  $group          = $owner
 
-  $jdk_version = '1.6.0_30'
+  $jdk_version    = '1.6.0_30'
 
 }

modules/tcserver/manifests/service.pp

 class tcserver::service (
   $instance_name,
   $service_name,
+  $owner,
+  $group,
   $instance_dir
 ) {
 
-  Class['tcserver::instance'] -> Class['tcserver::service']
-
-
   # where to find files; first try local filesystem, then the puppet master
-  $prefix = "/etc/puppet/modules"
   $module = "tcserver"
+  $prefix = "/etc/puppet/modules"
   $p1     = "${prefix}/${module}/files"
-  $p2     = "${prefix}/${module}/filesz"
-#  $p2 = "puppet://modules/${module}"
+  $p2     = "puppet://modules/${module}"
 
   # Create initd (service) file
   file { "/etc/init.d/${service_name}":
     path    => "${instance_dir}/bin/status.sh",
     source  => ["${p1}/server-status.sh", "${p2}/server-status.sh"],
     mode    => '700',
-    owner   => 'tc-server',
-    group   => 'tc-server',
+    owner   => $owner,
+    group   => $group,
     require => Class['tcserver::instance'],
   }
 
       hasstatus  => false,
       status     => "${instance_dir}/bin/status.sh",
       hasrestart => true,
-      require    => File["/etc/init.d/${service_name}", "${instance_name}_status_script"],
+      require    => [File["/etc/init.d/${service_name}", "${instance_name}_status_script"], Class['tcserver::instance']]
   }
 
 }

modules/tcserver/spec/classes/install_spec.rb

 
 describe 'tcserver::install' do
 
+  let :params do
+    {
+      package_name: 'tc_server_package',
+      version:      'tcs_version',
+      owner:        'test-user',
+      group:        'test-group',
+    }
+  end
+
   let(:facts) { {operatingsystem: 'CentOS'} }
 
-  describe "with custom params" do
-    let :params do
-      {
-        package_name: 'tc_server_package',
-        version: 'tcs_version',
-      }
-    end
-
-    it "should make sure Java is installed" do
-      should contain_class('sun_jdk').with(
-        jdk_version: '1.6.0_30',
-      )
-    end
-
-    it "should install the package" do
-      should contain_package('tc-server').with(
-        name:'tc_server_package',
-        ensure: 'tcs_version-1',
-      )
-      should contain_user('tc-server').with(
-        home: "/opt/tc_server_package-tcs_version",
-      )
-    end
+  it "should make sure Java is installed" do
+    should contain_class('sun_jdk').with(
+      jdk_version: '1.6.0_30',
+    )
+  end
+
+  it "should install the package" do
+    should contain_package('tc-server').with(
+      name:'tc_server_package',
+      ensure: 'tcs_version-1',
+    )
+    should contain_user(params[:owner]).with(
+      home: "/opt/#{params[:package_name]}-#{params[:version]}",
+    )
   end
 
   it "should have the user/group set up" do
-    should contain_group('tc-server').with_ensure(:present)
-    should contain_user('tc-server').with(
+    should contain_group(params[:group]).with_ensure(:present)
+    should contain_user(params[:owner]).with(
       ensure: :present,
-      gid: 'tc-server',
-      shell: '',
+      gid:    params[:group],
+      shell:  '',
     )
   end
 
   it "should make sure the ownership is set correctly" do
     should contain_exec('set_tcserver_dir_ownership').with(
-      command: 'chown -R tc-server.tc-server /opt/vfabric-tc-server-developer-2.6.2.RELEASE',
-      unless: 'test `stat -c %U /opt/vfabric-tc-server-developer-2.6.2.RELEASE` = tc-server',
+      command: "chown -R #{params[:owner]}.#{params[:group]} /opt/#{params[:package_name]}-#{params[:version]}",
+      unless: "test `stat -c %U /opt/#{params[:package_name]}-#{params[:version]}` = #{params[:owner]}",
     )
   end
 

modules/tcserver/spec/classes/instance_spec.rb

 
   let(:params) do
     {
-      name: 'my_app',
+      name:  'my_app',
+      owner: 'test-user',
+      group: 'test-group',
     }
   end
   let(:facts) { {operatingsystem: 'CentOS'} }
 
   it "should install the package" do
     should contain_package('tc-server').with(
-      name:'vfabric-tc-server-developer',
+      name:   'vfabric-tc-server-developer',
       ensure: '2.6.2.RELEASE-1',
     )
   end
 
   it "should create an instance of my_app" do
     should contain_exec('create_tcserver_my_app').with(
-      cwd: '/opt/vfabric-tc-server-developer-2.6.2.RELEASE',
-      command: "/opt/vfabric-tc-server-developer-2.6.2.RELEASE/tcruntime-instance.sh create --java-home  --version  --instance-directory /opt/vfabric-tc-server-developer-2.6.2.RELEASE #{params[:name]}",
+      cwd:      '/opt/vfabric-tc-server-developer-2.6.2.RELEASE',
+      command:  "export JAVA_HOME=/usr/java/jdk1.6.0_30 ; /opt/vfabric-tc-server-developer-2.6.2.RELEASE/tcruntime-instance.sh create --java-home /usr/java/jdk1.6.0_30 --version 7.0.22.A.RELEASE --instance-directory /opt/vfabric-tc-server-developer-2.6.2.RELEASE #{params[:name]}",
       provider: :shell,
-      user: 'tc-server',
-      group: 'tc-server',
+      user:     params[:owner],
+      group:    params[:group],
     )
   end
 

modules/tcserver/tests/init.pp

+Package {
+  provider => 'yum',
+}
+
+class { 'tcserver':
+  instance_name => 'a_server_instance',
+  owner => 'tc-server',
+  group => 'tc-server',
+  service_name => "tcserver-a_server_instance",
+}

modules/tcserver/tests/install.pp

+Package {
+  provider => 'yum',
+}
+
+class {'tcserver::install':
+  owner => 'tc-server',
+  group => 'tc-server',
+}

modules/tcserver/tests/instance.pp

 }
 
 class {'tcserver::instance':
-  instance_name =>'a_server_instance',
+  instance_name => 'a_server_instance',
+  owner => 'tc-server',
+  group => 'tc-server',
+  service_name => "tcserver-a_server_instance",
 }

modules/webapp/manifests/ext_conf.pp

 define webapp::ext_conf (
-  $app_name = $name,
   $sysproperty_name,
   $conf_dir,
-  $template_file = '',
+  $server_dir,
+  $owner,
+  $group = 'root',
+  $mode = '600',
+  $app_name = $name,
+  $template_file = 'UNSET',
   $template_files = [],
-  $service_name = '',
-  $server_dir) {
+  $service_name = 'UNSET'
+) {
 
   if !defined(Exec["update_external_conf_${name}"]) {
     # escape the slashes in the path for the regular expression
     }
   }
 
+  if !defined(File['/var/conf']) {
+    file { '/var/conf':
+      ensure  => directory,
+      owner   => 'root',
+      group   => 'root',
+      mode    => '755',
+    }
+  }
+
   if !defined(File[$conf_dir]) {
     file { $conf_dir:
       ensure  => directory,
-      owner   => 'tc-server',
-      group   => 'tc-server',
-      require => Class['tcserver::instance'],
+      owner   => $owner,
+      group   => $group,
+      mode    => $mode,
+      require => File['/var/conf'],
     }
   }
 
-  if $template_file != '' {
+  if $template_file != 'UNSET' {
     ext_template_conf{ $template_file:
       conf_dir     => $conf_dir,
-      service_name => $service_name
+      owner        => $owner,
+      group        => $group,
+      mode         => $mode,
+      service_name => $service_name,
+      require      => File[$conf_dir],
     }
   }
 
   if $template_files != [] {
     ext_template_conf{ $template_files:
       conf_dir     => $conf_dir,
-      service_name => $service_name
+      owner        => $owner,
+      group        => $group,
+      mode         => $mode,
+      service_name => $service_name,
+      require      => File[$conf_dir],
     }
   }
 

modules/webapp/manifests/ext_template_conf.pp

 define webapp::ext_template_conf (
   $conf_dir,
-  $service_name = '',
-  $template_file = $name) {
+  $owner,
+  $group = 'root',
+  $mode = '600',
+  $service_name = 'UNSET',
+  $template_file = $name
+) {
 
-#  require stdlib
   validate_re($name, ['.erb$'])
 
   $filename = regsubst($name, '.*?([^\/]*)\.erb$', '\1')
 
-  if $service_name == '' {
-    file {"${conf_dir}/${filename}":
-      content => template($name),
-    }
+  file {"${conf_dir}/${filename}":
+    content => template($name),
+    owner   => $owner,
+    group   => $group,
+    mode    => $mode,
   }
-  else {
-    file {"${conf_dir}/${filename}":
-      content => template($name),
-      notify  => Service[$service_name],
-    }
+
+  if $service_name != 'UNSET' {
+    File["${conf_dir}/${filename}"] -> Service[$service_name]
   }
 
 }

modules/webapp/manifests/init.pp

 class webapp (
-  $group_name = '',
-  $app_name = '',
-  $version = '',
+  $app_name,
+  $version,
+  $server_dir,
+  $owner,
+  $group,
+  $artifactory_username,
+  $artifactory_password,
+  $conf_dir = 'UNSET',
+  $sysproperty_name = '!UNSET!',
+  $group_name = "com.canoeventures.${app_name}",
+  $template_file = 'UNSET',
+  $template_files = [],
   $release = true
 ) {
 
+  webapp::install { $app_name:
+    group_name           => $group_name,
+    version              => $version,
+    server_dir           => $server_dir,
+    owner                => $owner,
+    group                => $group,
+    artifactory_username => $artifactory_username,
+    artifactory_password => $artifactory_password,
+    release              => $release,
+  }
+
+  if $conf_dir != 'UNSET' {
+    webapp::ext_conf { $app_name:
+      sysproperty_name => $sysproperty_name,
+      conf_dir         => $conf_dir,
+      server_dir       => $server_dir,
+      owner            => $owner,
+      group            => $group,
+      template_file    => $template_file,
+      template_files   => $template_files,
+      service_name     => $service_name,
+    }
+  }
+
 }

modules/webapp/manifests/install.pp

   $group_name = "com.canoeventures.${name}",
   $app_name = $name,
   $version,
-  $conf_dir,
   $server_dir,
+  $owner,
+  $group,
   $artifactory_username,
   $artifactory_password,
-  $release = true) {
+  $service_name = 'UNSET',
+  $release = true
+) {
 
   $url_group_name = regsubst($group_name, '\.', '/', 'G')
   $filename       = "${app_name}-${version}.war"
   exec {"get_${filename}":
     path    => "/usr/bin:/bin:/opt/local/bin",
     cwd     => $server_dir,
-    user    => 'tc-server',
-    group   => 'tc-server',
+    user    => $owner,
+    group   => $group,
     command => "wget --no-check-certificate ${credential_url}",
-    require => Class['tcserver::instance'],
     unless  => "test -f ${filename}",
+    require => Package['wget'],
   }
 
   exec {"mv_${filename}_to_webapps":
     command => "mv ${filename} webapps/",
     unless  => "test -f ${server_dir}/webapps/${filename}",
     require => Exec["get_${filename}"],
-    notify  => Service[$tcserver::instance::service_name],
+  }
+
+  if $service_name != 'UNSET' {
+    Exec["mv_${filename}_to_webapps"] -> Service[$service_name]
   }
 
 }

modules/webapp/tests/ext_conf.pp

+webapp::ext_conf { 'the_conf':
+  sysproperty_name => 'THECONF',
+  conf_dir         => '/conf',
+  server_dir       => '/opt/server',
+  owner            => 'test-user',
+  template_file    => 'sysdata_web/log4j.groovy.erb',
+}
+
+webapp::ext_conf { 'the_confs':
+  sysproperty_name => 'THECONF',
+  conf_dir         => '/conf',
+  server_dir       => '/opt/server',
+  owner            => 'test-user',
+  template_files   => ['sysdata_web/navigation.groovy.erb'],
+}

modules/webapp/tests/ext_template_conf.pp

+webapp::ext_template_conf { 'sysdata_web/log4j.groovy.erb':
+  conf_dir => '/conf',
+  owner => 'test-user',
+}

modules/webapp/tests/init.pp

-$artifactory_username = 'testclient'
-$artifactory_password = 'testpw'
-
 class {"webapp": 
-  group_name => "com.canoeventures.sysdata",
-  app_name => "sysdata",
-  version => "1.4.2_7",
+  group_name           => "com.canoeventures.a_app",
+  app_name             => 'a_app',
+  version              => '14.5',
+  conf_dir             => '/var/conf/a_app',
+  server_dir           => '/opt/tcs',
+  owner                => 'test-user',
+  group                => 'test-group',
+  artifactory_username => 'art-user',
+  artifactory_password => 'art-pw',
+  release              => true,
 }

modules/webapp/tests/install.pp

+webapp::install { 'a_app' : 
+  group_name           => "com.canoeventures.a_app",
+  version              => '14.5',
+  server_dir           => '/opt/tcs',
+  owner                => 'test-user',
+  group                => 'test-group',
+  artifactory_username => 'art-user',
+  artifactory_password => 'art-pw',
+  release              => true,
+}
+
+service {'tcserver-b_app':}
+
+webapp::install { 'b_app' : 
+  group_name           => "com.canoeventures.b_app",
+  version              => '14.5',
+  server_dir           => '/opt/tcs',
+  owner                => 'test-user',
+  group                => 'test-group',
+  artifactory_username => 'art-user',
+  artifactory_password => 'art-pw',
+  service_name         => 'tcserver-b_app',
+  release              => true,
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.