├── .gitignore ├── LICENSE ├── README.md ├── bin └── esvm.js ├── examples ├── custom_config.md ├── five_nodes.md ├── plugins_advanced.md └── shield_config.md ├── index.js ├── lib ├── explodeBy.js ├── flattenConfig.js ├── flattenWith.js ├── formatClusters.js └── mergeConfig.js ├── package.json └── test ├── fixtures ├── config.json └── defaults.json └── merge_config.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | esvm 2 | ==== 3 | 4 | **Elasticsearch Version Manager** is a command line application used for development to manage different versions of Elasticsearch. It should not be used in production since it's probably a bad idea to wrap a process with Node.js. But nevertheless it's extremely useful if you need to develop against multiple versions of Elasticsearch (I'm looking at you Kibana team). 5 | 6 | ## Installation 7 | ``` 8 | npm install esvm -g 9 | ``` 10 | 11 | ### Usage 12 | ``` 13 | Usage: esvm [options] 14 | 15 | Options: 16 | 17 | -h, --help output usage information 18 | -V, --version output the version number 19 | -p, --purge purge the data directory 20 | -f, --fresh preform a fresh install 21 | -b, --branch install from a branch release 22 | -n, --nodes the number of nodes to start 23 | -c, --config the config file to use 24 | -l, --list list clusters in the config file 25 | --cluster-name the cluster name to use 26 | ``` 27 | 28 | Note: `` can either be a semver expression of a named cluster (which is found in the configuration). 29 | 30 | ### Configuration 31 | 32 | **esvm** will look for an .esvmrc file in the current working directory. If it doesn't find one there it will continue to walk up the directory tree until it does. There are two main sections for the configuration file: 33 | 34 | * `defaults` - The defaults to apply to every instance 35 | * `clusters` - The named clusters 36 | 37 | Both the defaults and named clusters will take the following options: 38 | 39 | Option | Description 40 | ------------- | ----------- 41 | `version` | The semver statment for the released version of Elasticsearch to install. Will override branch and binary options, and install the latest version by default 42 | `branch` | The nightly branch to install 43 | `binary` | The path to the tarball to use. This can either be URL or file path. 44 | `directory` | The directory where everything is installed. If the directory doesn't exist it will be created. (Default: ~/.esvm) 45 | `plugins` | The plugins to install. This should be an array of plugin install directives. 46 | `purge` | Purge the data directory when starting the server (Default: false). 47 | `fresh` | Remove the current copy before installing a new copy (Default: false). 48 | `nodes` | The number of nodes to start. This can either be a number or an array of config objects (Default: 1) 49 | `config` | The config to start the server with. 50 | `shield` | Configuration settings for Shield. Check the examples for help 51 | 52 | For some example configurations, please consult the [example files](https://github.com/simianhacker/esvm/tree/master/examples) 53 | -------------------------------------------------------------------------------- /bin/esvm.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var libesvm = require('libesvm'); 3 | var clc = require('cli-color'); 4 | var moment = require('moment'); 5 | var _ = require('lodash'); 6 | var ProgressBar = require('progress'); 7 | var RcLoader = require('rcloader'); 8 | var os = require('os'); 9 | var fs = require('fs'); 10 | var commander = require('commander'); 11 | var packageInfo = require('../package.json'); 12 | var join = require('path').join; 13 | var flattenConfig = require('../lib/flattenConfig'); 14 | var flattenWith = require('../lib/flattenWith'); 15 | var mergeConfig = require('../lib/mergeConfig'); 16 | var formatter = require('../lib/formatClusters'); 17 | 18 | var rcloader = new RcLoader('.esvmrc'); 19 | var config = rcloader.for('.esvmrc'); 20 | 21 | var levels = { 22 | INFO: clc.green, 23 | DEBUG: clc.cyan, 24 | WARN: clc.yellow, 25 | FATAL: clc.magentaBright, 26 | ERROR: clc.white.bgRed 27 | }; 28 | 29 | 30 | commander 31 | .version(packageInfo.version) 32 | .usage('[options] ') 33 | .option('-p, --purge', 'purge the data directory') 34 | .option('-f, --fresh', 'preform a fresh install') 35 | .option('-b, --branch', 'install from a branch release') 36 | .option('-n, --nodes ', 'the number of nodes to start', parseInt) 37 | .option('-c, --config ', 'the config file to use') 38 | .option('-l, --list', 'list clusters in the config file') 39 | .option('--cluster-name ', 'the cluster name to use') 40 | .parse(process.argv); 41 | 42 | var version = commander.args[0]; 43 | var options = {}; 44 | 45 | 46 | // If a config is passed via command line use that instead of the rcfile 47 | if (commander.config) { 48 | try { 49 | config = JSON.parse(fs.readFileSync(commander.config)); 50 | } catch (e) { 51 | console.log(clc.red("Falied to parse config file: " + commander.config), "\n", e.stack); 52 | process.exit(1); 53 | } 54 | } 55 | 56 | var defaults = mergeConfig(flattenConfig(config.defaults || {}), { 57 | directory: process.env.HOME+'/.esvm', 58 | plugins: [], 59 | purge: false, // Purge the data directory 60 | fresh: false, // Download a fresh copy 61 | nodes: 1, 62 | config: { 63 | 'cluster.name': os.hostname() 64 | } 65 | }); 66 | 67 | // If the version is a named config use that otherwise 68 | // use the version as the actual version 69 | if (version) { 70 | if (config.clusters && config.clusters[version]) { 71 | options = flattenConfig(config.clusters[version]); 72 | } else if (commander.branch) { 73 | delete defaults.version; 74 | options = { branch: version }; 75 | } else { 76 | options = { version: version }; 77 | } 78 | } 79 | 80 | // Assign the overrides from the CLI options 81 | _.assign(options, _.pick(commander, ['fresh', 'nodes', 'purge'])); 82 | 83 | // Set the defaults 84 | options = mergeConfig(options, defaults); 85 | 86 | // Merge configs with nodes 87 | if (_.isArray(options.nodes)) { 88 | options.nodes = options.nodes.map(function (value) { 89 | return _.defaults(flattenWith('.', value), options.config); 90 | }); 91 | } 92 | 93 | // If we don't have a version, branch, and binary then we need to set the version 94 | // to the latest. 95 | if (!options.version && !options.branch && !options.binary) { 96 | options.version = '*'; 97 | } 98 | 99 | // Override the cluster name 100 | if (commander.clusterName) { 101 | options.clusterNameOverride = commander.clusterName; 102 | } 103 | 104 | // If given the list command and a config file, list clusters and exit 105 | if (commander.list) { 106 | console.log(formatter(config.clusters)) 107 | process.exit(); 108 | } 109 | 110 | options.config = options.config; 111 | var cluster = libesvm.createCluster(options); 112 | 113 | cluster.on('error', function (log) { 114 | // do nothing for now. 115 | }); 116 | 117 | // Setup the logging 118 | cluster.on('log', function (log) { 119 | var bar, pattern; 120 | if (log.type === 'progress' && process.stdout.isTTY) { 121 | pattern = log.op + ' [:bar] :percent :etas'; 122 | bar = new ProgressBar(pattern, { 123 | complete: '=', 124 | incomplete: ' ', 125 | width: 80, 126 | clear: true, 127 | total: log.total 128 | }); 129 | log.on('progress', _.bindKey(bar, 'tick')); 130 | return; 131 | } 132 | var level = levels[log.level] || function (msg) { return msg; }; 133 | var message = clc.blackBright(moment(log.timestamp).format('lll')); 134 | message += ' '+level(log.level); 135 | if (log.node) { 136 | message += ' ' + clc.magenta(log.node); 137 | } 138 | message += ' ' + clc.yellow(log.type) + ' '; 139 | message += log.message; 140 | console.log(message); 141 | }); 142 | 143 | // Install and then start the cluster 144 | cluster.install().then(function () { 145 | return cluster.installPlugins(); 146 | }).then(function () { 147 | return cluster.start(); 148 | }).then(function () { 149 | process.on('SIGINT', function () { 150 | cluster.shutdown().then(function () { 151 | console.log(clc.black.bgWhite("Bye Bye!")); 152 | process.exit(); 153 | }); 154 | }); 155 | process.stdin.read(); 156 | }).catch(function (err) { 157 | console.log('Oops', err.stack); 158 | }); 159 | -------------------------------------------------------------------------------- /examples/custom_config.md: -------------------------------------------------------------------------------- 1 | Custom Elasticsearch configurations, which would normally be placed in the `elasticsearch.yml` file. 2 | 3 | This also shows the power of `defaults` in a configuration, as all of these Elasticsearch settings would be applied to any and all cluster configurations, and optionally overwritten as needed. The dot syntax is preferred, but deep object syntax would also work. 4 | 5 | Run as `esvm config` 6 | 7 | ``` 8 | { 9 | "defaults": { 10 | "config": { 11 | "http.host": "0.0.0.0", 12 | "http.cors.enabled": true, 13 | "discovery.zen.ping.multicast.enabled": false, 14 | "bootstrap.mlockall": true 15 | } 16 | } 17 | } 18 | ``` -------------------------------------------------------------------------------- /examples/five_nodes.md: -------------------------------------------------------------------------------- 1 | - Installs the [elasticsearch-head](https://mobz.github.io/elasticsearch-head/) plugin 2 | - plugin would be installed by default for any other clusters defined as well 3 | - 5 total nodes 4 | - 2 Master Nodes 5 | - 3 Data nodes 6 | - Cluster named *2m3d* 7 | 8 | To load this configuration, run `esvm 2m3d` 9 | 10 | ``` 11 | { 12 | "clusters": { 13 | "2m3d": { 14 | "plugins": ["mobz/elasticsearch-head"], 15 | "nodes": [ 16 | { 17 | "cluster": { "name": "2m3d" }, 18 | "node": { "name": "master-1", "data": false, "master": true } 19 | }, 20 | { 21 | "cluster": { "name": "2m3d" }, 22 | "node": { "name": "master-2", "data": false, "master": true } 23 | }, 24 | { 25 | "cluster": { "name": "2m3d" }, 26 | "node": { "name": "data-1", "data": true, "master": false } 27 | }, 28 | { 29 | "cluster": { "name": "2m3d" }, 30 | "node": { "name": "data-2", "data": true, "master": false } 31 | }, 32 | { 33 | "cluster": { "name": "2m3d" }, 34 | "node": { "name": "data-3", "data": true, "master": false } 35 | } 36 | ] 37 | } 38 | } 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /examples/plugins_advanced.md: -------------------------------------------------------------------------------- 1 | This is an example that installs a number of Elasticsearch plugins at run time, with specific settings for the given plugins using objects instead of strings. 2 | 3 | - Install latest available version of Elasticsearch 4 | - Name node *es-shield* 5 | - Install 3 plugins, including commercial Elastic plugin shield 6 | 7 | Run as `esvm plugins` 8 | 9 | Plugin objects can recieve one of the following: 10 | 11 | `path` - The file location of the given plugin, can be a file path or URL 12 | `staging` - Use the staged builds uploaded to S3 13 | `snapshot` - Use internal SNAPSHOT builds (requires credentials in `.esvm_snapshot_credentials.json`) 14 | 15 | ``` 16 | { 17 | "clusters": { 18 | "plugins": { 19 | "nodes": [{ 20 | "node": { "name": "es-shield" } 21 | }], 22 | "plugins": [ 23 | "mobz/elasticsearch-head", 24 | { name: "license", "snapshot": true }, 25 | { name: "shield", "snapshot": true } 26 | ] 27 | } 28 | } 29 | } 30 | ``` -------------------------------------------------------------------------------- /examples/shield_config.md: -------------------------------------------------------------------------------- 1 | Installs the [Shield plugin](https://www.elastic.co/products/shield), configuring users and roles for Kibana 2 | 3 | - Cluster with 3 nodes 4 | - Latest verison of Elasticsearch 5 | - Installs Shield and required license companion 6 | - Add 3 users to Shield 7 | 8 | Run as `esvm sield` 9 | 10 | ``` 11 | { 12 | "clusters": { 13 | "shield": { 14 | "directory": "/home/vagrant/elasticsearch/es-with-plugins", 15 | "nodes": 3, 16 | "plugins": [ 17 | "license", 18 | "shield" 19 | ], 20 | "shield": { 21 | "users": [ 22 | { 23 | "username": "kibana", 24 | "password": "notsecure", 25 | "roles": ["kibana4_server"] 26 | }, 27 | { 28 | "username": "user", 29 | "password": "notsecure", 30 | "roles": ["kibana4", "marvel_user"] 31 | }, 32 | { 33 | "username": "admin", 34 | "password": "notsecure", 35 | "roles": ["admin"] 36 | } 37 | ] 38 | } 39 | }, 40 | } 41 | } 42 | ``` -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | require('./bin/esvm'); 2 | -------------------------------------------------------------------------------- /lib/explodeBy.js: -------------------------------------------------------------------------------- 1 | var explodeBy = module.exports = function (dot, flatObject) { 2 | var _ = require('lodash'); 3 | var fullObject = {}; 4 | _.each(flatObject, function (value, key) { 5 | var keys = key.split("."); 6 | (function walk(memo, keys, value) { 7 | var _key = keys.shift(); 8 | if (keys.length === 0) { 9 | memo[_key] = value; 10 | } else { 11 | if (!memo[_key]) memo[_key] = {}; 12 | walk(memo[_key], keys, value); 13 | } 14 | })(fullObject, keys, value); 15 | }); 16 | return fullObject; 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /lib/flattenConfig.js: -------------------------------------------------------------------------------- 1 | var flattenWith = require('./flattenWith'); 2 | module.exports = function (options) { 3 | if (options.config) options.config = flattenWith('.', options.config); 4 | return options; 5 | }; 6 | -------------------------------------------------------------------------------- /lib/flattenWith.js: -------------------------------------------------------------------------------- 1 | var flattenWith = module.exports = function (dot, nestedObj, flattenArrays) { 2 | var _ = require('lodash'); 3 | var key; // original key 4 | var stack = []; // track key stack 5 | var flatObj = {}; 6 | (function flattenObj(obj) { 7 | _.keys(obj).forEach(function (key) { 8 | stack.push(key); 9 | if (!flattenArrays && _.isArray(obj[key])) flatObj[stack.join(dot)] = obj[key]; 10 | else if (_.isObject(obj[key])) flattenObj(obj[key]); 11 | else flatObj[stack.join(dot)] = obj[key]; 12 | stack.pop(); 13 | }); 14 | }(nestedObj)); 15 | return flatObj; 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /lib/formatClusters.js: -------------------------------------------------------------------------------- 1 | var Table = require('cli-table'); 2 | var _ = require('lodash'); 3 | 4 | function formatPlugins(plugin) { 5 | if (_.isPlainObject(plugin)) return plugin.name; 6 | return plugin; 7 | } 8 | 9 | module.exports = function (clusters) { 10 | var table = new Table({ 11 | head: ['Cluster Name', 'Version', 'Plugins'] 12 | }); 13 | 14 | var clusterNames = Object.keys(clusters); 15 | clusterNames.forEach(function (clusterName) { 16 | var cluster = clusters[clusterName]; 17 | 18 | // append cluster name 19 | var output = [clusterName]; 20 | 21 | // append branch/version 22 | if (cluster.branch) output.push(cluster.branch + ' branch'); 23 | else if (cluster.version) output.push('v' + cluster.version); 24 | else output.push('n/a'); 25 | 26 | // append plugins 27 | if (cluster.plugins) output.push(cluster.plugins.map(formatPlugins).join(',')); 28 | else output.push(''); 29 | 30 | // append cluster row to table 31 | return table.push(output); 32 | }); 33 | 34 | return table.toString(); 35 | } 36 | -------------------------------------------------------------------------------- /lib/mergeConfig.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var mergeConfig = module.exports = function (config, defaults) { 3 | return _.merge(defaults, config); 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esvm", 3 | "version": "3.2.13", 4 | "description": "Elasticsearch Version Manager", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/simianhacker/esvm.git" 12 | }, 13 | "keywords": [ 14 | "elasticsearch", 15 | "version", 16 | "manager", 17 | "libesvm" 18 | ], 19 | "author": "Chris Cowan", 20 | "license": "Apache-2.0", 21 | "bugs": { 22 | "url": "https://github.com/simianhacker/esvm/issues" 23 | }, 24 | "homepage": "https://github.com/simianhacker/esvm", 25 | "bin": { 26 | "esvm": "./bin/esvm.js" 27 | }, 28 | "dependencies": { 29 | "cli-color": "^0.3.2", 30 | "cli-table": "^0.3.1", 31 | "commander": "^2.3.0", 32 | "libesvm": "^3.9.0", 33 | "lodash": "^4.0.0", 34 | "moment": "^2.8.1", 35 | "optimist": "^0.6.1", 36 | "progress": "^1.1.8", 37 | "rcloader": "^0.1.2" 38 | }, 39 | "devDependencies": { 40 | "chai": "^3.4.1", 41 | "mocha": "^2.3.4", 42 | "requirefrom": "^0.2.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /test/fixtures/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "test.enable": true, 4 | "example.foo.enable": true 5 | }, 6 | "cluster": { 7 | "node": { 8 | "enable": true 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "test.enable": false, 4 | "test.hosts": ["localhost:9200"] 5 | }, 6 | "cluster": { 7 | "node": { 8 | "name": "foo-bar", 9 | ".index": ["something"] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/merge_config.js: -------------------------------------------------------------------------------- 1 | var config = require('./fixtures/config.json'); 2 | var defaults = require('./fixtures/defaults.json'); 3 | var expect = require('chai').expect; 4 | var mergeConfig = require('../lib/mergeConfig'); 5 | describe('mergeConfig', function () { 6 | it('should merge config recursivly', function () { 7 | expect(mergeConfig(config, defaults)) 8 | .to.eql({ 9 | config: { 10 | 'test.enable': true, 11 | 'example.foo.enable': true, 12 | 'test.hosts': ['localhost:9200'] 13 | }, 14 | cluster: { 15 | node: { 16 | enable: true, 17 | name: 'foo-bar', 18 | '.index': ['something'] 19 | } 20 | } 21 | }); 22 | }); 23 | }); 24 | --------------------------------------------------------------------------------