Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kbn/es] add --download flag to snapshot command to warm the cache #25830

Merged
merged 2 commits into from Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/kbn-es/src/cli_commands/snapshot.js
Expand Up @@ -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:

Expand All @@ -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 });
}
};
24 changes: 23 additions & 1 deletion packages/kbn-es/src/cluster.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es/src/install/index.js
Expand Up @@ -19,4 +19,5 @@

exports.installArchive = require('./archive').installArchive;
exports.installSnapshot = require('./snapshot').installSnapshot;
exports.downloadSnapshot = require('./snapshot').downloadSnapshot;
exports.installSource = require('./source').installSource;
41 changes: 36 additions & 5 deletions packages/kbn-es/src/install/snapshot.js
Expand Up @@ -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),
Expand All @@ -56,7 +54,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,
Expand Down