Skip to content

Commit 8422787

Browse files
committed
removed cassandra domain env var since we connect through the dsn in config file
1 parent fd5f3e5 commit 8422787

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

cassandra/wrapper/init.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
const (
1919
schemaDefaultPath = "/usr/local/bin"
2020
schemaDefaultFileName = "schema.sql"
21-
defaultCassandraDomain = "db"
2221
defaultCassandraClusterConsistency = gocql.Quorum
2322
defaultUsername = ""
2423
defaultPassword = ""
@@ -27,7 +26,6 @@ const (
2726
envCassandraClusterConsistency = "CLUSTER_CONSISTENCY"
2827
envCassandraSchemaPath = "CASSANDRA_SCHEMA_PATH"
2928
envCassandraSchemaFileName = "CASSANDRA_SCHEMA_FILE_NAME"
30-
envCassandraDomain = "CASSANDRA_DOMAIN_NAME"
3129
envUsername = "CASSANDRA_USERNAME"
3230
envPassword = "CASSANDRA_PASSWORD"
3331
envSSLCert = "CASSANDRA_SSL_CERT"
@@ -36,7 +34,6 @@ const (
3634
var schemaPath = "/usr/local/bin"
3735
var schemaFileName = "schema.sql"
3836
var clusterConsistency = gocql.Quorum
39-
var domain = "db"
4037
var username = ""
4138
var password = ""
4239
var sslCert = ""
@@ -49,15 +46,13 @@ func init() {
4946
// reading and setting up environment variables
5047
schemaPath = getenv(envCassandraSchemaPath, schemaDefaultPath)
5148
schemaFileName = getenv(envCassandraSchemaFileName, schemaDefaultFileName)
52-
domain = getenv(envCassandraDomain, defaultCassandraDomain)
5349
clusterConsistency = checkConsistency(getenv(envCassandraClusterConsistency, defaultCassandraClusterConsistency.String()))
5450
username = getenvnolog(envUsername, defaultUsername)
5551
password = getenvnolog(envPassword, defaultPassword)
5652
sslCert = getenvnolog(envSSLCert, defaultSSLCert)
5753

5854
log.Debugf("Got schema path: %s", schemaPath)
5955
log.Debugf("Got schema file name: %s", schemaFileName)
60-
log.Debugf("Got domain name: %s", domain)
6156
log.Debugf("Got cluster consistency: %s", clusterConsistency)
6257
log.Debugf("Got username: %s", username)
6358
}
@@ -78,11 +73,11 @@ type sessionHolder struct {
7873
}
7974

8075
// New return a cassandra session Initializer
81-
func New(keyspace string) Initializer {
76+
func New(clusterHostName, keyspace string) Initializer {
8277
log.Debugf("in new")
8378

8479
return sessionInitializer{
85-
clusterHostName: domain,
80+
clusterHostName: clusterHostName,
8681
clusterHostUsername: username,
8782
clusterHostPassword: password,
8883
clusterHostSSLCert: sslCert,
@@ -99,17 +94,17 @@ func New(keyspace string) Initializer {
9994
// systemKeyspace: System keyspace
10095
// appKeyspace: Application keyspace
10196
// connectionTimeout: timeout to get the connection
102-
func Initialize(systemKeyspace, appKeyspace string, connectionTimeout time.Duration) {
97+
func Initialize(clusterHostName, systemKeyspace, appKeyspace string, connectionTimeout time.Duration) {
10398
log.Debug("Setting up cassandra db")
104-
connectionHolder, err := loop(connectionTimeout, New(systemKeyspace), "cassandra-db")
99+
connectionHolder, err := loop(connectionTimeout, New(clusterHostName, systemKeyspace), "cassandra-db")
105100
if err != nil {
106101
log.Fatalf("error connecting to Cassandra db: %v", err)
107102
panic(err)
108103
}
109104
defer connectionHolder.CloseSession()
110105

111106
log.Debug("Setting up cassandra keyspace")
112-
err = createAppKeyspaceIfRequired(systemKeyspace, appKeyspace)
107+
err = createAppKeyspaceIfRequired(clusterHostName, systemKeyspace, appKeyspace)
113108
if err != nil {
114109
log.Fatalf("error creating keyspace for Cassandra db: %v", err)
115110
panic(err)
@@ -168,7 +163,7 @@ func newKeyspaceSession(clusterHostName, keyspace, username, password, sslCert s
168163
}
169164

170165
// createAppKeyspaceIfRequired creates the keyspace for the app if it doesn't exist
171-
func createAppKeyspaceIfRequired(systemKeyspace, appKeyspace string) error {
166+
func createAppKeyspaceIfRequired(clusterHostName, systemKeyspace, appKeyspace string) error {
172167
// Getting the schema file if exist
173168
stmtList, err := getStmtsFromFile(path.Join(schemaPath, schemaFileName))
174169
if err != nil {
@@ -179,7 +174,7 @@ func createAppKeyspaceIfRequired(systemKeyspace, appKeyspace string) error {
179174
}
180175

181176
log.Info("about to create a session with a 5 minute timeout to allow for all schema creation")
182-
session, err := newKeyspaceSession(domain, systemKeyspace, username, password, sslCert, clusterConsistency, 5*time.Minute)
177+
session, err := newKeyspaceSession(clusterHostName, systemKeyspace, username, password, sslCert, clusterConsistency, 5*time.Minute)
183178
if err != nil {
184179
return err
185180
}
@@ -204,7 +199,7 @@ func createAppKeyspaceIfRequired(systemKeyspace, appKeyspace string) error {
204199
if (isCaseSensitive && newKeyspace != currentKeyspace) || (!isCaseSensitive &&
205200
strings.ToLower(newKeyspace) != strings.ToLower(currentKeyspace)) {
206201
log.Infof("about to create a session with a 5 minute timeout to set keyspace: %s", newKeyspace)
207-
session, err = newKeyspaceSession(domain, newKeyspace, username, password, sslCert, clusterConsistency, 5*time.Minute) //5 minutes
202+
session, err = newKeyspaceSession(clusterHostName, newKeyspace, username, password, sslCert, clusterConsistency, 5*time.Minute) //5 minutes
208203
if err != nil {
209204
return err
210205
}

pkg/api/cassandra_repository.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func NewCassandraRepository(dsn string, refreshTime time.Duration) (*CassandraRe
4343
}
4444

4545
// Wait for Cassandra to start, setup Cassandra keyspace if required
46-
wrapper.Initialize(cass.SystemKeyspace, cass.AppKeyspace, cass.Timeout*time.Second)
46+
wrapper.Initialize(cass.ClusterHostName, cass.SystemKeyspace, cass.AppKeyspace, cass.Timeout*time.Second)
4747

4848
// Getting a cassandra connection initializer
49-
initializer := wrapper.New(cass.AppKeyspace)
49+
initializer := wrapper.New(cass.ClusterHostName, cass.AppKeyspace)
5050

5151
// Starting a new cassandra Session
5252
sessionHolder, err := initializer.NewSession()

0 commit comments

Comments
 (0)