Source: api/api/dangling_indices.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-Dangling-Indices */
  32. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  33. const acceptedQuerystring = [
  34. 'accept_data_loss',
  35. 'timeout',
  36. 'cluster_manager_timeout',
  37. 'master_timeout',
  38. 'pretty',
  39. 'human',
  40. 'error_trace',
  41. 'source',
  42. 'filter_path',
  43. ];
  44. const snakeCase = {
  45. acceptDataLoss: 'accept_data_loss',
  46. clusterManagerTimeout: 'cluster_manager_timeout',
  47. masterTimeout: 'master_timeout',
  48. errorTrace: 'error_trace',
  49. filterPath: 'filter_path',
  50. };
  51. function DanglingIndicesApi(transport, ConfigurationError) {
  52. this.transport = transport;
  53. this[kConfigurationError] = ConfigurationError;
  54. }
  55. /**
  56. * Deletes the specified dangling index
  57. * <br/> See also: {@link https://opensearch.org/docs/latest/api-reference/index-apis/dangling-index/ OpenSearch - Dangling Indexes}
  58. * @memberOf API-Dangling-Indices
  59. *
  60. * @param {Object} params
  61. * @param {string} params.index_uuid - The UUID of the dangling index
  62. * @param {boolean} [params.accept_data_loss] - Must be set to true in order to delete the dangling index
  63. * @param {string} [params.timeout=30s] - Explicit operation timeout
  64. * @param {string} [params.cluster_manager_timeout] - Specify timeout for connection to cluster_manager
  65. *
  66. * @param {Object} [options] - Options for {@link Transport#request}
  67. * @param {function} [callback] - Callback that handles errors and response
  68. *
  69. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  70. */
  71. DanglingIndicesApi.prototype.deleteDanglingIndex = function danglingIndicesDeleteDanglingIndexApi(
  72. params,
  73. options,
  74. callback
  75. ) {
  76. [params, options, callback] = normalizeArguments(params, options, callback);
  77. // check required parameters
  78. if (params.index_uuid == null && params.indexUuid == null) {
  79. const err = new this[kConfigurationError](
  80. 'Missing required parameter: index_uuid or indexUuid'
  81. );
  82. return handleError(err, callback);
  83. }
  84. let { method, body, indexUuid, index_uuid, ...querystring } = params;
  85. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  86. let path = '';
  87. if (method == null) method = 'DELETE';
  88. path = '/' + '_dangling' + '/' + encodeURIComponent(index_uuid || indexUuid);
  89. // build request object
  90. const request = {
  91. method,
  92. path,
  93. body: body || '',
  94. querystring,
  95. };
  96. return this.transport.request(request, options, callback);
  97. };
  98. /**
  99. * Imports the specified dangling index
  100. * <br/> See also: {@link https://opensearch.org/docs/latest/api-reference/index-apis/dangling-index/ OpenSearch - Dangling Indexes}
  101. * @memberOf API-Dangling-Indices
  102. *
  103. * @param {Object} params
  104. * @param {string} params.index_uuid - The UUID of the dangling index
  105. * @param {boolean} [params.accept_data_loss] - Must be set to true in order to delete the dangling index
  106. * @param {string} [params.timeout=30s] - Explicit operation timeout
  107. * @param {string} [params.cluster_manager_timeout] - Specify timeout for connection to cluster_manager
  108. *
  109. * @param {Object} [options] - Options for {@link Transport#request}
  110. * @param {function} [callback] - Callback that handles errors and response
  111. *
  112. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  113. */
  114. DanglingIndicesApi.prototype.importDanglingIndex = function danglingIndicesImportDanglingIndexApi(
  115. params,
  116. options,
  117. callback
  118. ) {
  119. [params, options, callback] = normalizeArguments(params, options, callback);
  120. // check required parameters
  121. if (params.index_uuid == null && params.indexUuid == null) {
  122. const err = new this[kConfigurationError](
  123. 'Missing required parameter: index_uuid or indexUuid'
  124. );
  125. return handleError(err, callback);
  126. }
  127. let { method, body, indexUuid, index_uuid, ...querystring } = params;
  128. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  129. let path = '';
  130. if (method == null) method = 'POST';
  131. path = '/' + '_dangling' + '/' + encodeURIComponent(index_uuid || indexUuid);
  132. // build request object
  133. const request = {
  134. method,
  135. path,
  136. body: body || '',
  137. querystring,
  138. };
  139. return this.transport.request(request, options, callback);
  140. };
  141. /**
  142. * Retrieve all dangling indices.
  143. * <br/> See also: {@link https://opensearch.org/docs/latest/api-reference/index-apis/dangling-index/ OpenSearch - Dangling Indexes}
  144. * @memberOf API-Dangling-Indices
  145. *
  146. * @param {Object} params - (Unused)
  147. * @param {Object} [options] - Options for {@link Transport#request}
  148. * @param {function} [callback] - Callback that handles errors and response
  149. *
  150. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  151. */
  152. DanglingIndicesApi.prototype.listDanglingIndices = function danglingIndicesListDanglingIndicesApi(
  153. params,
  154. options,
  155. callback
  156. ) {
  157. [params, options, callback] = normalizeArguments(params, options, callback);
  158. let { method, body, ...querystring } = params;
  159. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  160. let path = '';
  161. if (method == null) method = 'GET';
  162. path = '/' + '_dangling';
  163. // build request object
  164. const request = {
  165. method,
  166. path,
  167. body: null,
  168. querystring,
  169. };
  170. return this.transport.request(request, options, callback);
  171. };
  172. Object.defineProperties(DanglingIndicesApi.prototype, {
  173. delete_dangling_index: {
  174. get() {
  175. return this.deleteDanglingIndex;
  176. },
  177. },
  178. import_dangling_index: {
  179. get() {
  180. return this.importDanglingIndex;
  181. },
  182. },
  183. list_dangling_indices: {
  184. get() {
  185. return this.listDanglingIndices;
  186. },
  187. },
  188. });
  189. module.exports = DanglingIndicesApi;