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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'manifests/schema.pp', line 35
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 = {},
$permissions = {},
$tables = {},
$users = {},
Boolean $use_scl = $cassandra::params::use_scl,
String[1] $scl_name = $cassandra::params::scl_name,
) inherits cassandra::params {
require 'cassandra'
# Pass the SCL info to create_resources below as a hash
$scl = {
'use_scl' => $use_scl,
'scl_name' => $scl_name,
}
if $cqlsh_client_config != undef {
file { $cqlsh_client_config :
ensure => file,
group => $facts['identity']['gid'],
mode => '0600',
owner => $facts['identity']['uid'],
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_tmp = "${cqlsh_opts} -e 'DESC KEYSPACES' ${cqlsh_conn}"
if $use_scl {
$connection_test = "/usr/bin/scl enable ${scl_name} \"${connection_test_tmp}\""
} else {
$connection_test = $connection_test_tmp
}
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, $scl)
}
# manage cql_types if present
if $cql_types {
create_resources('cassandra::schema::cql_type', $cql_types, $scl)
}
# manage tables if present
if $tables {
create_resources('cassandra::schema::table', $tables, $scl)
}
# manage indexes if present
if $indexes {
create_resources('cassandra::schema::index', $indexes, $scl)
}
# manage users if present
if $users {
create_resources('cassandra::schema::user', $users, $scl)
}
# manage permissions if present
if $permissions {
create_resources('cassandra::schema::permission', $permissions, $scl)
}
# Resource Ordering
Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Cql_type <| |>
Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Table <| |>
Cassandra::Schema::Keyspace <| |> -> Cassandra::Schema::Permission <| |>
Cassandra::Schema::Cql_type <| |> -> Cassandra::Schema::Table <| |>
Cassandra::Schema::Table <| |> -> Cassandra::Schema::Index <| |>
Cassandra::Schema::Table <| |> -> Cassandra::Schema::Permission <| |>
Cassandra::Schema::Index <| |> -> Cassandra::Schema::User <| |>
Cassandra::Schema::User <| |> -> Cassandra::Schema::Permission <| |>
}
|