Skip to content

Commit

Permalink
Adds check-health command to temporal-cassandra-tool and switches sta…
Browse files Browse the repository at this point in the history
…rt.sh to use that instead of cqlsh (#885)

There are two changes:

Add check-health to the temporal-cassandra-tool. This enables us to test connectivity to a Cassandra Cluster using username, password and any TLS settings.
Switch startup.sh to use this new check-health command instead of cqlsh for auto-setup.
This change will enable auto-setup to work against a Cassandra DB configured with TLS or username/password when launching from the docker-compose file.

Tested auto-setup locally and the check-health command against a deployed Cassandra environment with username/password and mTLS enabled.

Low risk change
  • Loading branch information
mastermanu committed Oct 21, 2020
1 parent b320bc7 commit 9e3ed33
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
12 changes: 10 additions & 2 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ setup_schema() {
}

wait_for_cassandra() {
server=`echo $CASSANDRA_SEEDS | awk -F ',' '{print $1}'`
until cqlsh --cqlversion=3.4.4 $server < /dev/null; do
export CASSANDRA_USER=$CASSANDRA_USER
export CASSANDRA_PORT=$CASSANDRA_PORT
export CASSANDRA_ENABLE_TLS=$CASSANDRA_TLS_ENABLED
export CASSANDRA_TLS_CERT=$CASSANDRA_CERT
export CASSANDRA_TLS_KEY=$CASSANDRA_CERT_KEY
export CASSANDRA_TLS_CA=$CASSANDRA_CA

{ export CASSANDRA_PASSWORD=$CASSANDRA_PASSWORD; } 2> /dev/null

until temporal-cassandra-tool --ep $CASSANDRA_SEEDS validate-health < /dev/null; do
echo 'waiting for cassandra to start up'
sleep 1
done
Expand Down
20 changes: 18 additions & 2 deletions tools/cassandra/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func updateSchema(cli *cli.Context) error {
return nil
}

// createKeyspace creates a cassandra Keyspace
func createKeyspace(cli *cli.Context) error {
config, err := newCQLClientConfig(cli)
if err != nil {
Expand All @@ -150,11 +149,28 @@ func createKeyspace(cli *cli.Context) error {
}
err = doCreateKeyspace(*config, keyspace)
if err != nil {
return handleErr(fmt.Errorf("error creating Keyspace:%v", err))
return handleErr(fmt.Errorf("error creating Keyspace:%+v", err))
}
return nil
}

func validateHealth(cli *cli.Context) error {
config, err := newCQLClientConfig(cli)
if err != nil {
return handleErr(schema.NewConfigError(err.Error()))
}

config.Keyspace = systemKeyspace

client, err := newCQLClient(config)
if err != nil {
return handleErr(fmt.Errorf("unable to establish CQL session:%+v", err))
}

defer client.Close()
return nil
}

func doCreateKeyspace(cfg CQLClientConfig, name string) error {
cfg.Keyspace = systemKeyspace
client, err := newCQLClient(&cfg)
Expand Down
8 changes: 8 additions & 0 deletions tools/cassandra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ func buildCLIOptions() *cli.App {
cliHandler(c, createKeyspace)
},
},
{
Name: "validate-health",
Aliases: []string{"vh"},
Usage: "validates health of cassandra by attempting to establish CQL session to system keyspace",
Action: func(c *cli.Context) {
cliHandler(c, validateHealth)
},
},
}

return app
Expand Down

0 comments on commit 9e3ed33

Please sign in to comment.