@@ -27,10 +27,15 @@ func main() {
27
27
28
28
// If node name and base directory were provided on the command line, then override the config file values
29
29
if len (os .Args ) == 3 {
30
- com .NodeName = os .Args [1 ]
30
+ com .Conf . Live . Nodename = os .Args [1 ]
31
31
com .Conf .Live .StorageDir = os .Args [2 ]
32
32
}
33
33
34
+ // If we don't have the node name or storage dir after reading both the config and command line, then abort
35
+ if com .Conf .Live .Nodename == "" || com .Conf .Live .StorageDir == "" {
36
+ log .Fatal ("Node name or Storage directory missing. Aborting" )
37
+ }
38
+
34
39
// If it doesn't exist, create the base directory for storing SQLite files
35
40
_ , err = os .Stat (com .Conf .Live .StorageDir )
36
41
if err != nil {
@@ -81,9 +86,9 @@ func main() {
81
86
err = json .Unmarshal (d .Body , & req )
82
87
if err != nil {
83
88
log .Println (err )
84
- err = com .MQCreateResponse (d , ch , com .NodeName , "failure" )
89
+ err = com .MQCreateResponse (d , ch , com .Conf . Live . Nodename , "failure" )
85
90
if err != nil {
86
- log .Printf ("Error: occurred on live node '%s' in the create db code, while constructing an AMQP error message response: '%s'" , com .NodeName , err )
91
+ log .Printf ("Error: occurred on live node '%s' in the create db code, while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
87
92
}
88
93
continue
89
94
}
@@ -92,23 +97,23 @@ func main() {
92
97
err = setupLiveDB (req .DBOwner , req .DBName )
93
98
if err != nil {
94
99
log .Println (err )
95
- err = com .MQCreateResponse (d , ch , com .NodeName , "failure" )
100
+ err = com .MQCreateResponse (d , ch , com .Conf . Live . Nodename , "failure" )
96
101
if err != nil {
97
- log .Printf ("Error: occurred on live node '%s' in the create db code, while constructing an AMQP error message response (location 2): '%s'" , com .NodeName , err )
102
+ log .Printf ("Error: occurred on live node '%s' in the create db code, while constructing an AMQP error message response (location 2): '%s'" , com .Conf . Live . Nodename , err )
98
103
}
99
104
continue
100
105
}
101
106
102
107
// Respond to the creation request with a success message
103
- err = com .MQCreateResponse (d , ch , com .NodeName , "success" )
108
+ err = com .MQCreateResponse (d , ch , com .Conf . Live . Nodename , "success" )
104
109
if err != nil {
105
110
continue
106
111
}
107
112
}
108
113
}()
109
114
110
115
// Create the queue for receiving database queries
111
- queryQueue , err := com .MQCreateQueryQueue (ch , com .NodeName )
116
+ queryQueue , err := com .MQCreateQueryQueue (ch , com .Conf . Live . Nodename )
112
117
if err != nil {
113
118
log .Fatal (err )
114
119
}
@@ -121,23 +126,23 @@ func main() {
121
126
go func () {
122
127
for msg := range requests {
123
128
if com .AmqpDebug {
124
- log .Printf ("'%s' received AMQP REQUEST (of not-yet-determined type)" , com .NodeName )
129
+ log .Printf ("'%s' received AMQP REQUEST (of not-yet-determined type)" , com .Conf . Live . Nodename )
125
130
}
126
131
127
132
// Decode JSON request
128
133
var req com.LiveDBRequest
129
134
err = json .Unmarshal (msg .Body , & req )
130
135
if err != nil {
131
136
log .Println (err )
132
- err = com .MQErrorResponse (msg , ch , com .NodeName , err .Error ())
137
+ err = com .MQErrorResponse (msg , ch , com .Conf . Live . Nodename , err .Error ())
133
138
if err != nil {
134
- log .Printf ("Error: occurred on '%s' the main live node switch{} while constructing an AMQP error message response: '%s'" , com .NodeName , err )
139
+ log .Printf ("Error: occurred on '%s' the main live node switch{} while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
135
140
}
136
141
continue
137
142
}
138
143
139
144
if com .AmqpDebug {
140
- log .Printf ("Decoded request on '%s'. Correlation ID: '%s', request operation: '%s', request query: '%s'" , com .NodeName , msg .CorrelationId , req .Operation , req .Query )
145
+ log .Printf ("Decoded request on '%s'. Correlation ID: '%s', request operation: '%s', request query: '%s'" , com .Conf . Live . Nodename , msg .CorrelationId , req .Operation , req .Query )
141
146
}
142
147
143
148
// Handle each operation
@@ -146,129 +151,129 @@ func main() {
146
151
var columns []sqlite.Column
147
152
columns , err = com .SQLiteGetColumnsLive (com .Conf .Live .StorageDir , req .DBOwner , req .DBName , req .Query ) // We use the req.Query field to pass the table name
148
153
if err != nil {
149
- err = com .MQColumnsResponse (msg , ch , com .NodeName , nil , err .Error ())
154
+ err = com .MQColumnsResponse (msg , ch , com .Conf . Live . Nodename , nil , err .Error ())
150
155
if err != nil {
151
- log .Printf ("Error: occurred on '%s' in MQColumnsResponse() while constructing an AMQP error message response: '%s'" , com .NodeName , err )
156
+ log .Printf ("Error: occurred on '%s' in MQColumnsResponse() while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
152
157
}
153
158
continue
154
159
}
155
160
156
161
// Return the columns list to the caller
157
- err = com .MQColumnsResponse (msg , ch , com .NodeName , columns , "" )
162
+ err = com .MQColumnsResponse (msg , ch , com .Conf . Live . Nodename , columns , "" )
158
163
if err != nil {
159
- log .Printf ("Error: occurred on '%s' in MQColumnsResponse() while constructing the AMQP columns list response: '%s'" , com .NodeName , err )
164
+ log .Printf ("Error: occurred on '%s' in MQColumnsResponse() while constructing the AMQP columns list response: '%s'" , com .Conf . Live . Nodename , err )
160
165
}
161
166
continue
162
167
163
168
case "delete" :
164
169
// Delete the database file on the node
165
170
err = removeLiveDB (req .DBOwner , req .DBName )
166
171
if err != nil {
167
- err = com .MQDeleteResponse (msg , ch , com .NodeName , err .Error ())
172
+ err = com .MQDeleteResponse (msg , ch , com .Conf . Live . Nodename , err .Error ())
168
173
continue
169
174
}
170
175
171
176
// Return a success message (empty string in this case) to the caller
172
- err = com .MQDeleteResponse (msg , ch , com .NodeName , "" )
177
+ err = com .MQDeleteResponse (msg , ch , com .Conf . Live . Nodename , "" )
173
178
if err != nil {
174
- log .Printf ("Error: occurred on '%s' in MQDeleteResponse() while constructing the AMQP delete database response: '%s'" , com .NodeName , err )
179
+ log .Printf ("Error: occurred on '%s' in MQDeleteResponse() while constructing the AMQP delete database response: '%s'" , com .Conf . Live . Nodename , err )
175
180
}
176
181
continue
177
182
178
183
case "exec" :
179
184
// Execute a query on the database file
180
185
err = com .SQLiteExecQueryLive (com .Conf .Live .StorageDir , req .DBOwner , req .DBName , req .RequestingUser , req .Query )
181
186
if err != nil {
182
- err = com .MQExecResponse (msg , ch , com .NodeName , err .Error ())
187
+ err = com .MQExecResponse (msg , ch , com .Conf . Live . Nodename , err .Error ())
183
188
continue
184
189
}
185
190
186
191
// Return a success message (empty string in this case) to the caller
187
- err = com .MQExecResponse (msg , ch , com .NodeName , "" )
192
+ err = com .MQExecResponse (msg , ch , com .Conf . Live . Nodename , "" )
188
193
if err != nil {
189
- log .Printf ("Error: occurred on '%s' in MQExecResponse() while constructing the AMQP execute query response: '%s'" , com .NodeName , err )
194
+ log .Printf ("Error: occurred on '%s' in MQExecResponse() while constructing the AMQP execute query response: '%s'" , com .Conf . Live . Nodename , err )
190
195
}
191
196
continue
192
197
193
198
case "indexes" :
194
199
var indexes []com.APIJSONIndex
195
200
indexes , err = com .SQLiteGetIndexesLive (com .Conf .Live .StorageDir , req .DBOwner , req .DBName )
196
201
if err != nil {
197
- err = com .MQIndexesResponse (msg , ch , com .NodeName , nil , err .Error ())
202
+ err = com .MQIndexesResponse (msg , ch , com .Conf . Live . Nodename , nil , err .Error ())
198
203
if err != nil {
199
- log .Printf ("Error: occurred on '%s' in MQIndexesResponse() while constructing an AMQP error message response: '%s'" , com .NodeName , err )
204
+ log .Printf ("Error: occurred on '%s' in MQIndexesResponse() while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
200
205
}
201
206
continue
202
207
}
203
208
204
209
// Return the indexes list to the caller
205
- err = com .MQIndexesResponse (msg , ch , com .NodeName , indexes , "" )
210
+ err = com .MQIndexesResponse (msg , ch , com .Conf . Live . Nodename , indexes , "" )
206
211
if err != nil {
207
- log .Printf ("Error: occurred on '%s' in MQIndexesResponse() while constructing the AMQP indexes list response: '%s'" , com .NodeName , err )
212
+ log .Printf ("Error: occurred on '%s' in MQIndexesResponse() while constructing the AMQP indexes list response: '%s'" , com .Conf . Live . Nodename , err )
208
213
}
209
214
continue
210
215
211
216
case "query" :
212
217
var rows com.SQLiteRecordSet
213
218
rows , err = com .SQLiteRunQueryLive (com .Conf .Live .StorageDir , req .DBOwner , req .DBName , req .RequestingUser , req .Query )
214
219
if err != nil {
215
- err = com .MQQueryResponse (msg , ch , com .NodeName , com.SQLiteRecordSet {}, err .Error ())
220
+ err = com .MQQueryResponse (msg , ch , com .Conf . Live . Nodename , com.SQLiteRecordSet {}, err .Error ())
216
221
if err != nil {
217
- log .Printf ("Error: occurred on '%s' in MQQueryResponse() while constructing an AMQP error message response: '%s'" , com .NodeName , err )
222
+ log .Printf ("Error: occurred on '%s' in MQQueryResponse() while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
218
223
}
219
224
continue
220
225
}
221
226
222
227
// Return the query response to the caller
223
- err = com .MQQueryResponse (msg , ch , com .NodeName , rows , "" )
228
+ err = com .MQQueryResponse (msg , ch , com .Conf . Live . Nodename , rows , "" )
224
229
if err != nil {
225
- log .Printf ("Error: occurred on '%s' in MQQueryResponse() while constructing the AMQP query response: '%s'" , com .NodeName , err )
230
+ log .Printf ("Error: occurred on '%s' in MQQueryResponse() while constructing the AMQP query response: '%s'" , com .Conf . Live . Nodename , err )
226
231
}
227
232
continue
228
233
229
234
case "tables" :
230
235
var tables []string
231
236
tables , err = com .SQLiteGetTablesLive (com .Conf .Live .StorageDir , req .DBOwner , req .DBName )
232
237
if err != nil {
233
- err = com .MQTablesResponse (msg , ch , com .NodeName , nil , err .Error ())
238
+ err = com .MQTablesResponse (msg , ch , com .Conf . Live . Nodename , nil , err .Error ())
234
239
if err != nil {
235
- log .Printf ("Error: occurred on '%s' in MQTablesResponse() while constructing an AMQP error message response: '%s'" , com .NodeName , err )
240
+ log .Printf ("Error: occurred on '%s' in MQTablesResponse() while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
236
241
}
237
242
continue
238
243
}
239
244
240
245
// Return the tables list to the caller
241
- err = com .MQTablesResponse (msg , ch , com .NodeName , tables , "" )
246
+ err = com .MQTablesResponse (msg , ch , com .Conf . Live . Nodename , tables , "" )
242
247
if err != nil {
243
- log .Printf ("Error: occurred on '%s' in MQTablesResponse() while constructing the AMQP tables list response: '%s'" , com .NodeName , err )
248
+ log .Printf ("Error: occurred on '%s' in MQTablesResponse() while constructing the AMQP tables list response: '%s'" , com .Conf . Live . Nodename , err )
244
249
}
245
250
continue
246
251
247
252
case "views" :
248
253
var views []string
249
254
views , err = com .SQLiteGetViewsLive (com .Conf .Live .StorageDir , req .DBOwner , req .DBName )
250
255
if err != nil {
251
- err = com .MQViewsResponse (msg , ch , com .NodeName , nil , err .Error ())
256
+ err = com .MQViewsResponse (msg , ch , com .Conf . Live . Nodename , nil , err .Error ())
252
257
if err != nil {
253
- log .Printf ("Error: occurred on '%s' in MQViewsResponse() while constructing an AMQP error message response: '%s'" , com .NodeName , err )
258
+ log .Printf ("Error: occurred on '%s' in MQViewsResponse() while constructing an AMQP error message response: '%s'" , com .Conf . Live . Nodename , err )
254
259
}
255
260
continue
256
261
}
257
262
258
263
// Return the views list to the caller
259
- err = com .MQViewsResponse (msg , ch , com .NodeName , views , "" )
264
+ err = com .MQViewsResponse (msg , ch , com .Conf . Live . Nodename , views , "" )
260
265
if err != nil {
261
- log .Printf ("Error: occurred on '%s' in MQViewsResponse() while constructing the AMQP views list response: '%s'" , com .NodeName , err )
266
+ log .Printf ("Error: occurred on '%s' in MQViewsResponse() while constructing the AMQP views list response: '%s'" , com .Conf . Live . Nodename , err )
262
267
}
263
268
continue
264
269
265
270
default :
266
- log .Printf ("'%s' received unknown '%s' request on this queue for %s/%s" , com .NodeName , req .Operation , req .DBOwner , req .DBName )
271
+ log .Printf ("'%s' received unknown '%s' request on this queue for %s/%s" , com .Conf . Live . Nodename , req .Operation , req .DBOwner , req .DBName )
267
272
}
268
273
}
269
274
}()
270
275
271
- log .Printf ("Live server '%s' listening for requests" , com .NodeName )
276
+ log .Printf ("Live server '%s' listening for requests" , com .Conf . Live . Nodename )
272
277
273
278
// Endless loop
274
279
var forever chan struct {}
@@ -311,7 +316,7 @@ func removeLiveDB(dbOwner, dbName string) (err error) {
311
316
312
317
if com .AmqpDebug {
313
318
log .Printf ("Live node '%s': Database file '%s/%s' removed from filesystem path: '%s'" ,
314
- com .NodeName , dbOwner , dbName , dbPath )
319
+ com .Conf . Live . Nodename , dbOwner , dbName , dbPath )
315
320
}
316
321
return
317
322
}
0 commit comments