@@ -16,6 +16,7 @@ const { get_boolean_or_string_value, throw_cli_error, write_stdout_response,
16
16
get_bucket_owner_account_by_id, get_service_status, NOOBAA_SERVICE_NAME } = require ( './manage_nsfs_cli_utils' ) ;
17
17
const { ManageCLIResponse } = require ( './manage_nsfs_cli_responses' ) ;
18
18
const ManageCLIError = require ( './manage_nsfs_cli_errors' ) . ManageCLIError ;
19
+ const notifications_util = require ( '../util/notifications_util' ) ;
19
20
20
21
21
22
const HOSTNAME = 'localhost' ;
@@ -101,6 +102,7 @@ class NSFSHealth {
101
102
this . https_port = options . https_port ;
102
103
this . all_account_details = options . all_account_details ;
103
104
this . all_bucket_details = options . all_bucket_details ;
105
+ this . all_connection_details = options . all_connection_details ;
104
106
this . config_fs = options . config_fs ;
105
107
}
106
108
@@ -128,12 +130,14 @@ class NSFSHealth {
128
130
129
131
let bucket_details ;
130
132
let account_details ;
133
+ let connection_details ;
131
134
const endpoint_response_code = ( endpoint_state && endpoint_state . response ?. response_code ) || 'UNKNOWN_ERROR' ;
132
135
const health_check_params = { service_status, pid, endpoint_response_code, config_directory_status } ;
133
136
const service_health = this . _calc_health_status ( health_check_params ) ;
134
137
const error_code = this . get_error_code ( health_check_params ) ;
135
138
if ( this . all_bucket_details ) bucket_details = await this . get_bucket_status ( ) ;
136
139
if ( this . all_account_details ) account_details = await this . get_account_status ( ) ;
140
+ if ( this . all_connection_details ) connection_details = await this . get_connection_status ( ) ;
137
141
const health = {
138
142
service_name : NOOBAA_SERVICE_NAME ,
139
143
status : service_health ,
@@ -155,11 +159,13 @@ class NSFSHealth {
155
159
invalid_buckets : bucket_details === undefined ? undefined : bucket_details . invalid_storages ,
156
160
valid_buckets : bucket_details === undefined ? undefined : bucket_details . valid_storages ,
157
161
error_type : health_errors_tyes . PERSISTENT ,
158
- }
162
+ } ,
163
+ connections_status : connection_details
159
164
}
160
165
} ;
161
166
if ( ! this . all_account_details ) delete health . checks . accounts_status ;
162
167
if ( ! this . all_bucket_details ) delete health . checks . buckets_status ;
168
+ if ( ! this . all_connection_details ) delete health . checks . connections_status ;
163
169
return health ;
164
170
}
165
171
@@ -323,6 +329,17 @@ class NSFSHealth {
323
329
} ;
324
330
}
325
331
332
+ async validate_config_dir_exists ( path , type ) {
333
+ const config_root_type_exists = await this . config_fs . validate_config_dir_exists ( path ) ;
334
+ if ( ! config_root_type_exists ) {
335
+ dbg . log1 ( `Config directory type - ${ type } is missing, ${ path } ` ) ;
336
+ return {
337
+ invalid_storages : [ ] ,
338
+ valid_storages : [ ]
339
+ } ;
340
+ }
341
+ }
342
+
326
343
async get_bucket_status ( ) {
327
344
const bucket_details = await this . get_storage_status ( TYPES . BUCKET , this . all_bucket_details ) ;
328
345
return bucket_details ;
@@ -333,34 +350,38 @@ class NSFSHealth {
333
350
return account_details ;
334
351
}
335
352
353
+ async get_connection_status ( ) {
354
+ const connection_details = await this . get_storage_status ( TYPES . CONNECTION , this . all_connection_details ) ;
355
+ //if there were in failed test notifications, mark error as temp
356
+ if ( connection_details . invalid_storages && connection_details . invalid_storages . length > 0 ) {
357
+ connection_details . error_type = health_errors_tyes . TEMPORARY ;
358
+ }
359
+ return connection_details ;
360
+ }
361
+
336
362
async get_storage_status ( type , all_details ) {
337
363
const invalid_storages = [ ] ;
338
364
const valid_storages = [ ] ;
339
365
//check for account and buckets dir paths
340
- let config_root_type_exists ;
341
366
let config_dir_path ;
342
367
if ( type === TYPES . BUCKET ) {
343
368
config_dir_path = this . config_fs . buckets_dir_path ;
344
- config_root_type_exists = await this . config_fs . validate_config_dir_exists ( config_dir_path ) ;
345
369
} else if ( type === TYPES . ACCOUNT ) {
346
370
// TODO - handle iam accounts when directory structure changes - read_account_by_id
347
371
config_dir_path = this . config_fs . accounts_by_name_dir_path ;
348
- config_root_type_exists = await this . config_fs . validate_config_dir_exists ( config_dir_path ) ;
349
- }
350
- // TODO - this is not a good handling for that - we need to take it to an upper level
351
- if ( ! config_root_type_exists ) {
352
- dbg . log1 ( `Config directory type - ${ type } is missing, ${ config_dir_path } ` ) ;
353
- return {
354
- invalid_storages : invalid_storages ,
355
- valid_storages : valid_storages
356
- } ;
372
+ } else {
373
+ config_dir_path = this . config_fs . connections_dir_path ;
357
374
}
375
+ const missing = await this . validate_config_dir_exists ( config_dir_path , type ) ;
376
+ if ( missing ) return missing ;
358
377
359
378
let config_files_names ;
360
379
if ( type === TYPES . BUCKET ) {
361
380
config_files_names = await this . config_fs . list_buckets ( ) ;
362
- } else {
381
+ } else if ( type === TYPES . ACCOUNT ) {
363
382
config_files_names = await this . config_fs . list_accounts ( ) ;
383
+ } else {
384
+ config_files_names = await this . config_fs . list_connections ( ) ;
364
385
}
365
386
for ( const config_file_name of config_files_names ) {
366
387
// config_file get data or push error
@@ -376,13 +397,24 @@ class NSFSHealth {
376
397
let res ;
377
398
const storage_path = type === TYPES . BUCKET ?
378
399
config_data . path :
379
- config_data . nsfs_account_config . new_buckets_path ;
400
+ config_data . nsfs_account_config ? .new_buckets_path ;
380
401
381
402
if ( type === TYPES . ACCOUNT ) {
382
403
const config_file_path = this . config_fs . get_account_path_by_name ( config_file_name ) ;
383
404
res = await is_new_buckets_path_valid ( config_file_path , config_data , storage_path ) ;
384
405
} else if ( type === TYPES . BUCKET ) {
385
406
res = await is_bucket_storage_and_owner_exists ( this . config_fs , config_data , storage_path ) ;
407
+ } else {
408
+ const connection_file_path = this . config_fs . get_connection_path_by_name ( config_file_name ) ;
409
+ const test_notif_err = await notifications_util . test_notifications ( [ {
410
+ name : config_data . name ,
411
+ topic : [ this . config_fs . json ( config_file_name ) ]
412
+ } ] , this . config_fs . config_root ) ;
413
+ if ( test_notif_err ) {
414
+ res = get_invalid_object ( config_data . name , connection_file_path , undefined , test_notif_err . code ) ;
415
+ } else {
416
+ res = get_valid_object ( config_data . name , connection_file_path , undefined ) ;
417
+ }
386
418
}
387
419
if ( all_details && res . valid_storage ) {
388
420
valid_storages . push ( res . valid_storage ) ;
@@ -406,16 +438,41 @@ class NSFSHealth {
406
438
let config_data ;
407
439
let err_obj ;
408
440
try {
409
- config_data = type === TYPES . BUCKET ?
410
- await this . config_fs . get_bucket_by_name ( config_file_name ) :
411
- // TODO - should be changed to id when moving to new structure for supporting iam accounts
412
- await this . config_fs . get_account_by_name ( config_file_name ) ;
441
+ switch ( type ) {
442
+ case TYPES . BUCKET : {
443
+ config_data = await this . config_fs . get_bucket_by_name ( config_file_name ) ;
444
+ break ;
445
+ }
446
+ case TYPES . ACCOUNT : {
447
+ // TODO - should be changed to id when moving to new structure for supporting iam accounts
448
+ config_data = await this . config_fs . get_account_by_name ( config_file_name ) ;
449
+ break ;
450
+ }
451
+ case TYPES . CONNECTION : {
452
+ config_data = await this . config_fs . get_connection_by_name ( config_file_name ) ;
453
+ break ;
454
+ }
455
+ default : //shouldn't happen, for js-lint
456
+ }
413
457
} catch ( err ) {
414
458
let err_code ;
415
- const config_file_path = type === TYPES . BUCKET ?
416
- this . config_fs . get_bucket_path_by_name ( config_file_name ) :
417
- // TODO - should be changed to id when moving to new structure for supporting iam accounts
418
- this . config_fs . get_account_path_by_name ( config_file_name ) ;
459
+ let config_file_path ;
460
+ switch ( type ) {
461
+ case TYPES . BUCKET : {
462
+ config_file_path = await this . config_fs . get_bucket_path_by_name ( config_file_name ) ;
463
+ break ;
464
+ }
465
+ case TYPES . ACCOUNT : {
466
+ // TODO - should be changed to id when moving to new structure for supporting iam accounts
467
+ config_file_path = await this . config_fs . get_account_path_by_name ( config_file_name ) ;
468
+ break ;
469
+ }
470
+ case TYPES . CONNECTION : {
471
+ config_file_path = await this . config_fs . get_connection_path_by_name ( config_file_name ) ;
472
+ break ;
473
+ }
474
+ default : //shouldn't happen, for js-lint
475
+ }
419
476
420
477
if ( err . code === 'ENOENT' ) {
421
478
dbg . log1 ( `Error: Config file path should be a valid path` , config_file_path , err ) ;
@@ -536,9 +593,10 @@ async function get_health_status(argv, config_fs) {
536
593
const deployment_type = argv . deployment_type || 'nc' ;
537
594
const all_account_details = get_boolean_or_string_value ( argv . all_account_details ) ;
538
595
const all_bucket_details = get_boolean_or_string_value ( argv . all_bucket_details ) ;
596
+ const all_connection_details = get_boolean_or_string_value ( argv . all_connection_details ) ;
539
597
540
598
if ( deployment_type === 'nc' ) {
541
- const health = new NSFSHealth ( { https_port, all_account_details, all_bucket_details, config_fs } ) ;
599
+ const health = new NSFSHealth ( { https_port, all_account_details, all_bucket_details, all_connection_details , config_fs } ) ;
542
600
const health_status = await health . nc_nsfs_health ( ) ;
543
601
write_stdout_response ( ManageCLIResponse . HealthStatus , health_status ) ;
544
602
} else {
0 commit comments