|
| 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 | +function buildDataFrameGetDataFrameTransformStats (opts) { |
| 26 | + // eslint-disable-next-line no-unused-vars |
| 27 | + const { makeRequest, ConfigurationError, handleError } = opts |
| 28 | + /** |
| 29 | + * Perform a [data_frame.get_data_frame_transform_stats](https://www.elastic.co/guide/en/elasticsearch/reference/current/get-data-frame-transform-stats.html) request |
| 30 | + * |
| 31 | + * @param {string} transform_id - The id of the transform for which to get stats. '_all' or '*' implies all transforms |
| 32 | + * @param {number} from - skips a number of transform stats, defaults to 0 |
| 33 | + * @param {number} size - specifies a max number of transform stats to get, defaults to 100 |
| 34 | + */ |
| 35 | + |
| 36 | + const acceptedQuerystring = [ |
| 37 | + 'from', |
| 38 | + 'size' |
| 39 | + ] |
| 40 | + |
| 41 | + const snakeCase = { |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | + return function dataFrameGetDataFrameTransformStats (params, options, callback) { |
| 46 | + options = options || {} |
| 47 | + if (typeof options === 'function') { |
| 48 | + callback = options |
| 49 | + options = {} |
| 50 | + } |
| 51 | + if (typeof params === 'function' || params == null) { |
| 52 | + callback = params |
| 53 | + params = {} |
| 54 | + options = {} |
| 55 | + } |
| 56 | + |
| 57 | + // check required parameters |
| 58 | + if (params.body != null) { |
| 59 | + const err = new ConfigurationError('This API does not require a body') |
| 60 | + return handleError(err, callback) |
| 61 | + } |
| 62 | + |
| 63 | + // validate headers object |
| 64 | + if (options.headers != null && typeof options.headers !== 'object') { |
| 65 | + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) |
| 66 | + return handleError(err, callback) |
| 67 | + } |
| 68 | + |
| 69 | + var warnings = null |
| 70 | + var { method, body, transformId, transform_id } = params |
| 71 | + var querystring = semicopy(params, ['method', 'body', 'transformId', 'transform_id']) |
| 72 | + |
| 73 | + if (method == null) { |
| 74 | + method = 'GET' |
| 75 | + } |
| 76 | + |
| 77 | + var ignore = options.ignore || null |
| 78 | + if (typeof ignore === 'number') { |
| 79 | + ignore = [ignore] |
| 80 | + } |
| 81 | + |
| 82 | + var path = '' |
| 83 | + |
| 84 | + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + '/' + '_stats' |
| 85 | + |
| 86 | + // build request object |
| 87 | + const request = { |
| 88 | + method, |
| 89 | + path, |
| 90 | + body: null, |
| 91 | + querystring |
| 92 | + } |
| 93 | + |
| 94 | + const requestOptions = { |
| 95 | + ignore, |
| 96 | + requestTimeout: options.requestTimeout || null, |
| 97 | + maxRetries: options.maxRetries || null, |
| 98 | + asStream: options.asStream || false, |
| 99 | + headers: options.headers || null, |
| 100 | + querystring: options.querystring || null, |
| 101 | + compression: options.compression || false, |
| 102 | + warnings |
| 103 | + } |
| 104 | + |
| 105 | + return makeRequest(request, requestOptions, callback) |
| 106 | + |
| 107 | + function semicopy (obj, exclude) { |
| 108 | + var target = {} |
| 109 | + var keys = Object.keys(obj) |
| 110 | + for (var i = 0, len = keys.length; i < len; i++) { |
| 111 | + var key = keys[i] |
| 112 | + if (exclude.indexOf(key) === -1) { |
| 113 | + target[snakeCase[key] || key] = obj[key] |
| 114 | + if (acceptedQuerystring.indexOf(snakeCase[key] || key) === -1) { |
| 115 | + warnings = warnings || [] |
| 116 | + warnings.push('Client - Unknown parameter: "' + key + '", sending it as query parameter') |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + return target |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +module.exports = buildDataFrameGetDataFrameTransformStats |
0 commit comments