Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.

Added rackdc.properties #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ Simple example:


If you're running on Amazon EC2 (or a similar environment) you might want to set the `broadcast_address`
and the `endpoint_snitch` accordingly.
and the `endpoint_snitch` accordingly. It can be also important to set proper datacenter suffix to
diffrentiate datacenters.

class { 'cassandra':
cluster_name => 'YourEc2CassandraCluster',
seeds => [ '192.0.2.5', '192.0.2.23', '192.0.2.42', ],
listen_address => $ec2_local_ipv4,
broadcast_address => $ec2_public_ipv4,
dc_suffix => 'DC2',
prefer_local_ip => 'true',
endpoint_snitch => 'Ec2MultiRegionSnitch',
}

Expand Down
7 changes: 7 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
$start_rpc,
$listen_address,
$broadcast_address,
$dc_suffix,
$prefer_local_ip,
$rpc_address,
$rpc_port,
$rpc_server_type,
Expand Down Expand Up @@ -62,4 +64,9 @@
ensure => file,
content => template("${module_name}/cassandra.yaml.erb"),
}

file { "${config_path}/cassandra-rackdc.properties":
ensure => file,
content => template("${module_name}/cassandra-rackdc.properties.erb"),
}
}
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
$cluster_name = $cassandra::params::cluster_name,
$listen_address = $cassandra::params::listen_address,
$broadcast_address = $cassandra::params::broadcast_address,
$dc_suffix = $cassandra::params::dc_suffix,
$prefer_local_ip = $cassandra::params::prefer_local_ip,
$start_native_transport = $cassandra::params::start_native_transport,
$start_rpc = $cassandra::params::start_rpc,
$rpc_address = $cassandra::params::rpc_address,
Expand Down Expand Up @@ -89,6 +91,10 @@
fail('broadcast_address must be an IP address')
}

if(!empty($prefer_local_ip)) {
validate_re($prefer_local_ip, '^(true|false)$')
}

if(!is_ip_address($rpc_address)) {
fail('rpc_address must be an IP address')
}
Expand Down Expand Up @@ -147,6 +153,8 @@
start_rpc => $start_rpc,
listen_address => $listen_address,
broadcast_address => $broadcast_address,
dc_suffix => $dc_suffix,
prefer_local_ip => $prefer_local_ip,
rpc_address => $rpc_address,
rpc_port => $rpc_port,
rpc_server_type => $rpc_server_type,
Expand Down
10 changes: 10 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
default => $::cassandra_broadcast_address,
}

$dc_suffix = $::cassandra_dc_suffix ? {
undef => '',
default => $::cassandra_dc_suffix,
}

$prefer_local_ip = $::cassandra_prefer_local_ip ? {
undef => '',
default => $::cassandra_prefer_local_ip,
}

$rpc_address = $::cassandra_rpc_address ? {
undef => '0.0.0.0',
default => $::cassandra_rpc_address,
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/cassandra_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
:cluster_name => 'Cassandra',
:listen_address => '1.2.3.4',
:broadcast_address => '4.3.2.1',
:dc_suffix => 'DC2',
:prefer_local_ip => 'true',
:rpc_address => '0.0.0.0',
:rpc_port => 9160,
:rpc_server_type => 'hsha',
Expand Down Expand Up @@ -95,6 +97,8 @@
:cluster_name => 'Cassandra',
:listen_address => '1.2.3.4',
:broadcast_address => '4.3.2.1',
:dc_suffix => 'DC2',
:prefer_local_ip => 'true',
:rpc_address => '0.0.0.0',
:rpc_port => 9160,
:rpc_server_type => 'hsha',
Expand Down Expand Up @@ -154,6 +158,17 @@
:content => /cluster_name: 'Cassandra'/,
})
end

it 'does contain file /etc/cassandra/conf/cassandra-rackdc.properties' do
should contain_file('/etc/cassandra/conf/cassandra-rackdc.properties').with({
:ensure => 'file',
:owner => 'cassandra',
:group => 'cassandra',
:mode => '0644',
:content => /dc_suffix=DC2/,
:content => /prefer_local=true/,
})
end
end

end
8 changes: 6 additions & 2 deletions spec/classes/cassandra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
end

let(:params) {{ :seeds => ['1.2.3.4'], :broadcast_address => '4.3.2.1' }}
let(:params) {{ :seeds => ['1.2.3.4'], :broadcast_address => '4.3.2.1', 'dc_suffix' => 'DC2', 'prefer_local_ip' => 'true'}}

context 'verify module' do

Expand Down Expand Up @@ -90,6 +90,8 @@
:cluster_name => 'Cassandra',
:listen_address => '1.2.3.4',
:broadcast_address => '4.3.2.1',
:dc_suffix => 'DC2',
:prefer_local_ip => 'true',
:rpc_address => '0.0.0.0',
:rpc_port => 9160,
:rpc_server_type => 'hsha',
Expand Down Expand Up @@ -162,7 +164,9 @@
:data_file_directories => [[['a', 'b']], ['bozo', '']],
:jmx_port => [[1, 65535], [420000, true]],
:listen_address => [['1.2.3.4'], ['4.5.6']],
:broadcast_address => [['1.2.3.4'], ['1.2', 'foo']],
:broadcast_address => [['1.2.3.4'], ['1.2', 'foo']],
:dc_suffix => [['DC2'], []],
:prefer_local_ip => [['true', 'false'], ['123', 'foo']],
:rpc_address => [['1.2.3.4'], ['4.5.6']],
:rpc_port => [[1, 65535], [420000, true]],
:storage_port => [[1, 65535], [420000, true]],
Expand Down
32 changes: 32 additions & 0 deletions templates/cassandra-rackdc.properties.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=DC1
rack=RAC1

# Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch
# to append a string to the EC2 region name.
<% unless @dc_suffix.nil? || @dc_suffix.empty? %>
dc_suffix=<%= @dc_suffix %>
<% end %>

# Uncomment the following line to make this snitch prefer the internal ip when possible, as the Ec2MultiRegionSnitch does.
<% unless @prefer_local_ip.nil? || @prefer_local_ip.empty? %>
prefer_local=true
<% end %>