@@ -18,7 +18,6 @@ import (
18
18
const (
19
19
schemaDefaultPath = "/usr/local/bin"
20
20
schemaDefaultFileName = "schema.sql"
21
- defaultCassandraDomain = "db"
22
21
defaultCassandraClusterConsistency = gocql .Quorum
23
22
defaultUsername = ""
24
23
defaultPassword = ""
@@ -27,7 +26,6 @@ const (
27
26
envCassandraClusterConsistency = "CLUSTER_CONSISTENCY"
28
27
envCassandraSchemaPath = "CASSANDRA_SCHEMA_PATH"
29
28
envCassandraSchemaFileName = "CASSANDRA_SCHEMA_FILE_NAME"
30
- envCassandraDomain = "CASSANDRA_DOMAIN_NAME"
31
29
envUsername = "CASSANDRA_USERNAME"
32
30
envPassword = "CASSANDRA_PASSWORD"
33
31
envSSLCert = "CASSANDRA_SSL_CERT"
@@ -36,7 +34,6 @@ const (
36
34
var schemaPath = "/usr/local/bin"
37
35
var schemaFileName = "schema.sql"
38
36
var clusterConsistency = gocql .Quorum
39
- var domain = "db"
40
37
var username = ""
41
38
var password = ""
42
39
var sslCert = ""
@@ -49,15 +46,13 @@ func init() {
49
46
// reading and setting up environment variables
50
47
schemaPath = getenv (envCassandraSchemaPath , schemaDefaultPath )
51
48
schemaFileName = getenv (envCassandraSchemaFileName , schemaDefaultFileName )
52
- domain = getenv (envCassandraDomain , defaultCassandraDomain )
53
49
clusterConsistency = checkConsistency (getenv (envCassandraClusterConsistency , defaultCassandraClusterConsistency .String ()))
54
50
username = getenvnolog (envUsername , defaultUsername )
55
51
password = getenvnolog (envPassword , defaultPassword )
56
52
sslCert = getenvnolog (envSSLCert , defaultSSLCert )
57
53
58
54
log .Debugf ("Got schema path: %s" , schemaPath )
59
55
log .Debugf ("Got schema file name: %s" , schemaFileName )
60
- log .Debugf ("Got domain name: %s" , domain )
61
56
log .Debugf ("Got cluster consistency: %s" , clusterConsistency )
62
57
log .Debugf ("Got username: %s" , username )
63
58
}
@@ -78,11 +73,11 @@ type sessionHolder struct {
78
73
}
79
74
80
75
// New return a cassandra session Initializer
81
- func New (keyspace string ) Initializer {
76
+ func New (clusterHostName , keyspace string ) Initializer {
82
77
log .Debugf ("in new" )
83
78
84
79
return sessionInitializer {
85
- clusterHostName : domain ,
80
+ clusterHostName : clusterHostName ,
86
81
clusterHostUsername : username ,
87
82
clusterHostPassword : password ,
88
83
clusterHostSSLCert : sslCert ,
@@ -99,17 +94,17 @@ func New(keyspace string) Initializer {
99
94
// systemKeyspace: System keyspace
100
95
// appKeyspace: Application keyspace
101
96
// 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 ) {
103
98
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" )
105
100
if err != nil {
106
101
log .Fatalf ("error connecting to Cassandra db: %v" , err )
107
102
panic (err )
108
103
}
109
104
defer connectionHolder .CloseSession ()
110
105
111
106
log .Debug ("Setting up cassandra keyspace" )
112
- err = createAppKeyspaceIfRequired (systemKeyspace , appKeyspace )
107
+ err = createAppKeyspaceIfRequired (clusterHostName , systemKeyspace , appKeyspace )
113
108
if err != nil {
114
109
log .Fatalf ("error creating keyspace for Cassandra db: %v" , err )
115
110
panic (err )
@@ -168,7 +163,7 @@ func newKeyspaceSession(clusterHostName, keyspace, username, password, sslCert s
168
163
}
169
164
170
165
// 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 {
172
167
// Getting the schema file if exist
173
168
stmtList , err := getStmtsFromFile (path .Join (schemaPath , schemaFileName ))
174
169
if err != nil {
@@ -179,7 +174,7 @@ func createAppKeyspaceIfRequired(systemKeyspace, appKeyspace string) error {
179
174
}
180
175
181
176
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 )
183
178
if err != nil {
184
179
return err
185
180
}
@@ -204,7 +199,7 @@ func createAppKeyspaceIfRequired(systemKeyspace, appKeyspace string) error {
204
199
if (isCaseSensitive && newKeyspace != currentKeyspace ) || (! isCaseSensitive &&
205
200
strings .ToLower (newKeyspace ) != strings .ToLower (currentKeyspace )) {
206
201
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
208
203
if err != nil {
209
204
return err
210
205
}
0 commit comments