Ottomata has submitted this change and it was merged.

Change subject: Initial commit of zookeeper module.
......................................................................


Initial commit of zookeeper module.

Change-Id: I88f9f7c4eb9ac736c3d31be845b5d12e0fd3c6c3
---
M README.md
A manifests/defaults.pp
A manifests/init.pp
A manifests/server.pp
A templates/log4j.properties.erb
A templates/zoo.cfg.erb
A templates/zookeeper.default.erb
A tests/Makefile
A tests/server.pp
A tests/zookeeper.pp
10 files changed, 306 insertions(+), 0 deletions(-)

Approvals:
  Ottomata: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/README.md b/README.md
index e69de29..8da7b61 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,30 @@
+# Puppet Zookeeper Module
+
+Installs and configures a Zookeeper client and/or Zookeeper server.
+
+This module has been implemented and tested on Ubuntu Precise, and uses
+the Zookeeper package in upstream Debian/Ubuntu repositories.
+
+# Usage
+
+class { 'zookeeper':
+    hosts    => { 'zoo1.domain.org' => 1, 'zoo2.domain.org' => 2, 
'zoo3.domain.org' => 3 },
+    data_dir => '/var/lib/zookeeper',
+}
+
+The above setup should be used to configure a 3 node zookeeper cluster.
+You can include the above class on any of your nodes that will need to talk
+to the zookeeper cluster.
+
+On the 3 zookeeper server nodes, you should also include:
+
+class { 'zookeeper::server': }
+
+This will ensure that the zookeeper server is running.
+Remember that this requires that you also include the
+zookeeper class as defined above as well as the server class.
+
+On each of the defined zookeeper hosts, a myid file must be created
+that identifies the host in the zookeeper quorum.  This myid number
+will be extracted from the hosts Hash keyed by the node's $fqdn.
+E.g.  zoo1.domain.org's myid will be '1', zoo2.domain.org's myid will be 2, 
etc.
\ No newline at end of file
diff --git a/manifests/defaults.pp b/manifests/defaults.pp
new file mode 100644
index 0000000..7bfedac
--- /dev/null
+++ b/manifests/defaults.pp
@@ -0,0 +1,21 @@
+# == Class zookeeper::defaults
+# Default zookeeper configs.
+class zookeeper::defaults {
+    $hosts            = { "${::fqdn}" => 1 }
+
+    $data_dir         = '/var/lib/zookeeper'
+    $data_log_dir     = undef
+    $log_file         = '/var/log/zookeeper/zookeeper.log'
+    $jmx_port         = 9998
+
+    # Default puppet paths to template config files.
+    # This allows us to use custom template config files
+    # if we want to override more settings than this
+    # module yet supports.
+    $conf_template    = 'zookeeper/zoo.cfg.erb'
+    $default_template = 'zookeeper/zookeeper.default.erb'
+    $log4j_template   = 'zookeeper/log4j.properties.erb'
+
+    # Zookeeper package version.
+    $version          = 'installed'
+}
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..d3036df
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,51 @@
+# == Class zookeeper
+# Installs common zookeeper package and configs.
+#
+# == Parameters
+# $hosts         - Hash of zookeeper fqdns to myids.
+# $data_dir      - Zookeeper dataDir.     Default: /var/lib/zookeeper
+# $data_log_dir  - Zookeeper dataLogDir.  Default: undef.
+# $version       - Zookeeper package version number.  Set this if you need to
+#                  override the default package version.  Default: installed.
+#
+# == Usage
+#
+# class { 'zookeeper':
+#   hosts    => { 'zoo1.domain.org' => 1, 'zoo2.domain.org' => 2, 
'zoo3.domain.org' => 3 },
+#   data_dir => '/var/lib/zookeeper',
+# }
+#
+# The above setup should be used to configure a 3 node zookeeper cluster.
+# You can include the above class on any of your nodes that will need to talk
+# to the zookeeper cluster.
+#
+# On the 3 zookeeper server nodes, you should also include:
+#
+# class { 'zookeeper::server': }
+#
+# This will ensure that the zookeeper server is running.
+# Remember that this requires that you also include the
+# zookeeper class as defined above as well as the server class.
+#
+# On each of the defined zookeeper hosts, a myid file must be created
+# that identifies the host in the zookeeper quorum.  This myid number
+# will be inferred from the nodes index in the zookeeper hosts array.
+# e.g.  zoo1.domain.org's myid will be '1', zoo2.domain.org's myid will be 2, 
etc.
+#
+class zookeeper(
+    $hosts         = $::zookeeper::defaults::hosts,
+    $data_dir      = $::zookeeper::defaults::data_dir,
+    $data_log_dir  = $::zookeeper::defaults::data_log_dir,
+    $conf_template = $::zookeeper::defaults::conf_template,
+    $version       = $::zookeeper::defaults::version
+) inherits zookeeper::defaults
+{
+    package { 'zookeeper':
+        ensure => $version,
+    }
+
+    file { '/etc/zookeeper/conf/zoo.cfg':
+        content => template($conf_template),
+        require => Package['zookeeper'],
+    }
+}
diff --git a/manifests/server.pp b/manifests/server.pp
new file mode 100644
index 0000000..fc39ba7
--- /dev/null
+++ b/manifests/server.pp
@@ -0,0 +1,70 @@
+# == Class zookeeper::server
+# Configures a zookeeper server.
+# This requires that zookeeper is installed
+# And that the current nodes fqdn is an entry in the
+# $::zookeeper::hosts array.
+#
+# == Parameters
+# $jmx_port            - JMX port.    Set this to false if you don't want to 
expose JMX.
+# $log_file            - zookeeper.log file.    Default: 
/var/log/zookeeper/zookeeper.log
+#
+class zookeeper::server(
+    $jmx_port         = $::zookeeper::defaults::jmx_port,
+    $log_file         = $::zookeeper::defaults::log_file,
+    $default_template = $::zookeeper::defaults::default_template,
+    $log4j_template   = $::zookeeper::defaults::log4j_template
+)
+{
+    # need zookeeper common package and config.
+    Class['zookeeper'] -> Class['zookeeper::server']
+
+    # Install zookeeper server package
+    package { 'zookeeperd':
+        ensure    => $::zookeeper::version,
+    }
+
+    file { '/etc/default/zookeeper':
+        content => template($default_template),
+        require => Package['zookeeperd'],
+    }
+
+    file { '/etc/zookeeper/conf/log4j.properties':
+        content => template($log4j_template),
+        require => Package['zookeeperd'],
+    }
+
+    file { $::zookeeper::data_dir:
+        ensure => 'directory',
+        owner  => 'zookeeper',
+        group  => 'zookeeper',
+        mode   => '0755',
+    }
+
+    # Get this host's $myid from the $fqdn in the $zookeeper_hosts hash.
+    $myid = $::zookeeper::hosts[$::fqdn]
+    file { '/etc/zookeeper/conf/myid':
+        content => $myid,
+    }
+    file { "${::zookeeper::data_dir}/myid":
+        ensure  => 'link',
+        target  => '/etc/zookeeper/conf/myid',
+    }
+
+    service { 'zookeeper':
+        ensure     => running,
+        require    => [
+            Package['zookeeperd'],
+            File[ $::zookeeper::data_dir],
+            File["${::zookeeper::data_dir}/myid"],
+        ],
+        hasrestart => true,
+        hasstatus  => true,
+        subscribe  => [
+            File['/etc/default/zookeeper'],
+            File['/etc/zookeeper/conf/zoo.cfg'],
+            File['/etc/zookeeper/conf/myid'],
+            File['/etc/zookeeper/conf/log4j.properties'],
+        ],
+    }
+
+}
\ No newline at end of file
diff --git a/templates/log4j.properties.erb b/templates/log4j.properties.erb
new file mode 100644
index 0000000..dbf29c9
--- /dev/null
+++ b/templates/log4j.properties.erb
@@ -0,0 +1,31 @@
+# Note: This file is managed by Puppet.
+
+#
+# ZooKeeper Logging Configuration
+#
+
+# Format is "<default threshold> (, <appender>)+
+
+log4j.rootLogger=${zookeeper.root.logger}, ROLLINGFILE
+
+#
+# Log INFO level and above messages to the console
+#
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Threshold=INFO
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p 
[%t:%C{1}@%L] - %m%n
+
+#
+# Add ROLLINGFILE to rootLogger to get log file output
+#    Log INFO level and above messages to a log file
+log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLLINGFILE.Threshold=INFO
+log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/zookeeper.log
+
+# Max log file size of 10MB
+log4j.appender.ROLLINGFILE.MaxFileSize=10MB
+# Keep only 10 files
+log4j.appender.ROLLINGFILE.MaxBackupIndex=10
+log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p 
[%t:%C{1}@%L] - %m%n
\ No newline at end of file
diff --git a/templates/zoo.cfg.erb b/templates/zoo.cfg.erb
new file mode 100644
index 0000000..ba939a5
--- /dev/null
+++ b/templates/zoo.cfg.erb
@@ -0,0 +1,64 @@
+# Note: This file is managed by Puppet.
+
+# http://hadoop.apache.org/zookeeper/docs/current/zookeeperAdmin.html
+
+# specify all zookeeper servers
+# The fist port is used by followers to connect to the leader
+# The second one is used for leader election
+<%
+if @hosts
+# sort hosts by myid and output a server config
+# for each host and myid.  (sort_by returns an array of key,value tuples)
+hosts.sort_by { |name, id| id }.each do |host_id|
+-%>
+server.<%= host_id[1] %>=<%= host_id[0] %>:2182:2183
+<% end -%>
+<% end -%>
+
+# the port at which the clients will connect
+clientPort=2181
+
+# the directory where the snapshot is stored.
+dataDir=<%= data_dir %>
+
+# Place the dataLogDir to a separate physical disc for better performance
+<%= @data_log_dir ? "dataLogDir=#{data_log_dir}" : '# 
dataLogDir=/disk2/zookeeper' %>
+
+
+# The number of milliseconds of each tick
+tickTime=2000
+
+# The number of ticks that the initial
+# synchronization phase can take
+initLimit=10
+
+# The number of ticks that can pass between
+# sending a request and getting an acknowledgement
+syncLimit=5
+
+# To avoid seeks ZooKeeper allocates space in the transaction log file in
+# blocks of preAllocSize kilobytes. The default block size is 64M. One reason
+# for changing the size of the blocks is to reduce the block size if snapshots
+# are taken more often. (Also, see snapCount).
+#preAllocSize=65536
+
+# Clients can submit requests faster than ZooKeeper can process them,
+# especially if there are a lot of clients. To prevent ZooKeeper from running
+# out of memory due to queued requests, ZooKeeper will throttle clients so that
+# there is no more than globalOutstandingLimit outstanding requests in the
+# system. The default limit is 1,000.ZooKeeper logs transactions to a
+# transaction log. After snapCount transactions are written to a log file a
+# snapshot is started and a new transaction log file is started. The default
+# snapCount is 10,000.
+#snapCount=1000
+
+# If this option is defined, requests will be will logged to a trace file named
+# traceFile.year.month.day.
+#traceFile=
+
+# Leader accepts client connections. Default value is "yes". The leader machine
+# coordinates updates. For higher update throughput at thes slight expense of
+# read throughput the leader can be configured to not accept clients and focus
+# on coordination.
+#leaderServes=yes
+
diff --git a/templates/zookeeper.default.erb b/templates/zookeeper.default.erb
new file mode 100644
index 0000000..4018160
--- /dev/null
+++ b/templates/zookeeper.default.erb
@@ -0,0 +1,14 @@
+# Note: This file is managed by Puppet.
+
+# See the following page for extensive details on setting
+# up the JVM to accept JMX remote management:
+# http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
+
+<% if @jmx_port -%>
+# Enable JMX connections on port <%= jmx_port %>
+JMXLOCALONLY=false
+JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=<%= jmx_port %> 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.authenticate=false"
+<% else -%>
+JMXDISABLE=true
+<% end -%>
+
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..2572fda
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,11 @@
+MANIFESTS=zookeeper.po server.po
+TESTS_DIR=$(dir $(CURDIR))
+MODULE_DIR=$(TESTS_DIR:/=)
+MODULES_DIR=$(dir $(MODULE_DIR))
+
+all:   test
+
+test: $(MANIFESTS) 
+
+%.po:  %.pp
+       puppet apply --noop --modulepath $(MODULES_DIR) $<
diff --git a/tests/server.pp b/tests/server.pp
new file mode 100644
index 0000000..67808d1
--- /dev/null
+++ b/tests/server.pp
@@ -0,0 +1,8 @@
+$fqdn = 'zoo1.domain.org'
+
+class { 'zookeeper':
+    hosts    => { 'zoo1.domain.org' => 1, 'zoo2.domain.org' => 2, 
'zoo3.domain.org' => 3 },
+    data_dir => '/var/lib/zookeeper',
+}
+
+class { 'zookeeper::server': }
diff --git a/tests/zookeeper.pp b/tests/zookeeper.pp
new file mode 100644
index 0000000..fee4b07
--- /dev/null
+++ b/tests/zookeeper.pp
@@ -0,0 +1,6 @@
+$fqdn = 'zoo1.domain.org'
+
+class { 'zookeeper':
+    hosts    => { 'zoo1.domain.org' => 1, 'zoo2.domain.org' => 2, 
'zoo3.domain.org' => 3 },
+    data_dir => '/var/lib/zookeeper',
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/66882
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I88f9f7c4eb9ac736c3d31be845b5d12e0fd3c6c3
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet/zookeeper
Gerrit-Branch: master
Gerrit-Owner: Ottomata <[email protected]>
Gerrit-Reviewer: Akosiaris <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Faidon <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to