go.temporal.io/server/tools/cassandra/handler.go
233 LOC · 102 covered · 131 uncovered · 39 ranges · 20 concepts · 14 introducers · 9 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package cassandra
import (
"fmt"
"strings"
"github.com/urfave/cli"
"go.temporal.io/server/common/auth"
c "go.temporal.io/server/common/config"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/temporal/environment"
"go.temporal.io/server/tools/common/schema"
)
const defaultNumReplicas = 1
// SetupSchemaConfig contains the configuration params needed to setup schema tables
type SetupSchemaConfig struct {
CQLClientConfig
schema.SetupConfig
}
// setupSchema executes the setupSchemaTask
// using the given command line arguments
// as input
config, err := newCQLClientConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if err != nil {
logger.Error("Unable to establish CQL session.", tag.Error(err))
return err
}
if err := schema.Setup(cli, client, logger); err != nil {
return err
}
}
// updateSchema executes the updateSchemaTask
// using the given command line args as input
config, err := newCQLClientConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if err != nil {
logger.Error("Unable to establish CQL session.", tag.Error(err))
return err
}
if err := schema.Update(cli, client, logger); err != nil {
logger.Error("Unable to update CQL schema.", tag.Error(err))
return err
}
}
config, err := newCQLClientConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if keyspace == "" {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if err != nil {
logger.Error("Unable to create keyspace.", tag.Error(err))
return err
}
}
config, err := newCQLClientConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
if keyspace == "" {
err := fmt.Errorf("missing %s argument", flag(schema.CLIOptKeyspace))
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
err = doDropKeyspace(config, keyspace, logger)
if err != nil {
logger.Error("Unable to drop keyspace.", tag.Error(err))
return err
}
return nil
}
func validateHealth(cli *cli.Context, logger log.Logger) error {
config, err := newCQLClientConfig(cli)
if err != nil {
logger.Error("Unable to read config.", tag.Error(schema.NewConfigError(err.Error())))
return err
}
config.Keyspace = systemKeyspace
client, err := newCQLClient(config, logger)
if err != nil {
logger.Error("Unable to establish CQL session.", tag.Error(err))
return err
}
defer client.Close()
return nil
}
func doCreateKeyspace(cfg *CQLClientConfig, name string, logger log.Logger) error {
handler.go ×4
cfg.Keyspace = systemKeyspace
client, err := newCQLClient(cfg, logger)
if err != nil {
return err
}
return client.createKeyspace(name)
}
func doDropKeyspace(cfg *CQLClientConfig, name string, logger log.Logger) error {
cfg.Keyspace = systemKeyspace
client, err := newCQLClient(cfg, logger)
if err != nil {
return err
}
defer client.Close()
return client.dropKeyspace(name)
}
config := &CQLClientConfig{
Hosts: cli.GlobalString(schema.CLIOptEndpoint),
Port: cli.GlobalInt(schema.CLIOptPort),
User: cli.GlobalString(schema.CLIOptUser),
Password: cli.GlobalString(schema.CLIOptPassword),
AllowedAuthenticators: cli.GlobalStringSlice(schema.CLIOptAllowedAuthenticators),
Timeout: cli.GlobalInt(schema.CLIOptTimeout),
Keyspace: cli.GlobalString(schema.CLIOptKeyspace),
numReplicas: cli.Int(schema.CLIOptReplicationFactor),
Datacenter: cli.String(schema.CLIOptDatacenter),
Consistency: cli.String(schema.CLIOptConsistency),
DisableInitialHostLookup: cli.GlobalBool(schema.CLIFlagDisableInitialHostLookup),
}
if cli.GlobalBool(schema.CLIFlagEnableTLS) {
config.TLS = &auth.TLS{
Enabled: true,
CertFile: cli.GlobalString(schema.CLIFlagTLSCertFile),
KeyFile: cli.GlobalString(schema.CLIFlagTLSKeyFile),
CaFile: cli.GlobalString(schema.CLIFlagTLSCaFile),
ServerName: cli.GlobalString(schema.CLIFlagTLSHostName),
EnableHostVerification: !cli.GlobalBool(schema.CLIFlagTLSDisableHostVerification),
}
}
Translator: cli.GlobalString(schema.CLIOptAddressTranslator),
Options: parseOptionsMap(cli.GlobalString(schema.CLIOptAddressTranslatorOptions)),
}
if err := validateCQLClientConfig(config); err != nil {
return nil, err
}
}
if len(value) == 0 {
}
for pair := range strings.SplitSeq(value, ",") {
trimmedPair := strings.ReplaceAll(pair, " ", "")
if len(trimmedPair) == 0 {
continue
}
if len(splitPair) != 2 {
continue
}
continue
}
}
}
if len(config.Hosts) == 0 {
return schema.NewConfigError("missing cassandra endpoint argument " + flag(schema.CLIOptEndpoint))
handler.go ×3
}
return schema.NewConfigError("missing " + flag(schema.CLIOptKeyspace) + " argument ")
handler.go ×3
}
}
}
if config.AddressTranslator != nil && len(config.AddressTranslator.Options) != 0 {
handler.go ×6
if len(config.AddressTranslator.Translator) == 0 {
return schema.NewConfigError("missing address translator argument " + flag(schema.CLIOptAddressTranslator))
}
}
}
return "(-" + opt + ")"
}