Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Add cassandra port support (#275)
Browse files Browse the repository at this point in the history
* Add cassandra port support
  • Loading branch information
kobeyang committed Aug 16, 2017
1 parent 1341daf commit 1f9a72d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions clients/metadata/metadata_cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func NewCassandraMetadataService(cfg configure.CommonMetadataConfig, log bark.Lo
}

cluster := newCluster(cfg.GetCassandraHosts())
cluster.Port = cfg.GetPort()
cluster.Keyspace = cfg.GetKeyspace()
cluster.ProtoVersion = cassandraProtoVersion

Expand Down
9 changes: 7 additions & 2 deletions clients/metadata/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func newCluster(clusterHosts string) *gocql.ClusterConfig {
// CreateKeyspaceNoSession is used to create a keyspace when we don't have a session
func CreateKeyspaceNoSession(
clusterHosts string,
port int,
keyspace string,
replicas int,
overwrite bool,
Expand All @@ -112,6 +113,7 @@ func CreateKeyspaceNoSession(
// open a session to the "system" keyspace just to create the new keyspace
// TODO: Find out if we can do this "outside" of a session (cqlsh?)
cluster := newCluster(clusterHosts)
cluster.Port = port
cluster.Consistency = gocql.One
cluster.Keyspace = "system"
cluster.Timeout = 40 * time.Second
Expand Down Expand Up @@ -159,7 +161,8 @@ func (s *TestCluster) SetupTestCluster() {
golangLog.SetOutput(ioutil.Discard)

ip := `127.0.0.1`
s.createCluster(ip, gocql.Consistency(1), generateRandomKeyspace(10))
port := 9042
s.createCluster(ip, port, gocql.Consistency(1), generateRandomKeyspace(10))
s.createKeyspace(1)
s.loadSchema("schema/metadata.cql")

Expand All @@ -172,6 +175,7 @@ func (s *TestCluster) SetupTestCluster() {
var err error
s.client, err = NewCassandraMetadataService(&configure.MetadataConfig{
CassandraHosts: ip,
Port: port,
Keyspace: s.keyspace,
Consistency: "One",
Authentication: auth,
Expand All @@ -188,8 +192,9 @@ func (s *TestCluster) TearDownTestCluster() {
s.session.Close()
}

func (s *TestCluster) createCluster(clusterHosts string, cons gocql.Consistency, keyspace string) {
func (s *TestCluster) createCluster(clusterHosts string, port int, cons gocql.Consistency, keyspace string) {
s.cluster = newCluster(clusterHosts)
s.cluster.Port = port
s.cluster.Consistency = cons
s.cluster.Keyspace = "system"
s.cluster.Timeout = 40 * time.Second
Expand Down
6 changes: 6 additions & 0 deletions common/configure/commonmetadataconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Authentication struct {
// MetadataConfig holds the config info related to our metadata
type MetadataConfig struct {
CassandraHosts string `yaml:"CassandraHosts"`
Port int `yaml:"Port"`
Keyspace string `yaml:"Keyspace"`
Authentication Authentication `yaml:"Authentication"`
Consistency string `yaml:"Consistency"`
Expand All @@ -50,6 +51,11 @@ func (r *MetadataConfig) GetCassandraHosts() string {
return r.CassandraHosts
}

// GetPort gets the cassandra host port
func (r *MetadataConfig) GetPort() int {
return r.Port
}

// GetKeyspace returns the keyspace to be used for cherami cluster
func (r *MetadataConfig) GetKeyspace() string {
return r.Keyspace
Expand Down
2 changes: 2 additions & 0 deletions common/configure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type (
CommonMetadataConfig interface {
// GetCassandraHosts gets the cassandra seed hosts
GetCassandraHosts() string
// GetPort() gets the cassandra host port
GetPort() int
// GetKeyspace returns the keyspace for our cassandra cluster
GetKeyspace() string
// GetAuthentication returns the authentication info for our cassandra cluster
Expand Down
1 change: 1 addition & 0 deletions config/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ServiceConfig:
# MetadataConfig specifies location of the Cassandra and ketspace
MetadataConfig:
CassandraHosts: ""
Port: 9042
Keyspace: "cherami"
Consistency: "one"
ClusterName: "base"
Expand Down
1 change: 1 addition & 0 deletions config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DefaultDestinationConfig:

MetadataConfig:
CassandraHosts: "127.0.0.1"
Port: 9042
Authentication:
Enabled: false
Username:
Expand Down
3 changes: 2 additions & 1 deletion test/integration/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ func (tb *testBase) setupSuiteImpl(t *testing.T) {
}

// create the keyspace first
err := metadata.CreateKeyspaceNoSession("127.0.0.1", tb.keyspace, 1, true, auth)
err := metadata.CreateKeyspaceNoSession("127.0.0.1", 9042, tb.keyspace, 1, true, auth)
tb.NoError(err)

tb.mClient, _ = metadata.NewCassandraMetadataService(&configure.MetadataConfig{
CassandraHosts: "127.0.0.1",
Port: 9042,
Keyspace: tb.keyspace,
Consistency: "One",
Authentication: auth,
Expand Down

0 comments on commit 1f9a72d

Please sign in to comment.