Source: api/api/cluster.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-Cluster */
  32. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  33. const acceptedQuerystring = [
  34. 'include_yes_decisions',
  35. 'include_disk_info',
  36. 'pretty',
  37. 'human',
  38. 'error_trace',
  39. 'source',
  40. 'filter_path',
  41. 'timeout',
  42. 'cluster_manager_timeout',
  43. 'master_timeout',
  44. 'wait_for_removal',
  45. 'local',
  46. 'flat_settings',
  47. 'include_defaults',
  48. 'expand_wildcards',
  49. 'level',
  50. 'wait_for_active_shards',
  51. 'wait_for_nodes',
  52. 'wait_for_events',
  53. 'wait_for_no_relocating_shards',
  54. 'wait_for_no_initializing_shards',
  55. 'wait_for_status',
  56. 'node_ids',
  57. 'node_names',
  58. 'create',
  59. 'dry_run',
  60. 'explain',
  61. 'retry_failed',
  62. 'metric',
  63. 'wait_for_metadata_version',
  64. 'wait_for_timeout',
  65. 'ignore_unavailable',
  66. 'allow_no_indices',
  67. ];
  68. const snakeCase = {
  69. includeYesDecisions: 'include_yes_decisions',
  70. includeDiskInfo: 'include_disk_info',
  71. errorTrace: 'error_trace',
  72. filterPath: 'filter_path',
  73. clusterManagerTimeout: 'cluster_manager_timeout',
  74. masterTimeout: 'master_timeout',
  75. waitForRemoval: 'wait_for_removal',
  76. flatSettings: 'flat_settings',
  77. includeDefaults: 'include_defaults',
  78. expandWildcards: 'expand_wildcards',
  79. waitForActiveShards: 'wait_for_active_shards',
  80. waitForNodes: 'wait_for_nodes',
  81. waitForEvents: 'wait_for_events',
  82. waitForNoRelocatingShards: 'wait_for_no_relocating_shards',
  83. waitForNoInitializingShards: 'wait_for_no_initializing_shards',
  84. waitForStatus: 'wait_for_status',
  85. nodeIds: 'node_ids',
  86. nodeNames: 'node_names',
  87. dryRun: 'dry_run',
  88. retryFailed: 'retry_failed',
  89. waitForMetadataVersion: 'wait_for_metadata_version',
  90. waitForTimeout: 'wait_for_timeout',
  91. ignoreUnavailable: 'ignore_unavailable',
  92. allowNoIndices: 'allow_no_indices',
  93. };
  94. function ClusterApi(transport, ConfigurationError) {
  95. this.transport = transport;
  96. this[kConfigurationError] = ConfigurationError;
  97. }
  98. /**
  99. * The most basic cluster allocation explain request finds an unassigned shard and explains why it can’t be allocated to a node. If you add some options, you can instead get information on a specific shard, including why OpenSearch assigned it to its current node.
  100. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/cluster-allocation/ OpenSearch - Cluster allocation explain}
  101. *
  102. * @memberOf API-Cluster
  103. *
  104. * @param {Object} params
  105. * @param {boolean} [params.include_yes_decisions=false] - OpenSearch makes a series of yes or no decisions when trying to allocate a shard to a node. If this parameter is true, OpenSearch includes the (generally more numerous) “yes” decisions in its response.
  106. * @param {boolean} [params.include_disk_info=false] - Whether to include information about disk usage in the response.
  107. * @param {Object} [params.body]
  108. * @param {string} [params.body.current_node] - If you only want an explanation if the shard happens to be on a particular node, specify that node name here.
  109. * @param {string} [params.body.index] - The name of the shard’s index.
  110. * @param {boolean} [params.body.primary] - Whether to provide an explanation for the primary shard (true) or its first replica (false), which share the same shard ID.
  111. * @param {number} [params.body.shard] - The shard ID that you want an explanation for.
  112. *
  113. * @param {Object} options - Options for {@link Transport#request}
  114. * @param {function} callback - Callback that handles errors and response
  115. *
  116. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/cluster-allocation/#response Cluster allocation explain Response}
  117. */
  118. ClusterApi.prototype.allocationExplain = function clusterAllocationExplainApi(
  119. params,
  120. options,
  121. callback
  122. ) {
  123. [params, options, callback] = normalizeArguments(params, options, callback);
  124. let { method, body, ...querystring } = params;
  125. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  126. let path = '';
  127. if (method == null) method = body == null ? 'GET' : 'POST';
  128. path = '/' + '_cluster' + '/' + 'allocation' + '/' + 'explain';
  129. // build request object
  130. const request = {
  131. method,
  132. path,
  133. body: body || '',
  134. querystring,
  135. };
  136. return this.transport.request(request, options, callback);
  137. };
  138. /**
  139. * Delete Component Template(s)
  140. *
  141. * @memberOf API-Cluster
  142. *
  143. * @param {Object} params
  144. * @param {string} [params.name] The name of the component template to be deleted.
  145. *
  146. * @param {Object} options - Options for {@link Transport#request}
  147. * @param {function} callback - Callback that handles errors and response
  148. *
  149. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  150. */
  151. ClusterApi.prototype.deleteComponentTemplate = function clusterDeleteComponentTemplateApi(
  152. params,
  153. options,
  154. callback
  155. ) {
  156. [params, options, callback] = normalizeArguments(params, options, callback);
  157. // check required parameters
  158. if (params.name == null) {
  159. const err = new this[kConfigurationError]('Missing required parameter: name');
  160. return handleError(err, callback);
  161. }
  162. let { method, body, name, ...querystring } = params;
  163. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  164. let path = '';
  165. if (method == null) method = 'DELETE';
  166. path = '/' + '_component_template' + '/' + encodeURIComponent(name);
  167. // build request object
  168. const request = {
  169. method,
  170. path,
  171. body: body || '',
  172. querystring,
  173. };
  174. return this.transport.request(request, options, callback);
  175. };
  176. /**
  177. * Clears cluster voting config exclusions.
  178. *
  179. * @memberOf API-Cluster
  180. *
  181. * @param {Object} params
  182. * @param {boolean} [params.wait_for_removal] Specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list.
  183. *
  184. * @param {Object} options - Options for {@link Transport#request}
  185. * @param {function} callback - Callback that handles errors and response
  186. *
  187. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  188. */
  189. ClusterApi.prototype.deleteVotingConfigExclusions = function clusterDeleteVotingConfigExclusionsApi(
  190. params,
  191. options,
  192. callback
  193. ) {
  194. [params, options, callback] = normalizeArguments(params, options, callback);
  195. let { method, body, ...querystring } = params;
  196. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  197. let path = '';
  198. if (method == null) method = 'DELETE';
  199. path = '/' + '_cluster' + '/' + 'voting_config_exclusions';
  200. // build request object
  201. const request = {
  202. method,
  203. path,
  204. body: body || '',
  205. querystring,
  206. };
  207. return this.transport.request(request, options, callback);
  208. };
  209. /**
  210. * Information about whether a particular component template exist
  211. *
  212. * @memberOf API-Cluster
  213. *
  214. * @param {Object} params
  215. * @param {boolean} [params.name] Name of the template
  216. *
  217. * @param {Object} options - Options for {@link Transport#request}
  218. * @param {function} callback - Callback that handles errors and response
  219. *
  220. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  221. */
  222. ClusterApi.prototype.existsComponentTemplate = function clusterExistsComponentTemplateApi(
  223. params,
  224. options,
  225. callback
  226. ) {
  227. [params, options, callback] = normalizeArguments(params, options, callback);
  228. // check required parameters
  229. if (params.name == null) {
  230. const err = new this[kConfigurationError]('Missing required parameter: name');
  231. return handleError(err, callback);
  232. }
  233. let { method, body, name, ...querystring } = params;
  234. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  235. let path = '';
  236. if (method == null) method = 'HEAD';
  237. path = '/' + '_component_template' + '/' + encodeURIComponent(name);
  238. // build request object
  239. const request = {
  240. method,
  241. path,
  242. body: null,
  243. querystring,
  244. };
  245. return this.transport.request(request, options, callback);
  246. };
  247. /**
  248. * Returns one or more component templates
  249. *
  250. * @memberOf API-Cluster
  251. *
  252. * @param {Object} params
  253. * @param {string | string[]} [params.name] Name(s) of the template(s)
  254. *
  255. * @param {Object} options - Options for {@link Transport#request}
  256. * @param {function} callback - Callback that handles errors and response
  257. *
  258. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  259. */
  260. ClusterApi.prototype.getComponentTemplate = function clusterGetComponentTemplateApi(
  261. params,
  262. options,
  263. callback
  264. ) {
  265. [params, options, callback] = normalizeArguments(params, options, callback);
  266. let { method, body, name, ...querystring } = params;
  267. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  268. let path = '';
  269. if (name != null) {
  270. if (method == null) method = 'GET';
  271. path = '/' + '_component_template' + '/' + encodeURIComponent(name);
  272. } else {
  273. if (method == null) method = 'GET';
  274. path = '/' + '_component_template';
  275. }
  276. // build request object
  277. const request = {
  278. method,
  279. path,
  280. body: null,
  281. querystring,
  282. };
  283. return this.transport.request(request, options, callback);
  284. };
  285. /**
  286. * Get Cluster Settings
  287. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/cluster-settings/ OpenSearch - Cluster Settings}
  288. * @memberOf API-Cluster
  289. *
  290. * @param {Object} params
  291. * ç
  292. * @param {boolean} [params.include_defaults] Whether to include default settings as part of the response. This parameter is useful for identifying the names and current values of settings you want to update.
  293. * @param {string} [params.cluster_manager_timeout=30s] - The amount of time to wait for a connection to the cluster manager node.
  294. *
  295. * @param {Object} options - Options for {@link Transport#request}
  296. * @param {function} callback - Callback that handles errors and response
  297. *
  298. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  299. */
  300. ClusterApi.prototype.getSettings = function clusterGetSettingsApi(params, options, callback) {
  301. [params, options, callback] = normalizeArguments(params, options, callback);
  302. let { method, body, ...querystring } = params;
  303. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  304. let path = '';
  305. if (method == null) method = 'GET';
  306. path = '/' + '_cluster' + '/' + 'settings';
  307. // build request object
  308. const request = {
  309. method,
  310. path,
  311. body: null,
  312. querystring,
  313. };
  314. return this.transport.request(request, options, callback);
  315. };
  316. /**
  317. * The most basic cluster health request returns a simple status of the health of your cluster. OpenSearch expresses cluster health in three colors: green, yellow, and red. A green status means all primary shards and their replicas are allocated to nodes. A yellow status means all primary shards are allocated to nodes, but some replicas aren’t. A red status means at least one primary shard is not allocated to any node.
  318. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/cluster-health/ OpenSearch - Cluster Health}
  319. * @memberOf API-Cluster
  320. *
  321. * @param {Object} params
  322. * @param {} [params.index] - To get the status of a specific index, provide the index name.
  323. * @param {string} [params.expand_wildcards=open] - Expands wildcard expressions to concrete indices. Combine multiple values with commas. Supported values are 'all', 'open', 'closed', 'hidden', and 'none'.
  324. * @param {string} [params.level=cluster] - The level of detail for returned health information. Supported values are 'cluster', 'indices', and 'shards'.
  325. * @param {boolean} [params.local=false] - Whether to return information from the local node only instead of from the cluster manager node.
  326. * @param {string} [params.cluster_manager_timeout=30s] - The amount of time to wait for a connection to the cluster manager node.
  327. * @param {string} [params.timeout=30s] - The amount of time to wait for a response from the cluster.
  328. * @param {string} [params.wait_for_active_shards=0] - Wait until the specified number of shards is active before returning a response. 'all' for all shards
  329. * @param {string} [params.wait_for_nodes] - Wait for N number of nodes. Use 12 for exact match, >12 and <12 for range.
  330. * @param {string} [params.wait_for_events] - Wait until all currently queued events with the given priority are processed. Supported values are 'immediate', 'urgent', 'high', 'normal', 'low', and 'languid'.
  331. * @param {boolean} [params.wait_for_no_relocating_shards=false] - Whether to wait until there are no relocating shards in the cluster.
  332. * @param {boolean} [params.wait_for_no_initializing_shards=false] - Whether to wait until there are no initializing shards in the cluster.
  333. * @param {string} [params.wait_for_status] - Wait until the cluster health reaches the specified status or better. Supported values are 'green', 'yellow', and 'red'.
  334. *
  335. * @param {Object} options - Options for {@link Transport#request}
  336. * @param {function} callback - Callback that handles errors and response
  337. *
  338. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/cluster-health/#response Cluster Health Response}
  339. */
  340. ClusterApi.prototype.health = function clusterHealthApi(params, options, callback) {
  341. [params, options, callback] = normalizeArguments(params, options, callback);
  342. let { method, body, index, ...querystring } = params;
  343. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  344. let path = '';
  345. if (index != null) {
  346. if (method == null) method = 'GET';
  347. path = '/' + '_cluster' + '/' + 'health' + '/' + encodeURIComponent(index);
  348. } else {
  349. if (method == null) method = 'GET';
  350. path = '/' + '_cluster' + '/' + 'health';
  351. }
  352. // build request object
  353. const request = {
  354. method,
  355. path,
  356. body: null,
  357. querystring,
  358. };
  359. return this.transport.request(request, options, callback);
  360. };
  361. /**
  362. * Get a list of any cluster-level changes
  363. * @memberOf API-Cluster
  364. *
  365. * @param {Object} params
  366. * @param {boolean} [params.local=false] - Whether to return information from the local node only instead of from the cluster manager node.
  367. * @param {string} [params.cluster_manager_timeout=30s] - The amount of time to wait for a connection to the cluster manager node.
  368. *
  369. * @param {Object} options - Options for {@link Transport#request}
  370. * @param {function} callback - Callback that handles errors and response
  371. *
  372. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  373. */
  374. ClusterApi.prototype.pendingTasks = function clusterPendingTasksApi(params, options, callback) {
  375. [params, options, callback] = normalizeArguments(params, options, callback);
  376. let { method, body, ...querystring } = params;
  377. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  378. let path = '';
  379. if (method == null) method = 'GET';
  380. path = '/' + '_cluster' + '/' + 'pending_tasks';
  381. // build request object
  382. const request = {
  383. method,
  384. path,
  385. body: null,
  386. querystring,
  387. };
  388. return this.transport.request(request, options, callback);
  389. };
  390. /**
  391. * Updates the cluster voting config exclusions by node ids or node names.
  392. * @memberOf API-Cluster
  393. *
  394. * @param {Object} params
  395. * @param {string} [params.node_names] - A comma-separated list of the persistent ids of the nodes to exclude from the voting configuration. If specified, you may not also specify node_names.
  396. * @param {string} [params.node_ids] - A comma-separated list of the names of the nodes to exclude from the voting configuration. If specified, you may not also specify node_ids.
  397. *
  398. * @param {Object} options - Options for {@link Transport#request}
  399. * @param {function} callback - Callback that handles errors and response
  400. *
  401. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  402. */
  403. ClusterApi.prototype.postVotingConfigExclusions = function clusterPostVotingConfigExclusionsApi(
  404. params,
  405. options,
  406. callback
  407. ) {
  408. [params, options, callback] = normalizeArguments(params, options, callback);
  409. let { method, body, ...querystring } = params;
  410. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  411. let path = '';
  412. if (method == null) method = 'POST';
  413. path = '/' + '_cluster' + '/' + 'voting_config_exclusions';
  414. // build request object
  415. const request = {
  416. method,
  417. path,
  418. body: body || '',
  419. querystring,
  420. };
  421. return this.transport.request(request, options, callback);
  422. };
  423. /**
  424. * Creates or updates a component template
  425. *
  426. * @memberOf API-Cluster
  427. *
  428. * @param {Object} params
  429. * @param {string} params.name - The name of the component template.
  430. * @param {object} params.body - The template definition.
  431. * @param {string} [params.cluster_manager_timeout=30s] - The amount of time to wait for a connection to the cluster manager node.
  432. * @param {boolean} [params.create=false] - Whether the index template should only be added if new or can also replace an existing one.
  433. *
  434. * @param {Object} options - Options for {@link Transport#request}
  435. * @param {function} callback - Callback that handles errors and response
  436. *
  437. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  438. */
  439. ClusterApi.prototype.putComponentTemplate = function clusterPutComponentTemplateApi(
  440. params,
  441. options,
  442. callback
  443. ) {
  444. [params, options, callback] = normalizeArguments(params, options, callback);
  445. // check required parameters
  446. if (params.name == null) {
  447. const err = new this[kConfigurationError]('Missing required parameter: name');
  448. return handleError(err, callback);
  449. }
  450. if (params.body == null) {
  451. const err = new this[kConfigurationError]('Missing required parameter: body');
  452. return handleError(err, callback);
  453. }
  454. let { method, body, name, ...querystring } = params;
  455. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  456. let path = '';
  457. if (method == null) method = 'PUT';
  458. path = '/' + '_component_template' + '/' + encodeURIComponent(name);
  459. // build request object
  460. const request = {
  461. method,
  462. path,
  463. body: body || '',
  464. querystring,
  465. };
  466. return this.transport.request(request, options, callback);
  467. };
  468. /**
  469. * Updates the cluster settings.
  470. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/cluster-settings/ OpenSearch - Cluster Settings}
  471. * @memberOf API-Cluster
  472. *
  473. * @param {Object} params
  474. * @param {boolean} [params.flat_settings] Whether to return settings in the flat form, which can improve readability, especially for heavily nested settings.
  475. * @param {string} [params.cluster_manager_timeout=30s] - The amount of time to wait for a connection to the cluster manager node.
  476. * @param {string} [params.timeout=30s] - The amount of time to wait for a response from the cluster.
  477. * @param {object} params.body - The settings to be updated. Can be either 'transient' or 'persistent' (survives cluster restart).
  478. *
  479. * @param {Object} options - Options for {@link Transport#request}
  480. * @param {function} callback - Callback that handles errors and response
  481. *
  482. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  483. */
  484. ClusterApi.prototype.putSettings = function clusterPutSettingsApi(params, options, callback) {
  485. [params, options, callback] = normalizeArguments(params, options, callback);
  486. // check required parameters
  487. if (params.body == null) {
  488. const err = new this[kConfigurationError]('Missing required parameter: body');
  489. return handleError(err, callback);
  490. }
  491. let { method, body, ...querystring } = params;
  492. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  493. let path = '';
  494. if (method == null) method = 'PUT';
  495. path = '/' + '_cluster' + '/' + 'settings';
  496. // build request object
  497. const request = {
  498. method,
  499. path,
  500. body: body || '',
  501. querystring,
  502. };
  503. return this.transport.request(request, options, callback);
  504. };
  505. /**
  506. * This operation provides connection information for any remote OpenSearch clusters that you’ve configured for the local cluster, such as the remote cluster alias, connection mode (sniff or proxy), IP addresses for seed nodes, and timeout settings.
  507. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/remote-info/ OpenSearch - Remote cluster information}
  508. * @memberOf API-Cluster
  509. *
  510. * @param {Object} params - (Unused)
  511. * @param {Object} options - Options for {@link Transport#request}
  512. * @param {function} callback - Callback that handles errors and response
  513. *
  514. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/remote-info/#response Remote cluster information }
  515. */
  516. ClusterApi.prototype.remoteInfo = function clusterRemoteInfoApi(params, options, callback) {
  517. [params, options, callback] = normalizeArguments(params, options, callback);
  518. let { method, body, ...querystring } = params;
  519. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  520. let path = '';
  521. if (method == null) method = 'GET';
  522. path = '/' + '_remote' + '/' + 'info';
  523. // build request object
  524. const request = {
  525. method,
  526. path,
  527. body: null,
  528. querystring,
  529. };
  530. return this.transport.request(request, options, callback);
  531. };
  532. /**
  533. * Allows to manually change the allocation of individual shards in the cluster.
  534. *
  535. * @memberOf API-Cluster
  536. *
  537. * @param {Object} params
  538. * @param {object} [params.body] - The definition of 'commands' to perform ('move', 'cancel', 'allocate')
  539. * @param {boolean} [params.dry_run] - Simulate the operation only and return the resulting state
  540. * @param {boolean} [params.explain] - Return an explanation of why the commands can or cannot be executed
  541. * @param {boolean} [params.retry_failed] - Retries allocation of shards that are blocked due to too many subsequent allocation failures
  542. * @param {string | string[]} [params.metric] - Limit the information returned to the specified metrics. Defaults to all but metadata (options: _all, blocks, metadata, nodes, routing_table, cluster_manager_node, version)
  543. *
  544. * @param {Object} options - Options for {@link Transport#request}
  545. * @param {function} callback - Callback that handles errors and response
  546. *
  547. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  548. */
  549. ClusterApi.prototype.reroute = function clusterRerouteApi(params, options, callback) {
  550. [params, options, callback] = normalizeArguments(params, options, callback);
  551. let { method, body, ...querystring } = params;
  552. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  553. let path = '';
  554. if (method == null) method = 'POST';
  555. path = '/' + '_cluster' + '/' + 'reroute';
  556. // build request object
  557. const request = {
  558. method,
  559. path,
  560. body: body || '',
  561. querystring,
  562. };
  563. return this.transport.request(request, options, callback);
  564. };
  565. /**
  566. * Get comprehensive information about the state of the cluster.
  567. *
  568. * @memberOf API-Cluster
  569. *
  570. * @param {Object} params
  571. * @param {string | string[]} [params.metric] - Limit the information returned to the specified metrics. Defaults to all but metadata (options: _all, blocks, metadata, nodes, routing_table, cluster_manager_node, version).
  572. * @param {string | string[]} [params.index] - List of index names; use '_all' or empty string to perform the operation on all indices.
  573. * @param {boolean} [params.local=false] - Whether to return information from the local node only instead of from the cluster manager node.
  574. * @param {string} [params.cluster_manager_timeout=30s] - The amount of time to wait for a connection to the cluster manager node.
  575. * @param {boolean} [params.flat_settings=false] - Whether to return settings in the flat form, which can improve readability, especially for heavily nested settings.
  576. * @param {number} [params.wait_for_metadata_version] - Wait for the metadata version to be equal or greater than the specified metadata version.
  577. * @param {string} [params.wait_for_timeout=30s] - The maximum time to wait for wait_for_metadata_version before timing out
  578. * @param {boolean} [params.ignore_unavailable] - Whether specified concrete indices should be ignored when unavailable (missing or closed)
  579. * @param {boolean} [params.allow_no_indices] - Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
  580. * @param {string} [params.expand_wildcards=open] - Expands wildcard expressions to concrete indices. Combine multiple values with commas. Supported values are 'all', 'open', 'closed', 'hidden', and 'none'. Default is 'open'.
  581. *
  582. * @param {Object} options - Options for {@link Transport#request}
  583. * @param {function} callback - Callback that handles errors and response
  584. *
  585. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  586. */
  587. ClusterApi.prototype.state = function clusterStateApi(params, options, callback) {
  588. [params, options, callback] = normalizeArguments(params, options, callback);
  589. // check required url components
  590. if (params.index != null && params.metric == null) {
  591. const err = new this[kConfigurationError]('Missing required parameter of the url: metric');
  592. return handleError(err, callback);
  593. }
  594. let { method, body, metric, index, ...querystring } = params;
  595. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  596. let path = '';
  597. if (metric != null && index != null) {
  598. if (method == null) method = 'GET';
  599. path =
  600. '/' +
  601. '_cluster' +
  602. '/' +
  603. 'state' +
  604. '/' +
  605. encodeURIComponent(metric) +
  606. '/' +
  607. encodeURIComponent(index);
  608. } else if (metric != null) {
  609. if (method == null) method = 'GET';
  610. path = '/' + '_cluster' + '/' + 'state' + '/' + encodeURIComponent(metric);
  611. } else {
  612. if (method == null) method = 'GET';
  613. path = '/' + '_cluster' + '/' + 'state';
  614. }
  615. // build request object
  616. const request = {
  617. method,
  618. path,
  619. body: null,
  620. querystring,
  621. };
  622. return this.transport.request(request, options, callback);
  623. };
  624. /**
  625. * The CAT aliases operation lists the mapping of aliases to indices, plus routing and filtering information.
  626. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/cluster-stats/ OpenSearch - Cluster stats}
  627. *
  628. * @memberOf API-Cluster
  629. *
  630. * @param {Object} params
  631. * @param {string | 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.
  632. *
  633. *
  634. * @param {Object} [options] - Options for {@link Transport#request}
  635. * @param {function} [callback] - Callback that handles errors and response
  636. *
  637. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/cluster-stats/#response Cluster stats Response}
  638. */
  639. ClusterApi.prototype.stats = function clusterStatsApi(params, options, callback) {
  640. [params, options, callback] = normalizeArguments(params, options, callback);
  641. let { method, body, nodeId, node_id, ...querystring } = params;
  642. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  643. let path = '';
  644. if ((node_id || nodeId) != null) {
  645. if (method == null) method = 'GET';
  646. path =
  647. '/' +
  648. '_cluster' +
  649. '/' +
  650. 'stats' +
  651. '/' +
  652. 'nodes' +
  653. '/' +
  654. encodeURIComponent(node_id || nodeId);
  655. } else {
  656. if (method == null) method = 'GET';
  657. path = '/' + '_cluster' + '/' + 'stats';
  658. }
  659. // build request object
  660. const request = {
  661. method,
  662. path,
  663. body: null,
  664. querystring,
  665. };
  666. return this.transport.request(request, options, callback);
  667. };
  668. Object.defineProperties(ClusterApi.prototype, {
  669. allocation_explain: {
  670. get() {
  671. return this.allocationExplain;
  672. },
  673. },
  674. delete_component_template: {
  675. get() {
  676. return this.deleteComponentTemplate;
  677. },
  678. },
  679. delete_voting_config_exclusions: {
  680. get() {
  681. return this.deleteVotingConfigExclusions;
  682. },
  683. },
  684. exists_component_template: {
  685. get() {
  686. return this.existsComponentTemplate;
  687. },
  688. },
  689. get_component_template: {
  690. get() {
  691. return this.getComponentTemplate;
  692. },
  693. },
  694. get_settings: {
  695. get() {
  696. return this.getSettings;
  697. },
  698. },
  699. pending_tasks: {
  700. get() {
  701. return this.pendingTasks;
  702. },
  703. },
  704. post_voting_config_exclusions: {
  705. get() {
  706. return this.postVotingConfigExclusions;
  707. },
  708. },
  709. put_component_template: {
  710. get() {
  711. return this.putComponentTemplate;
  712. },
  713. },
  714. put_settings: {
  715. get() {
  716. return this.putSettings;
  717. },
  718. },
  719. remote_info: {
  720. get() {
  721. return this.remoteInfo;
  722. },
  723. },
  724. });
  725. module.exports = ClusterApi;