diff --git a/packages/kbn-es/src/cli_commands/snapshot.js b/packages/kbn-es/src/cli_commands/snapshot.js index 0a585e92cfd74..c01a4fa08ec59 100644 --- a/packages/kbn-es/src/cli_commands/snapshot.js +++ b/packages/kbn-es/src/cli_commands/snapshot.js @@ -35,6 +35,7 @@ exports.help = (defaults = {}) => { --install-path Installation path, defaults to 'source' within base-path --password Sets password for elastic user [default: ${password}] -E Additional key=value settings to pass to Elasticsearch + --download-only Download the snapshot but don't actually start it Example: @@ -51,10 +52,16 @@ exports.run = async (defaults = {}) => { esArgs: 'E', }, + boolean: ['download-only'], + default: defaults, }); const cluster = new Cluster(); - const { installPath } = await cluster.installSnapshot(options); - await cluster.run(installPath, { esArgs: options.esArgs }); + if (options['download-only']) { + await cluster.downloadSnapshot(options); + } else { + const { installPath } = await cluster.installSnapshot(options); + await cluster.run(installPath, { esArgs: options.esArgs }); + } }; diff --git a/packages/kbn-es/src/cluster.js b/packages/kbn-es/src/cluster.js index f14be3582f71a..50f3c5db2d8ca 100644 --- a/packages/kbn-es/src/cluster.js +++ b/packages/kbn-es/src/cluster.js @@ -19,7 +19,7 @@ const execa = require('execa'); const chalk = require('chalk'); -const { installSnapshot, installSource, installArchive } = require('./install'); +const { downloadSnapshot, installSnapshot, installSource, installArchive } = require('./install'); const { ES_BIN } = require('./paths'); const { log: defaultLog, parseEsLog, extractConfigFiles } = require('./utils'); const { createCliError } = require('./errors'); @@ -50,6 +50,28 @@ exports.Cluster = class Cluster { return { installPath }; } + /** + * Download ES from a snapshot + * + * @param {Object} options + * @property {Array} options.installPath + * @property {Array} options.sourcePath + * @returns {Promise<{installPath}>} + */ + async downloadSnapshot(options = {}) { + this._log.info(chalk.bold('Downloading snapshot')); + this._log.indent(4); + + const { installPath } = await downloadSnapshot({ + log: this._log, + ...options, + }); + + this._log.indent(-4); + + return { installPath }; + } + /** * Download and installs ES from a snapshot * diff --git a/packages/kbn-es/src/install/index.js b/packages/kbn-es/src/install/index.js index 69de1004e4e72..e2b3f692b2203 100644 --- a/packages/kbn-es/src/install/index.js +++ b/packages/kbn-es/src/install/index.js @@ -19,4 +19,5 @@ exports.installArchive = require('./archive').installArchive; exports.installSnapshot = require('./snapshot').installSnapshot; +exports.downloadSnapshot = require('./snapshot').downloadSnapshot; exports.installSource = require('./source').installSource; diff --git a/packages/kbn-es/src/install/snapshot.js b/packages/kbn-es/src/install/snapshot.js index 47edd8e3db6f9..42c1307a04614 100644 --- a/packages/kbn-es/src/install/snapshot.js +++ b/packages/kbn-es/src/install/snapshot.js @@ -28,19 +28,17 @@ const { installArchive } = require('./archive'); const { log: defaultLog, cache } = require('../utils'); /** - * Installs ES from snapshot + * Download an ES snapshot * * @param {Object} options * @property {('oss'|'basic'|'trial')} options.license - * @property {String} options.password * @property {String} options.version * @property {String} options.basePath * @property {String} options.installPath * @property {ToolingLog} options.log */ -exports.installSnapshot = async function installSnapshot({ +exports.downloadSnapshot = async function installSnapshot({ license = 'basic', - password = 'password', version, basePath = BASE_PATH, installPath = path.resolve(basePath, version), @@ -55,7 +53,40 @@ exports.installSnapshot = async function installSnapshot({ log.info('license: %s', chalk.bold(license)); await downloadFile(url, dest, log); - return await installArchive(dest, { + + return { + downloadPath: dest, + }; +}; + +/** + * Installs ES from snapshot + * + * @param {Object} options + * @property {('oss'|'basic'|'trial')} options.license + * @property {String} options.password + * @property {String} options.version + * @property {String} options.basePath + * @property {String} options.installPath + * @property {ToolingLog} options.log + */ +exports.installSnapshot = async function installSnapshot({ + license = 'basic', + password = 'password', + version, + basePath = BASE_PATH, + installPath = path.resolve(basePath, version), + log = defaultLog, +}) { + const { downloadPath } = await exports.downloadSnapshot({ + license, + version, + basePath, + installPath, + log, + }); + + return await installArchive(downloadPath, { license, password, basePath,