Modify es_archiver to allow saving of raw archives (#19348)

This commit is contained in:
Chris Davies 2018-05-30 11:36:13 -04:00 committed by GitHub
parent 8de20f23fd
commit 9d08ab7f49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 13 deletions

View file

@ -35,7 +35,7 @@ import {
createGenerateDocRecordsStream,
} from '../lib';
export async function saveAction({ name, indices, client, dataDir, log }) {
export async function saveAction({ name, indices, client, dataDir, log, raw }) {
const outputDir = resolve(dataDir, name);
const stats = createStats(name, log);
@ -60,8 +60,8 @@ export async function saveAction({ name, indices, client, dataDir, log }) {
createPromiseFromStreams([
createListStream(resolvedIndexes),
createGenerateDocRecordsStream(client, stats),
...createFormatArchiveStreams({ gzip: true }),
createWriteStream(resolve(outputDir, 'data.json.gz'))
...createFormatArchiveStreams({ gzip: !raw }),
createWriteStream(resolve(outputDir, `data.json${raw ? '' : '.gz'}`))
])
]);

View file

@ -49,21 +49,23 @@ cmd
console.log(readFileSync(resolve(__dirname, './cli_help.txt'), 'utf8'));
});
cmd.command('save <name> <indices...>')
cmd
.option('--raw', `don't gzip the archive`)
.command('save <name> <indices...>')
.description('archive the <indices ...> into the --dir with <name>')
.action((name, indices) => execute('save', name, indices));
.action((name, indices) => execute((archiver, { raw }) => archiver.save(name, indices, { raw })));
cmd.command('load <name>')
.description('load the archive in --dir with <name>')
.action(name => execute('load', name));
.action(name => execute(archiver => archiver.load(name)));
cmd.command('unload <name>')
.description('remove indices created by the archive in --dir with <name>')
.action(name => execute('unload', name));
.action(name => execute(archiver => archiver.unload(name)));
cmd.command('rebuild-all')
.description('[internal] read and write all archives in --dir to remove any inconsistencies')
.action(() => execute('rebuildAll'));
.action(() => execute(archiver => archiver.rebuildAll()));
cmd.parse(process.argv);
@ -72,7 +74,7 @@ if (missingCommand) {
execute();
}
async function execute(operation, ...args) {
async function execute(fn) {
try {
const log = createToolingLog(cmd.verbose ? 'debug' : 'info');
log.pipe(process.stdout);
@ -91,7 +93,6 @@ async function execute(operation, ...args) {
log.error(msg);
};
if (!operation) error('Missing or invalid command');
if (!cmd.esUrl) {
error('You must specify either --es-url or --config flags');
}
@ -106,7 +107,6 @@ async function execute(operation, ...args) {
}
// run!
const client = new elasticsearch.Client({
host: cmd.esUrl,
log: cmd.verbose ? 'trace' : []
@ -118,7 +118,7 @@ async function execute(operation, ...args) {
client,
dataDir: resolve(cmd.dir),
});
await esArchiver[operation](...args);
await fn(esArchiver, cmd);
} finally {
await client.close();
}

View file

@ -37,12 +37,15 @@ export class EsArchiver {
*
* @param {String} name - the name of this archive, used to determine filename
* @param {String|Array<String>} indices - the indices to archive
* @param {Object} options
* @property {Boolean} options.raw - should the archive be raw (unzipped) or not
* @return Promise<Stats>
*/
async save(name, indices) {
async save(name, indices, { raw = false } = {}) {
return await saveAction({
name,
indices,
raw,
client: this.client,
dataDir: this.dataDir,
log: this.log,