Skip to content

Commit dbe6dab

Browse files
authored
Merge pull request #8308 from romayalon/romy-online-upgrade-cli
NC | Online Upgrade CLI
2 parents 0d9d1f7 + 5bbc82c commit dbe6dab

File tree

10 files changed

+337
-15
lines changed

10 files changed

+337
-15
lines changed

src/cmd/manage_nsfs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const ManageCLIResponse = require('../manage_nsfs/manage_nsfs_cli_responses').Ma
1818
const manage_nsfs_glacier = require('../manage_nsfs/manage_nsfs_glacier');
1919
const manage_nsfs_logging = require('../manage_nsfs/manage_nsfs_logging');
2020
const noobaa_cli_diagnose = require('../manage_nsfs/diagnose');
21+
const noobaa_cli_upgrade = require('../manage_nsfs/upgrade');
2122
const { print_usage } = require('../manage_nsfs/manage_nsfs_help_utils');
2223
const { TYPES, ACTIONS, LIST_ACCOUNT_FILTERS, LIST_BUCKET_FILTERS, GLACIER_ACTIONS } = require('../manage_nsfs/manage_nsfs_constants');
2324
const { throw_cli_error, get_bucket_owner_account, write_stdout_response, get_boolean_or_string_value, has_access_keys, set_debug_level,
@@ -65,6 +66,8 @@ async function main(argv = minimist(process.argv.slice(2))) {
6566
await logging_management();
6667
} else if (type === TYPES.DIAGNOSE) {
6768
await noobaa_cli_diagnose.manage_diagnose_operations(action, user_input, config_fs);
69+
} else if (type === TYPES.UPGRADE) {
70+
await noobaa_cli_upgrade.manage_upgrade_operations(action, config_fs);
6871
} else {
6972
throw_cli_error(ManageCLIError.InvalidType);
7073
}

src/manage_nsfs/manage_nsfs_cli_errors.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ManageCLIError.InvalidArgumentType = Object.freeze({
8989

9090
ManageCLIError.InvalidType = Object.freeze({
9191
code: 'InvalidType',
92-
message: 'Invalid type, available types are account, bucket, logging or whitelist',
92+
message: 'Invalid type, available types are account, bucket, logging, whitelist or upgrade',
9393
http_code: 400,
9494
});
9595

@@ -445,6 +445,40 @@ ManageCLIError.BucketNotEmpty = Object.freeze({
445445
http_code: 400,
446446
});
447447

448+
449+
///////////////////////////////
450+
// UPGRADE ERRORS //
451+
///////////////////////////////
452+
453+
ManageCLIError.InvalidUpgradeAction = Object.freeze({
454+
code: 'InvalidUpgradeAction',
455+
message: 'Invalid Upgrade action',
456+
http_code: 400,
457+
});
458+
459+
ManageCLIError.UpgradeFailed = Object.freeze({
460+
code: 'UpgradeFailed',
461+
message: 'Upgrade request failed',
462+
http_code: 500,
463+
});
464+
465+
ManageCLIError.UpgradeStatusFailed = Object.freeze({
466+
code: 'UpgradeStatusFailed',
467+
message: 'Upgrade status request failed',
468+
http_code: 500,
469+
});
470+
471+
ManageCLIError.UpgradeHistoryFailed = Object.freeze({
472+
code: 'UpgradeHistoryFailed',
473+
message: 'Upgrade history request failed',
474+
http_code: 500,
475+
});
476+
477+
///////////////////////////////
478+
// ERRORS MAPPING //
479+
///////////////////////////////
480+
481+
448482
ManageCLIError.FS_ERRORS_TO_MANAGE = Object.freeze({
449483
EACCES: ManageCLIError.AccessDenied,
450484
EPERM: ManageCLIError.AccessDenied,

src/manage_nsfs/manage_nsfs_cli_responses.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,37 @@ ManageCLIResponse.BucketList = Object.freeze({
117117
});
118118

119119
///////////////////////////////
120-
// LOGGING RESPONSES ///
120+
// LOGGING RESPONSES //
121121
///////////////////////////////
122+
122123
ManageCLIResponse.LoggingExported = Object.freeze({
123124
code: 'LoggingExported',
124125
status: {}
125126
});
126127

128+
///////////////////////////////
129+
// UPGRADE RESPONSES //
130+
///////////////////////////////
131+
132+
ManageCLIResponse.UpgradeSuccessful = Object.freeze({
133+
code: 'UpgradeSuccessful',
134+
status: {}
135+
});
136+
137+
ManageCLIResponse.UpgradeStatus = Object.freeze({
138+
code: 'UpgradeStatus',
139+
status: {}
140+
});
141+
142+
ManageCLIResponse.UpgradeHistory = Object.freeze({
143+
code: 'UpgradeHistory',
144+
status: {}
145+
});
146+
147+
///////////////////////////////
148+
// RESPONSES-EVENT MAPPING //
149+
///////////////////////////////
150+
127151
const NSFS_CLI_SUCCESS_EVENT_MAP = {
128152
AccountCreated: NoobaaEvent.ACCOUNT_CREATED,
129153
AccountDeleted: NoobaaEvent.ACCOUNT_DELETED,

src/manage_nsfs/manage_nsfs_constants.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
11
/* Copyright (C) 2024 NooBaa */
22
'use strict';
33

4-
const TYPES = {
4+
const TYPES = Object.freeze({
55
ACCOUNT: 'account',
66
BUCKET: 'bucket',
77
IP_WHITELIST: 'whitelist',
88
GLACIER: 'glacier',
99
LOGGING: 'logging',
10-
DIAGNOSE: 'diagnose'
11-
};
10+
DIAGNOSE: 'diagnose',
11+
UPGRADE: 'upgrade'
12+
});
1213

13-
const ACTIONS = {
14+
const ACTIONS = Object.freeze({
1415
ADD: 'add',
1516
UPDATE: 'update',
1617
DELETE: 'delete',
1718
LIST: 'list',
1819
STATUS: 'status'
19-
};
20+
});
2021

21-
const GLACIER_ACTIONS = {
22+
const GLACIER_ACTIONS = Object.freeze({
2223
MIGRATE: 'migrate',
2324
RESTORE: 'restore',
2425
EXPIRY: 'expiry',
25-
};
26+
});
2627

27-
const DIAGNOSE_ACTIONS = {
28+
const DIAGNOSE_ACTIONS = Object.freeze({
2829
HEALTH: 'health',
2930
GATHER_LOGS: 'gather-logs',
3031
METRICS: 'metrics'
31-
};
32+
});
3233

34+
const UPGRADE_ACTIONS = Object.freeze({
35+
START: 'start',
36+
STATUS: 'status',
37+
HISTORY: 'history'
38+
});
3339

3440
const CONFIG_ROOT_FLAG = 'config_root';
3541
const CLI_MUTUAL_OPTIONS = new Set([CONFIG_ROOT_FLAG, 'config_root_backend', 'debug']);
@@ -134,6 +140,7 @@ exports.TYPES = TYPES;
134140
exports.ACTIONS = ACTIONS;
135141
exports.GLACIER_ACTIONS = GLACIER_ACTIONS;
136142
exports.DIAGNOSE_ACTIONS = DIAGNOSE_ACTIONS;
143+
exports.UPGRADE_ACTIONS = UPGRADE_ACTIONS;
137144
exports.VALID_OPTIONS = VALID_OPTIONS;
138145
exports.OPTION_TYPE = OPTION_TYPE;
139146
exports.FROM_FILE = FROM_FILE;

src/manage_nsfs/manage_nsfs_help_utils.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright (C) 2024 NooBaa */
22
'use strict';
33

4-
const { TYPES, ACTIONS, GLACIER_ACTIONS, DIAGNOSE_ACTIONS } = require('./manage_nsfs_constants');
4+
const { TYPES, ACTIONS, GLACIER_ACTIONS, DIAGNOSE_ACTIONS, UPGRADE_ACTIONS } = require('./manage_nsfs_constants');
55

66
const HELP = `
77
Help:
@@ -281,6 +281,43 @@ Usage:
281281
282282
`;
283283

284+
285+
const UPGRADE_OPTIONS = `
286+
Usage:
287+
288+
noobaa-cli upgrade <action> [flags]
289+
290+
List of actions supported:
291+
292+
start
293+
status
294+
history
295+
296+
`;
297+
298+
const UPGRADE_START_OPTIONS = `
299+
'upgrade start' is a noobaa-cli command that will start config directory upgrade run.
300+
Run 'upgrade start' after upgrading NooBaa RPMs on all the cluster nodes, after starting an upgrade of the config directory,
301+
S3 I/O, S3 Buckets getters and NooBaa CLI Account/Buckets/Whitelist getters operations will still be working
302+
But updates of the config directory will be blocked during the upgrade of the config directory.
303+
'upgrade start' should be executed on one node, the config directory changes will be available for all the nodes of the cluster.
304+
`;
305+
306+
const UPGRADE_STATUS_OPTIONS = `
307+
'upgrade status' is a noobaa-cli command that will return the status of an ongoing upgrade run,
308+
the available status information is upgrade start timestmp, from_version, to_version, config_dir_from_version,
309+
config_dir_to_version, running_host etc.
310+
311+
`;
312+
313+
const UPGRADE_HISTORY_OPTIONS = `
314+
'upgrade history' is a noobaa-cli command that will return the history of past upgrades,
315+
the available history information is an array of upgrade information - upgrade start timestmp, from_version, to_version, config_dir_from_version,
316+
config_dir_to_version, running_host etc.
317+
318+
`;
319+
320+
284321
/**
285322
* print_usage would print the help according to the arguments that were passed
286323
* @param {string} type
@@ -306,6 +343,9 @@ function print_usage(type, action) {
306343
case TYPES.DIAGNOSE:
307344
print_help_diagnose(action);
308345
break;
346+
case TYPES.UPGRADE:
347+
print_help_upgrade(action);
348+
break;
309349
default:
310350
process.stdout.write(HELP + '\n');
311351
process.stdout.write(USAGE.trimStart() + '\n');
@@ -368,6 +408,9 @@ function print_help_bucket(action) {
368408
process.exit(0);
369409
}
370410

411+
/**
412+
* @param {string} action
413+
*/
371414
function print_help_glacier(action) {
372415
switch (action) {
373416
case GLACIER_ACTIONS.MIGRATE:
@@ -384,6 +427,9 @@ function print_help_glacier(action) {
384427
}
385428
}
386429

430+
/**
431+
* @param {string} action
432+
*/
387433
function print_help_diagnose(action) {
388434
switch (action) {
389435
case DIAGNOSE_ACTIONS.HEALTH:
@@ -400,5 +446,25 @@ function print_help_diagnose(action) {
400446
}
401447
}
402448

449+
/**
450+
* @param {string} action
451+
*/
452+
function print_help_upgrade(action) {
453+
switch (action) {
454+
case UPGRADE_ACTIONS.START:
455+
process.stdout.write(UPGRADE_START_OPTIONS.trimStart());
456+
break;
457+
case UPGRADE_ACTIONS.STATUS:
458+
process.stdout.write(UPGRADE_STATUS_OPTIONS.trimStart());
459+
break;
460+
case UPGRADE_ACTIONS.HISTORY:
461+
process.stdout.write(UPGRADE_HISTORY_OPTIONS.trimStart());
462+
break;
463+
default:
464+
process.stdout.write(UPGRADE_OPTIONS.trimStart());
465+
}
466+
}
467+
468+
403469
// EXPORTS
404470
exports.print_usage = print_usage;

src/manage_nsfs/manage_nsfs_validations.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const bucket_policy_utils = require('../endpoint/s3/s3_bucket_policy_utils');
1212
const { throw_cli_error, get_bucket_owner_account, get_options_from_file, get_boolean_or_string_value,
1313
check_root_account_owns_user, is_name_update, is_access_key_update } = require('../manage_nsfs/manage_nsfs_cli_utils');
1414
const { TYPES, ACTIONS, VALID_OPTIONS, OPTION_TYPE, FROM_FILE, BOOLEAN_STRING_VALUES, BOOLEAN_STRING_OPTIONS,
15-
GLACIER_ACTIONS, LIST_UNSETABLE_OPTIONS, ANONYMOUS, DIAGNOSE_ACTIONS } = require('../manage_nsfs/manage_nsfs_constants');
15+
GLACIER_ACTIONS, LIST_UNSETABLE_OPTIONS, ANONYMOUS, DIAGNOSE_ACTIONS, UPGRADE_ACTIONS } = require('../manage_nsfs/manage_nsfs_constants');
1616
const iam_utils = require('../endpoint/iam/iam_utils');
1717

1818
/////////////////////////////
@@ -76,6 +76,8 @@ function validate_type_and_action(type, action) {
7676
if (!Object.values(GLACIER_ACTIONS).includes(action)) throw_cli_error(ManageCLIError.InvalidAction);
7777
} else if (type === TYPES.DIAGNOSE) {
7878
if (!Object.values(DIAGNOSE_ACTIONS).includes(action)) throw_cli_error(ManageCLIError.InvalidDiagnoseAction);
79+
} else if (type === TYPES.UPGRADE) {
80+
if (!Object.values(UPGRADE_ACTIONS).includes(action)) throw_cli_error(ManageCLIError.InvalidUpgradeAction);
7981
}
8082
}
8183

src/manage_nsfs/upgrade.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright (C) 2024 NooBaa */
2+
'use strict';
3+
4+
const dbg = require('../util/debug_module')(__filename);
5+
const { ManageCLIError } = require('./manage_nsfs_cli_errors');
6+
const { UPGRADE_ACTIONS } = require('./manage_nsfs_constants');
7+
const { ManageCLIResponse } = require('../manage_nsfs/manage_nsfs_cli_responses');
8+
const { throw_cli_error, write_stdout_response } = require('./manage_nsfs_cli_utils');
9+
10+
/**
11+
* manage_upgrade_operations handles cli upgrade operations
12+
* @param {string} action
13+
* @returns {Promise<Void>}
14+
*/
15+
async function manage_upgrade_operations(action, config_fs) {
16+
switch (action) {
17+
case UPGRADE_ACTIONS.START:
18+
await exec_config_dir_upgrade();
19+
break;
20+
case UPGRADE_ACTIONS.STATUS:
21+
await get_upgrade_status(config_fs);
22+
break;
23+
case UPGRADE_ACTIONS.HISTORY:
24+
await get_upgrade_history(config_fs);
25+
break;
26+
default:
27+
throw_cli_error(ManageCLIError.InvalidUpgradeAction);
28+
}
29+
}
30+
31+
/**
32+
* exec_config_dir_upgrade handles cli upgrade operation
33+
* @returns {Promise<Void>}
34+
*/
35+
async function exec_config_dir_upgrade() {
36+
try {
37+
// TODO - add verifications and a call to the config directory upgrade
38+
throw new Error('Upgrade Config Directory is not implemented yet');
39+
} catch (err) {
40+
dbg.error('could not upgrade config directory successfully - err', err);
41+
throw_cli_error({ ...ManageCLIError.UpgradeFailed, cause: err });
42+
}
43+
}
44+
45+
/**
46+
* get_upgrade_status handles cli upgrade status operation
47+
* @param {import('../sdk/config_fs').ConfigFS} config_fs
48+
* @returns {Promise<Void>}
49+
*/
50+
async function get_upgrade_status(config_fs) {
51+
try {
52+
const system_config = await config_fs.get_system_config_file({ silent_if_missing: true });
53+
let upgrade_status = system_config?.config_directory?.in_progress_upgrade;
54+
if (!upgrade_status) upgrade_status = { message: 'Config directory upgrade status is empty, there is no ongoing config directory upgrade' };
55+
write_stdout_response(ManageCLIResponse.UpgradeStatus, upgrade_status);
56+
} catch (err) {
57+
dbg.error('could not get upgrade status response', err);
58+
throw_cli_error({ ...ManageCLIError.UpgradeStatusFailed, cause: err });
59+
}
60+
}
61+
62+
/**
63+
* get_upgrade_history handles cli upgrade history operation
64+
* @param {import('../sdk/config_fs').ConfigFS} config_fs
65+
* @returns {Promise<Void>}
66+
*/
67+
async function get_upgrade_history(config_fs) {
68+
try {
69+
const system_config = await config_fs.get_system_config_file({ silent_if_missing: true });
70+
let upgrade_history = system_config?.config_directory?.upgrade_history;
71+
if (!upgrade_history) upgrade_history = { message: 'Config directory upgrade history is empty' };
72+
write_stdout_response(ManageCLIResponse.UpgradeHistory, upgrade_history);
73+
} catch (err) {
74+
dbg.error('could not get upgrade history response', err);
75+
throw_cli_error({ ...ManageCLIError.UpgradeHistoryFailed, cause: err });
76+
}
77+
}
78+
79+
exports.manage_upgrade_operations = manage_upgrade_operations;

0 commit comments

Comments
 (0)