Skip to content

Commit

Permalink
Merge pull request #8670 from romayalon/romy-online-upgrade-events
Browse files Browse the repository at this point in the history
NC | Online Upgrade events
  • Loading branch information
romayalon authored Jan 9, 2025
2 parents cf83c72 + 7931c7d commit 56cab66
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/manage_nsfs/manage_nsfs_cli_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ const NSFS_CLI_ERROR_EVENT_MAP = {
BucketSetForbiddenBucketOwnerNotExists: NoobaaEvent.UNAUTHORIZED, // GAP - add event
BucketSetForbiddenBucketOwnerIsIAMAccount: NoobaaEvent.UNAUTHORIZED, // // GAP - add event
LoggingExportFailed: NoobaaEvent.LOGGING_FAILED,
UpgradeFailed: NoobaaEvent.CONFIG_DIR_UPGRADE_FAILED
};

exports.ManageCLIError = ManageCLIError;
Expand Down
2 changes: 2 additions & 0 deletions src/manage_nsfs/manage_nsfs_cli_responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ const NSFS_CLI_SUCCESS_EVENT_MAP = {
BucketDeleted: NoobaaEvent.BUCKET_DELETE,
WhiteListIPUpdated: NoobaaEvent.WHITELIST_UPDATED,
LoggingExported: NoobaaEvent.LOGGING_EXPORTED,
UpgradeStarted: NoobaaEvent.CONFIG_DIR_UPGRADE_STARTED,
UpgradeSuccessful: NoobaaEvent.CONFIG_DIR_UPGRADE_SUCCESSFUL
};

exports.ManageCLIResponse = ManageCLIResponse;
Expand Down
37 changes: 37 additions & 0 deletions src/manage_nsfs/manage_nsfs_events_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,41 @@ NoobaaEvent.LOGGING_FAILED = Object.freeze({
state: 'DEGRADED',
});

/////////////////////////////////////
// CONFIG DIRECTORY UPGRADE EVENTS //
/////////////////////////////////////

NoobaaEvent.CONFIG_DIR_UPGRADE_STARTED = Object.freeze({
event_code: 'config_dir_upgrade_started',
entity_type: 'NODE',
event_type: 'INFO',
message: 'Config directory upgrade started.',
description: 'Config directory upgrade started.',
scope: 'NODE',
severity: 'INFO',
state: 'HEALTHY',
});

NoobaaEvent.CONFIG_DIR_UPGRADE_SUCCESSFUL = Object.freeze({
event_code: 'config_dir_upgrade_successful',
entity_type: 'NODE',
event_type: 'INFO',
message: 'Config directory upgrade finished successfully.',
description: 'Config directory upgrade finished successfully.',
scope: 'NODE',
severity: 'INFO',
state: 'HEALTHY',
});

NoobaaEvent.CONFIG_DIR_UPGRADE_FAILED = Object.freeze({
event_code: 'config_dir_upgrade_failed',
entity_type: 'NODE',
event_type: 'ERROR',
message: 'Config directory upgrade failed.',
description: 'Config directory upgrade failed due to an error',
scope: 'NODE',
severity: 'ERROR',
state: 'DEGRADED',
});

exports.NoobaaEvent = NoobaaEvent;
9 changes: 6 additions & 3 deletions src/manage_nsfs/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { UPGRADE_ACTIONS } = require('./manage_nsfs_constants');
const { NCUpgradeManager } = require('../upgrade/nc_upgrade_manager');
const { ManageCLIResponse } = require('../manage_nsfs/manage_nsfs_cli_responses');
const { throw_cli_error, write_stdout_response } = require('./manage_nsfs_cli_utils');
const { NoobaaEvent } = require('./manage_nsfs_events_utils');

/**
* manage_upgrade_operations handles cli upgrade operations
Expand Down Expand Up @@ -45,16 +46,18 @@ async function start_config_dir_upgrade(user_input, config_fs) {
const expected_hosts = user_input.expected_hosts && user_input.expected_hosts.split(',').filter(host => !_.isEmpty(host));
const custom_upgrade_scripts_dir = user_input.custom_upgrade_scripts_dir;

new NoobaaEvent(NoobaaEvent.CONFIG_DIR_UPGRADE_STARTED).create_event(undefined, { expected_version, expected_hosts }, undefined);

if (!expected_version) throw new Error('expected_version flag is required');
if (!expected_hosts) throw new Error('expected_hosts flag is required');

const nc_upgrade_manager = new NCUpgradeManager(config_fs, { custom_upgrade_scripts_dir });
const upgrade_res = await nc_upgrade_manager.upgrade_config_dir(expected_version, expected_hosts, { skip_verification });
if (!upgrade_res) throw new Error('Upgrade config directory failed', { cause: upgrade_res });
write_stdout_response(ManageCLIResponse.UpgradeSuccessful, upgrade_res);
write_stdout_response(ManageCLIResponse.UpgradeSuccessful, upgrade_res, { expected_version, expected_hosts });
} catch (err) {
dbg.error('could not upgrade config directory successfully - err', err);
throw_cli_error({ ...ManageCLIError.UpgradeFailed, cause: err });
dbg.error('could not upgrade config directory successfully - error', err);
throw_cli_error({ ...ManageCLIError.UpgradeFailed, cause: err }, undefined, { error: err.stack || err });
}
}

Expand Down

0 comments on commit 56cab66

Please sign in to comment.