Puppet Class: cassandra

Defined in:
modules/cassandra/manifests/init.pp

Overview

Class: cassandra

Installs and configures a Cassandra server

(Much of this module was adapted from: github.com/msimonin/puppet-cassandra)

Note: This class requires the Puppet stdlib module, particularly the pick() function.

Usage

class { '::cassandra':

cluster_name => 'my_cluster',
seeds        => ['10.11.12.13', '10.11.13.14'],
dc           => 'my_datacenter1',
rack         => 'my_rack1',

# … }

Parameters

cluster_name

The logical name of this Cassandra cluster. Default: Test Cluster

tls_cluster_name

If specified, use private keys (client and server) from private.git belonging to this cluster. Also install the cluster's CA as trusted. Default: undef

tls_use_pki

Whether or not to use PKI for TLS certificates. See T288470 Default: false

tls_use_pki_truststore

Whether or not to use a special truststore to support PKI TLS certificates. See T288470 Default: false

tls_use_pki_keep_old_ca

Whether or not to keep the old root CA around when a PKI trustore is used. Only needed to keep consistency when upgrading to PKI. See T352647 Default: false

tls_keystore_password

Password of the TLS keystore to use. Needed only if tls_use_pki is true. Default: undef

instances

An hash from instance name to several instance-specific parameters, including:

* jmx_port        must be unique per-host
* listen_address  address to use for cassandra clients
* rpc_address     address to use for cassandra cluster traffic

See also cassandra::instance

Unless default behaviour (as in Cassandra's Debian package) is wanted, each instance will have its configuration deployed at /etc/cassandra-<TITLE> with data at /srv/cassandra-<TITLE> and a corresponding nodetool binary named nodetool-<TITLE> to be used to access instances individually. Similarly each instance service will be available under “cassandra-<TITLE>”.

default_instance_params

A hash of default instance parameters, to reduce duplication when multiple instances share the same configuration. A hash is used instead of parameters on the cassandra class to better identify parameters that only apply to instances and not to the cassandra class. Some shared parameters are still present on the cassandra class, either because they are used directly by the cassandra class, or because they are referenced from other classes / modules. Default: {}

seeds

Array of seed IPs for this Cassandra cluster. Default: [$::ipaddress]

listen_address

Cassandra listen IP address. Default $::ipaddress

additional_jvm_opts

Additional options to pass to the JVM. Default: []

extra_classpath

Additional files and/or directories to append to the JVM classpath. Default: []

target_version

The Cassandra version to configure for. Valid choices are '2.2', '3.x', '4.x', and 'dev' Default: 2.2

memory_allocator

The off-heap memory allocator. Default: JEMallocAllocator

cassandra_passwords

A hash containing user->pass mappings Default: undef

native_transport_port

Native transport listen port. Default: 9042

dc

Logical name datacenter name. This will only be used if $endpoint_snitch is GossipingPropertyFileSnitch. Default: dc1

rack

Logical rack name. This will only be used if $endpoint_snitch is GossipingPropertyFileSnitch. Default rack1

start_rpc

Whether to start the thrift rpc server. Default: true

super_username

Cassandra superuser username. Username and password for superuser will be written to /etc/cassandra/cqlshrc for easy/unattended usage by cqlsh. Default: cassandra

super_password

Cassandra superuser password. Default: cassandra

java_package

The java package name responsible for installing java If present this is used to add dependencies on the cassandra install

auto_apply_grants

If true, automatically apply grants files on this node when there is a change.

Parameters:

  • cluster_name (String) (defaults to: 'Test Cluster')
  • tls_cluster_name (Optional[String]) (defaults to: undef)
  • tls_use_pki (Boolean) (defaults to: false)
  • tls_use_pki_truststore (Boolean) (defaults to: false)
  • tls_use_pki_keep_old_ca (Boolean) (defaults to: false)
  • tls_keystore_password (Optional[String]) (defaults to: undef)
  • instances (Hash) (defaults to: {})
  • default_instance_params (Hash) (defaults to: {})
  • seeds (Array[Stdlib::Host]) (defaults to: [$::ipaddress])
  • listen_address (Stdlib::IP::Address) (defaults to: $::ipaddress)
  • additional_jvm_opts (Array[String]) (defaults to: [])
  • extra_classpath (Array[String]) (defaults to: [])
  • target_version (Enum['2.2', '3.x', 'dev', '4.x']) (defaults to: '2.2')
  • memory_allocator (String) (defaults to: 'JEMallocAllocator')
  • cassandra_passwords (Hash[String, String]) (defaults to: {})
  • native_transport_port (Stdlib::Port) (defaults to: 9042)
  • dc (String) (defaults to: 'datacenter1')
  • rack (String) (defaults to: 'rack1')
  • logstash_host (Stdlib::Host) (defaults to: 'logstash.svc.eqiad.wmnet')
  • logstash_port (Stdlib::Port) (defaults to: 11514)
  • start_rpc (Boolean) (defaults to: true)
  • jbod_devices (Array[String]) (defaults to: [])
  • super_username (String) (defaults to: 'cassandra')
  • super_password (String) (defaults to: 'cassandra')
  • version (Optional[String]) (defaults to: undef)
  • users (Array[String]) (defaults to: [])
  • java_package (Optional[String]) (defaults to: undef)
  • auto_apply_grants (Boolean) (defaults to: false)


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'modules/cassandra/manifests/init.pp', line 132

class cassandra (
    String                           $cluster_name            = 'Test Cluster',
    Optional[String]                 $tls_cluster_name        = undef,
    Boolean                          $tls_use_pki             = false,
    Boolean                          $tls_use_pki_truststore  = false,
    Boolean                          $tls_use_pki_keep_old_ca = false,
    Optional[String]                 $tls_keystore_password   = undef,
    Hash                             $instances               = {},
    Hash                             $default_instance_params = {},
    Array[Stdlib::Host]              $seeds                   = [$::ipaddress],
    Stdlib::IP::Address              $listen_address          = $::ipaddress,
    Array[String]                    $additional_jvm_opts     = [],
    Array[String]                    $extra_classpath         = [],
    Enum['2.2', '3.x', 'dev', '4.x'] $target_version          = '2.2',
    String                           $memory_allocator        = 'JEMallocAllocator',
    Hash[String, String]             $cassandra_passwords     = {},
    Stdlib::Port                     $native_transport_port   = 9042,
    String                           $dc                      = 'datacenter1',
    String                           $rack                    = 'rack1',
    Stdlib::Host                     $logstash_host           = 'logstash.svc.eqiad.wmnet',
    Stdlib::Port                     $logstash_port           = 11514,
    Boolean                          $start_rpc               = true,
    Array[String]                    $jbod_devices            = [],
    String                           $super_username          = 'cassandra',
    String                           $super_password          = 'cassandra',
    Optional[String]                 $version                 = undef,
    Array[String]                    $users                   = [],
    Optional[String]                 $java_package            = undef,
    Boolean                          $auto_apply_grants       = false,
) {

    ensure_packages(['cassandra-tools-wmf', 'jvm-tools'])

    # We pin the version to a specific one.
    $package_version = $target_version ? {
        '2.2' => pick($version, '2.2.6-wmf5'),
        '3.x' => pick($version, '3.11.14'),
        '4.x' => pick($version, '4.1.1'),
        'dev' => pick($version, '4.1.1-wmf1')
    }

    $component = $target_version  ? {
        '2.2' => 'component/cassandra22',
        '3.x' => 'component/cassandra311',
        '4.x' => 'component/cassandra41',
        'dev' => 'component/cassandradev'
    }


    $cassandra_require = $java_package ? {
        undef   => undef,
        default => Package[$java_package]
    }
    apt::package_from_component { 'cassandra':
        packages  => { 'cassandra' => $package_version},
        component => $component,
        require   => $cassandra_require,
    }

    package { 'cassandra-tools':
      ensure  => $package_version,
      require => Package['cassandra'],
    }

    # Make sure libjemalloc is installed if we are going to use the JEMallocAllocator.
    if $memory_allocator == 'JEMallocAllocator' {
        ensure_packages('libjemalloc2')
    }

    # Create non-default cassandra instances if requested.
    # Default is to keep Debian package behaviour,
    # in other words create a "default" instance.
    $default_common = {
        cluster_name            => $cluster_name,
        tls_cluster_name        => $tls_cluster_name,
        tls_use_pki             => $tls_use_pki,
        tls_use_pki_truststore  => $tls_use_pki_truststore,
        tls_use_pki_keep_old_ca => $tls_use_pki_keep_old_ca,
        tls_keystore_password   => $tls_keystore_password,
        seeds                   => $seeds,
        additional_jvm_opts     => $additional_jvm_opts,
        extra_classpath         => $extra_classpath,
        memory_allocator        => $memory_allocator,
        listen_address          => $listen_address,
        users                   => $users,
        native_transport_port   => $native_transport_port,
        target_version          => $target_version,
        dc                      => $dc,
        rack                    => $rack,
        logstash_host           => $logstash_host,
        logstash_port           => $logstash_port,
        start_rpc               => $start_rpc,
        super_username          => $super_username,
        super_password          => $super_password,
        cassandra_passwords     => $cassandra_passwords,
        auto_apply_grants       => $auto_apply_grants,
    }

    if empty($instances) {
        $defaults_for_single_instance = {
            config_directory       => '/etc/cassandra',
            service_name           => 'cassandra',
            tls_hostname           => $::hostname,
            pid_file               => '/var/run/cassandra/cassandra.pid',
            instance_id            => $::hostname,
            jmx_port               => 7199,
            data_directory_base    => '/var/lib/cassandra',
            commitlog_directory    => '/var/lib/cassandra/commitlog',
            hints_directory        => '/var/lib/cassandra/data/hints',
            heapdump_directory     => '/var/lib/cassandra/',
            saved_caches_directory => '/var/lib/cassandra/saved_caches',
            nodetool_path          => '/usr/bin/nodetool',
        }
        $actual_defaults = merge(
            $default_common,
            $defaults_for_single_instance,
            $default_instance_params
        )
        $instances_to_create = {
            'default' => {}
        }
    } else {
        $instances_to_create = $instances
        $actual_defaults = merge(
            $default_common,
            $default_instance_params
        )
        # if running multi-instances, make sure the default instance is stopped
        service { 'cassandra':
            ensure => stopped,
        }
    }
    $instances_to_create.each |$instance, $params| {
        cassandra::instance {$instance:
            * => $actual_defaults + $params,
        }
    }
    cassandra::jbod_device { $jbod_devices: }

    # nodetool wrapper to handle multiple instances, for each instance there
    # will be symlinks from /usr/local/bin/nodetool-<INSTANCE_NAME> to
    # nodetool-instance
    file { '/usr/local/bin/nodetool-instance':
        ensure  => present,
        source  => "puppet:///modules/${module_name}/nodetool-instance",
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0555',
        require => Package['cassandra'],
    }

    # sstable utility wrapper to handle multiple instances, for each instance
    # there will be symlinks from /usr/local/bin/<UTILITY>-<INSTANCE_NAME> to
    # sstable-util-instance
    file { '/usr/local/bin/sstable-util-instance':
        ensure  => present,
        source  => "puppet:///modules/${module_name}/sstable-util-instance",
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0555',
        require => Package['cassandra'],
    }

    file { '/etc/cassandra.in.sh':
        ensure  => present,
        content => template("${module_name}/cassandra.in.sh-${target_version}.erb"),
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
        require => Package['cassandra'],
    }

    # no-op sysv init script
    file { '/etc/init.d/cassandra':
        ensure  => present,
        source  => "puppet:///modules/${module_name}/cassandra-init.d",
        owner   => 'root',
        group   => 'root',
        mode    => '0755',
        require => Package['cassandra'],
    }

    file { '/etc/tmpfiles.d/cassandra.conf':
        ensure  => present,
        source  => "puppet:///modules/${module_name}/cassandra-tmpfiles.conf",
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0444',
        require => Package['cassandra'],
    }

    file { '/etc/cassandra-instances.d':
        ensure  => directory,
        owner   => 'cassandra',
        group   => 'cassandra',
        mode    => '0755',
        require => Package['cassandra'],
    }
    file { '/usr/local/bin/cassandra_validate_grants':
        ensure  => present,
        source  => "puppet:///modules/${module_name}/validate_grant_statements.py",
        owner   => 'root',
        group   => 'root',
        mode    => '0755',
        require => Package['cassandra'],
    }

}