Browse Source

Implement Ceilometer-Redis plugin

In details:
  * Adapt Redis puppet module for plugin usage:
    - update tests
    - improvements for sentinel installation
    - uncomment CentOS params for plugin usage on next Fuel releases
  * Prepare main puppet script for:
    - Redis and sentinel installation
    - Work with ceilometer-agent-central service as pacemaker resource
     (remove old one and configure new with clone set)
    - Configure redis under pacemaker
    - Add ocf scripts for redis-server
  * Add tasks for plugin
  * Add metadata for plugin
  * Add Redis packages (2.8 version) and their dependencies
  * Use existing ceilometer network role for redis

Partially implements: blueprint ceilometer-central-agent-ha

Change-Id: I77c75e05b28f3ff4690e89034e345cc9c64af5e5
iberezovskiy 3 years ago
parent
commit
a53478afe9

+ 34
- 0
deployment_scripts/puppet/manifests/controller.pp View File

@@ -0,0 +1,34 @@
1
+#    Copyright 2015 Mirantis, Inc.
2
+#
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+
15
+prepare_network_config(hiera('network_scheme', {}))
16
+
17
+$redis_roles = ["primary-controller", "controller"]
18
+$redis_nodes = get_nodes_hash_by_roles(hiera('network_metadata'), $redis_roles)
19
+# Use ceilometer network role
20
+$redis_address_map  = get_node_to_ipaddr_map_by_network_role($redis_nodes, 'ceilometer/api')
21
+$redis_hosts        = values($redis_address_map)
22
+$redis_bind_address = get_network_role_property('ceilometer/api', 'ipaddr')
23
+
24
+# Set primary redis on primary-controller
25
+$redis_primary_nodes       = get_nodes_hash_by_roles(hiera('network_metadata'), ["primary-controller"])
26
+$redis_primary_address_map = get_node_to_ipaddr_map_by_network_role($redis_primary_nodes, 'ceilometer/api')
27
+$primary_redis_node        = values($redis_primary_address_map)
28
+
29
+class {'::redis::main':
30
+  primary_redis_node => $primary_redis_node[0],
31
+  redis_hosts        => $redis_hosts,
32
+  redis_bind_address => $redis_bind_address,
33
+  primary_controller => false,
34
+}

+ 34
- 0
deployment_scripts/puppet/manifests/primary-controller.pp View File

@@ -0,0 +1,34 @@
1
+#    Copyright 2015 Mirantis, Inc.
2
+#
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+
15
+prepare_network_config(hiera('network_scheme', {}))
16
+
17
+$redis_roles = ["primary-controller", "controller"]
18
+$redis_nodes = get_nodes_hash_by_roles(hiera('network_metadata'), $redis_roles)
19
+# Use ceilometer network role
20
+$redis_address_map  = get_node_to_ipaddr_map_by_network_role($redis_nodes, 'ceilometer/api')
21
+$redis_hosts        = values($redis_address_map)
22
+$redis_bind_address = get_network_role_property('ceilometer/api', 'ipaddr')
23
+
24
+# Set primary redis on primary-controller
25
+$redis_primary_nodes       = get_nodes_hash_by_roles(hiera('network_metadata'), ["primary-controller"])
26
+$redis_primary_address_map = get_node_to_ipaddr_map_by_network_role($redis_primary_nodes, 'ceilometer/api')
27
+$primary_redis_node        = values($redis_primary_address_map)
28
+
29
+class {'::redis::main':
30
+  primary_redis_node => $primary_redis_node[0],
31
+  redis_hosts        => $redis_hosts,
32
+  redis_bind_address => $redis_bind_address,
33
+  primary_controller => true,
34
+}

+ 14
- 1
deployment_scripts/puppet/modules/redis/Rakefile View File

@@ -1,6 +1,6 @@
1
+require 'rubygems'
1 2
 require 'puppetlabs_spec_helper/rake_tasks'
2 3
 require 'puppet-lint/tasks/puppet-lint'
3
-
4 4
 PuppetLint.configuration.fail_on_warnings
5 5
 PuppetLint.configuration.send('relative')
6 6
 PuppetLint.configuration.send('disable_80chars')
@@ -9,3 +9,16 @@ PuppetLint.configuration.send('disable_class_parameter_defaults')
9 9
 PuppetLint.configuration.send('disable_documentation')
10 10
 PuppetLint.configuration.send('disable_single_quote_string_with_variables')
11 11
 PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
12
+
13
+desc "Validate manifests, templates, and ruby files in lib."
14
+task :validate do
15
+  Dir['manifests/**/*.pp'].each do |manifest|
16
+    sh "puppet parser validate --noop #{manifest}"
17
+  end
18
+  Dir['lib/**/*.rb'].each do |lib_file|
19
+    sh "ruby -c #{lib_file}"
20
+  end
21
+  Dir['templates/**/*.erb'].each do |template|
22
+    sh "erb -P -x -T '-' #{template} | ruby -c"
23
+  end
24
+end

+ 348
- 0
deployment_scripts/puppet/modules/redis/files/ocf/redis-server View File

@@ -0,0 +1,348 @@
1
+#!/bin/sh
2
+#
3
+#
4
+# Redis Service (redis-server)
5
+#
6
+# Description:
7
+# Redis is an open source, BSD licensed, advanced key-value cache and store.
8
+# It is often referred to as a data structure server since keys can contain
9
+# strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.
10
+#
11
+#
12
+# License: Apache Software License (ASL) 2.0
13
+#
14
+#
15
+# See usage() function below for more details ...
16
+#
17
+# OCF instance parameters:
18
+# OCF_RESKEY_binary
19
+# OCF_RESKEY_config
20
+# OCF_RESKEY_user
21
+# OCF_RESKEY_pid
22
+# OCF_RESKEY_monitor_binary
23
+# OCF_RESKEY_redis_server_port
24
+# OCF_RESKEY_additional_parameters
25
+#######################################################################
26
+# Initialization:
27
+
28
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
29
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
30
+
31
+#######################################################################
32
+
33
+# Fill in some defaults if no values are specified
34
+
35
+OCF_RESKEY_binary_default="redis-server"
36
+if [ -f "/etc/redis.conf" ]; then
37
+  OCF_RESKEY_config_default="/etc/redis.conf"
38
+else
39
+  OCF_RESKEY_config_default="/etc/redis/redis.conf"
40
+fi
41
+OCF_RESKEY_user_default="redis"
42
+OCF_RESKEY_pid_default="/var/run/redis/redis-server.pid"
43
+OCF_RESKEY_redis_server_port_default="6379"
44
+
45
+: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
46
+: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}}
47
+: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}
48
+: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
49
+: ${OCF_RESKEY_redis_server_port=${OCF_RESKEY_redis_server_port_default}}
50
+
51
+#######################################################################
52
+
53
+usage() {
54
+    cat <<UEND
55
+        usage: $0 (start|stop|validate-all|meta-data|status|monitor)
56
+
57
+        $0 manages an Redis Service (redis-server) process as an HA resource
58
+
59
+        The 'start' operation starts the scheduler service.
60
+        The 'stop' operation stops the scheduler service.
61
+        The 'validate-all' operation reports whether the parameters are valid
62
+        The 'meta-data' operation reports this RA's meta-data information
63
+        The 'status' operation reports whether the scheduler service is running
64
+        The 'monitor' operation reports whether the scheduler service seems to be working
65
+
66
+UEND
67
+}
68
+
69
+meta_data() {
70
+    cat <<END
71
+<?xml version="1.0"?>
72
+<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
73
+<resource-agent name="redis-server">
74
+<version>1.0</version>
75
+
76
+<longdesc lang="en">
77
+Resource agent for the Redis Service (redis-server)
78
+May manage a redis-server instance or a clone set that
79
+creates a distributed redis-server cluster.
80
+</longdesc>
81
+<shortdesc lang="en">Manages the Redis Service (redis)</shortdesc>
82
+<parameters>
83
+
84
+<parameter name="binary" unique="0" required="0">
85
+<longdesc lang="en">
86
+Location of the Redis server binary (redis-server)
87
+</longdesc>
88
+<shortdesc lang="en">Redis server binary (redis-server)</shortdesc>
89
+<content type="string" default="${OCF_RESKEY_binary_default}" />
90
+</parameter>
91
+
92
+<parameter name="config" unique="0" required="0">
93
+<longdesc lang="en">
94
+Redis service (redis-server) configuration file
95
+</longdesc>
96
+<shortdesc lang="en">Rredis (redis-server) config file</shortdesc>
97
+<content type="string" default="${OCF_RESKEY_config_default}" />
98
+</parameter>
99
+
100
+<parameter name="user" unique="0" required="0">
101
+<longdesc lang="en">
102
+User running Redis Service (redis)
103
+</longdesc>
104
+<shortdesc lang="en">Redis Service (redis-server) user</shortdesc>
105
+<content type="string" default="${OCF_RESKEY_user_default}" />
106
+</parameter>
107
+
108
+<parameter name="pid" unique="0" required="0">
109
+<longdesc lang="en">
110
+The pid file to use for this Redis Service (redis-server) instance
111
+</longdesc>
112
+<shortdesc lang="en">Redis Service (redis-server) pid file</shortdesc>
113
+<content type="string" default="${OCF_RESKEY_pid_default}" />
114
+</parameter>
115
+
116
+<parameter name="redis_server_port" unique="0" required="0">
117
+<longdesc lang="en">
118
+The listening port number of the Redis server. Use for monitoring purposes
119
+</longdesc>
120
+<shortdesc lang="en">Redis server listening port</shortdesc>
121
+<content type="integer" default="${OCF_RESKEY_redis_server_port_default}" />
122
+</parameter>
123
+
124
+<parameter name="additional_parameters" unique="0" required="0">
125
+<longdesc lang="en">
126
+Additional parameters to pass on to the Redis Service (redis-server)
127
+</longdesc>
128
+<shortdesc lang="en">Additional parameters for redis-server</shortdesc>
129
+<content type="string" />
130
+</parameter>
131
+
132
+</parameters>
133
+
134
+<actions>
135
+<action name="start" timeout="20" />
136
+<action name="stop" timeout="20" />
137
+<action name="status" timeout="20" />
138
+<action name="monitor" timeout="30" interval="20" />
139
+<action name="validate-all" timeout="5" />
140
+<action name="meta-data" timeout="5" />
141
+</actions>
142
+</resource-agent>
143
+END
144
+}
145
+
146
+#######################################################################
147
+# Functions invoked by resource manager actions
148
+
149
+redis_server_check_port() {
150
+    local int
151
+    local cnt
152
+
153
+    int="$1"
154
+    cnt=${#int}
155
+    echo $int |egrep -qx '[0-9]+(:[0-9]+)?(,[0-9]+(:[0-9]+)?)*'
156
+
157
+    if [ $? -ne 0 ] || [ $cnt -ne 4 ]; then
158
+        ocf_log err "Invalid port number: $1"
159
+        exit $OCF_ERR_CONFIGURED
160
+    fi
161
+}
162
+
163
+redis_server_validate() {
164
+    local rc
165
+
166
+    check_binary $OCF_RESKEY_binary
167
+    check_binary netstat
168
+    redis_server_check_port $OCF_RESKEY_redis_server_port
169
+
170
+    # A config file on shared storage that is not available
171
+    # during probes is OK.
172
+    if [ ! -f $OCF_RESKEY_config ]; then
173
+        if ! ocf_is_probe; then
174
+            ocf_log err "Config $OCF_RESKEY_config doesn't exist"
175
+            return $OCF_ERR_INSTALLED
176
+        fi
177
+        ocf_log_warn "Config $OCF_RESKEY_config not available during a probe"
178
+    fi
179
+
180
+    getent passwd $OCF_RESKEY_user >/dev/null 2>&1
181
+    rc=$?
182
+    if [ $rc -ne 0 ]; then
183
+        ocf_log err "User $OCF_RESKEY_user doesn't exist"
184
+        return $OCF_ERR_INSTALLED
185
+    fi
186
+
187
+    true
188
+}
189
+
190
+redis_server_status() {
191
+    local pid
192
+    local rc
193
+
194
+    # check and make PID file dir
195
+    local PID_DIR="$( dirname ${OCF_RESKEY_pid} )"
196
+    if [ ! -d "${PID_DIR}" ] ; then
197
+        ocf_log debug "Create pid file dir: ${PID_DIR} and chown to ${OCF_RESKEY_user}"
198
+        mkdir -p "${PID_DIR}"
199
+        chown -R ${OCF_RESKEY_user} "${PID_DIR}"
200
+        chmod 755 "${PID_DIR}"
201
+    fi
202
+
203
+    if [ ! -f $OCF_RESKEY_pid ]; then
204
+        ocf_log info "Redis service (redis-server) is not running"
205
+        return $OCF_NOT_RUNNING
206
+    else
207
+        pid=`cat $OCF_RESKEY_pid`
208
+    fi
209
+
210
+    if [ -n "${pid}" ]; then
211
+      ocf_run -warn kill -s 0 $pid
212
+      rc=$?
213
+    else
214
+      ocf_log err "PID file ${OCF_RESKEY_pid} is empty!"
215
+      return $OCF_ERR_GENERIC
216
+    fi
217
+
218
+    if [ $rc -eq 0 ]; then
219
+        return $OCF_SUCCESS
220
+    else
221
+        ocf_log info "Old PID file found, but Redis service (redis-server) is not running"
222
+        return $OCF_NOT_RUNNING
223
+    fi
224
+}
225
+
226
+redis_server_monitor() {
227
+    local rc
228
+    local pid
229
+
230
+    redis_server_status
231
+    rc=$?
232
+
233
+    # If status returned anything but success, return that immediately
234
+    if [ $rc -ne $OCF_SUCCESS ]; then
235
+        return $rc
236
+    fi
237
+
238
+    ocf_log debug "Redis service (redis-server) monitor succeeded"
239
+    return $OCF_SUCCESS
240
+}
241
+
242
+redis_server_start() {
243
+    local rc
244
+
245
+    redis_server_status
246
+    rc=$?
247
+    if [ $rc -eq $OCF_SUCCESS ]; then
248
+        ocf_log info "Redis service (redis-server) already running"
249
+        return $OCF_SUCCESS
250
+    fi
251
+
252
+    # run the actual redis-server daemon. Don't use ocf_run as we're sending the tool's output
253
+    # straight to /dev/null anyway and using ocf_run would break stdout-redirection here.
254
+    su ${OCF_RESKEY_user} -s /bin/sh -c "${OCF_RESKEY_binary} $OCF_RESKEY_config \
255
+       $OCF_RESKEY_additional_parameters"' >> /dev/null 2>&1'
256
+
257
+    # Spin waiting for the server to come up.
258
+    while true; do
259
+    redis_server_monitor
260
+    rc=$?
261
+    [ $rc -eq $OCF_SUCCESS ] && break
262
+    if [ $rc -ne $OCF_NOT_RUNNING ]; then
263
+        ocf_log err "Redis service (redis_server) start failed"
264
+        exit $OCF_ERR_GENERIC
265
+    fi
266
+    sleep 3
267
+    done
268
+
269
+    ocf_log info "Redis service (redis_server) started"
270
+    return $OCF_SUCCESS
271
+}
272
+
273
+redis_server_stop() {
274
+    local rc
275
+    local pid
276
+
277
+    redis_server_status
278
+    rc=$?
279
+    if [ $rc -eq $OCF_NOT_RUNNING ]; then
280
+        ocf_log info "Redis service (redis-server) already stopped"
281
+        return $OCF_SUCCESS
282
+    fi
283
+
284
+    # Try SIGTERM
285
+    pid=`cat $OCF_RESKEY_pid`
286
+    ocf_run kill -s TERM $pid
287
+    rc=$?
288
+    if [ $rc -ne 0 ]; then
289
+        ocf_log err "Redis service (redis-server) couldn't be stopped"
290
+        exit $OCF_ERR_GENERIC
291
+    fi
292
+
293
+    # stop waiting
294
+    shutdown_timeout=15
295
+    if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
296
+        shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5))
297
+    fi
298
+    count=0
299
+    while [ $count -lt $shutdown_timeout ]; do
300
+        redis_server_status
301
+        rc=$?
302
+        if [ $rc -eq $OCF_NOT_RUNNING ]; then
303
+            break
304
+        fi
305
+        count=`expr $count + 1`
306
+        sleep 1
307
+        ocf_log debug "Redis service (redis-server) still hasn't stopped yet. Waiting ..."
308
+    done
309
+
310
+    redis_server_status
311
+    rc=$?
312
+    if [ $rc -ne $OCF_NOT_RUNNING ]; then
313
+        # SIGTERM didn't help either, try SIGKILL
314
+        ocf_log info "Redis service (redis-server) failed to stop after ${shutdown_timeout}s \
315
+          using SIGTERM. Trying SIGKILL ..."
316
+        ocf_run kill -s KILL $pid
317
+    fi
318
+
319
+    ocf_log info "Redis service (redis-server) stopped"
320
+
321
+    ocf_log debug "Delete pid file: ${OCF_RESKEY_pid} with content $(cat $OCF_RESKEY_pid)"
322
+    rm -f $OCF_RESKEY_pid
323
+
324
+    return $OCF_SUCCESS
325
+}
326
+
327
+#######################################################################
328
+
329
+case "$1" in
330
+  meta-data) meta_data
331
+                exit $OCF_SUCCESS;;
332
+  usage|help) usage
333
+                exit $OCF_SUCCESS;;
334
+esac
335
+
336
+# Anything except meta-data and help must pass validation
337
+redis_server_validate || exit $?
338
+
339
+# What kind of method was invoked?
340
+case "$1" in
341
+  start) redis_server_start;;
342
+  stop) redis_server_stop;;
343
+  status) redis_server_status;;
344
+  monitor) redis_server_monitor;;
345
+  validate-all) ;;
346
+  *) usage
347
+                exit $OCF_ERR_UNIMPLEMENTED;;
348
+esac

+ 5
- 0
deployment_scripts/puppet/modules/redis/lib/facter/check_mode.rb View File

@@ -0,0 +1,5 @@
1
+Facter.add('cluster_mode') do
2
+  setcode do
3
+    Facter::Util::Resolution.exec("cat /etc/astute.yaml | grep deployment_mode | awk '{print $2}'")
4
+  end
5
+end

+ 21
- 0
deployment_scripts/puppet/modules/redis/lib/puppet/parser/functions/redis_backend_url.rb View File

@@ -0,0 +1,21 @@
1
+module Puppet::Parser::Functions
2
+  newfunction(:redis_backend_url, :type => :rvalue) do |args|
3
+    if args.length != 3
4
+      raise "Wrong number of arguments"
5
+    end
6
+    nodes = args[0]
7
+    port = args[1]
8
+    timeout = args[2]
9
+
10
+    backend_url="redis://" + nodes[0] + ":" + port + "?sentinel=" + nodes[0]
11
+
12
+    nodes.each do |value|
13
+      if value != nodes[0]
14
+        backend_url=backend_url + "&sentinel_fallback=" + value + ":" + port
15
+      end
16
+    end
17
+    backend_url=backend_url + "&timeout=" + timeout
18
+
19
+    backend_url
20
+  end
21
+end

+ 23
- 0
deployment_scripts/puppet/modules/redis/lib/puppet/parser/functions/sentinel_confs.rb View File

@@ -0,0 +1,23 @@
1
+module Puppet::Parser::Functions
2
+  newfunction(:sentinel_confs, :type => :rvalue) do |args|
3
+    if args.length != 6
4
+      raise "Wrong number of arguments"
5
+    end
6
+    nodes = args[0]
7
+    port = args[1]
8
+    quorum = args[2]
9
+    parallel_syncs = args[3]
10
+    down_after_milliseconds = args[4]
11
+    failover_timeout = args[5]
12
+    hash = {}
13
+
14
+    nodes.each do |value|
15
+      hash[value] = { 'monitor' => value + ' ' + port + ' ' + quorum,
16
+                      'down-after-milliseconds' => down_after_milliseconds,
17
+                      'failover-timeout' => failover_timeout,
18
+                      'parallel-syncs' => parallel_syncs }
19
+    end
20
+
21
+    hash
22
+  end
23
+end

+ 2
- 2
deployment_scripts/puppet/modules/redis/manifests/init.pp View File

@@ -161,8 +161,8 @@ class redis (
161 161
   file { $conf_redis:
162 162
     path    => $conf_redis,
163 163
     content => template('redis/redis.conf.erb'),
164
-    owner   => root,
165
-    group   => root,
164
+    owner   => redis,
165
+    group   => redis,
166 166
     mode    => '0644',
167 167
     require => Package['redis'],
168 168
   }

+ 221
- 0
deployment_scripts/puppet/modules/redis/manifests/main.pp View File

@@ -0,0 +1,221 @@
1
+#
2
+# == Class: redis::main
3
+#
4
+# Installs and configures Redis
5
+#
6
+# === Parameters:
7
+#
8
+# [*primary_controller*]
9
+#   Status of controller node
10
+#   Defaults to false
11
+#
12
+# [*parallel_syncs*]
13
+#   How many slaves we can reconfigure to point to the new slave simultaneously
14
+#   during the failover
15
+#   Defaults to 2
16
+#
17
+# [*quorum*]
18
+#   Tells Sentinel to monitor this master, and to consider it in O_DOWN
19
+#   (Objectively Down) state only if at least <quorum> sentinels agree
20
+#   Defaults to 2
21
+#
22
+# [*down_after_milliseconds*]
23
+#   Number of milliseconds the master (or any attached slave or sentinel) should
24
+#   be unreachable (as in, not acceptable reply to PING, continuously, for the
25
+#   specified period) in order to consider it in S_DOWN state (Subjectively Down)
26
+#   Defaults to 30000
27
+#
28
+# [*failover_timeout*]
29
+#   Specifies the failover timeout in milliseconds
30
+#   Defaults to 60000
31
+#
32
+# [*timeout*]
33
+#   Specifes timeout for ceilometer coordination url
34
+#   Defaults to 10
35
+#
36
+# [*redis_port*]
37
+#   Port for redis-server to listen on
38
+#   Defaults to '6379'
39
+#
40
+# [*redis_sentinel_port*]
41
+#   Port for redis-sentinel to listen on
42
+#   Defaults to '26379'
43
+#
44
+
45
+class redis::main (
46
+  $primary_controller      = false,
47
+  $parallel_syncs          = '2',
48
+  $quorum                  = '2',
49
+  $down_after_milliseconds = '30000',
50
+  $failover_timeout        = '60000',
51
+  $timeout                 = '10',
52
+  $primary_redis_node      = '127.0.0.1',
53
+  $redis_hosts             = ['127.0.0.1'],
54
+  $redis_bind_address      = '0.0.0.0',
55
+  $redis_port              = '6379',
56
+  $redis_sentinel_port     = '26379',
57
+) {
58
+
59
+  include ceilometer::params
60
+  include redis::params
61
+
62
+  case $::osfamily {
63
+    'RedHat': {
64
+      $manage_upstart_scripts = false
65
+    }
66
+    'Debian': {
67
+      $manage_upstart_scripts = true
68
+    }
69
+    default: {
70
+      fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}")
71
+    }
72
+  }
73
+
74
+  firewall {'121 redis_port':
75
+    port   => $redis_port,
76
+    proto  => 'tcp',
77
+    action => 'accept',
78
+  }
79
+
80
+  firewall {'122 redis_sentinel_port':
81
+    port   => $redis_sentinel_port,
82
+    proto  => 'tcp',
83
+    action => 'accept',
84
+  }
85
+
86
+  if $primary_controller {
87
+    $conf_slaveof = undef
88
+  } else {
89
+    $conf_slaveof = "$primary_redis_node $redis_port"
90
+  }
91
+
92
+  # Use custom function to generate sentinel configuration
93
+  $sentinel_confs = sentinel_confs($redis_hosts, $redis_port, $quorum,
94
+                                   $parallel_syncs, $down_after_milliseconds,
95
+                                   $failover_timeout)
96
+
97
+  package {'python-redis':
98
+    ensure => 'present',
99
+  } ->
100
+
101
+  class { '::redis':
102
+    conf_bind            => $redis_bind_address,
103
+    conf_slave_read_only => 'no',
104
+    service_enable       => false,
105
+    service_ensure       => 'stopped',
106
+    conf_slaveof         => $conf_slaveof,
107
+  } ->
108
+
109
+  class { '::redis::sentinel':
110
+    conf_port              => $redis_sentinel_port,
111
+    sentinel_confs         => $sentinel_confs,
112
+    manage_upstart_scripts => $manage_upstart_scripts,
113
+  }
114
+
115
+  ceilometer_config {
116
+    'coordination/backend_url'    : value => redis_backend_url($redis_hosts, $redis_sentinel_port, $timeout);
117
+    'coordination/heartbeat'      : value => '1.0';
118
+    'coordination/check_watchers' : value => $timeout;
119
+  }
120
+
121
+  if $primary_controller {
122
+    exec {'remove_old_resource_central_agent':
123
+      path    => '/usr/sbin:/usr/bin:/sbin:/bin',
124
+      command => 'pcs resource delete p_ceilometer-agent-central --wait=120',
125
+      onlyif  => 'pcs resource show p_ceilometer-agent-central > /dev/null 2>&1',
126
+    }
127
+
128
+    Exec['remove_old_resource_central_agent'] -> Cluster::Corosync::Cs_service["$::ceilometer::params::agent_central_service_name"]
129
+  }
130
+
131
+  file {'redis_ocf_script':
132
+    path   => '/usr/lib/ocf/resource.d/fuel/redis-server',
133
+    owner  => 'root',
134
+    group  => 'root',
135
+    mode   => '0755',
136
+    source => 'puppet:///modules/redis/ocf/redis-server'
137
+  }
138
+
139
+  cluster::corosync::cs_service { "$::ceilometer::params::agent_central_service_name":
140
+    ocf_script          => 'ceilometer-agent-central',
141
+    csr_parameters      => {},
142
+    csr_metadata        => undef,
143
+    csr_complex_type    => 'clone',
144
+    csr_ms_metadata     => { 'interleave' => true },
145
+    csr_mon_intr        => '20',
146
+    csr_mon_timeout     => '10',
147
+    csr_timeout         => '60',
148
+    service_name        => $::ceilometer::params::agent_central_service_name,
149
+    package_name        => $::ceilometer::params::agent_central_package_name,
150
+    service_title       => 'ceilometer-agent-central',
151
+    primary             => $primary_controller,
152
+    hasrestart          => false,
153
+  }
154
+
155
+  cluster::corosync::cs_service { 'redis':
156
+    ocf_script          => 'redis-server',
157
+    csr_parameters      => {},
158
+    csr_metadata        => undef,
159
+    csr_complex_type    => 'clone',
160
+    csr_ms_metadata     => { 'interleave' => true },
161
+    csr_mon_intr        => '20',
162
+    csr_mon_timeout     => '10',
163
+    csr_timeout         => '60',
164
+    service_name        => $::redis::params::service,
165
+    package_name        => $::redis::params::package,
166
+    service_title       => 'redis',
167
+    primary             => $primary_controller,
168
+    hasrestart          => false,
169
+  }
170
+
171
+
172
+  File['redis_ocf_script'] ->
173
+  Cluster::Corosync::Cs_service['redis'] ->
174
+  Ceilometer_config <||> ->
175
+  Cluster::Corosync::Cs_service["$::ceilometer::params::agent_central_service_name"]
176
+
177
+  if !$primary_controller {
178
+    exec {'waiting-for-agent-up-on-primary':
179
+      tries     => 10,
180
+      try_sleep => 30,
181
+      command   => "pcs resource | grep -A 1 p_${::ceilometer::params::agent_central_service_name} | grep Started > /dev/null 2>&1",
182
+      path      => '/usr/sbin:/usr/bin:/sbin:/bin',
183
+    }
184
+
185
+    exec {'waiting-for-redis-up-on-primary':
186
+      tries     => 10,
187
+      try_sleep => 30,
188
+      command   => "pcs resource | grep -A 1 p_${::redis::params::service} | grep Started > /dev/null 2>&1",
189
+      path      => '/usr/sbin:/usr/bin:/sbin:/bin',
190
+    }
191
+
192
+    service {"p_${::ceilometer::params::agent_central_service_name}":
193
+      enable     => true,
194
+      ensure     => 'running',
195
+      hasstatus  => true,
196
+      hasrestart => true,
197
+      provider   => 'pacemaker',
198
+    }
199
+
200
+    service {"p_${::redis::params::service}":
201
+      enable     => true,
202
+      ensure     => 'running',
203
+      hasstatus  => true,
204
+      hasrestart => true,
205
+      provider   => 'pacemaker',
206
+    }
207
+
208
+    Exec['waiting-for-redis-up-on-primary'] ->
209
+    Service["p_${::redis::params::service}"] ->
210
+    Cluster::Corosync::Cs_service['redis'] ->
211
+    Exec['waiting-for-agent-up-on-primary'] ->
212
+    Ceilometer_config <||> ->
213
+    Cluster::Corosync::Cs_service["$::ceilometer::params::agent_central_service_name"]
214
+  }
215
+
216
+  service { 'ceilometer-agent-central':
217
+    ensure  => 'stopped',
218
+    name    => $::ceilometer::params::agent_central_service_name,
219
+    enable  => false,
220
+  }
221
+}

+ 19
- 17
deployment_scripts/puppet/modules/redis/manifests/sentinel.pp View File

@@ -50,6 +50,7 @@ class redis::sentinel (
50 50
 ) {
51 51
 
52 52
   include redis::sentinel_params
53
+  include redis
53 54
 
54 55
   $conf_sentinel      = $redis::sentinel_params::conf
55 56
   $conf_sentinel_orig = "${conf_sentinel}.puppet"
@@ -74,18 +75,13 @@ class redis::sentinel (
74 75
     $conf_logfile_real = $::redis::sentinel_params::logfile
75 76
   }
76 77
 
77
-  package { 'redis':
78
-    ensure => $package_ensure,
79
-    name   => $package,
80
-  }
81
-
82 78
   if $manage_upstart_scripts == true {
83 79
     service { 'sentinel':
84 80
       ensure     => $service_ensure,
85 81
       name       => $service,
86 82
       hasrestart => true,
87 83
       hasstatus  => true,
88
-      require    => [ File[$conf_sentinel_orig],
84
+      require    => [ File[$conf_sentinel],
89 85
                       File[$upstart_script] ],
90 86
       provider   => 'upstart'
91 87
     }
@@ -97,7 +93,7 @@ class redis::sentinel (
97 93
       hasrestart => true,
98 94
       hasstatus  => true,
99 95
       require    => [ Package['redis'],
100
-                      File[$conf_sentinel_orig] ],
96
+                      File[$conf_sentinel] ],
101 97
     }
102 98
   }
103 99
 
@@ -107,26 +103,33 @@ class redis::sentinel (
107 103
   # only if it changed.
108 104
   file { $conf_sentinel_orig:
109 105
     content => template('redis/sentinel.conf.erb'),
110
-    owner   => redis,
111
-    group   => redis,
106
+    owner   => root,
107
+    group   => root,
112 108
     mode    => '0644',
113 109
     require => Package['redis'],
114
-    notify  => Exec["cp ${conf_sentinel_orig} ${conf_sentinel}"],
115 110
   }
116 111
 
117 112
   file { $conf_sentinel:
118 113
     owner   => redis,
119 114
     group   => redis,
120
-    require => Package['redis'],
115
+    require => [ Package['redis'],
116
+                 Exec["cp ${conf_sentinel_orig} ${conf_sentinel}"] ],
117
+  }
118
+
119
+  exec {"mv ${conf_sentinel} ${conf_sentinel}.original":
120
+    path    => '/bin:/usr/bin:/sbin:/usr/sbin',
121
+    user    => root,
122
+    group   => root,
123
+    require => [ Package['redis'],
124
+                 File[$conf_sentinel_orig] ],
121 125
   }
122 126
 
123 127
   exec { "cp ${conf_sentinel_orig} ${conf_sentinel}":
124 128
     path        => '/bin:/usr/bin:/sbin:/usr/sbin',
125
-    refreshonly => true,
126
-    user        => redis,
127
-    group       => redis,
129
+    user        => root,
130
+    group       => root,
128 131
     notify      => Service['sentinel'],
129
-    require     => File[$conf_sentinel],
132
+    require     => Exec["mv ${conf_sentinel} ${conf_sentinel}.original"],
130 133
   }
131 134
 
132 135
   file { $conf_logrotate:
@@ -138,8 +141,7 @@ class redis::sentinel (
138 141
   }
139 142
 
140 143
   if $service_restart == true {
141
-    # https://github.com/fsalum/puppet-redis/pull/28
142
-    File[$conf_sentinel_orig] ~> Service['sentinel']
144
+    File[$conf_sentinel] ~> Service['sentinel']
143 145
   }
144 146
 
145 147
   if $manage_upstart_scripts == true {

+ 10
- 10
deployment_scripts/puppet/modules/redis/manifests/sentinel_params.pp View File

@@ -14,16 +14,16 @@ class redis::sentinel_params {
14 14
 
15 15
   case $::osfamily {
16 16
     # TODO: add redhat support
17
-    #'redhat': {
18
-    #  $package        = 'redis'
19
-    #  $service        = 'redis-sentinel'
20
-    #  $conf           = '/etc/sentinel.conf'
21
-    #  $conf_dir       = undef
22
-    #  $conf_logrotate = '/etc/logrotate.d/sentinel'
23
-    #  $pidfile        = '/var/run/redis/sentinel.pid'
24
-    #  $logfile        = '/var/log/redis/sentinel.log'
25
-    #  $upstart_script = '/etc/init/redis-sentinel.conf'
26
-    #}
17
+    'redhat': {
18
+      $package        = 'redis'
19
+      $service        = 'redis-sentinel'
20
+      $conf           = '/etc/redis-sentinel.conf'
21
+      $conf_dir       = undef
22
+      $conf_logrotate = '/etc/logrotate.d/sentinel'
23
+      $pidfile        = '/var/run/redis/sentinel.pid'
24
+      $logfile        = '/var/log/redis/sentinel.log'
25
+      $upstart_script = '/etc/init/redis-sentinel.conf'
26
+    }
27 27
     'debian': {
28 28
       $package        = 'redis-server'
29 29
       $service        = 'redis-sentinel'

+ 6
- 0
environment_config.yaml View File

@@ -0,0 +1,6 @@
1
+attributes:
2
+  # Install redis only if ceilometer is enabled
3
+  metadata:
4
+    restrictions:
5
+      - condition: settings:additional_components.ceilometer.value == false
6
+        action: hide

+ 34
- 0
metadata.yaml View File

@@ -0,0 +1,34 @@
1
+# Plugin name
2
+name: ceilometer-redis
3
+# Human-readable name for your plugin
4
+title: Redis plugin for Ceilometer
5
+# Plugin version
6
+version: 1.0.0
7
+# Description
8
+description: Ceilometer extension that provide workload-partitioning and HA for ceilometer services
9
+# Required fuel version
10
+fuel_version: ['7.0']
11
+# Specify license of your plugin
12
+licenses: ['Apache License Version 2.0']
13
+# Specify author or company name
14
+authors: ['Ivan Berezovskiy', 'Ilya Tyaptin']
15
+# A link to the plugin's page
16
+homepage: 'https://github.com/stackforge/fuel-plugin-ceilometer-redis'
17
+# Groups
18
+groups: []
19
+
20
+# The plugin is compatible with releases in the list
21
+releases:
22
+  - os: ubuntu
23
+    version: 2015.1.0-7.0
24
+    mode: ['ha']
25
+    deployment_scripts_path: deployment_scripts/
26
+    repository_path: repositories/ubuntu
27
+#  - os: centos
28
+#    version: 2015.1.0-7.0
29
+#    mode: ['ha']
30
+#    deployment_scripts_path: deployment_scripts/
31
+#    repository_path: repositories/centos
32
+
33
+# Version of plugin package
34
+package_version: '2.0.0'

+ 5
- 0
pre_build_hook View File

@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+
3
+# Add here any the actions which are required before plugin build
4
+# like packages building, packages downloading from mirrors and so on.
5
+# The script should return 0 if there were no errors.

BIN
repositories/centos/jemalloc-3.6.0-1.el6.x86_64.rpm View File


BIN
repositories/centos/redis-2.8.18-2.el6.remi.x86_64.rpm View File


BIN
repositories/ubuntu/libjemalloc1_3.5.1-2_amd64.deb View File


BIN
repositories/ubuntu/redis-server_2%3a2.8.4-2_amd64.deb View File


BIN
repositories/ubuntu/redis-tools_2%3a2.8.4-2_amd64.deb View File


+ 15
- 0
tasks.yaml View File

@@ -0,0 +1,15 @@
1
+- role: ['primary-controller']
2
+  stage: post_deployment
3
+  type: puppet
4
+  parameters:
5
+    puppet_manifest: puppet/manifests/primary-controller.pp
6
+    puppet_modules: puppet/modules:/etc/puppet/modules
7
+    timeout: 720
8
+
9
+- role: ['controller']
10
+  stage: post_deployment
11
+  type: puppet
12
+  parameters:
13
+    puppet_manifest: puppet/manifests/controller.pp
14
+    puppet_modules: puppet/modules:/etc/puppet/modules
15
+    timeout: 720

Loading…
Cancel
Save