Stopped overriding the ping method provided by the 1.0 API, but it didn't match the "castExists" regex so...
Fixed the lack of castExists for ping/1.0 by removing castExists all together from the API. It was the case anyway that all HEAD requests needed to be cast, so now the clientAction module will set that param when the spec is set to make HEAD requests. The transport.request still expects that parameter. Switched the apiVersion implementation to use funcEnum, and exposed the options on the Client constructor. Docs to come.
This commit is contained in:
@ -9,7 +9,6 @@ module.exports = function (branch, done) {
|
||||
var chalk = require('chalk');
|
||||
var path = require('path');
|
||||
var templates = require('./templates');
|
||||
var castExistsRE = /exists/;
|
||||
var usesBulkBodyRE = /^(bulk|msearch)$/;
|
||||
var urlParamRE = /\{(\w+)\}/g;
|
||||
|
||||
@ -167,10 +166,6 @@ module.exports = function (branch, done) {
|
||||
spec.bulkBody = true;
|
||||
}
|
||||
|
||||
if (castExistsRE.test(name)) {
|
||||
spec.castExists = true;
|
||||
}
|
||||
|
||||
var urls = _.difference(def.url.paths, aliases[name]);
|
||||
var urlSignatures = [];
|
||||
urls = _.map(urls, function (url) {
|
||||
@ -240,9 +235,7 @@ module.exports = function (branch, done) {
|
||||
'url',
|
||||
'urls',
|
||||
'needBody',
|
||||
'bulkBody',
|
||||
'castExists',
|
||||
'castNotFound'
|
||||
'bulkBody'
|
||||
]),
|
||||
location: location,
|
||||
docUrl: def.documentation,
|
||||
@ -283,11 +276,7 @@ module.exports = function (branch, done) {
|
||||
method = 'POST';
|
||||
}
|
||||
else if (methodsAre('GET', 'HEAD')) {
|
||||
if (action.spec.castExists) {
|
||||
method = 'HEAD';
|
||||
} else {
|
||||
method = 'GET';
|
||||
}
|
||||
method = 'GET';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Submodule src/elasticsearch updated: 258c49ea23...612044b386
119
src/lib/api.js
119
src/lib/api.js
@ -184,6 +184,53 @@ api.cat.prototype.allocation = ca({
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* Perform a [cat.count](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-count.html) request
|
||||
*
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false)
|
||||
* @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node
|
||||
* @param {String, String[], Boolean} params.h - Comma-separated list of column names to display
|
||||
* @param {Boolean} params.help - Return help information
|
||||
* @param {Boolean} params.v - Verbose mode. Display column headers
|
||||
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to limit the returned information
|
||||
*/
|
||||
api.cat.prototype.count = ca({
|
||||
params: {
|
||||
local: {
|
||||
type: 'boolean'
|
||||
},
|
||||
masterTimeout: {
|
||||
type: 'time',
|
||||
name: 'master_timeout'
|
||||
},
|
||||
h: {
|
||||
type: 'list'
|
||||
},
|
||||
help: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
},
|
||||
v: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
}
|
||||
},
|
||||
urls: [
|
||||
{
|
||||
fmt: '/_cat/count/<%=index%>',
|
||||
req: {
|
||||
index: {
|
||||
type: 'list'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
fmt: '/_cat/count'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* Perform a [cat.health](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-health.html) request
|
||||
*
|
||||
@ -192,6 +239,7 @@ api.cat.prototype.allocation = ca({
|
||||
* @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node
|
||||
* @param {String, String[], Boolean} params.h - Comma-separated list of column names to display
|
||||
* @param {Boolean} params.help - Return help information
|
||||
* @param {Boolean} [params.ts=true] - Set to false to disable timestamping
|
||||
* @param {Boolean} params.v - Verbose mode. Display column headers
|
||||
*/
|
||||
api.cat.prototype.health = ca({
|
||||
@ -210,6 +258,10 @@ api.cat.prototype.health = ca({
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
},
|
||||
ts: {
|
||||
type: 'boolean',
|
||||
'default': true
|
||||
},
|
||||
v: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
@ -247,6 +299,7 @@ api.cat.prototype.help = ca({
|
||||
* @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node
|
||||
* @param {String, String[], Boolean} params.h - Comma-separated list of column names to display
|
||||
* @param {Boolean} params.help - Return help information
|
||||
* @param {Boolean} params.pri - Set to true to return stats only for primary shards
|
||||
* @param {Boolean} params.v - Verbose mode. Display column headers
|
||||
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to limit the returned information
|
||||
*/
|
||||
@ -275,6 +328,10 @@ api.cat.prototype.indices = ca({
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
},
|
||||
pri: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
},
|
||||
v: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
@ -403,6 +460,63 @@ api.cat.prototype.pendingTasks = ca({
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Perform a [cat.recovery](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-recovery.html) request
|
||||
*
|
||||
* @param {Object} params - An object with parameters used to carry out this action
|
||||
* @param {String} params.bytes - The unit in which to display byte values
|
||||
* @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false)
|
||||
* @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node
|
||||
* @param {String, String[], Boolean} params.h - Comma-separated list of column names to display
|
||||
* @param {Boolean} params.help - Return help information
|
||||
* @param {Boolean} params.v - Verbose mode. Display column headers
|
||||
* @param {String, String[], Boolean} params.index - A comma-separated list of index names to limit the returned information
|
||||
*/
|
||||
api.cat.prototype.recovery = ca({
|
||||
params: {
|
||||
bytes: {
|
||||
type: 'enum',
|
||||
options: [
|
||||
'b',
|
||||
'k',
|
||||
'm',
|
||||
'g'
|
||||
]
|
||||
},
|
||||
local: {
|
||||
type: 'boolean'
|
||||
},
|
||||
masterTimeout: {
|
||||
type: 'time',
|
||||
name: 'master_timeout'
|
||||
},
|
||||
h: {
|
||||
type: 'list'
|
||||
},
|
||||
help: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
},
|
||||
v: {
|
||||
type: 'boolean',
|
||||
'default': false
|
||||
}
|
||||
},
|
||||
urls: [
|
||||
{
|
||||
fmt: '/_cat/recovery/<%=index%>',
|
||||
req: {
|
||||
index: {
|
||||
type: 'list'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
fmt: '/_cat/recovery'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* Perform a [cat.shards](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-shards.html) request
|
||||
*
|
||||
@ -1607,7 +1721,6 @@ api.exists = ca({
|
||||
},
|
||||
sortOrder: -3
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -2415,7 +2528,6 @@ api.indices.prototype.exists = ca({
|
||||
},
|
||||
sortOrder: -1
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -2481,7 +2593,6 @@ api.indices.prototype.existsAlias = ca({
|
||||
}
|
||||
}
|
||||
],
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -2501,7 +2612,6 @@ api.indices.prototype.existsTemplate = ca({
|
||||
},
|
||||
sortOrder: -1
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -2547,7 +2657,6 @@ api.indices.prototype.existsType = ca({
|
||||
},
|
||||
sortOrder: -2
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
|
||||
@ -775,7 +775,6 @@ api.exists = ca({
|
||||
},
|
||||
sortOrder: -3
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -1512,7 +1511,6 @@ api.indices.prototype.exists = ca({
|
||||
},
|
||||
sortOrder: -1
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -1557,7 +1555,6 @@ api.indices.prototype.existsAlias = ca({
|
||||
}
|
||||
}
|
||||
],
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
@ -1593,7 +1590,6 @@ api.indices.prototype.existsType = ca({
|
||||
},
|
||||
sortOrder: -2
|
||||
},
|
||||
castExists: true,
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
|
||||
@ -29,11 +29,6 @@ module.exports = Client;
|
||||
var Transport = require('./transport');
|
||||
var ca = require('./client_action');
|
||||
var _ = require('./utils');
|
||||
var defaultApi = 'master';
|
||||
var apis = {
|
||||
'0.90': require('./api_0_90'),
|
||||
'master': require('./api')
|
||||
};
|
||||
|
||||
function Client(config) {
|
||||
config = config || {};
|
||||
@ -48,14 +43,17 @@ function Client(config) {
|
||||
config.host = 'http://localhost:9200';
|
||||
}
|
||||
|
||||
this.ping = ca({
|
||||
method: 'HEAD',
|
||||
url: {
|
||||
fmt: '/'
|
||||
},
|
||||
castExists: true,
|
||||
requestTimeout: 100
|
||||
});
|
||||
if (!this.ping) {
|
||||
// 0.90 api does not include ping
|
||||
this.ping = ca({
|
||||
method: 'HEAD',
|
||||
url: {
|
||||
fmt: '/'
|
||||
},
|
||||
castExists: true,
|
||||
requestTimeout: 100
|
||||
});
|
||||
}
|
||||
|
||||
this.close = function () {
|
||||
this.transport.close();
|
||||
@ -71,12 +69,11 @@ function Client(config) {
|
||||
delete this._namespaces;
|
||||
}
|
||||
|
||||
var apiVersion = config.apiVersion || defaultApi;
|
||||
if (apis.hasOwnProperty(apiVersion)) {
|
||||
EsApiClient.prototype = apis[apiVersion];
|
||||
} else {
|
||||
throw new Error('Invalid apiVersion "' + apiVersion + '", expected one of ' + _.keys(apis).join(', '));
|
||||
}
|
||||
|
||||
EsApiClient.prototype = _.funcEnum(config, 'apiVersion', Client.apis, 'master');
|
||||
return new EsApiClient(config);
|
||||
}
|
||||
|
||||
Client.apis = {
|
||||
'master': require('./api'),
|
||||
'0.90': require('./api_0_90')
|
||||
};
|
||||
@ -196,8 +196,13 @@ function exec(transport, spec, params, cb) {
|
||||
}
|
||||
|
||||
// control params
|
||||
spec.bulkBody && (request.bulkBody = true);
|
||||
spec.castExists && (request.castExists = true);
|
||||
if (spec.bulkBody) {
|
||||
request.bulkBody = true;
|
||||
}
|
||||
|
||||
if (spec.method === 'HEAD') {
|
||||
request.castExists = true;
|
||||
}
|
||||
|
||||
// pick the url
|
||||
if (spec.url) {
|
||||
|
||||
@ -559,9 +559,9 @@ describe('Client Action runner', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes castExists', function (done) {
|
||||
it('sets castExists when the method in the spec is HEAD', function (done) {
|
||||
var action = makeClientAction({
|
||||
castExists: true
|
||||
method: 'HEAD'
|
||||
});
|
||||
|
||||
action({}, function (err, params) {
|
||||
|
||||
Reference in New Issue
Block a user