|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +'use strict' |
| 21 | + |
| 22 | +/* eslint camelcase: 0 */ |
| 23 | +/* eslint no-unused-vars: 0 */ |
| 24 | + |
| 25 | +const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils') |
| 26 | +const acceptedQuerystring = ['pretty', 'human', 'error_trace', 'source', 'filter_path'] |
| 27 | +const snakeCase = { errorTrace: 'error_trace', filterPath: 'filter_path' } |
| 28 | + |
| 29 | +function ShutdownApi (transport, ConfigurationError) { |
| 30 | + this.transport = transport |
| 31 | + this[kConfigurationError] = ConfigurationError |
| 32 | +} |
| 33 | + |
| 34 | +ShutdownApi.prototype.deleteNode = function shutdownDeleteNodeApi (params, options, callback) { |
| 35 | + ;[params, options, callback] = normalizeArguments(params, options, callback) |
| 36 | + |
| 37 | + // check required parameters |
| 38 | + if (params.node_id == null && params.nodeId == null) { |
| 39 | + const err = new this[kConfigurationError]('Missing required parameter: node_id or nodeId') |
| 40 | + return handleError(err, callback) |
| 41 | + } |
| 42 | + |
| 43 | + let { method, body, nodeId, node_id, ...querystring } = params |
| 44 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) |
| 45 | + |
| 46 | + let path = '' |
| 47 | + if (method == null) method = 'DELETE' |
| 48 | + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'shutdown' |
| 49 | + |
| 50 | + // build request object |
| 51 | + const request = { |
| 52 | + method, |
| 53 | + path, |
| 54 | + body: body || '', |
| 55 | + querystring |
| 56 | + } |
| 57 | + |
| 58 | + return this.transport.request(request, options, callback) |
| 59 | +} |
| 60 | + |
| 61 | +ShutdownApi.prototype.getNode = function shutdownGetNodeApi (params, options, callback) { |
| 62 | + ;[params, options, callback] = normalizeArguments(params, options, callback) |
| 63 | + |
| 64 | + let { method, body, nodeId, node_id, ...querystring } = params |
| 65 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) |
| 66 | + |
| 67 | + let path = '' |
| 68 | + if ((node_id || nodeId) != null) { |
| 69 | + if (method == null) method = 'GET' |
| 70 | + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'shutdown' |
| 71 | + } else { |
| 72 | + if (method == null) method = 'GET' |
| 73 | + path = '/' + '_nodes' + '/' + 'shutdown' |
| 74 | + } |
| 75 | + |
| 76 | + // build request object |
| 77 | + const request = { |
| 78 | + method, |
| 79 | + path, |
| 80 | + body: null, |
| 81 | + querystring |
| 82 | + } |
| 83 | + |
| 84 | + return this.transport.request(request, options, callback) |
| 85 | +} |
| 86 | + |
| 87 | +ShutdownApi.prototype.putNode = function shutdownPutNodeApi (params, options, callback) { |
| 88 | + ;[params, options, callback] = normalizeArguments(params, options, callback) |
| 89 | + |
| 90 | + // check required parameters |
| 91 | + if (params.node_id == null && params.nodeId == null) { |
| 92 | + const err = new this[kConfigurationError]('Missing required parameter: node_id or nodeId') |
| 93 | + return handleError(err, callback) |
| 94 | + } |
| 95 | + if (params.body == null) { |
| 96 | + const err = new this[kConfigurationError]('Missing required parameter: body') |
| 97 | + return handleError(err, callback) |
| 98 | + } |
| 99 | + |
| 100 | + let { method, body, nodeId, node_id, ...querystring } = params |
| 101 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) |
| 102 | + |
| 103 | + let path = '' |
| 104 | + if (method == null) method = 'PUT' |
| 105 | + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'shutdown' |
| 106 | + |
| 107 | + // build request object |
| 108 | + const request = { |
| 109 | + method, |
| 110 | + path, |
| 111 | + body: body || '', |
| 112 | + querystring |
| 113 | + } |
| 114 | + |
| 115 | + return this.transport.request(request, options, callback) |
| 116 | +} |
| 117 | + |
| 118 | +Object.defineProperties(ShutdownApi.prototype, { |
| 119 | + delete_node: { get () { return this.deleteNode } }, |
| 120 | + get_node: { get () { return this.getNode } }, |
| 121 | + put_node: { get () { return this.putNode } } |
| 122 | +}) |
| 123 | + |
| 124 | +module.exports = ShutdownApi |
0 commit comments