@@ -15,6 +15,7 @@ const { TYPES } = require('./manage_nsfs_constants');
15
15
const { get_boolean_or_string_value, throw_cli_error, write_stdout_response, get_bucket_owner_account_by_id } = require ( './manage_nsfs_cli_utils' ) ;
16
16
const { ManageCLIResponse } = require ( './manage_nsfs_cli_responses' ) ;
17
17
const ManageCLIError = require ( './manage_nsfs_cli_errors' ) . ManageCLIError ;
18
+ const notifications_util = require ( '../util/notifications_util' ) ;
18
19
19
20
20
21
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 ,
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
@@ -333,6 +339,17 @@ class NSFSHealth {
333
339
} ;
334
340
}
335
341
342
+ async validate_config_dir_exists ( path , type ) {
343
+ const config_root_type_exists = await this . config_fs . validate_config_dir_exists ( path ) ;
344
+ if ( ! config_root_type_exists ) {
345
+ dbg . log1 ( `Config directory type - ${ type } is missing, ${ path } ` ) ;
346
+ return {
347
+ invalid_storages : [ ] ,
348
+ valid_storages : [ ]
349
+ } ;
350
+ }
351
+ }
352
+
336
353
async get_bucket_status ( ) {
337
354
const bucket_details = await this . get_storage_status ( TYPES . BUCKET , this . all_bucket_details ) ;
338
355
return bucket_details ;
@@ -343,34 +360,38 @@ class NSFSHealth {
343
360
return account_details ;
344
361
}
345
362
363
+ async get_connection_status ( ) {
364
+ const connection_details = await this . get_storage_status ( TYPES . CONNECTION , this . all_connection_details ) ;
365
+ //if there were in failed test notifications, mark error as temp
366
+ if ( connection_details . invalid_storages && connection_details . invalid_storages . length > 0 ) {
367
+ connection_details . error_type = health_errors_tyes . TEMPORARY ;
368
+ }
369
+ return connection_details ;
370
+ }
371
+
346
372
async get_storage_status ( type , all_details ) {
347
373
const invalid_storages = [ ] ;
348
374
const valid_storages = [ ] ;
349
375
//check for account and buckets dir paths
350
- let config_root_type_exists ;
351
376
let config_dir_path ;
352
377
if ( type === TYPES . BUCKET ) {
353
378
config_dir_path = this . config_fs . buckets_dir_path ;
354
- config_root_type_exists = await this . config_fs . validate_config_dir_exists ( config_dir_path ) ;
355
379
} else if ( type === TYPES . ACCOUNT ) {
356
380
// TODO - handle iam accounts when directory structure changes - read_account_by_id
357
381
config_dir_path = this . config_fs . accounts_by_name_dir_path ;
358
- config_root_type_exists = await this . config_fs . validate_config_dir_exists ( config_dir_path ) ;
359
- }
360
- // TODO - this is not a good handling for that - we need to take it to an upper level
361
- if ( ! config_root_type_exists ) {
362
- dbg . log1 ( `Config directory type - ${ type } is missing, ${ config_dir_path } ` ) ;
363
- return {
364
- invalid_storages : invalid_storages ,
365
- valid_storages : valid_storages
366
- } ;
382
+ } else {
383
+ config_dir_path = this . config_fs . connections_dir_path ;
367
384
}
385
+ const missing = await this . validate_config_dir_exists ( config_dir_path , type ) ;
386
+ if ( missing ) return missing ;
368
387
369
388
let config_files_names ;
370
389
if ( type === TYPES . BUCKET ) {
371
390
config_files_names = await this . config_fs . list_buckets ( ) ;
372
- } else {
391
+ } else if ( type === TYPES . ACCOUNT ) {
373
392
config_files_names = await this . config_fs . list_accounts ( ) ;
393
+ } else {
394
+ config_files_names = await this . config_fs . list_connections ( ) ;
374
395
}
375
396
for ( const config_file_name of config_files_names ) {
376
397
// config_file get data or push error
@@ -386,13 +407,24 @@ class NSFSHealth {
386
407
let res ;
387
408
const storage_path = type === TYPES . BUCKET ?
388
409
config_data . path :
389
- config_data . nsfs_account_config . new_buckets_path ;
410
+ config_data . nsfs_account_config ? .new_buckets_path ;
390
411
391
412
if ( type === TYPES . ACCOUNT ) {
392
413
const config_file_path = this . config_fs . get_account_path_by_name ( config_file_name ) ;
393
414
res = await is_new_buckets_path_valid ( config_file_path , config_data , storage_path ) ;
394
415
} else if ( type === TYPES . BUCKET ) {
395
416
res = await is_bucket_storage_and_owner_exists ( this . config_fs , config_data , storage_path ) ;
417
+ } else {
418
+ const connection_file_path = this . config_fs . get_connection_path_by_name ( config_file_name ) ;
419
+ const test_notif_err = await notifications_util . test_notifications ( [ {
420
+ name : config_data . name ,
421
+ topic : [ this . config_fs . json ( config_file_name ) ]
422
+ } ] , this . config_fs . config_root ) ;
423
+ if ( test_notif_err ) {
424
+ res = get_invalid_object ( config_data . name , connection_file_path , undefined , test_notif_err . code ) ;
425
+ } else {
426
+ res = get_valid_object ( config_data . name , connection_file_path , undefined ) ;
427
+ }
396
428
}
397
429
if ( all_details && res . valid_storage ) {
398
430
valid_storages . push ( res . valid_storage ) ;
@@ -416,16 +448,41 @@ class NSFSHealth {
416
448
let config_data ;
417
449
let err_obj ;
418
450
try {
419
- config_data = type === TYPES . BUCKET ?
420
- await this . config_fs . get_bucket_by_name ( config_file_name ) :
421
- // TODO - should be changed to id when moving to new structure for supporting iam accounts
422
- await this . config_fs . get_account_by_name ( config_file_name ) ;
451
+ switch ( type ) {
452
+ case TYPES . BUCKET : {
453
+ config_data = await this . config_fs . get_bucket_by_name ( config_file_name ) ;
454
+ break ;
455
+ }
456
+ case TYPES . ACCOUNT : {
457
+ // TODO - should be changed to id when moving to new structure for supporting iam accounts
458
+ config_data = await this . config_fs . get_account_by_name ( config_file_name ) ;
459
+ break ;
460
+ }
461
+ case TYPES . CONNECTION : {
462
+ config_data = await this . config_fs . get_connection_by_name ( config_file_name ) ;
463
+ break ;
464
+ }
465
+ default : //shouldn't happen, for js-lint
466
+ }
423
467
} catch ( err ) {
424
468
let err_code ;
425
- const config_file_path = type === TYPES . BUCKET ?
426
- this . config_fs . get_bucket_path_by_name ( config_file_name ) :
427
- // TODO - should be changed to id when moving to new structure for supporting iam accounts
428
- this . config_fs . get_account_path_by_name ( config_file_name ) ;
469
+ let config_file_path ;
470
+ switch ( type ) {
471
+ case TYPES . BUCKET : {
472
+ config_file_path = await this . config_fs . get_bucket_path_by_name ( config_file_name ) ;
473
+ break ;
474
+ }
475
+ case TYPES . ACCOUNT : {
476
+ // TODO - should be changed to id when moving to new structure for supporting iam accounts
477
+ config_file_path = await this . config_fs . get_account_path_by_name ( config_file_name ) ;
478
+ break ;
479
+ }
480
+ case TYPES . CONNECTION : {
481
+ config_file_path = await this . config_fs . get_connection_path_by_name ( config_file_name ) ;
482
+ break ;
483
+ }
484
+ default : //shouldn't happen, for js-lint
485
+ }
429
486
430
487
if ( err . code === 'ENOENT' ) {
431
488
dbg . log1 ( `Error: Config file path should be a valid path` , config_file_path , err ) ;
@@ -546,9 +603,10 @@ async function get_health_status(argv, config_fs) {
546
603
const deployment_type = argv . deployment_type || 'nc' ;
547
604
const all_account_details = get_boolean_or_string_value ( argv . all_account_details ) ;
548
605
const all_bucket_details = get_boolean_or_string_value ( argv . all_bucket_details ) ;
606
+ const all_connection_details = get_boolean_or_string_value ( argv . all_connection_details ) ;
549
607
550
608
if ( deployment_type === 'nc' ) {
551
- const health = new NSFSHealth ( { https_port, all_account_details, all_bucket_details, config_fs } ) ;
609
+ const health = new NSFSHealth ( { https_port, all_account_details, all_bucket_details, all_connection_details , config_fs } ) ;
552
610
const health_status = await health . nc_nsfs_health ( ) ;
553
611
write_stdout_response ( ManageCLIResponse . HealthStatus , health_status ) ;
554
612
} else {
0 commit comments