-
Notifications
You must be signed in to change notification settings - Fork 890
/
snapshot.js
112 lines (91 loc) · 4.09 KB
/
snapshot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const dedent = require('dedent');
const getopts = require('getopts');
const { Cluster } = require('../cluster');
exports.description = 'Downloads and run from a nightly snapshot';
exports.help = (defaults = {}) => {
const { license = 'basic', password = 'changeme', 'base-path': basePath } = defaults;
return dedent`
Options:
--license Run with a 'oss', 'basic', or 'trial' license [default: ${license}]
--version Version of OpenSearch 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 OpenSearch data directory to seed the cluster with.
--password Sets password for opensearch user [default: ${password}]
-E Additional key=value settings to pass to OpenSearch
--download-only Download the snapshot but don't actually start it
--ssl Sets up SSL on OpenSearch
--security Installs and sets up the OpenSearch Security plugin on the cluster
--sql Installs and sets up the required OpenSearch SQL/PPL plugins on the cluster
--P OpenSearch plugin artifact URL to install it on the cluster. We can use the flag multiple times
to install multiple plugins on the cluster snapshot. The argument value can be url to zip file, maven coordinates of the plugin
or for local zip files, use file:<followed by the absolute or relative path to the plugin zip file>.
Example:
opensearch snapshot --version 2.2.0 -E cluster.name=test -E path.data=/tmp/opensearch-data --P org.opensearch.plugin:test-plugin:2.2.0.0 --P file:/home/user/opensearch-test-plugin-2.2.0.0.zip
`;
};
exports.run = async (defaults = {}) => {
const argv = process.argv.slice(2);
const options = getopts(argv, {
alias: {
basePath: 'base-path',
installPath: 'install-path',
dataArchive: 'data-archive',
opensearchArgs: 'E',
opensearchPlugins: 'P',
},
string: ['version'],
boolean: ['download-only'],
boolean: ['security'],
boolean: ['sql'],
default: defaults,
});
const cluster = new Cluster({ ssl: options.ssl });
if (options['download-only']) {
await cluster.downloadSnapshot(options);
} else {
const { installPath } = await cluster.installSnapshot(options);
if (options.dataArchive) {
await cluster.extractDataDirectory(installPath, options.dataArchive);
}
if (options.opensearchPlugins) {
await cluster.installOpenSearchPlugins(installPath, options.opensearchPlugins);
}
if (options.security) {
await cluster.setupSecurity(installPath, options.version ?? defaults.version);
}
if (options.sql) {
await cluster.setupSql(installPath, options.version ?? defaults.version);
}
options.bundledJDK = true;
await cluster.run(installPath, options);
}
};