Puppet Class: cassandra::schema

Inherits:
cassandra::params
Defined in:
manifests/schema.pp

Overview

A class to maintain the database schema. Please note that cqlsh expects Python 2.7 to be installed. This may be a problem of older distributions (CentOS 6 for example).

Parameters:

  • connection_tries (integer) (defaults to: 6)

    How many times do try to connect to Cassandra. See also connection_try_sleep.

  • connection_try_sleep (integer) (defaults to: 30)

    How much time to allow between the number of tries specified in connection_tries.

  • cql_types (hash) (defaults to: {})

    Creates new cassandra::schema::cql_type resources.

  • cqlsh_additional_options (string) (defaults to: '')

    Any additional options to be passed to the cqlsh command.

  • cqlsh_client_config (string) (defaults to: undef)

    Set this to a file name (e.g. '/root/.puppetcqlshrc') that will then be used to contain the the credentials for connecting to Cassandra. This is a more secure option than having the credentials appearing on the command line. This option is only available in Cassandra >= 2.1.

  • cqlsh_client_tmpl (string) (defaults to: 'cassandra/cqlshrc.erb')

    The location of the template for configuring the credentials for the cqlsh client. This is ignored unless cqlsh_client_config is set.

  • cqlsh_command (string) (defaults to: '/usr/bin/cqlsh')

    The full path to the cqlsh command.

  • cqlsh_host (string) (defaults to: 'localhost')

    The host for the cqlsh command to connect to. See also cqlsh_port.

  • cqlsh_password (string) (defaults to: undef)

    If credentials are require for connecting, specify the password here. See also cqlsh_user, cqlsh_client_config.

  • cqlsh_port (integer) (defaults to: 9042)

    The host for the cqlsh command to connect to. See also cqlsh_host.

  • cqlsh_user (string) (defaults to: 'cassandra')

    If credentials are required for connecting, specify the password here. See also cqlsh_password, cqlsh_client_config

  • indexes (hash) (defaults to: {})

    Creates new cassandra::schema::index resources.

  • keyspaces (hash) (defaults to: {})

    Creates new cassandra::schema::keyspace resources.

  • tables (hash) (defaults to: {})

    Creates new cassandra::schema::table resources.

  • users (hash) (defaults to: {})

    Creates new cassandra::schema::user resources.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'manifests/schema.pp', line 33

class cassandra::schema (
  $connection_tries         = 6,
  $connection_try_sleep     = 30,
  $cql_types                = {},
  $cqlsh_additional_options = '',
  $cqlsh_client_config      = undef,
  $cqlsh_client_tmpl        = 'cassandra/cqlshrc.erb',
  $cqlsh_command            = '/usr/bin/cqlsh',
  $cqlsh_host               = 'localhost',
  $cqlsh_password           = undef,
  $cqlsh_port               = 9042,
  $cqlsh_user               = 'cassandra',
  $indexes                  = {},
  $keyspaces                = {},
  $tables                   = {},
  $users                    = {},
  ) inherits cassandra::params {
  require '::cassandra'

  if $cqlsh_client_config != undef {
    file { $cqlsh_client_config :
      ensure  => file,
      group   => $::gid,
      mode    => '0600',
      owner   => $::id,
      content => template( $cqlsh_client_tmpl ),
      before  => Exec['::cassandra::schema connection test'],
    }

    $cmdline_login = "--cqlshrc=${cqlsh_client_config}"
  } else {
    if $cqlsh_password != undef {
      warning('You may want to consider using the cqlsh_client_config attribute')
      $cmdline_login = "-u ${cqlsh_user} -p ${cqlsh_password}"
    } else {
      $cmdline_login = ''
    }
  }

  $cqlsh_opts = "${cqlsh_command} ${cmdline_login} ${cqlsh_additional_options}"
  $cqlsh_conn = "${cqlsh_host} ${cqlsh_port}"

  # See if we can make a connection to Cassandra.  Try $connection_tries
  # number of times with $connection_try_sleep in seconds between each try.
  $connection_test = "${cqlsh_opts} -e 'DESC KEYSPACES' ${cqlsh_conn}"
  exec { '::cassandra::schema connection test':
    command   => $connection_test,
    returns   => 0,
    tries     => $connection_tries,
    try_sleep => $connection_try_sleep,
    unless    => $connection_test,
  }

  # manage keyspaces if present
  if $keyspaces {
    create_resources('cassandra::schema::keyspace', $keyspaces)
  }

  # manage cql_types if present
  if $keyspaces {
    create_resources('cassandra::schema::cql_type', $cql_types)
  }

  # manage tables if present
  if $tables {
    create_resources('cassandra::schema::table', $tables)
  }

  # manage indexes if present
  if $indexes {
    create_resources('cassandra::schema::index', $indexes)
  }

  # manage users if present
  if $users {
    create_resources('cassandra::schema::user', $users)
  }

  # Resource Ordering
  Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Cql_type <| |>
  Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Table <| |>
  Cassandra::Schema::Cql_type <| |> -> Cassandra::Schema::Table <| |>
  Cassandra::Schema::Table <| |> -> Cassandra::Schema::Index <| |>
  Cassandra::Schema::Index <| |> -> Cassandra::Schema::User <| |>
}