@@ -13,8 +13,7 @@ const NsfsObjectSDK = require('../sdk/nsfs_object_sdk');
13
13
const native_fs_utils = require ( '../util/native_fs_utils' ) ;
14
14
const { NoobaaEvent } = require ( './manage_nsfs_events_utils' ) ;
15
15
const ManageCLIError = require ( './manage_nsfs_cli_errors' ) . ManageCLIError ;
16
- const ManageCLIResponse = require ( '../manage_nsfs/manage_nsfs_cli_responses' ) . ManageCLIResponse ;
17
- const { write_stdout_response, throw_cli_error, get_service_status, NOOBAA_SERVICE_NAME ,
16
+ const { throw_cli_error, get_service_status, NOOBAA_SERVICE_NAME ,
18
17
is_desired_time, record_current_time } = require ( './manage_nsfs_cli_utils' ) ;
19
18
20
19
// TODO:
@@ -24,7 +23,7 @@ const { write_stdout_response, throw_cli_error, get_service_status, NOOBAA_SERVI
24
23
// 3. GPFS ILM policy and apply for scanning and filtering optimization
25
24
// TODO - we will filter during the scan except for get_candidates_by_expiration_rule on GPFS that does the filter on the file system
26
25
27
- const CLUSTER_LOCK = 'cluster .lock' ;
26
+ const LIFECYCLE_CLUSTER_LOCK = 'lifecycle_cluster .lock' ;
28
27
const LIFECYLE_TIMESTAMP_FILE = 'lifecycle.timestamp' ;
29
28
const config_fs_options = { silent_if_missing : true } ;
30
29
@@ -33,7 +32,7 @@ const lifecycle_run_status = {
33
32
total_stats : _get_default_stats ( ) , buckets_statuses : { }
34
33
} ;
35
34
36
- let short_status = false ;
35
+ let return_short_status = false ;
37
36
38
37
const TIMED_OPS = Object . freeze ( {
39
38
RUN_LIFECYLE : 'run_lifecycle' ,
@@ -50,36 +49,40 @@ const TIMED_OPS = Object.freeze({
50
49
* run_lifecycle_under_lock runs the lifecycle workflow under a file system lock
51
50
* lifecycle workflow is being locked to prevent multiple instances from running the lifecycle workflow
52
51
* @param {import('../sdk/config_fs').ConfigFS } config_fs
53
- * @param {{disable_service_validation?: boolean, disable_runtime_validation?: boolean, short?: boolean} } flags
52
+ * @param {{disable_service_validation?: boolean, disable_runtime_validation?: boolean, short_status?: boolean} } flags
53
+ * @returns {Promise<{should_run: Boolean, lifecycle_run_status: Object}> }
54
54
*/
55
55
async function run_lifecycle_under_lock ( config_fs , flags ) {
56
- const { disable_service_validation = false , disable_runtime_validation = false , short = false } = flags ;
57
- short_status = short ;
56
+ const { disable_service_validation = false , disable_runtime_validation = false , short_status = false } = flags ;
57
+ return_short_status = short_status ;
58
58
const fs_context = config_fs . fs_context ;
59
59
const lifecyle_logs_dir_path = config . NC_LIFECYCLE_LOGS_DIR ;
60
- const lock_path = path . join ( lifecyle_logs_dir_path , CLUSTER_LOCK ) ;
61
- const lifecycle_timestamp_file_path = path . join ( lifecyle_logs_dir_path , LIFECYLE_TIMESTAMP_FILE ) ;
60
+ const lifecycle_config_dir_path = path . join ( config_fs . config_root , config . NC_LIFECYCLE_CONFIG_DIR_NAME ) ;
61
+ const lock_path = path . join ( lifecycle_config_dir_path , LIFECYCLE_CLUSTER_LOCK ) ;
62
+ const lifecycle_timestamp_file_path = path . join ( lifecycle_config_dir_path , LIFECYLE_TIMESTAMP_FILE ) ;
62
63
await config_fs . create_dir_if_missing ( lifecyle_logs_dir_path ) ;
64
+ await config_fs . create_dir_if_missing ( lifecycle_config_dir_path ) ;
63
65
66
+ let should_run = true ;
64
67
await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
65
- dbg . log0 ( 'run_lifecycle_under_lock acquired lock - start lifecycle ' ) ;
66
- const should_run = await _should_lifecycle_run ( fs_context , lifecycle_timestamp_file_path , disable_runtime_validation ) ;
67
- if ( ! should_run ) write_stdout_response ( ManageCLIResponse . LifecycleWorkerNotRunning ) ;
68
+ dbg . log0 ( 'run_lifecycle_under_lock acquired lock - verifying ' ) ;
69
+ should_run = await _should_lifecycle_run ( fs_context , lifecycle_timestamp_file_path , disable_runtime_validation ) ;
70
+ if ( ! should_run ) return ;
68
71
69
72
try {
70
73
dbg . log0 ( 'run_lifecycle_under_lock acquired lock - start lifecycle' ) ;
71
74
new NoobaaEvent ( NoobaaEvent . LIFECYCLE_STARTED ) . create_event ( ) ;
72
75
await run_lifecycle_or_timeout ( config_fs , disable_service_validation ) ;
73
- write_stdout_response ( ManageCLIResponse . LifecycleSuccessful , lifecycle_run_status ) ;
74
76
} catch ( err ) {
75
77
dbg . error ( 'run_lifecycle_under_lock failed with error' , err , err . code , err . message ) ;
76
- throw_cli_error ( err ) ;
78
+ throw err ;
77
79
} finally {
78
80
await record_current_time ( fs_context , lifecycle_timestamp_file_path ) ;
79
81
await write_lifecycle_log_file ( config_fs . fs_context , lifecyle_logs_dir_path ) ;
80
82
dbg . log0 ( 'run_lifecycle_under_lock done lifecycle - released lock' ) ;
81
83
}
82
84
} ) ;
85
+ return { should_run, lifecycle_run_status } ;
83
86
}
84
87
85
88
/**
@@ -627,7 +630,7 @@ async function _call_op_and_update_status({ bucket_name = undefined, rule_id = u
627
630
let error ;
628
631
let reply ;
629
632
try {
630
- if ( ! short_status ) update_status ( { ...update_options , op_times : { start_time } } ) ;
633
+ if ( ! return_short_status ) update_status ( { ...update_options , op_times : { start_time } } ) ;
631
634
reply = await op_func ( ) ;
632
635
return reply ;
633
636
} catch ( e ) {
@@ -636,7 +639,7 @@ async function _call_op_and_update_status({ bucket_name = undefined, rule_id = u
636
639
} finally {
637
640
end_time = Date . now ( ) ;
638
641
took_ms = end_time - start_time ;
639
- const op_times = short_status ? { took_ms } : { end_time, took_ms } ;
642
+ const op_times = return_short_status ? { took_ms } : { end_time, took_ms } ;
640
643
update_status ( { ...update_options , op_times, reply, error } ) ;
641
644
}
642
645
}
0 commit comments