Skip to content

Commit

Permalink
Setup OpenSearch plugin dependencies on cluster snapshot (#2734)
Browse files Browse the repository at this point in the history
* Adding yarn opensearch args to setup opensearch plugin dependencies on snapshot
* Updating the example opensearch snapshot help command with --P arg
* Adding tests to the plugin installation function
* Adding documentation for the new flag in developer guide

Signed-off-by: Manasvini B Suryanarayana <manasvis@amazon.com>
  • Loading branch information
manasvinibs authored Nov 18, 2022
1 parent 80cf748 commit ab98411
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Save Object Aggregation View] Fix for export all after scroll count response changed in PR#2656 ([#2696](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2696))
- [Vis Builder] Add an experimental table visualization in vis builder ([#2705](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2705))
- [Vis Builder] Add field summary popovers ([#2682](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2682))
- Add yarn opensearch arg to setup plugin dependencies ([#2544](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2544))

### 🐛 Bug Fixes

Expand Down
24 changes: 24 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ Dashboards. In a separate terminal you can run the latest snapshot built using:
$ yarn opensearch snapshot
```

If you would like to download a specific OpenSearch plugin on the cluster snapshot, pass the `--P` flag after `yarn opensearch snapshot`. We can use the flag multiple times to install multiple plugins on the cluster snapshot. The argument value can be URL to the plugin's 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. Below is the example help command:

```
$ yarn opensearch snapshot --P https://repo1.maven.org/maven2/org/opensearch/plugin/opensearch-test-plugin/2.4.0.0/opensearch-test-plugin-2.4.0.0.zip
```

Following are the list of options that can be passed after `yarn opensearch snapshot` to configure the cluster snapshot.
Options:

--license Run with a 'oss', 'basic', or 'trial' license [default: oss]
--version Version of OpenSearch to download [default: 3.0.0}]
--base-path Path containing cache/installations [default: /home/ubuntu/OpenSearch-Dashboards/.opensearch]
--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: changeme]
-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
--P OpenSearch plugin artifact URL to install it on the cluster.

```
$ yarn 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
```

**Warning:** Starting the Dashboards instance before or during the initialization of the OpenSearch Server can cause Dashboards to sometimes misbehave. Ensure that the OpenSearch server instance is up and running first before starting up the Dashboards dev server from the next step.

### Run OpenSearch Dashboards
Expand Down
10 changes: 9 additions & 1 deletion packages/osd-opensearch/src/cli_commands/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ exports.help = (defaults = {}) => {
-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
--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 5.6.8 -E cluster.name=test -E path.data=/tmp/opensearch-data
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
`;
};

Expand All @@ -64,6 +67,7 @@ exports.run = async (defaults = {}) => {
installPath: 'install-path',
dataArchive: 'data-archive',
opensearchArgs: 'E',
opensearchPlugins: 'P',
},

string: ['version'],
Expand All @@ -83,6 +87,10 @@ exports.run = async (defaults = {}) => {
await cluster.extractDataDirectory(installPath, options.dataArchive);
}

if (options.opensearchPlugins) {
await cluster.installOpenSearchPlugins(installPath, options.opensearchPlugins);
}

options.bundledJDK = true;

await cluster.run(installPath, options);
Expand Down
25 changes: 24 additions & 1 deletion packages/osd-opensearch/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const execa = require('execa');
const chalk = require('chalk');
const path = require('path');
const { downloadSnapshot, installSnapshot, installSource, installArchive } = require('./install');
const { OPENSEARCH_BIN } = require('./paths');
const { OPENSEARCH_BIN, OPENSEARCH_PLUGIN } = require('./paths');
const { log: defaultLog, parseOpenSearchLog, extractConfigFiles, decompress } = require('./utils');
const { createCliError } = require('./errors');
const { promisify } = require('util');
Expand Down Expand Up @@ -170,6 +170,29 @@ exports.Cluster = class Cluster {
this._log.indent(-4);
}

/**
* Unpacks a tar or zip file containing the OpenSearch plugin directory for an
* OpenSearch cluster.
*
* @param {string} installPath
* @param {Array|string} opensearchPlugins Array or string of OpenSearch plugin(s) artifact url
*/
async installOpenSearchPlugins(installPath, opensearchPluginsPath) {
if (opensearchPluginsPath) {
this._log.info(chalk.bold(`Downloading OpenSearch plugin(s) on the cluster snapshot`));
this._log.indent(4);
opensearchPluginsPath =
typeof opensearchPluginsPath === 'string' ? [opensearchPluginsPath] : opensearchPluginsPath;
// Run opensearch-plugin tool script to download OpenSearch plugin artifacts
for (const pluginPath of opensearchPluginsPath) {
this._log.info(`Installing OpenSearch Plugin from the path: ${pluginPath}`);
await execa(OPENSEARCH_PLUGIN, [`install`, `--batch`, pluginPath], { cwd: installPath });
}
this._log.info(`Plugin installation complete`);
this._log.indent(-4);
}
}

/**
* Starts OpenSearch and returns resolved promise once started
*
Expand Down
27 changes: 27 additions & 0 deletions packages/osd-opensearch/src/integration_tests/cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,33 @@ describe('#start(installPath)', () => {
});
});

describe('#installOpenSearchPlugins()', () => {
it('install array of plugins on cluster snapshot', async () => {
const cluster = new Cluster({ log });
await cluster.installOpenSearchPlugins('foo', ['foo1', 'foo2']);
expect(execa).toHaveBeenCalledTimes(2);
expect(execa).toHaveBeenCalledWith('./bin/opensearch-plugin', ['install', '--batch', 'foo1'], {
cwd: 'foo',
});
expect(execa).toHaveBeenCalledWith('./bin/opensearch-plugin', ['install', '--batch', 'foo2'], {
cwd: 'foo',
});
});
it('installs single plugin on cluster snapshot', async () => {
const cluster = new Cluster({ log });
await cluster.installOpenSearchPlugins('foo', 'foo1');
expect(execa).toHaveBeenCalledTimes(1);
expect(execa).toHaveBeenCalledWith('./bin/opensearch-plugin', ['install', '--batch', 'foo1'], {
cwd: 'foo',
});
});
it('do not execute plugin installation script when no plugins in the param list', async () => {
const cluster = new Cluster({ log });
await cluster.installOpenSearchPlugins('foo');
expect(execa).toHaveBeenCalledTimes(0);
});
});

describe('#run()', () => {
it('resolves when bin/opensearch exists with 0', async () => {
mockOpenSearchBin({ exitCode: 0 });
Expand Down
1 change: 1 addition & 0 deletions packages/osd-opensearch/src/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ exports.OPENSEARCH_BIN = maybeUseBat('bin/opensearch');
exports.OPENSEARCH_CONFIG = 'config/opensearch.yml';

exports.OPENSEARCH_KEYSTORE_BIN = maybeUseBat('./bin/opensearch-keystore');
exports.OPENSEARCH_PLUGIN = maybeUseBat('./bin/opensearch-plugin');

0 comments on commit ab98411

Please sign in to comment.