Skip to content

Commit

Permalink
Add support to kbn-es and kbn-test for data archives
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Jan 15, 2019
1 parent 0ba1db2 commit e3d57d1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
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 });
};
20 changes: 19 additions & 1 deletion packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const execa = require('execa');
const chalk = require('chalk');
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 +116,24 @@ 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(`Extracing data directory`));
this._log.indent(4);
this._log.info(`Data archive: ${archivePath}`);
this._log.info(`Install path: ${installPath}`);

await decompress(archivePath, installPath);

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

0 comments on commit e3d57d1

Please sign in to comment.