diff --git a/src/manage_nsfs/manage_nsfs_cli_errors.js b/src/manage_nsfs/manage_nsfs_cli_errors.js index 19ad998768..5dfe53ddd0 100644 --- a/src/manage_nsfs/manage_nsfs_cli_errors.js +++ b/src/manage_nsfs/manage_nsfs_cli_errors.js @@ -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; diff --git a/src/manage_nsfs/manage_nsfs_cli_responses.js b/src/manage_nsfs/manage_nsfs_cli_responses.js index 57600f6680..94be1f1ab3 100644 --- a/src/manage_nsfs/manage_nsfs_cli_responses.js +++ b/src/manage_nsfs/manage_nsfs_cli_responses.js @@ -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; diff --git a/src/manage_nsfs/manage_nsfs_events_utils.js b/src/manage_nsfs/manage_nsfs_events_utils.js index 94b2cf7835..7b738c8618 100644 --- a/src/manage_nsfs/manage_nsfs_events_utils.js +++ b/src/manage_nsfs/manage_nsfs_events_utils.js @@ -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; diff --git a/src/manage_nsfs/upgrade.js b/src/manage_nsfs/upgrade.js index ddae9b2f15..b53d6c4667 100644 --- a/src/manage_nsfs/upgrade.js +++ b/src/manage_nsfs/upgrade.js @@ -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 @@ -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 }); } }