Defined Type: cassandra::schema::cql_type

Defined in:
manifests/schema/cql_type.pp

Overview

Create or drop user defined data types within the schema.

Examples:

cassandra::schema::cql_type { 'fullname':
  keyspace => 'mykeyspace',
  fields   => {
    'fname' => 'text',
    'lname' => 'text',
  },
}

Parameters:

  • keyspace (string)

    The name of the keyspace that the data type is to be associated with.

  • ensure (present|absent) (defaults to: present)

    ensure the data type is created, or is dropped.

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

    A hash of the fields that will be components for the data type.

  • cql_type_name (string) (defaults to: $title)

    The name of the CQL type to be created.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'manifests/schema/cql_type.pp', line 14

define cassandra::schema::cql_type (
  $keyspace,
  $ensure = present,
  $fields = {},
  $cql_type_name = $title,
  ){
  include 'cassandra::schema'
  $read_script = "DESC TYPE ${keyspace}.${cql_type_name}"
  $read_command = "${::cassandra::schema::cqlsh_opts} -e \"${read_script}\" ${::cassandra::schema::cqlsh_conn}"

  if $ensure == present {
    $create_script1 = "CREATE TYPE IF NOT EXISTS ${keyspace}.${cql_type_name}"
    $create_script2 = join(join_keys_to_values($fields, ' '), ', ')
    $create_script = "${create_script1} (${create_script2})"
    $create_command = "${::cassandra::schema::cqlsh_opts} -e \"${create_script}\" ${::cassandra::schema::cqlsh_conn}"
    exec { $create_command:
      unless  => $read_command,
      require => Exec['::cassandra::schema connection test'],
    }
  } elsif $ensure == absent {
    $delete_script = "DROP type ${keyspace}.${cql_type_name}"
    $delete_command = "${::cassandra::schema::cqlsh_opts} -e \"${delete_script}\" ${::cassandra::schema::cqlsh_conn}"
    exec { $delete_command:
      onlyif  => $read_command,
      require => Exec['::cassandra::schema connection test'],
    }
  } else {
    fail("Unknown action (${ensure}) for ensure attribute.")
  }
}