Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSFS | NC | Events | bugs & events addition to manage nsfs CLI #7759

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 104 additions & 2 deletions docs/dev_guide/non_containerized_NSFS_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,114 @@ arguments : `bucket_path`, `object_name`
#### Resolutions
- Verify the bucket path.

### 10. noobaa_object_uplaod_failed
### 10. noobaa_object_upload_failed
arguments : `bucket_path`, `object_name`
#### Reasons
- Bucket path is outside the bucket boundaries.
- Bucket storage class is not supported.
- Object I/O operation is failed.
#### Resolutions
- Make sure bucket storage class is supported.
- Check for I/O operations.
- Check for I/O operations.

### 11. noobaa_account_created
arguments : `account_name`
#### Reasons
- Account created using CLI command
#### Resolutions
- Nil

### 12. noobaa_account_deleted
arguments : `account_name`
#### Reasons
- Account deleted using CLI.
#### Resolutions
- Nil

### 13. noobaa_bucket_created
arguments : `bucket_name`
#### Reasons
- Bucket created using CLI or S3.
#### Resolutions
- Nil

### 14. noobaa_bucket_deleted
arguments : `bucket_name`
#### Reasons
- Bucket deleted using CLI or S3.
#### Resolutions
- Nil

### 15. noobaa_whitelist_updated
arguments : `whitelist_ips`
#### Reasons
- Whitelist IPs updated using CLI.
#### Resolutions
- Nil

### 16. noobaa_no_such_bucket
arguments: `bucket_name`
#### Reasons
- Bucket does not exist with a name.
#### Resolutions
- List all the buckets and verify the bucket name exists in that list
- Check users have permission to access the buckets.

### 17. noobaa_bucket_already_exists
arguments: `bucket_name`
#### Reasons
- Bucket already exists with a name.
#### Resolutions
- change bucket name to unit value

### 18. noobaa_bucket_access_unauthorized
arguments: `bucket_name`
#### Reasons
- User does not have access to bucket or bucket directory
#### Resolutions
- Check users have permission to access the buckets.

### 19. noobaa_bucket_io_stream_item_timeout
arguments: `bucket_name`
#### Reasons
- Bucket stream IO output throws time out error
#### Resolutions
- Make sure the user have a fast internet connection
- Both Noobaa and directory resources are not overloaded.

### 20. noobaa_bucket_internal_error
arguments: `bucket_name`
#### Reasons
- Bucket access failed due to internal error
#### Resolutions
- Go through the event description and try to identify the root cause.

### 21. noobaa_account_exists
arguments: `account_name` or `access_key`
#### Reasons
- Noobaa account with name/access key already exists in the system
#### Resolutions
- verify the existing account name/access_key and make sure no account exists with the given name/access_key

### 22. noobaa_account_delete_forbidden
arguments: `account_name` or `access_key`
#### Reasons
- Noobaa account deletion forbidden. Cannot delete account that is the owner of buckets.
#### Resolutions
- make sure all buckets are deleted before deleting the account.

### 23. noobaa_whitelist_updated_failed
arguments: `config_path`
#### Reasons
- Whitelist updated with IPs failed. Whitelist updated with IPs failed. Error while updation config.json file with whitelist IPs
#### Resolutions
- Check that the user has the right permission
- config.json exists in the config root path
- config.json is a valid JSON schema format

### 24. bucket_invalid_bucket_state
arguments: `bucket_name`
#### Reasons
- Bucket is in invalid state. Bucket schema missing required property or invalid property gets added.
#### Resolutions
- Check the bucket schema definition and make sure the required property is missing and the invalid property gets added in the config root path.
32 changes: 21 additions & 11 deletions src/cmd/manage_nsfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,31 @@ const native_fs_utils = require('../util/native_fs_utils');
const mongo_utils = require('../util/mongo_utils');
const SensitiveString = require('../util/sensitive_string');
const ManageCLIError = require('../manage_nsfs/manage_nsfs_cli_errors').ManageCLIError;
const NSFS_CLI_ERROR_EVENT_MAP = require('../manage_nsfs/manage_nsfs_cli_errors').NSFS_CLI_ERROR_EVENT_MAP;
const ManageCLIResponse = require('../manage_nsfs/manage_nsfs_cli_responses').ManageCLIResponse;
const NSFS_CLI_SUCCESS_EVENT_MAP = require('../manage_nsfs/manage_nsfs_cli_responses').NSFS_CLI_SUCCESS_EVENT_MAP;
const bucket_policy_utils = require('../endpoint/s3/s3_bucket_policy_utils');
const nsfs_schema_utils = require('../manage_nsfs/nsfs_schema_utils');
const { print_usage } = require('../manage_nsfs/manage_nsfs_help_utils');
const { TYPES, ACTIONS, VALID_OPTIONS, OPTION_TYPE,
LIST_ACCOUNT_FILTERS, LIST_BUCKET_FILTERS} = require('../manage_nsfs/manage_nsfs_constants');
const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;

function throw_cli_error(error_code, detail) {
function throw_cli_error(error_code, detail, event_arg) {
const error_event = NSFS_CLI_ERROR_EVENT_MAP[error_code.code];
if (error_event) {
new NoobaaEvent(error_event).create_event(undefined, event_arg, undefined);
}
const err = new ManageCLIError(error_code).to_string(detail);
process.stdout.write(err + '\n');
process.exit(1);
}

function write_stdout_response(response_code, detail) {
function write_stdout_response(response_code, detail, event_arg) {
const response_event = NSFS_CLI_SUCCESS_EVENT_MAP[response_code.code];
if (response_event) {
new NoobaaEvent(response_event).create_event(undefined, event_arg, undefined);
}
const res = new ManageCLIResponse(response_code).to_string(detail);
process.stdout.write(res + '\n');
process.exit(0);
Expand Down Expand Up @@ -197,7 +208,7 @@ async function add_bucket(data) {
const fs_context = native_fs_utils.get_process_fs_context(config_root_backend);
const bucket_conf_path = get_config_file_path(buckets_dir_path, data.name);
const exists = await native_fs_utils.is_path_exists(fs_context, bucket_conf_path);
if (exists) throw_cli_error(ManageCLIError.BucketAlreadyExists, data.name.unwrap());
if (exists) throw_cli_error(ManageCLIError.BucketAlreadyExists, data.name.unwrap(), {bucket: data.name.unwrap()});
data._id = mongo_utils.mongoObjectId();
data.owner_account = account_id;
const data_json = JSON.stringify(data);
Expand All @@ -206,7 +217,7 @@ async function add_bucket(data) {
// for validating against the schema we need an object, hence we parse it back to object
nsfs_schema_utils.validate_bucket_schema(JSON.parse(data_json));
await native_fs_utils.create_config_file(fs_context, buckets_dir_path, bucket_conf_path, data_json);
write_stdout_response(ManageCLIResponse.BucketCreated, data_json);
write_stdout_response(ManageCLIResponse.BucketCreated, data_json, {bucket: data.name.unwrap()});
}

/** verify_bucket_owner will check if the bucket_owner has an account
Expand Down Expand Up @@ -238,7 +249,7 @@ async function verify_bucket_owner(bucket_owner, action) {

if (!is_bucket_owner_exist) {
const detail_msg = `bucket owner ${bucket_owner} does not exists`;
throw_cli_error(ManageCLIError.BucketSetForbiddenNoBucketOwner, detail_msg);
throw_cli_error(ManageCLIError.BucketSetForbiddenNoBucketOwner, detail_msg, {bucket_owner: bucket_owner});
}
if (action === ACTIONS.ADD && !is_allow_bucket_creation) {
throw_cli_error(ManageCLIError.BucketCreationNotAllowed, bucket_owner);
Expand Down Expand Up @@ -310,7 +321,7 @@ async function delete_bucket(data) {
if (err.code === 'ENOENT') throw_cli_error(ManageCLIError.NoSuchBucket, data.name);
throw err;
}
write_stdout_response(ManageCLIResponse.BucketDeleted);
write_stdout_response(ManageCLIResponse.BucketDeleted, '', {bucket: data.name.unwrap()});
}

async function manage_bucket_operations(action, data, argv) {
Expand Down Expand Up @@ -466,9 +477,10 @@ async function add_account(data) {
const name_exists = await native_fs_utils.is_path_exists(fs_context, account_config_path);
const access_key_exists = await native_fs_utils.is_path_exists(fs_context, account_config_access_key_path, true);

const event_arg = data.name ? data.name.unwrap() : access_key;
if (name_exists || access_key_exists) {
const err_code = name_exists ? ManageCLIError.AccountNameAlreadyExists : ManageCLIError.AccountAccessKeyAlreadyExists;
throw_cli_error(err_code);
throw_cli_error(err_code, '', {account: event_arg});
}
data._id = mongo_utils.mongoObjectId();
data = JSON.stringify(data);
Expand All @@ -479,8 +491,7 @@ async function add_account(data) {
await native_fs_utils.create_config_file(fs_context, accounts_dir_path, account_config_path, data);
await native_fs_utils._create_path(access_keys_dir_path, fs_context, config.BASE_MODE_CONFIG_DIR);
await nb_native().fs.symlink(fs_context, account_config_path, account_config_access_key_path);

write_stdout_response(ManageCLIResponse.AccountCreated, data);
write_stdout_response(ManageCLIResponse.AccountCreated, data, {account: event_arg});
}

async function update_account(data) {
Expand Down Expand Up @@ -545,8 +556,7 @@ async function delete_account(data) {

await native_fs_utils.delete_config_file(fs_context, accounts_dir_path, account_config_path);
await nb_native().fs.unlink(fs_context, access_key_config_path);

write_stdout_response(ManageCLIResponse.AccountDeleted);
write_stdout_response(ManageCLIResponse.AccountDeleted, '', {account: data.name.unwrap()});
}

/**
Expand Down
23 changes: 3 additions & 20 deletions src/cmd/nsfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const path = require('path');
const json_utils = require('../util/json_utils');
//const { RPC_BUFFERS } = require('../rpc');
const pkg = require('../../package.json');
const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;

const HELP = `
Help:
Expand Down Expand Up @@ -340,35 +341,17 @@ async function main(argv = minimist(process.argv.slice(2))) {
console.log('nsfs: listening on', util.inspect(`http://localhost:${http_port}`));
}
console.log('nsfs: listening on', util.inspect(`https://localhost:${https_port}`));

} catch (err) {
console.error('nsfs: exit on error', err.stack || err);
//noobaa crashed
dbg.event({
code: "noobaa_nsfs_crashed",
entity_type: "NODE",
event_type: "STATE_CHANGE",
message: "Noobaa NSFS crashed with error : " + err,
scope: "NODE",
severity: "ERROR",
state: "STOPPED"
});
new NoobaaEvent(NoobaaEvent.NSFS_CRASHED).create_event(undefined, undefined, err);
process.exit(2);
}
}

function verify_gpfslib() {
if (!nb_native().fs.gpfs) {
dbg.event({
code: "noobaa_gpfslib_missing",
entity_type: "NODE",
event_type: "STATE_CHANGE",
message: "Noobaa GPFS library file is missing",
scope: "NODE",
severity: "ERROR",
state: "DEGRADED",
arguments: { gpfs_dl_path: process.env.GPFS_DL_PATH },
});
new NoobaaEvent(NoobaaEvent.GPFSLIB_MISSING).create_event(undefined, { gpfs_dl_path: process.env.GPFS_DL_PATH }, undefined);
}
}

Expand Down
21 changes: 3 additions & 18 deletions src/endpoint/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const endpoint_stats_collector = require('../sdk/endpoint_stats_collector');
const { NamespaceMonitor } = require('../server/bg_services/namespace_monitor');
const { SemaphoreMonitor } = require('../server/bg_services/semaphore_monitor');
const prom_reporting = require('../server/analytic_services/prometheus_reporting');
const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;
const cluster = /** @type {import('node:cluster').Cluster} */ (
/** @type {unknown} */ (require('node:cluster'))
);
Expand Down Expand Up @@ -207,28 +208,12 @@ async function main(options = {}) {
}));
}
//noobaa started
dbg.event({
code: "noobaa_started",
entity_type: "NODE",
event_type: "STATE_CHANGE",
message: "Noobaa started",
scope: "NODE",
severity: "INFO",
state: "HEALTHY"
});
new NoobaaEvent(NoobaaEvent.NOOBAA_STARTED).create_event(undefined, undefined, undefined);
// Start a monitor to send periodic endpoint reports about endpoint usage.
start_monitor(internal_rpc_client, endpoint_group_id);
} catch (err) {
//noobaa crashed event
dbg.event({
code: "noobaa_endpoint_crashed",
entity_type: "NODE",
event_type: "STATE_CHANGE",
message: String("Noobaa crashed with error :" + err),
scope: "NODE",
severity: "ERROR",
state: "STOPPED"
});
new NoobaaEvent(NoobaaEvent.ENDPOINT_CRASHED).create_event(undefined, undefined, err);
handle_server_error(err);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/manage_nsfs/manage_nsfs_cli_errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;

/**
* @typedef {{
* code?: string,
Expand Down Expand Up @@ -357,4 +359,15 @@ ManageCLIError.RPC_ERROR_TO_MANAGE = Object.freeze({
NO_SUCH_USER: ManageCLIError.InvalidAccountDistinguishedName
});

const NSFS_CLI_ERROR_EVENT_MAP = {
WhiteListIPUpdateFailed: NoobaaEvent.WHITELIST_UPDATED_FAILED,
AccessDenied: NoobaaEvent.UNAUTHORIZED,
AccountAccessKeyAlreadyExists: NoobaaEvent.ACCOUNT_ALREADY_EXISTS,
AccountNameAlreadyExists: NoobaaEvent.ACCOUNT_ALREADY_EXISTS,
AccountDeleteForbiddenHasBuckets: NoobaaEvent.ACCOUNT_DELETE_FORBIDDEN,
BucketAlreadyExists: NoobaaEvent.BUCKET_ALREADY_EXISTS,
BucketSetForbiddenNoBucketOwner: NoobaaEvent.UNAUTHORIZED,
};

exports.ManageCLIError = ManageCLIError;
exports.NSFS_CLI_ERROR_EVENT_MAP = NSFS_CLI_ERROR_EVENT_MAP;
11 changes: 11 additions & 0 deletions src/manage_nsfs/manage_nsfs_cli_responses.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;

// TODO : define list & status types
/**
* @typedef {{
Expand Down Expand Up @@ -100,4 +102,13 @@ ManageCLIResponse.BucketList = Object.freeze({
list: {}
});

const NSFS_CLI_SUCCESS_EVENT_MAP = {
AccountCreated: NoobaaEvent.ACCOUNT_CREATED,
AccountDeleted: NoobaaEvent.ACCOUNT_DELETED,
BucketCreated: NoobaaEvent.BUCKET_CREATED,
BucketDeleted: NoobaaEvent.BUCKET_DELETE,
WhiteListIPUpdated: NoobaaEvent.WHITELIST_UPDATED,
};

exports.ManageCLIResponse = ManageCLIResponse;
exports.NSFS_CLI_SUCCESS_EVENT_MAP = NSFS_CLI_SUCCESS_EVENT_MAP;
Loading