Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/66882


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

Initial commit of zookeeper module.

(Not ready for review)

Change-Id: I88f9f7c4eb9ac736c3d31be845b5d12e0fd3c6c3
---
A manifests/init.pp
A manifests/zookeeper/defaults.pp
A manifests/zookeeper/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
9 files changed, 288 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet/zookeeper 
refs/changes/82/66882/1

diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..b3528c2
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,49 @@
+# == Class zookeeper
+# Installs common zookeeper package and configs.
+#
+# == Parameters
+# $hosts         - Array of zookeeper fqdns.  The order of this array matters.
+#                  Zookeeper 'myid's will be inferred from the node's index in 
this array.
+# $data_dir      - Zookeeper dataDir.     Default: /var/lib/zookeeper
+# $data_log_dir  - Zookeeper dataLogDir.  Default: undef.
+#
+# == Usage
+#
+# class { 'zookeeper':
+#   hosts    => ['zoo0.domain.org', 'zoo1.domain.org', 'zoo2.domain.org'],
+#   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.  zoo0.domain.org's myid will be '0', zoo1.domain.org's myid will be 1, 
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,
+) inherits zookeeper::defaults
+{
+  package { ['zookeeper', 'zookeeper-bin']:
+    ensure => 'installed',
+  }
+
+  file { '/etc/zookeeper/conf/zoo.cfg':
+    content => template($conf_template),
+    require => Package['zookeeper'],
+  }
+}
\ No newline at end of file
diff --git a/manifests/zookeeper/defaults.pp b/manifests/zookeeper/defaults.pp
new file mode 100644
index 0000000..f5e1804
--- /dev/null
+++ b/manifests/zookeeper/defaults.pp
@@ -0,0 +1,22 @@
+# == Class zookeeper::defaults
+# Default zookeeper configs.
+class zookeeper::defaults {
+  # NOTE: The order of this array matters.
+  # The Zookeeper 'myid' will be infered by the index of a node's
+  # fqdn in this array.  Changing the order will change the 'myid'
+  # of zookeeper servers.
+  $hosts            = [$::fqdn]
+
+  $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'
+}
diff --git a/manifests/zookeeper/server.pp b/manifests/zookeeper/server.pp
new file mode 100644
index 0000000..210a204
--- /dev/null
+++ b/manifests/zookeeper/server.pp
@@ -0,0 +1,67 @@
+# == 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  => 'installed',
+  }
+
+  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',
+  }
+
+  $zookeeper_hosts = $::zookeeper::hosts
+  # Infer this host's $myid from the index in the $zookeeper_hosts array.
+  $myid = inline_template('<%= zookeeper_hosts.index(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]],
+    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..e81538b
--- /dev/null
+++ b/templates/log4j.properties.erb
@@ -0,0 +1,53 @@
+# Note: This file is managed by Puppet.
+
+#
+# ZooKeeper Logging Configuration
+#
+
+# Format is "<default threshold> (, <appender>)+
+
+log4j.rootLogger=${zookeeper.root.logger}
+
+# Example: console appender only
+# log4j.rootLogger=INFO, CONSOLE
+
+# Example with rolling log file
+#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
+
+# Example with rolling log file and tracing
+#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
+
+#
+# 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 DEBUG level and above messages to a log file
+log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLLINGFILE.Threshold=DEBUG
+log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/zookeeper.log
+
+# Max log file size of 10MB
+log4j.appender.ROLLINGFILE.MaxFileSize=10MB
+# uncomment the next line to limit number of backup 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
+
+
+#
+# Add TRACEFILE to rootLogger to get log file output
+#    Log DEBUG level and above messages to a log file
+log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
+log4j.appender.TRACEFILE.Threshold=TRACE
+log4j.appender.TRACEFILE.File=${zookeeper.log.dir}/zookeeper_trace.log
+
+log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
+### Notice we are including log4j's NDC here (%x)
+log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} - %-5p 
[%t:%C{1}@%L][%x] - %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..43e7f57
--- /dev/null
+++ b/templates/zoo.cfg.erb
@@ -0,0 +1,62 @@
+# 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
+hosts.each_with_index do |name, id|
+-%>
+server.<%= id %>=<%= name %>: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..fb33bd3
--- /dev/null
+++ b/tests/server.pp
@@ -0,0 +1,6 @@
+class { 'zookeeper':
+  hosts    => ['zoo0.domain.org', 'zoo1.domain.org', 'zoo2.domain.org'],
+  data_dir => '/var/lib/zookeeper',
+}
+
+class { 'zookeeper::server': }
diff --git a/tests/zookeeper.pp b/tests/zookeeper.pp
new file mode 100644
index 0000000..60b6ef3
--- /dev/null
+++ b/tests/zookeeper.pp
@@ -0,0 +1,4 @@
+class { 'zookeeper':
+  hosts    => ['zoo0.domain.org', 'zoo1.domain.org', 'zoo2.domain.org'],
+  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: newchange
Gerrit-Change-Id: I88f9f7c4eb9ac736c3d31be845b5d12e0fd3c6c3
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet/zookeeper
Gerrit-Branch: master
Gerrit-Owner: Ottomata <[email protected]>

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

Reply via email to