From f7a95a1e0efa9874e08a8ac2eff997a58e8fea95 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Thu, 4 Apr 2013 19:32:42 -0700 Subject: [PATCH 1/3] Refactor and reduce The module in its previous incarnation was unnecessarily hard to read and use. This commit applies the "params" pattern in order to more clearly deliniate between logical variable selection and actual declarative configuration. --- manifests/init.pp | 109 ++++++----------------------------- manifests/package_debian.pp | 27 --------- manifests/package_redhat.pp | 28 --------- manifests/package_solaris.pp | 27 --------- manifests/package_suse.pp | 27 --------- manifests/params.pp | 46 +++++++++++++++ tests/init.pp | 12 +--- 7 files changed, 68 insertions(+), 208 deletions(-) delete mode 100644 manifests/package_debian.pp delete mode 100644 manifests/package_redhat.pp delete mode 100644 manifests/package_solaris.pp delete mode 100644 manifests/package_suse.pp create mode 100644 manifests/params.pp diff --git a/manifests/init.pp b/manifests/init.pp index 40363d5..038a776 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,111 +4,40 @@ # # Parameters: # +# [*distribution*] +# The java distribution to install. Can be one of "jdk" or "jre". +# +# [*version*] +# The version of java to install. By default, this module simply ensures +# that java is present, and does not require a specific version. +# # Actions: # # Requires: # # Sample Usage: # -# [Remember: No empty lines between comments and class definition] class java( $distribution = 'jdk', $version = 'present' ) { + include java::params - validate_re($distribution, '^jdk$|^jre$|^java.*$') - validate_re($version, 'installed|^[._0-9a-zA-Z:-]+$') - - anchor { 'java::begin': } - anchor { 'java::end': } - - case $::osfamily { - - 'RedHat': { - - if ($operatingsystem == 'Fedora') { - class { 'java::package_redhat': - version => $version, - distribution => 'java', - require => Anchor['java::begin'], - before => Anchor['java::end'], - } - } else { - class { 'java::package_redhat': - version => $version, - distribution => $distribution, - require => Anchor['java::begin'], - before => Anchor['java::end'], - } - } + validate_re($version, 'present|installed|latest|^[._0-9a-zA-Z:-]+$') + case $distribution { + default: { fail('distribution must be one of jdk, jre') } + 'jdk': { + $java_package_name = $java::params::jdk_package } - - 'Debian': { - - case $::lsbdistcodename { - squeeze, lucid: { - $distribution_debian = $distribution ? { - jdk => 'openjdk-6-jdk', - jre => 'openjdk-6-jre-headless', - } - } - wheezy, precise: { - $distribution_debian = $distribution ? { - jdk => 'openjdk-7-jdk', - jre => 'openjdk-7-jre-headless', - } - } - default: { - fail("operatingsystem distribution ${::lsbdistcodename} is not supported") - } - } - - class { 'java::package_debian': - version => $version, - distribution => $distribution_debian, - require => Anchor['java::begin'], - before => Anchor['java::end'], - } - - } - - 'Solaris': { - - $distribution_solaris = $distribution ? { - jdk => 'developer/java/jdk-7', - jre => 'runtime/java/jre-7', - } - - class { 'java::package_solaris': - version => $version, - distribution => $distribution_solaris, - require => Anchor['java::begin'], - before => Anchor['java::end'], - } - - } - - 'Suse': { - - $distribution_suse = $distribution ? { - jdk => 'java-1_6_0-ibm-devel', - jre => 'java-1_6_0-ibm', - } - - class { 'java::package_suse': - version => $version, - distribution => $distribution_suse, - require => Anchor['java::begin'], - before => Anchor['java::end'], - } - - } - - default: { - fail("osfamily ${::osfamily} is not supported") + 'jre': { + $java_package_name = $java::params::jre_package } + } + package { 'java': + ensure => $version, + name => $java_package_name, } } diff --git a/manifests/package_debian.pp b/manifests/package_debian.pp deleted file mode 100644 index 565399d..0000000 --- a/manifests/package_debian.pp +++ /dev/null @@ -1,27 +0,0 @@ -# Class: java::package_debian -# -# Implementation class of the Java package -# for debian based systems. -# -# This class is not meant to be used by the end user -# of the module. It is an implementation class -# of the composite Class[java] -# -# Parameters: -# -# Actions: -# -# Requires: -# -# Sample Usage: -# -class java::package_debian( - $version, - $distribution -) { - - package { 'java': - ensure => $version, - name => $distribution, - } -} diff --git a/manifests/package_redhat.pp b/manifests/package_redhat.pp deleted file mode 100644 index 681d978..0000000 --- a/manifests/package_redhat.pp +++ /dev/null @@ -1,28 +0,0 @@ -# Class: java::package_redhat -# -# Implementation class of the Java package -# for redhat based systems. -# -# This class is not meant to be used by the end user -# of the module. It is an implementation class -# of the composite Class[java] -# -# Parameters: -# -# Actions: -# -# Requires: -# -# Sample Usage: -# -class java::package_redhat( - $version, - $distribution -) { - - package { 'java': - ensure => $version, - name => $distribution, - } - -} diff --git a/manifests/package_solaris.pp b/manifests/package_solaris.pp deleted file mode 100644 index a9752c5..0000000 --- a/manifests/package_solaris.pp +++ /dev/null @@ -1,27 +0,0 @@ -# Class: java::package_solaris -# -# Implementation class of the Java package -# for Solaris based systems. -# -# This class is not meant to be used by the end user -# of the module. It is an implementation class -# of the composite Class[java] -# -# Parameters: -# -# Actions: -# -# Requires: -# -# Sample Usage: -# -class java::package_solaris( - $version, - $distribution -) { - - package { 'java': - ensure => $version, - name => $distribution, - } -} diff --git a/manifests/package_suse.pp b/manifests/package_suse.pp deleted file mode 100644 index 98f5e8f..0000000 --- a/manifests/package_suse.pp +++ /dev/null @@ -1,27 +0,0 @@ -# Class: java::package_suse -# -# Implementation class of the Java package -# for SUSE based systems. -# -# This class is not meant to be used by the end user -# of the module. It is an implementation class -# of the composite Class[java] -# -# Parameters: -# -# Actions: -# -# Requires: -# -# Sample Usage: -# -class java::package_suse( - $version, - $distribution -) { - - package { 'java': - ensure => $version, - name => $distribution, - } -} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..6261daa --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,46 @@ +# Class: java::params +# +# This class sets the value of two variables, jdk_package and jre_package, +# appropriate for the client system in question. +# +class java::params { + + case $::osfamily { + default: { fail("unsupported platform ${::osfamily}") } + 'RedHat': { + case $::operatingsystem { + default: { fail("unsupported os ${::operatingsystem}") } + 'RedHat', 'CentOS': { + $jdk_package = 'java-1.7.0-openjdk-devel' + $jre_package = 'java-1.7.0-openjdk' + } + 'Fedora': { + $jdk_package = 'java' + $jre_package = 'java' + } + } + } + 'Debian': { + case $::lsbdistcodename { + default: { fail("unsupported release ${::lsbdistcodename}") } + 'squeeze', 'lucid': { + $jdk_package = 'openjdk-6-jdk' + $jre_package = 'openjdk-6-jre-headless' + } + 'wheezy', 'precise': { + $jdk_package = 'openjdk-7-jdk' + $jre_package = 'openjdk-7-jre-headless' + } + } + } + 'Solaris': { + $jdk_package = 'developer/java/jdk-7' + $jre_package = 'runtime/java/jre-7' + } + 'Suse': { + $jdk_package = 'java-1_6_0-ibm-devel' + $jre_package = 'java-1_6_0-ibm' + } + } + +} diff --git a/tests/init.pp b/tests/init.pp index 4114e3b..bdd923e 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1,10 +1,4 @@ -node default { - - notify { "alpha": } -> - class { 'java': - distribution => 'jdk', - version => 'latest', - } -> - notify { "omega": } - +class { 'java': + distribution => 'jdk', + version => 'latest', } From 5091d7fd6a2901e9d1d271afaac90fc36e3bad80 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Thu, 4 Apr 2013 20:07:31 -0700 Subject: [PATCH 2/3] Add package as class parameter In case the defaults aren't good enough --- manifests/init.pp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 038a776..cc8981b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -11,6 +11,10 @@ # The version of java to install. By default, this module simply ensures # that java is present, and does not require a specific version. # +# [*package*] +# The name of the java package. This is configurable in case a non-standard +# java package is desired. +# # Actions: # # Requires: @@ -19,7 +23,8 @@ # class java( $distribution = 'jdk', - $version = 'present' + $version = 'present', + $package = undef, ) { include java::params @@ -28,16 +33,21 @@ class java( case $distribution { default: { fail('distribution must be one of jdk, jre') } 'jdk': { - $java_package_name = $java::params::jdk_package + $default_package_name = $java::params::jdk_package } 'jre': { - $java_package_name = $java::params::jre_package + $default_package_name = $java::params::jre_package } } + $use_java_package_name = $package ? { + default => $package, + undef => $default_package_name, + } + package { 'java': ensure => $version, - name => $java_package_name, + name => $use_java_package_name, } } From b46f256b11cfe777726472f8357d56656ca29de2 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Thu, 4 Apr 2013 19:53:44 -0700 Subject: [PATCH 3/3] Remove cruft and bumb version number --- CHANGELOG | 3 +++ LICENSE | 2 +- Modulefile | 2 +- README.markdown | 30 +----------------------------- spec/spec.opts | 6 ------ spec/spec_helper.rb | 18 ------------------ templates/sun-java6.preseed | 3 --- 7 files changed, 6 insertions(+), 58 deletions(-) delete mode 100644 spec/spec.opts delete mode 100644 spec/spec_helper.rb delete mode 100644 templates/sun-java6.preseed diff --git a/CHANGELOG b/CHANGELOG index 2c98ee2..e3eddad 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2013-04-04 Reid Vandewiele - 0.3.0 +* Refactor, introduce params pattern + 2012-11-15 Scott Schneider - 0.2.0 * Add Solaris support diff --git a/LICENSE b/LICENSE index 47c26bd..a33e812 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Puppet OpenNebula Module - Puppet module for managing OpenNebula +Puppet Java Module - Puppet module for managing Java Copyright (C) 2011 Puppet Labs Inc diff --git a/Modulefile b/Modulefile index 672bd0c..fbc1f39 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-java' -version '0.2.0' +version '0.3.0' source 'git://github.com/puppetlabs/puppetlabs-java' author 'puppetlabs' license 'Apache' diff --git a/README.markdown b/README.markdown index 4494835..545eacc 100644 --- a/README.markdown +++ b/README.markdown @@ -2,32 +2,4 @@ Manage the Java runtime for use with other application software. -Currently this simply deploys the package on Enterprise Linux based systems and Debian based systems. - -Tested on: - - * Centos 5.6 - * Ubuntu 10.04 Lucid - -# RedHat Support # - -The Java runtime this module is designed to configure are the RPM's provided by Oracle and obtained by extracting them from the "bin" installers. - -For example: - - ./jdk-6u25-linux-x64-rpm.bin -x - -Please download the installer from: - - * [Java Downloads](http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-download-346242.html) - -# Ubuntu Support # - -## Lucid ## - -You need to have the partner repository enabled in order to install the Sun JDK or JRE. - - aptitude install python-software-properties - sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" - aptitude update - +Currently this deploys the correct Java package on a variety of platforms. diff --git a/spec/spec.opts b/spec/spec.opts deleted file mode 100644 index 91cd642..0000000 --- a/spec/spec.opts +++ /dev/null @@ -1,6 +0,0 @@ ---format -s ---colour ---loadby -mtime ---backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index a4aeeae..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'pathname' -dir = Pathname.new(__FILE__).parent -$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') - -require 'mocha' -require 'puppet' -gem 'rspec', '=1.2.9' -require 'spec/autorun' - -Spec::Runner.configure do |config| - config.mock_with :mocha -end - -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should -end diff --git a/templates/sun-java6.preseed b/templates/sun-java6.preseed deleted file mode 100644 index b22f4b6..0000000 --- a/templates/sun-java6.preseed +++ /dev/null @@ -1,3 +0,0 @@ -sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true -sun-java6-jdk shared/accepted-sun-dlj-v1-1 boolean true -sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true