Programmatic way to change cassandra.yaml
We create a cassandra cluster at runtime, and information like "cluster name" and IP addresses of "seeds" are only available at runtime. Is there a java wrapper for cassandra.yaml that allows setters and getters for cassandra.yaml and saves them to disk? I realize that I can always create the wrapper myself, but would like to know if one of them is already available.
source to share
Is there a java wrapper for cassandra.yaml that allows setters and getters for cassandra.yaml and saves them to disk?
Not that I know. It's a good idea for an OpenSource project though!
I have done this several times in the past. One of them is a combination of a chef and a consul-template . Basically, your cassandra.yaml contains variable placeholders that are populated with a combination of default attributes (cook) and cluster-specific settings (consul-template) when your deployment recipe runs.
I also did it with a Bash script using sed
(for a couple of our non-chefs). This is an excerpt from a script I wrote to port my DataStax Enterprise installation to Apache Cassandra (open source):
#!/bin/bash
cp /etc/dse/cassandra/cassandra.yaml /etc/cassandra/conf
#set GossipingPropertyFileSnitch in cassandra.yaml
sed -i 's/endpoint_snitch: com.datastax.bdp.snitch.DseDelegateSnitch/endpoint_snitch: GossipingPropertyFileSnitch/' /etc/cassandra/conf/cassandra.yaml
#set truststore location
sed -i 's/truststore: \/etc\/dse\/cassandra\//truststore: \/etc\/cassandra\/conf\//g' /etc/cassandra/conf/cassandra.yaml
#set keystore location
sed -i 's/keystore: \/etc\/dse\/cassandra\//keystore: \/etc\/cassandra\/conf\//g' /etc/cassandra/conf/cassandra.yaml
Essentially, here you are using regex-replace for certain yaml property settings. Specifically, I needed to update the snitch and keystore / truststore location. It's not pretty, but it works.
source to share