Source: api/api/nodes.js

  1. /*
  2. * Copyright OpenSearch Contributors
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * The OpenSearch Contributors require contributions made to
  6. * this file be licensed under the Apache-2.0 license or a
  7. * compatible open source license.
  8. *
  9. */
  10. /*
  11. * Licensed to Elasticsearch B.V. under one or more contributor
  12. * license agreements. See the NOTICE file distributed with
  13. * this work for additional information regarding copyright
  14. * ownership. Elasticsearch B.V. licenses this file to you under
  15. * the Apache License, Version 2.0 (the "License"); you may
  16. * not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * http://www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing,
  22. * software distributed under the License is distributed on an
  23. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24. * KIND, either express or implied. See the License for the
  25. * specific language governing permissions and limitations
  26. * under the License.
  27. */
  28. 'use strict';
  29. /* eslint camelcase: 0 */
  30. /* eslint no-unused-vars: 0 */
  31. /** @namespace API-Nodes */
  32. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  33. const acceptedQuerystring = [
  34. 'pretty',
  35. 'human',
  36. 'error_trace',
  37. 'source',
  38. 'filter_path',
  39. 'interval',
  40. 'snapshots',
  41. 'threads',
  42. 'ignore_idle_threads',
  43. 'type',
  44. 'timeout',
  45. 'flat_settings',
  46. 'completion_fields',
  47. 'fielddata_fields',
  48. 'fields',
  49. 'groups',
  50. 'level',
  51. 'types',
  52. 'include_segment_file_sizes',
  53. 'include_unloaded_segments',
  54. ];
  55. const snakeCase = {
  56. errorTrace: 'error_trace',
  57. filterPath: 'filter_path',
  58. ignoreIdleThreads: 'ignore_idle_threads',
  59. flatSettings: 'flat_settings',
  60. completionFields: 'completion_fields',
  61. fielddataFields: 'fielddata_fields',
  62. includeSegmentFileSizes: 'include_segment_file_sizes',
  63. includeUnloadedSegments: 'include_unloaded_segments',
  64. };
  65. function NodesApi(transport, ConfigurationError) {
  66. this.transport = transport;
  67. this[kConfigurationError] = ConfigurationError;
  68. }
  69. NodesApi.prototype.clearMeteringArchive = function nodesClearMeteringArchiveApi(
  70. params,
  71. options,
  72. callback
  73. ) {
  74. [params, options, callback] = normalizeArguments(params, options, callback);
  75. // check required parameters
  76. if (params.node_id == null && params.nodeId == null) {
  77. const err = new this[kConfigurationError]('Missing required parameter: node_id or nodeId');
  78. return handleError(err, callback);
  79. }
  80. if (params.max_archive_version == null && params.maxArchiveVersion == null) {
  81. const err = new this[kConfigurationError](
  82. 'Missing required parameter: max_archive_version or maxArchiveVersion'
  83. );
  84. return handleError(err, callback);
  85. }
  86. // check required url components
  87. if (
  88. (params.max_archive_version != null || params.maxArchiveVersion != null) &&
  89. params.node_id == null &&
  90. params.nodeId == null
  91. ) {
  92. const err = new this[kConfigurationError]('Missing required parameter of the url: node_id');
  93. return handleError(err, callback);
  94. }
  95. let { method, body, nodeId, node_id, maxArchiveVersion, max_archive_version, ...querystring } =
  96. params;
  97. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  98. let path = '';
  99. if (method == null) method = 'DELETE';
  100. path =
  101. '/' +
  102. '_nodes' +
  103. '/' +
  104. encodeURIComponent(node_id || nodeId) +
  105. '/' +
  106. '_repositories_metering' +
  107. '/' +
  108. encodeURIComponent(max_archive_version || maxArchiveVersion);
  109. // build request object
  110. const request = {
  111. method,
  112. path,
  113. body: body || '',
  114. querystring,
  115. };
  116. return this.transport.request(request, options, callback);
  117. };
  118. NodesApi.prototype.getMeteringInfo = function nodesGetMeteringInfoApi(params, options, callback) {
  119. [params, options, callback] = normalizeArguments(params, options, callback);
  120. // check required parameters
  121. if (params.node_id == null && params.nodeId == null) {
  122. const err = new this[kConfigurationError]('Missing required parameter: node_id or nodeId');
  123. return handleError(err, callback);
  124. }
  125. let { method, body, nodeId, node_id, ...querystring } = params;
  126. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  127. let path = '';
  128. if (method == null) method = 'GET';
  129. path =
  130. '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + '_repositories_metering';
  131. // build request object
  132. const request = {
  133. method,
  134. path,
  135. body: null,
  136. querystring,
  137. };
  138. return this.transport.request(request, options, callback);
  139. };
  140. /**
  141. * Returns information about hot threads on each node in the cluster.
  142. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/nodes-apis/nodes-hot-threads/ OpenSearch - Nodes Hot Threads}
  143. * @memberOf API-Nodes
  144. *
  145. * @param {Object} params
  146. * @param {string} [params.node_id] - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
  147. * @param {string} [params.interval] - The interval for the second sampling of threads
  148. * @param {number} [params.snapshots] - Number of samples of thread stacktrace (default: 10)
  149. * @param {number} [params.threads] - Specify the number of threads to provide information for (default: 3)
  150. * @param {boolean} [params.ignore_idle_threads] - Don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true)
  151. * @param {string} [params.type] - The type to sample (default: cpu) (options: cpu, wait, block)
  152. * @param {string} [params.timeout] - Explicit operation timeout
  153. *
  154. * @param {Object} options - Options for {@link Transport#request}
  155. * @param {function} callback - Callback that handles errors and response
  156. *
  157. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  158. */
  159. NodesApi.prototype.hotThreads = function nodesHotThreadsApi(params, options, callback) {
  160. [params, options, callback] = normalizeArguments(params, options, callback);
  161. let { method, body, nodeId, node_id, ...querystring } = params;
  162. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  163. let path = '';
  164. if ((node_id || nodeId) != null) {
  165. if (method == null) method = 'GET';
  166. path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'hot_threads';
  167. } else if ((node_id || nodeId) != null) {
  168. if (method == null) method = 'GET';
  169. path =
  170. '/' +
  171. '_cluster' +
  172. '/' +
  173. 'nodes' +
  174. '/' +
  175. encodeURIComponent(node_id || nodeId) +
  176. '/' +
  177. 'hotthreads';
  178. } else if ((node_id || nodeId) != null) {
  179. if (method == null) method = 'GET';
  180. path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'hotthreads';
  181. } else if ((node_id || nodeId) != null) {
  182. if (method == null) method = 'GET';
  183. path =
  184. '/' +
  185. '_cluster' +
  186. '/' +
  187. 'nodes' +
  188. '/' +
  189. encodeURIComponent(node_id || nodeId) +
  190. '/' +
  191. 'hot_threads';
  192. } else {
  193. if (method == null) method = 'GET';
  194. path = '/' + '_nodes' + '/' + 'hot_threads';
  195. }
  196. // build request object
  197. const request = {
  198. method,
  199. path,
  200. body: null,
  201. querystring,
  202. };
  203. return this.transport.request(request, options, callback);
  204. };
  205. /**
  206. * Returns information about hot threads on each node in the cluster.
  207. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/nodes-apis/nodes-info/ OpenSearch - Nodes Info}
  208. * @memberOf API-Nodes
  209. *
  210. * @param {Object} params
  211. * @param {string} [params.node_id] - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
  212. * @param {string} [params.metric] - A comma-separated list of metrics you wish returned. Leave empty to return all. (options: settings, os, process, jvm, thread_pool, transport, http, plugins, ingest)
  213. * @param {boolean} [params.flat_settings] - Return settings in flat format (default: false)
  214. * @param {string} [params.timeout] - Explicit operation timeout
  215. *
  216. * @param {Object} options - Options for {@link Transport#request}
  217. * @param {function} callback - Callback that handles errors and response
  218. *
  219. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  220. */
  221. NodesApi.prototype.info = function nodesInfoApi(params, options, callback) {
  222. [params, options, callback] = normalizeArguments(params, options, callback);
  223. let { method, body, nodeId, node_id, metric, ...querystring } = params;
  224. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  225. let path = '';
  226. if ((node_id || nodeId) != null && metric != null) {
  227. if (method == null) method = 'GET';
  228. path =
  229. '/' +
  230. '_nodes' +
  231. '/' +
  232. encodeURIComponent(node_id || nodeId) +
  233. '/' +
  234. encodeURIComponent(metric);
  235. } else if ((node_id || nodeId) != null) {
  236. if (method == null) method = 'GET';
  237. path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId);
  238. } else if (metric != null) {
  239. if (method == null) method = 'GET';
  240. path = '/' + '_nodes' + '/' + encodeURIComponent(metric);
  241. } else {
  242. if (method == null) method = 'GET';
  243. path = '/' + '_nodes';
  244. }
  245. // build request object
  246. const request = {
  247. method,
  248. path,
  249. body: null,
  250. querystring,
  251. };
  252. return this.transport.request(request, options, callback);
  253. };
  254. /**
  255. * Reloads secure settings.
  256. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/nodes-apis/nodes-reload-secure/ OpenSearch - Nodes Reload Security Settings}
  257. * @memberOf API-Nodes
  258. *
  259. * @param {Object} params
  260. * @param {string} [params.node_id] - A comma-separated list of node IDs to span the reload/reinit call. Should stay empty because reloading usually involves all cluster nodes.
  261. * @param {string} [params.timeout] - Explicit operation timeout
  262. * @param {Object} [params.body] - An object containing the password for the opensearch keystore
  263. *
  264. * @param {Object} options - Options for {@link Transport#request}
  265. * @param {function} callback - Callback that handles errors and response
  266. *
  267. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  268. */
  269. NodesApi.prototype.reloadSecureSettings = function nodesReloadSecureSettingsApi(
  270. params,
  271. options,
  272. callback
  273. ) {
  274. [params, options, callback] = normalizeArguments(params, options, callback);
  275. let { method, body, nodeId, node_id, ...querystring } = params;
  276. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  277. let path = '';
  278. if ((node_id || nodeId) != null) {
  279. if (method == null) method = 'POST';
  280. path =
  281. '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'reload_secure_settings';
  282. } else {
  283. if (method == null) method = 'POST';
  284. path = '/' + '_nodes' + '/' + 'reload_secure_settings';
  285. }
  286. // build request object
  287. const request = {
  288. method,
  289. path,
  290. body: body || '',
  291. querystring,
  292. };
  293. return this.transport.request(request, options, callback);
  294. };
  295. /**
  296. * Returns statistical information about nodes in the cluster.
  297. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/nodes-apis/nodes-stats/ OpenSearch - Nodes Stats}
  298. * @memberOf API-Nodes
  299. *
  300. * @param {Object} params
  301. * @param {string} [params.node_id] - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
  302. * @param {string} [params.metric] - Limit the information returned to the specified metrics (options: _all, breaker, fs, http, indices, jvm, os, process, thread_pool, transport, discovery, indexing_pressure)
  303. * @param {string} [params.index_metric] - Limit the information returned for `indices` metric to the specific index metrics. Isn't used if `indices` (or `all`) metric isn't specified. (options: _all, completion, docs, fielddata, query_cache, flush, get, indexing, merge, request_cache, refresh, search, segments, store, warmer, suggest)
  304. * @param {string} [params.completion_fields] - A comma-separated list of fields for `fielddata` and `suggest` index metric (supports wildcards)
  305. * @param {string} [params.fielddata_fields] - A comma-separated list of fields for `fielddata` index metric (supports wildcards)
  306. * @param {string} [params.fields] - A comma-separated list of fields for `fielddata` and `completion` index metric (supports wildcards)
  307. * @param {boolean} [params.groups] - A comma-separated list of search groups for `search` index metric
  308. * @param {string} [params.level] - Return indices stats aggregated at index, node or shard level (options: indices, node, shards)
  309. * @param {string} [params.types] - A comma-separated list of document types for the `indexing` index metric
  310. * @param {string} [params.timeout] - Explicit operation timeout
  311. * @param {boolean} [params.include_segment_file_sizes] - Whether to report the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested)
  312. * @param {boolean} [params.include_unloaded_segments] - If set to true segment stats will include stats for segments that are not currently loaded into memory
  313. *
  314. * @param {Object} options - Options for {@link Transport#request}
  315. * @param {function} callback - Callback that handles errors and response
  316. *
  317. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  318. */
  319. NodesApi.prototype.stats = function nodesStatsApi(params, options, callback) {
  320. [params, options, callback] = normalizeArguments(params, options, callback);
  321. let { method, body, nodeId, node_id, metric, indexMetric, index_metric, ...querystring } = params;
  322. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  323. let path = '';
  324. if ((node_id || nodeId) != null && metric != null && (index_metric || indexMetric) != null) {
  325. if (method == null) method = 'GET';
  326. path =
  327. '/' +
  328. '_nodes' +
  329. '/' +
  330. encodeURIComponent(node_id || nodeId) +
  331. '/' +
  332. 'stats' +
  333. '/' +
  334. encodeURIComponent(metric) +
  335. '/' +
  336. encodeURIComponent(index_metric || indexMetric);
  337. } else if ((node_id || nodeId) != null && metric != null) {
  338. if (method == null) method = 'GET';
  339. path =
  340. '/' +
  341. '_nodes' +
  342. '/' +
  343. encodeURIComponent(node_id || nodeId) +
  344. '/' +
  345. 'stats' +
  346. '/' +
  347. encodeURIComponent(metric);
  348. } else if (metric != null && (index_metric || indexMetric) != null) {
  349. if (method == null) method = 'GET';
  350. path =
  351. '/' +
  352. '_nodes' +
  353. '/' +
  354. 'stats' +
  355. '/' +
  356. encodeURIComponent(metric) +
  357. '/' +
  358. encodeURIComponent(index_metric || indexMetric);
  359. } else if ((node_id || nodeId) != null) {
  360. if (method == null) method = 'GET';
  361. path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'stats';
  362. } else if (metric != null) {
  363. if (method == null) method = 'GET';
  364. path = '/' + '_nodes' + '/' + 'stats' + '/' + encodeURIComponent(metric);
  365. } else {
  366. if (method == null) method = 'GET';
  367. path = '/' + '_nodes' + '/' + 'stats';
  368. }
  369. // build request object
  370. const request = {
  371. method,
  372. path,
  373. body: null,
  374. querystring,
  375. };
  376. return this.transport.request(request, options, callback);
  377. };
  378. /**
  379. * Returns low-level information about REST actions usage on nodes.
  380. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/nodes-apis/nodes-usage/ OpenSearch - Nodes Usage}
  381. * @memberOf API-Nodes
  382. *
  383. * @param {Object} params
  384. * @param {string} [params.node_id] - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
  385. * @param {string} [params.metric] - Limit the information returned to the specified metrics (options: _all, rest_actions)
  386. * @param {string} [params.timeout] - Explicit operation timeout
  387. *
  388. * @param {Object} options - Options for {@link Transport#request}
  389. * @param {function} callback - Callback that handles errors and response
  390. *
  391. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  392. */
  393. NodesApi.prototype.usage = function nodesUsageApi(params, options, callback) {
  394. [params, options, callback] = normalizeArguments(params, options, callback);
  395. let { method, body, nodeId, node_id, metric, ...querystring } = params;
  396. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  397. let path = '';
  398. if ((node_id || nodeId) != null && metric != null) {
  399. if (method == null) method = 'GET';
  400. path =
  401. '/' +
  402. '_nodes' +
  403. '/' +
  404. encodeURIComponent(node_id || nodeId) +
  405. '/' +
  406. 'usage' +
  407. '/' +
  408. encodeURIComponent(metric);
  409. } else if ((node_id || nodeId) != null) {
  410. if (method == null) method = 'GET';
  411. path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'usage';
  412. } else if (metric != null) {
  413. if (method == null) method = 'GET';
  414. path = '/' + '_nodes' + '/' + 'usage' + '/' + encodeURIComponent(metric);
  415. } else {
  416. if (method == null) method = 'GET';
  417. path = '/' + '_nodes' + '/' + 'usage';
  418. }
  419. // build request object
  420. const request = {
  421. method,
  422. path,
  423. body: null,
  424. querystring,
  425. };
  426. return this.transport.request(request, options, callback);
  427. };
  428. Object.defineProperties(NodesApi.prototype, {
  429. clear_metering_archive: {
  430. get() {
  431. return this.clearMeteringArchive;
  432. },
  433. },
  434. get_metering_info: {
  435. get() {
  436. return this.getMeteringInfo;
  437. },
  438. },
  439. hot_threads: {
  440. get() {
  441. return this.hotThreads;
  442. },
  443. },
  444. reload_secure_settings: {
  445. get() {
  446. return this.reloadSecureSettings;
  447. },
  448. },
  449. });
  450. module.exports = NodesApi;