From af69d1810899660559bd730650b5f5b1102ed2bb Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Mon, 27 Oct 2014 23:14:36 -0700 Subject: [PATCH] [generate/aliases] merge the aliases into a single file --- package.json | 1 + scripts/generate/aliases.js | 264 +++++++++++++++++++------------ scripts/generate/aliases_0_90.js | 60 ------- scripts/generate/js_api.js | 25 ++- 4 files changed, 185 insertions(+), 165 deletions(-) delete mode 100644 scripts/generate/aliases_0_90.js diff --git a/package.json b/package.json index 5b0732bb5..674511560 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "nock": "~0.28.3", "open": "0.0.4", "optimist": "~0.6.0", + "semver": "~4.1.0", "sinon": "~1.7.3", "xmlbuilder": "~0.4.3" }, diff --git a/scripts/generate/aliases.js b/scripts/generate/aliases.js index 2c805ef18..3c4170ac9 100644 --- a/scripts/generate/aliases.js +++ b/scripts/generate/aliases.js @@ -1,98 +1,166 @@ -module.exports = { - 'nodes.hotThreads': [ - '/_cluster/nodes/hotthreads', - '/_cluster/nodes/hot_threads', - '/_nodes/hot_threads', - '/_cluster/nodes/{node_id}/hotthreads', - '/_cluster/nodes/{node_id}/hot_threads', - '/_nodes/{node_id}/hot_threads' - ], - 'nodes.info': [ - '/_cluster/nodes', - '/_nodes/settings', - '/_nodes/os', - '/_nodes/process', - '/_nodes/jvm', - '/_nodes/thread_pool', - '/_nodes/network', - '/_nodes/transport', - '/_nodes/http', - '/_nodes/plugin', - '/_cluster/nodes/{node_id}', - '/_nodes/{node_id}/settings', - '/_nodes/{node_id}/os', - '/_nodes/{node_id}/process', - '/_nodes/{node_id}/jvm', - '/_nodes/{node_id}/thread_pool', - '/_nodes/{node_id}/network', - '/_nodes/{node_id}/transport', - '/_nodes/{node_id}/http', - '/_nodes/{node_id}/plugin' - ], - 'nodes.shutdown': [ - '/_cluster/nodes/_shutdown' - ], - 'nodes.stats': [ - '/_cluster/nodes/stats', - '/_nodes/stats/{metric_family}', - '/_nodes/stats/indices/{metric}/{fields}', - '/_cluster/nodes/{node_id}/stats', - '/_nodes/{node_id}/stats/{metric_family}', - '/_nodes/{node_id}/stats/indices/{metric}/{fields}' - ], - 'get': [ - '/{index}/{type}/{id}/_source' - ], - 'indices.deleteMapping': [ - '/{index}/{type}', - '/{index}/_mapping/{type}', - '/{index}/{type}/_mappings', - '/{index}/_mappings/{type}' - ], - 'indices.putWarmer': [ - // '/_warmer/{name}', - // '/{index}/_warmer/{name}', - // '/{index}/{type}/_warmer/{name}', - '/_warmers/{name}', - '/{index}/_warmers/{name}', - '/{index}/{type}/_warmers/{name}' - ], - 'indices.deleteWarmer': [ - // '/{index}/_warmer/{name}', - '/{index}/_warmer', - '/{index}/_warmers', - '/{index}/_warmers/{name}' - ], - 'indices.deleteAlias': [ - // '/{index}/_alias/{name}', - '/{index}/_aliases/{name}' - ], - 'indices.putAlias': [ - // '/{index}/_alias/{name}', - // '/_alias/{name}', - '/{index}/_aliases/{name}', - '/_aliases/{name}' - ], - 'indices.putMapping': [ - // '/{index}/_mapping/{type}', - // '/_mapping/{type}', - '/{index}/{type}/_mapping', - '/{index}/{type}/_mappings', - '/{index}/_mappings/{type}', - '/_mappings/{type}' - ], - 'indices.stats': [ - '_stats/{metric_family}', - '/_stats/indexing', - '/_stats/indexing/{indexing_types}', - '/_stats/search/{search_groups}', - '/_stats/fielddata/{fields}', - '/{index}/_stats/{metric_family}', - '/{index}/_stats/indexing', - '/{index}/_stats/search/{search_groups}', - '/{index}/_stats/fielddata/{fields}' - ], - 'snapshot.create': [ - '/_snapshot/{repository}/{snapshot}/_create' - ] -}; \ No newline at end of file +module.exports = [ + { + version: '0.90.x', + aliases: { + 'cluster.nodeHotThreads': [ + '/_cluster/nodes/hotthreads', + '/_cluster/nodes/hot_threads', + '/_nodes/hot_threads', + '/_cluster/nodes/{node_id}/hotthreads', + '/_cluster/nodes/{node_id}/hot_threads', + '/_nodes/{node_id}/hot_threads' + ], + 'cluster.nodeInfo': [ + '/_cluster/nodes', + '/_nodes/settings', + '/_nodes/os', + '/_nodes/process', + '/_nodes/jvm', + '/_nodes/thread_pool', + '/_nodes/network', + '/_nodes/transport', + '/_nodes/http', + '/_nodes/plugin', + '/_cluster/nodes/{node_id}', + '/_nodes/{node_id}/settings', + '/_nodes/{node_id}/os', + '/_nodes/{node_id}/process', + '/_nodes/{node_id}/jvm', + '/_nodes/{node_id}/thread_pool', + '/_nodes/{node_id}/network', + '/_nodes/{node_id}/transport', + '/_nodes/{node_id}/http', + '/_nodes/{node_id}/plugin' + ], + 'cluster.nodeShutdown': [ + '/_cluster/nodes/_shutdown' + ], + 'cluster.nodeStats': [ + '/_cluster/nodes/stats', + '/_nodes/stats/{metric_family}', + '/_nodes/stats/indices/{metric}/{fields}', + '/_cluster/nodes/{node_id}/stats', + '/_nodes/{node_id}/stats/{metric_family}', + '/_nodes/{node_id}/stats/indices/{metric}/{fields}' + ], + 'get': [ + '/{index}/{type}/{id}/_source' + ], + 'indices.deleteMapping': [ + '/{index}/{type}/_mapping' + ], + 'indices.stats': [ + '_stats/{metric_family}', + '/_stats/indexing', + '/_stats/indexing/{indexing_types}', + '/_stats/search/{search_groups}', + '/_stats/fielddata/{fields}', + '/{index}/_stats/{metric_family}', + '/{index}/_stats/indexing', + '/{index}/_stats/search/{search_groups}', + '/{index}/_stats/fielddata/{fields}' + ] + } + }, + { + version: '>=1.0.0', + aliases: { + 'nodes.hotThreads': [ + '/_cluster/nodes/hotthreads', + '/_cluster/nodes/hot_threads', + '/_nodes/hot_threads', + '/_cluster/nodes/{node_id}/hotthreads', + '/_cluster/nodes/{node_id}/hot_threads', + '/_nodes/{node_id}/hot_threads' + ], + 'nodes.info': [ + '/_cluster/nodes', + '/_nodes/settings', + '/_nodes/os', + '/_nodes/process', + '/_nodes/jvm', + '/_nodes/thread_pool', + '/_nodes/network', + '/_nodes/transport', + '/_nodes/http', + '/_nodes/plugin', + '/_cluster/nodes/{node_id}', + '/_nodes/{node_id}/settings', + '/_nodes/{node_id}/os', + '/_nodes/{node_id}/process', + '/_nodes/{node_id}/jvm', + '/_nodes/{node_id}/thread_pool', + '/_nodes/{node_id}/network', + '/_nodes/{node_id}/transport', + '/_nodes/{node_id}/http', + '/_nodes/{node_id}/plugin' + ], + 'nodes.shutdown': [ + '/_cluster/nodes/_shutdown' + ], + 'nodes.stats': [ + '/_cluster/nodes/stats', + '/_nodes/stats/{metric_family}', + '/_nodes/stats/indices/{metric}/{fields}', + '/_cluster/nodes/{node_id}/stats', + '/_nodes/{node_id}/stats/{metric_family}', + '/_nodes/{node_id}/stats/indices/{metric}/{fields}' + ], + 'get': [ + '/{index}/{type}/{id}/_source' + ], + 'indices.deleteMapping': [ + '/{index}/{type}', + '/{index}/_mapping/{type}', + '/{index}/{type}/_mappings', + '/{index}/_mappings/{type}' + ], + 'indices.putWarmer': [ + // '/_warmer/{name}', + // '/{index}/_warmer/{name}', + // '/{index}/{type}/_warmer/{name}', + '/_warmers/{name}', + '/{index}/_warmers/{name}', + '/{index}/{type}/_warmers/{name}' + ], + 'indices.deleteWarmer': [ + // '/{index}/_warmer/{name}', + '/{index}/_warmer', + '/{index}/_warmers', + '/{index}/_warmers/{name}' + ], + 'indices.deleteAlias': [ + // '/{index}/_alias/{name}', + '/{index}/_aliases/{name}' + ], + 'indices.putAlias': [ + // '/{index}/_alias/{name}', + // '/_alias/{name}', + '/{index}/_aliases/{name}', + '/_aliases/{name}' + ], + 'indices.putMapping': [ + // '/{index}/_mapping/{type}', + // '/_mapping/{type}', + '/{index}/{type}/_mapping', + '/{index}/{type}/_mappings', + '/{index}/_mappings/{type}', + '/_mappings/{type}' + ], + 'indices.stats': [ + '_stats/{metric_family}', + '/_stats/indexing', + '/_stats/indexing/{indexing_types}', + '/_stats/search/{search_groups}', + '/_stats/fielddata/{fields}', + '/{index}/_stats/{metric_family}', + '/{index}/_stats/indexing', + '/{index}/_stats/search/{search_groups}', + '/{index}/_stats/fielddata/{fields}' + ], + 'snapshot.create': [ + '/_snapshot/{repository}/{snapshot}/_create' + ] + } + } +]; \ No newline at end of file diff --git a/scripts/generate/aliases_0_90.js b/scripts/generate/aliases_0_90.js deleted file mode 100644 index a65b081c9..000000000 --- a/scripts/generate/aliases_0_90.js +++ /dev/null @@ -1,60 +0,0 @@ -module.exports = { - 'cluster.nodeHotThreads': [ - '/_cluster/nodes/hotthreads', - '/_cluster/nodes/hot_threads', - '/_nodes/hot_threads', - '/_cluster/nodes/{node_id}/hotthreads', - '/_cluster/nodes/{node_id}/hot_threads', - '/_nodes/{node_id}/hot_threads' - ], - 'cluster.nodeInfo': [ - '/_cluster/nodes', - '/_nodes/settings', - '/_nodes/os', - '/_nodes/process', - '/_nodes/jvm', - '/_nodes/thread_pool', - '/_nodes/network', - '/_nodes/transport', - '/_nodes/http', - '/_nodes/plugin', - '/_cluster/nodes/{node_id}', - '/_nodes/{node_id}/settings', - '/_nodes/{node_id}/os', - '/_nodes/{node_id}/process', - '/_nodes/{node_id}/jvm', - '/_nodes/{node_id}/thread_pool', - '/_nodes/{node_id}/network', - '/_nodes/{node_id}/transport', - '/_nodes/{node_id}/http', - '/_nodes/{node_id}/plugin' - ], - 'cluster.nodeShutdown': [ - '/_cluster/nodes/_shutdown' - ], - 'cluster.nodeStats': [ - '/_cluster/nodes/stats', - '/_nodes/stats/{metric_family}', - '/_nodes/stats/indices/{metric}/{fields}', - '/_cluster/nodes/{node_id}/stats', - '/_nodes/{node_id}/stats/{metric_family}', - '/_nodes/{node_id}/stats/indices/{metric}/{fields}' - ], - 'get': [ - '/{index}/{type}/{id}/_source' - ], - 'indices.deleteMapping': [ - '/{index}/{type}/_mapping' - ], - 'indices.stats': [ - '_stats/{metric_family}', - '/_stats/indexing', - '/_stats/indexing/{indexing_types}', - '/_stats/search/{search_groups}', - '/_stats/fielddata/{fields}', - '/{index}/_stats/{metric_family}', - '/{index}/_stats/indexing', - '/{index}/_stats/search/{search_groups}', - '/{index}/_stats/fielddata/{fields}' - ] -}; \ No newline at end of file diff --git a/scripts/generate/js_api.js b/scripts/generate/js_api.js index 48b3051e2..458678088 100644 --- a/scripts/generate/js_api.js +++ b/scripts/generate/js_api.js @@ -9,6 +9,7 @@ module.exports = function (branch, done) { var async = require('async'); var chalk = require('chalk'); var path = require('path'); + var semver = require('semver'); var fromRoot = path.join.bind(path, require('find-root')(__dirname)); var templates = require('./templates'); var urlParamRE = /\{(\w+)\}/g; @@ -18,14 +19,24 @@ module.exports = function (branch, done) { var docVars; // slightly modified clone of apiSpec for the docs var branchSuffix = utils.branchSuffix(branch); + var branchAsVersion = (function () { + var m; + // master === the highest version number + if (branch === 'master') return '999.999.999'; + // n.m -> n.m.0 + if (m = branch.match(/^\d+\.\d+$/)) return branch + '.0'; + // n.x -> n.0.0 + if (m = branch.match(/^(\d+)\.x$/i)) return m[1] + '.0.0'; + + throw new Error('unable to convert branch "' + branch + '" to semver'); + }()); + var esDir = fromRoot('src/_elasticsearch_' + _.snakeCase(branch)); - var aliases; - try { - aliases = require('./aliases_' + _.snakeCase(branch)); - } catch (e) { - // fall back to the master aliases - aliases = require('./aliases'); - } + var aliases = _.transform(require('./aliases'), function (aliases, rule) { + if (semver.satisfies(branchAsVersion, rule.version)) { + _.assign(aliases, rule.aliases); + } + }, {}); var steps = [ readSpecFiles,