Skip to content

Commit ff1877a

Browse files
committed
S3 internal APIs gaps
Signed-off-by: Romy <[email protected]>
1 parent e1e56a8 commit ff1877a

File tree

12 files changed

+294
-11
lines changed

12 files changed

+294
-11
lines changed

Diff for: docs/NooBaaNonContainerized/CI&Tests.md

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ The following is a list of `NC jest tests` files -
115115
18. `test_cli_upgrade.test.js` - Tests of the upgrade CLI commands.
116116
19. `test_nc_online_upgrade_cli_integrations.test.js` - Tests CLI commands during mocked config directory upgrade.
117117
20. `test_nc_connection_cli.test.js` - Tests NooBaa CLI connection commands.
118+
21. `test_cli_versions.test.js` - Tests NooBaa CLI versions command.
118119

119120
#### nc_index.js File
120121
* The `nc_index.js` is a file that runs several NC and NSFS mocha related tests.

Diff for: docs/NooBaaNonContainerized/NooBaaCLI.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
3. [Connection Status](#connection-status)
3232
4. [List Connections][#list-connections]
3333
5. [Delete Connection](#delete-connection)
34-
11. [Global Options](#global-options)
35-
12. [Examples](#examples)
34+
11. [Fetching Versions Status](#fetching-versions-status)
35+
12. [Global Options](#global-options)
36+
13. [Examples](#examples)
3637
1. [Bucket Commands Examples](#bucket-commands-examples)
3738
2. [Account Commands Examples](#account-commands-examples)
3839
3. [White List Server IP Command Example](#white-list-server-ip-command-example)
@@ -634,6 +635,19 @@ noobaa-cli connection delete --name <connection_name>
634635
- Type: String
635636
- Description: Specifies the name of the connection to be deleted.
636637

638+
639+
## Fetching Versions Status
640+
641+
The `versions` command is used to print the status of the rpm_source_code_versions, host_running_service_versions and config_dir_version.
642+
- rpm_source_code_versions consists of the package_version and the config_fs version.
643+
- host_running_service_versions consists of the running service package_version and config_fs version.
644+
- config_dir_version is the current config_dir_version registered in system.json.
645+
646+
#### Usage
647+
```sh
648+
noobaa-cli versions
649+
```
650+
637651
## Global Options
638652

639653
Global options used by the CLI to define the config directory settings.

Diff for: src/cmd/manage_nsfs.js

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const manage_nsfs_glacier = require('../manage_nsfs/manage_nsfs_glacier');
2020
const manage_nsfs_logging = require('../manage_nsfs/manage_nsfs_logging');
2121
const noobaa_cli_diagnose = require('../manage_nsfs/diagnose');
2222
const noobaa_cli_upgrade = require('../manage_nsfs/upgrade');
23+
const noobaa_cli_versions = require('../manage_nsfs/versions');
2324
const { print_usage } = require('../manage_nsfs/manage_nsfs_help_utils');
2425
const { TYPES, ACTIONS, LIST_ACCOUNT_FILTERS, LIST_BUCKET_FILTERS, GLACIER_ACTIONS } = require('../manage_nsfs/manage_nsfs_constants');
2526
const { throw_cli_error, get_bucket_owner_account_by_name,
@@ -80,6 +81,8 @@ async function main(argv = minimist(process.argv.slice(2))) {
8081
await notification_management();
8182
} else if (type === TYPES.CONNECTION) {
8283
await connection_management(action, user_input);
84+
} else if (type === TYPES.VERSIONS) {
85+
await noobaa_cli_versions.versions_management(config_fs);
8386
} else {
8487
throw_cli_error(ManageCLIError.InvalidType);
8588
}

Diff for: src/endpoint/endpoint.js

+30-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const s3_rest = require('./s3/s3_rest');
2020
const blob_rest = require('./blob/blob_rest');
2121
const sts_rest = require('./sts/sts_rest');
2222
const iam_rest = require('./iam/iam_rest');
23+
const { CONFIG_DIR_VERSION } = require('../sdk/config_fs');
2324
const lambda_rest = require('./lambda/lambda_rest');
2425
const endpoint_utils = require('./endpoint_utils');
2526
const FuncSDK = require('../sdk/func_sdk');
@@ -60,6 +61,13 @@ const SERVICES_TYPES_ENUM = Object.freeze({
6061
METRICS: 'METRICS'
6162
});
6263

64+
const INTERNAL_APIS_OBJ = Object.freeze({
65+
VERSION: 'version',
66+
CONFIG_FS_VERSION: 'config_fs_version',
67+
ENDPOINT_FORK_ID: 'endpoint_fork_id',
68+
TOTAL_FORK_COUNT: 'total_fork_count'
69+
});
70+
6371
const new_umask = process.env.NOOBAA_ENDPOINT_UMASK || 0o000;
6472
const old_umask = process.umask(new_umask);
6573
let fork_count;
@@ -291,15 +299,17 @@ function create_endpoint_handler(server_type, init_request_sdk, { virtual_hosts,
291299
return lambda_rest_handler(req, res);
292300
} else if (req.headers['x-ms-version']) {
293301
return blob_rest_handler(req, res);
294-
} else if (req.url.startsWith('/total_fork_count')) {
295-
return fork_count_handler(req, res);
296-
} else if (req.url.startsWith('/endpoint_fork_id')) {
297-
return endpoint_fork_id_handler(req, res);
298302
} else if (req.url.startsWith('/_/')) {
299303
// internals non S3 requests
300304
const api = req.url.slice('/_/'.length);
301-
if (api === 'version') {
305+
if (api === INTERNAL_APIS_OBJ.VERSION) {
302306
return version_handler(req, res);
307+
} else if (api === INTERNAL_APIS_OBJ.CONFIG_FS_VERSION) {
308+
return config_fs_version_handler(req, res);
309+
} else if (api === INTERNAL_APIS_OBJ.ENDPOINT_FORK_ID) {
310+
return endpoint_fork_id_handler(req, res);
311+
} else if (api === INTERNAL_APIS_OBJ.TOTAL_FORK_COUNT) {
312+
return fork_count_handler(req, res);
303313
} else {
304314
return internal_api_error(req, res, `Unknown API call ${api}`);
305315
}
@@ -351,6 +361,21 @@ function version_handler(req, res) {
351361
res.end(noobaa_package_version);
352362
}
353363

364+
/**
365+
* config_fs_version_handler returns the version of configFS
366+
* this is not the actual config dir version
367+
* this is the version that NooBaa targets for writing configuration files.
368+
* @param {EndpointRequest} req
369+
* @param {import('http').ServerResponse} res
370+
*/
371+
function config_fs_version_handler(req, res) {
372+
const config_dir_version = CONFIG_DIR_VERSION;
373+
res.statusCode = 200;
374+
res.setHeader('Content-Type', 'text/plain');
375+
res.setHeader('Content-Length', Buffer.byteLength(config_dir_version));
376+
res.end(config_dir_version);
377+
}
378+
354379
/**
355380
* internal_api_error returns an internal api error response
356381
* @param {EndpointRequest} req

Diff for: src/manage_nsfs/health.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class NSFSHealth {
251251
}
252252

253253
async get_endpoint_fork_response() {
254-
let url_path = '/total_fork_count';
254+
let url_path = '/_/total_fork_count';
255255
const worker_ids = [];
256256
let total_fork_count = 0;
257257
let response;
@@ -266,7 +266,7 @@ class NSFSHealth {
266266
}
267267
total_fork_count = fork_count_response.fork_count;
268268
if (total_fork_count > 0) {
269-
url_path = '/endpoint_fork_id';
269+
url_path = '/_/endpoint_fork_id';
270270
await P.retry({
271271
attempts: total_fork_count * 2,
272272
delay_ms: 1,

Diff for: src/manage_nsfs/manage_nsfs_cli_errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ManageCLIError.UnsetArgumentIsInvalid = Object.freeze({
100100

101101
ManageCLIError.InvalidType = Object.freeze({
102102
code: 'InvalidType',
103-
message: 'Invalid type, available types are account, bucket, logging, whitelist, upgrade, notification or connection.',
103+
message: 'Invalid type, available types are account, bucket, logging, whitelist, upgrade, notification, connection, or versions.',
104104
http_code: 400,
105105
});
106106

Diff for: src/manage_nsfs/manage_nsfs_cli_responses.js

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ ManageCLIResponse.MetricsStatus = Object.freeze({
5757
status: {}
5858
});
5959

60+
///////////////////////////////
61+
////// VERSIONS RESPONSES ////
62+
///////////////////////////////
63+
64+
ManageCLIResponse.VersionsStatus = Object.freeze({
65+
code: 'VersionsStatus',
66+
message: 'Versions status retrieved successfully',
67+
status: {}
68+
});
69+
6070
///////////////////////////////
6171
// IPS WHITE LIST RESPONSES ///
6272
///////////////////////////////

Diff for: src/manage_nsfs/manage_nsfs_constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const TYPES = Object.freeze({
1010
DIAGNOSE: 'diagnose',
1111
UPGRADE: 'upgrade',
1212
NOTIFICATION: 'notification',
13-
CONNECTION: 'connection'
13+
CONNECTION: 'connection',
14+
VERSIONS: 'versions'
1415
});
1516

1617
const ACTIONS = Object.freeze({

Diff for: src/manage_nsfs/versions.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* Copyright (C) 2024 NooBaa */
2+
'use strict';
3+
4+
const dbg = require('../util/debug_module')(__filename);
5+
const config = require('../../config');
6+
const pkg = require('../../package.json');
7+
const http_utils = require('../util/http_utils');
8+
const buffer_utils = require('../util/buffer_utils');
9+
const { write_stdout_response } = require('./manage_nsfs_cli_utils');
10+
const { ManageCLIResponse } = require('./manage_nsfs_cli_responses');
11+
12+
////////////////////////
13+
// VERSIONS MANAGEMENT //
14+
////////////////////////
15+
16+
/**
17+
* versions_management
18+
*/
19+
async function versions_management(config_fs) {
20+
const system_json = await config_fs.get_system_config_file({ silent_if_missing: true });
21+
const versions = {
22+
rpm_source_code_versions: {
23+
package_version: pkg.version,
24+
config_fs_version: config_fs.config_dir_version,
25+
},
26+
host_running_service_versions: await get_running_service_versions(),
27+
config_dir_version: system_json?.config_directory.config_dir_version || 'unknown'
28+
};
29+
30+
const response = { code: ManageCLIResponse.VersionsStatus, detail: versions };
31+
write_stdout_response(response.code, response.detail);
32+
}
33+
34+
/**
35+
* get_running_service_versions returns the versions of the running service
36+
* @returns {Promise<Object>}
37+
*/
38+
async function get_running_service_versions() {
39+
const host_service_versions = {};
40+
try {
41+
const package_version_api = '/_/version';
42+
const config_dir_version_api = '/_/config_fs_version';
43+
host_service_versions.package_version = await get_version_api_response(package_version_api);
44+
host_service_versions.config_fs_version = await get_version_api_response(config_dir_version_api);
45+
} catch (err) {
46+
dbg.warn('could not receive versions response', err);
47+
}
48+
return host_service_versions;
49+
}
50+
51+
/**
52+
* get_version_api_response runs a GET request to the given api and returns the response
53+
* @param {string} api
54+
* @returns
55+
*/
56+
async function get_version_api_response(api) {
57+
let version;
58+
try {
59+
const res = await http_utils.make_https_request({
60+
hostname: 'localhost',
61+
port: config.ENDPOINT_SSL_PORT,
62+
path: api,
63+
method: 'GET',
64+
rejectUnauthorized: false
65+
});
66+
67+
if (res.statusCode === 200) {
68+
const buffer = await buffer_utils.read_stream_join(res);
69+
version = buffer.toString('utf8');
70+
} else if (res.statusCode >= 500) {
71+
const buffer = await buffer_utils.read_stream_join(res);
72+
const body = buffer.toString('utf8');
73+
dbg.log0(`get_version_api_response received an error from ${api} api, skipping', ${body}`);
74+
}
75+
} catch (err) {
76+
dbg.warn('get_version_api_response: err', err);
77+
}
78+
return version?.trim() || 'unknown';
79+
}
80+
81+
// EXPORTS
82+
exports.versions_management = versions_management;

Diff for: src/sdk/config_fs.js

+1
Original file line numberDiff line numberDiff line change
@@ -1402,4 +1402,5 @@ exports.JSON_SUFFIX = JSON_SUFFIX;
14021402
exports.CONFIG_SUBDIRS = CONFIG_SUBDIRS;
14031403
exports.CONFIG_TYPES = CONFIG_TYPES;
14041404
exports.CONFIG_DIR_PHASES = CONFIG_DIR_PHASES;
1405+
exports.CONFIG_DIR_VERSION = CONFIG_DIR_VERSION;
14051406
exports.ConfigFS = ConfigFS;

0 commit comments

Comments
 (0)