Skip to content

Commit 9517357

Browse files
committed
NC | Lifecycle | Small configuration adjustments/ fixes
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com> (cherry picked from commit 955f07e)
1 parent a7f4ae7 commit 9517357

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,20 +1001,21 @@ config.NC_DISABLE_SCHEMA_CHECK = false;
10011001
////////// NC LIFECYLE //////////
10021002

10031003
config.NC_LIFECYCLE_LOGS_DIR = '/var/log/noobaa/lifecycle';
1004-
config.NC_LIFECYCLE_TIMEOUT_MS = 6 * 60 * 60 * 1000;
1004+
config.NC_LIFECYCLE_CONFIG_DIR_NAME = 'lifecycle';
1005+
config.NC_LIFECYCLE_TIMEOUT_MS = 8 * 60 * 60 * 1000;
10051006

10061007
// NC_LIFECYCLE_RUN_TIME must be of the format hh:mm which specifies
10071008
// when NooBaa should allow running nc lifecycle process
10081009
// NOTE: This will also be in the same timezone as specified in
10091010
// NC_LIFECYCLE_TZ
1010-
config.NC_LIFECYCLE_RUN_TIME = '01:00';
1011+
config.NC_LIFECYCLE_RUN_TIME = '00:00';
10111012

10121013
// NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS configures the delay
10131014
// tolerance in minutes.
10141015
//
1015-
// eg. If the expiry run time is set to 01:00 and the tolerance is
1016-
// set to be 2 mins then the expiry can trigger till 01:02 (unless
1017-
// already triggered between 01:00 - 01:02
1016+
// eg. If the expiry run time is set to 00:00 and the tolerance is
1017+
// set to be 2 mins then the expiry can trigger till 00:02 (unless
1018+
// already triggered between 00:00 - 00:02
10181019
config.NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS = 2;
10191020

10201021
/** @type {'UTC' | 'LOCAL'} */

src/cmd/manage_nsfs.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,19 @@ async function connection_management(action, user_input) {
805805
async function lifecycle_management(args) {
806806
const disable_service_validation = get_boolean_or_string_value(args.disable_service_validation);
807807
const disable_runtime_validation = get_boolean_or_string_value(args.disable_runtime_validation);
808-
const short = get_boolean_or_string_value(args.short);
809-
await noobaa_cli_lifecycle.run_lifecycle_under_lock(config_fs, { disable_service_validation, disable_runtime_validation, short });
808+
const short_status = get_boolean_or_string_value(args.short_status);
809+
try {
810+
const options = { disable_service_validation, disable_runtime_validation, short_status };
811+
const { should_run, lifecycle_run_status } = await noobaa_cli_lifecycle.run_lifecycle_under_lock(config_fs, options);
812+
if (should_run) {
813+
write_stdout_response(ManageCLIResponse.LifecycleSuccessful, lifecycle_run_status);
814+
} else {
815+
write_stdout_response(ManageCLIResponse.LifecycleWorkerNotRunning);
816+
}
817+
} catch (err) {
818+
dbg.error('manage_nsfs.lifecycle_management: Error while running run_lifecycle_under_lock', config_fs.config_json_path, err);
819+
throw_cli_error(err);
820+
}
810821
}
811822

812823
exports.main = main;

src/manage_nsfs/manage_nsfs_constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const VALID_OPTIONS_CONNECTION = {
9696
'status': new Set(['name', 'decrypt', ...CLI_MUTUAL_OPTIONS]),
9797
};
9898

99-
const VALID_OPTIONS_LIFECYCLE = new Set(['disable_service_validation', 'disable_runtime_validation', 'short', ...CLI_MUTUAL_OPTIONS]);
99+
const VALID_OPTIONS_LIFECYCLE = new Set(['disable_service_validation', 'disable_runtime_validation', 'short_status', ...CLI_MUTUAL_OPTIONS]);
100100

101101
const VALID_OPTIONS_WHITELIST = new Set(['ips', ...CLI_MUTUAL_OPTIONS]);
102102

@@ -169,7 +169,7 @@ const OPTION_TYPE = {
169169

170170
const BOOLEAN_STRING_VALUES = ['true', 'false'];
171171
const BOOLEAN_STRING_OPTIONS = new Set(['allow_bucket_creation', 'regenerate', 'wide', 'show_secrets', 'force',
172-
'force_md5_etag', 'iam_operate_on_root_account', 'all_account_details', 'all_bucket_details', 'anonymous', 'disable_service_validation', 'disable_runtime_validation', 'short']);
172+
'force_md5_etag', 'iam_operate_on_root_account', 'all_account_details', 'all_bucket_details', 'anonymous', 'disable_service_validation', 'disable_runtime_validation', 'short_status']);
173173

174174
//options that can be unset using ''
175175
const LIST_UNSETABLE_OPTIONS = ['fs_backend', 's3_policy', 'force_md5_etag'];

src/manage_nsfs/nc_lifecycle.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const NsfsObjectSDK = require('../sdk/nsfs_object_sdk');
1313
const native_fs_utils = require('../util/native_fs_utils');
1414
const { NoobaaEvent } = require('./manage_nsfs_events_utils');
1515
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,
1817
is_desired_time, record_current_time } = require('./manage_nsfs_cli_utils');
1918

2019
// TODO:
@@ -24,7 +23,7 @@ const { write_stdout_response, throw_cli_error, get_service_status, NOOBAA_SERVI
2423
// 3. GPFS ILM policy and apply for scanning and filtering optimization
2524
// TODO - we will filter during the scan except for get_candidates_by_expiration_rule on GPFS that does the filter on the file system
2625

27-
const CLUSTER_LOCK = 'cluster.lock';
26+
const LIFECYCLE_CLUSTER_LOCK = 'lifecycle_cluster.lock';
2827
const LIFECYLE_TIMESTAMP_FILE = 'lifecycle.timestamp';
2928
const config_fs_options = { silent_if_missing: true };
3029

@@ -33,7 +32,7 @@ const lifecycle_run_status = {
3332
total_stats: _get_default_stats(), buckets_statuses: {}
3433
};
3534

36-
let short_status = false;
35+
let return_short_status = false;
3736

3837
const TIMED_OPS = Object.freeze({
3938
RUN_LIFECYLE: 'run_lifecycle',
@@ -50,36 +49,40 @@ const TIMED_OPS = Object.freeze({
5049
* run_lifecycle_under_lock runs the lifecycle workflow under a file system lock
5150
* lifecycle workflow is being locked to prevent multiple instances from running the lifecycle workflow
5251
* @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}>}
5454
*/
5555
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;
5858
const fs_context = config_fs.fs_context;
5959
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);
6263
await config_fs.create_dir_if_missing(lifecyle_logs_dir_path);
64+
await config_fs.create_dir_if_missing(lifecycle_config_dir_path);
6365

66+
let should_run = true;
6467
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;
6871

6972
try {
7073
dbg.log0('run_lifecycle_under_lock acquired lock - start lifecycle');
7174
new NoobaaEvent(NoobaaEvent.LIFECYCLE_STARTED).create_event();
7275
await run_lifecycle_or_timeout(config_fs, disable_service_validation);
73-
write_stdout_response(ManageCLIResponse.LifecycleSuccessful, lifecycle_run_status);
7476
} catch (err) {
7577
dbg.error('run_lifecycle_under_lock failed with error', err, err.code, err.message);
76-
throw_cli_error(err);
78+
throw err;
7779
} finally {
7880
await record_current_time(fs_context, lifecycle_timestamp_file_path);
7981
await write_lifecycle_log_file(config_fs.fs_context, lifecyle_logs_dir_path);
8082
dbg.log0('run_lifecycle_under_lock done lifecycle - released lock');
8183
}
8284
});
85+
return { should_run, lifecycle_run_status };
8386
}
8487

8588
/**
@@ -627,7 +630,7 @@ async function _call_op_and_update_status({ bucket_name = undefined, rule_id = u
627630
let error;
628631
let reply;
629632
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 } });
631634
reply = await op_func();
632635
return reply;
633636
} catch (e) {
@@ -636,7 +639,7 @@ async function _call_op_and_update_status({ bucket_name = undefined, rule_id = u
636639
} finally {
637640
end_time = Date.now();
638641
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 };
640643
update_status({ ...update_options, op_times, reply, error });
641644
}
642645
}

src/test/unit_tests/jest_tests/test_nc_lifecycle_cli.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('noobaa cli - lifecycle - lock check', () => {
4747
config.NC_LIFECYCLE_RUN_TIME = original_lifecycle_run_time;
4848
config.NC_LIFECYCLE_RUN_DELAY_LIMIT_MINS = original_lifecycle_run_delay;
4949
await fs_utils.folder_delete(config.NC_LIFECYCLE_LOGS_DIR);
50+
await fs_utils.folder_delete(config_root);
5051
});
5152

5253
afterAll(async () => {
@@ -104,7 +105,7 @@ describe('noobaa cli - lifecycle - lock check', () => {
104105
expect(parsed_res.message).toBe(ManageCLIResponse.LifecycleSuccessful.message);
105106
});
106107

107-
it('lifecycle_cli - change run time to 1 minutes ago - should fail ', async () => {
108+
it('lifecycle_cli - change run time to 1 minute in the future - should fail ', async () => {
108109
const lifecyle_run_date = new Date();
109110
lifecyle_run_date.setMinutes(lifecyle_run_date.getMinutes() + 1);
110111
await config_fs.create_config_json_file(JSON.stringify({

0 commit comments

Comments
 (0)