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 support to kbn-es and kbn-test for data archives #28723

Merged
merged 4 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/kbn-es/src/cli_commands/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports.help = (defaults = {}) => {
--version Version of ES to download [default: ${defaults.version}]
--base-path Path containing cache/installations [default: ${basePath}]
--install-path Installation path, defaults to 'source' within base-path
--data-archive Path to zip or tarball containing an ES data directory to seed the cluster with.
--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
Expand All @@ -49,6 +50,7 @@ exports.run = async (defaults = {}) => {
alias: {
basePath: 'base-path',
installPath: 'install-path',
dataArchive: 'data-archive',
esArgs: 'E',
},

Expand All @@ -62,6 +64,11 @@ exports.run = async (defaults = {}) => {
await cluster.downloadSnapshot(options);
} else {
const { installPath } = await cluster.installSnapshot(options);

if (options.dataArchive) {
await cluster.extractDataDirectory(installPath, options.dataArchive);
}

await cluster.run(installPath, { esArgs: options.esArgs });
}
};
7 changes: 7 additions & 0 deletions packages/kbn-es/src/cli_commands/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports.help = (defaults = {}) => {
--source-path Path to ES source [default: ${defaults['source-path']}]
--base-path Path containing cache/installations [default: ${basePath}]
--install-path Installation path, defaults to 'source' within base-path
--data-archive Path to zip or tarball containing an ES data directory to seed the cluster with.
--password Sets password for elastic user [default: ${password}]
-E Additional key=value settings to pass to Elasticsearch

Expand All @@ -49,6 +50,7 @@ exports.run = async (defaults = {}) => {
basePath: 'base-path',
installPath: 'install-path',
sourcePath: 'source-path',
dataArchive: 'data-archive',
esArgs: 'E',
},

Expand All @@ -57,5 +59,10 @@ exports.run = async (defaults = {}) => {

const cluster = new Cluster();
const { installPath } = await cluster.installSource(options);

if (options.dataArchive) {
await cluster.extractDataDirectory(installPath, options.dataArchive);
}

await cluster.run(installPath, { esArgs: options.esArgs });
};
23 changes: 22 additions & 1 deletion packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

const execa = require('execa');
const chalk = require('chalk');
const path = require('path');
const { downloadSnapshot, installSnapshot, installSource, installArchive } = require('./install');
const { ES_BIN } = require('./paths');
const { log: defaultLog, parseEsLog, extractConfigFiles } = require('./utils');
const { log: defaultLog, parseEsLog, extractConfigFiles, decompress } = require('./utils');
const { createCliError } = require('./errors');
const { promisify } = require('util');
const treeKillAsync = promisify(require('tree-kill'));
Expand Down Expand Up @@ -116,6 +117,26 @@ exports.Cluster = class Cluster {
return { installPath };
}

/**
* Unpakcs a tar or zip file containing the data directory for an
* ES cluster.
*
* @param {String} installPath
* @param {String} archivePath
*/
async extractDataDirectory(installPath, archivePath) {
this._log.info(chalk.bold(`Extracting data directory`));
this._log.indent(4);
this._log.info(`Data archive: ${archivePath}`);
this._log.info(`Install path: ${installPath}`);

// decompress excludes the root directory as that is how our archives are
// structured. This works in our favor as we can explicitly extract into the data dir
await decompress(archivePath, path.resolve(installPath, 'data'));

this._log.indent(-4);
}

/**
* Starts ES and returns resolved promise once started
*
Expand Down
5 changes: 5 additions & 0 deletions packages/kbn-test/src/es/es_test_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function createEsTestCluster(options = {}) {
log,
basePath = resolve(KIBANA_ROOT, '.es'),
esFrom = esTestConfig.getBuildFrom(),
dataArchive,
} = options;

const randomHash = Math.random()
Expand Down Expand Up @@ -74,6 +75,10 @@ export function createEsTestCluster(options = {}) {
throw new Error(`unknown option esFrom "${esFrom}"`);
}

if (dataArchive) {
await cluster.extractDataDirectory(installPath, dataArchive);
}

await cluster.start(installPath, {
esArgs: [
`cluster.name=${clusterName}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function runElasticsearch({ config, options }) {
log,
basePath: resolve(KIBANA_ROOT, '.es'),
esFrom: esFrom || config.get('esTestCluster.from'),
dataArchive: config.get('esTestCluster.dataArchive'),
});

const esArgs = config.get('esTestCluster.serverArgs');
Expand Down
1 change: 1 addition & 0 deletions src/functional_test_runner/lib/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const schema = Joi.object().keys({
license: Joi.string().default('oss'),
from: Joi.string().default('snapshot'),
serverArgs: Joi.array(),
dataArchive: Joi.string(),
}).default(),

kbnTestServer: Joi.object().keys({
Expand Down