|
job cadence-setup-schema { |
|
datacenters = ["dc1"] |
|
type = "batch" |
|
priority = 100 |
|
|
|
# constraint { |
|
# attribute = "${meta.tags}" |
|
# operator = "set_contains" |
|
# value = "cadence-services" |
|
# } |
|
|
|
parameterized { |
|
payload = "forbidden" |
|
} |
|
|
|
meta { |
|
keyspace = "cadence" |
|
visibility_keyspace = "cadence_visibility" |
|
} |
|
|
|
group cadence-setup-schema { |
|
task cadence-setup-schema { |
|
driver = "docker" |
|
kill_timeout = "45s" |
|
|
|
config { |
|
image = "ubercadence/server:0.11.0-auto-setup" |
|
command = "bash" |
|
args = ["/opt/cadence/bin/setup-schema.sh"] |
|
volumes = [ |
|
"local/setup-schema.sh:/opt/cadence/bin/setup-schema.sh" |
|
] |
|
network_mode = "host" |
|
} |
|
|
|
env { |
|
SKIP_SCHEMA_SETUP = false |
|
|
|
# change requires db reset |
|
NUM_HISTORY_SHARDS = 4 |
|
|
|
LOG_LEVEL = "info" |
|
CASSANDRA_SEEDS = "cassandra-cluster1-node1.node.consul,cassandra-cluster1-node2.node.consul,cassandra-cluster1-node3.node.consul" |
|
DB = "cassandra" |
|
RF = 3 |
|
KEYSPACE = "${NOMAD_META_keyspace}" |
|
VISIBILITY_KEYSPACE = "${NOMAD_META_visibility_keyspace}" |
|
} |
|
|
|
template { |
|
change_mode = "noop" |
|
destination = "local/setup-schema.sh" |
|
// language=sh |
|
data = <<EOH |
|
#!/bin/bash |
|
|
|
set -x |
|
|
|
DB="${DB:-cassandra}" |
|
RF=${RF:-3} |
|
|
|
# cassandra env |
|
export KEYSPACE="${KEYSPACE:-cadence}" |
|
export VISIBILITY_KEYSPACE="${VISIBILITY_KEYSPACE:-cadence_visibility}" |
|
|
|
setup_cassandra_schema() { |
|
SCHEMA_DIR=$CADENCE_HOME/schema/cassandra/cadence/versioned |
|
cadence-cassandra-tool --ep $CASSANDRA_SEEDS create -k $KEYSPACE --rf $RF |
|
cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $KEYSPACE setup-schema -v 0.0 |
|
cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $KEYSPACE update-schema -d $SCHEMA_DIR |
|
VISIBILITY_SCHEMA_DIR=$CADENCE_HOME/schema/cassandra/visibility/versioned |
|
cadence-cassandra-tool --ep $CASSANDRA_SEEDS create -k $VISIBILITY_KEYSPACE --rf $RF |
|
cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $VISIBILITY_KEYSPACE setup-schema -v 0.0 |
|
cadence-cassandra-tool --ep $CASSANDRA_SEEDS -k $VISIBILITY_KEYSPACE update-schema -d $VISIBILITY_SCHEMA_DIR |
|
} |
|
|
|
setup_schema() { |
|
if [ "$DB" == "cassandra" ]; then |
|
echo 'setup cassandra schema' |
|
setup_cassandra_schema |
|
fi |
|
} |
|
|
|
wait_for_cassandra() { |
|
server=`echo $CASSANDRA_SEEDS | awk -F ',' '{print $1}'` |
|
until cqlsh --cqlversion=3.4.4 $server < /dev/null; do |
|
echo 'waiting for cassandra to start up' |
|
sleep 1 |
|
done |
|
echo 'cassandra started' |
|
} |
|
|
|
wait_for_db() { |
|
if [ "$DB" == "cassandra" ]; then |
|
wait_for_cassandra |
|
fi |
|
} |
|
|
|
wait_for_db |
|
setup_schema |
|
EOH |
|
} |
|
} |
|
} |
|
} |
To have prometheus collect metrics automatically for the above services, set this in your
prometheus.yml
:If you use nomad to also run your prometheus instance, here's
prometheus.nomad
: