From 59e6d34c29fcb1ade342b221de12b3576ffda6bf Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Dec 2017 09:57:03 -0500 Subject: [PATCH] SQL: Bundle the CLI into x-pack (elastic/x-pack-elasticsearch#3316) This adds: * The CLI jar itself into the `bin`. It is an executable jar. * A shell and bat script to start the CLI. This isn't strictly required but folks will appreciate the consistency. * Basic packaging tests for the CLI. Relates to elastic/x-pack-elasticsearch#2979 Original commit: elastic/x-pack-elasticsearch@158f70a530ff6a38505a1adc56b30e634de78cd6 --- plugin/bin/x-pack/sql-cli | 16 +++++++++++ plugin/bin/x-pack/sql-cli.bat | 21 +++++++++++++++ plugin/build.gradle | 10 +++++++ .../packaging/tests/bootstrap_password.bash | 27 +++++++++++++++++++ .../test/resources/packaging/utils/xpack.bash | 3 ++- sql/cli/build.gradle | 1 + 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 plugin/bin/x-pack/sql-cli create mode 100644 plugin/bin/x-pack/sql-cli.bat diff --git a/plugin/bin/x-pack/sql-cli b/plugin/bin/x-pack/sql-cli new file mode 100755 index 00000000000..730d26a140e --- /dev/null +++ b/plugin/bin/x-pack/sql-cli @@ -0,0 +1,16 @@ +#!/bin/bash + +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License; +# you may not use this file except in compliance with the Elastic License. + +source "`dirname "$0"`"/../elasticsearch-env + +source "`dirname "$0"`"/x-pack-env + +CLI_JAR=$(ls $ES_HOME/bin/x-pack/sql-cli-*.jar) + +exec \ + "$JAVA" \ + -jar "$CLI_JAR" \ + "$@" diff --git a/plugin/bin/x-pack/sql-cli.bat b/plugin/bin/x-pack/sql-cli.bat new file mode 100644 index 00000000000..0be6ddf2454 --- /dev/null +++ b/plugin/bin/x-pack/sql-cli.bat @@ -0,0 +1,21 @@ +@echo off + +rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +rem or more contributor license agreements. Licensed under the Elastic License; +rem you may not use this file except in compliance with the Elastic License. + +setlocal enabledelayedexpansion +setlocal enableextensions + +call "%~dp0..\elasticsearch-env.bat" || exit /b 1 + +call "%~dp0x-pack-env.bat" || exit /b 1 + +set CLI_JAR=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/bin/sql-cli-*.jar + +%JAVA% ^ + -jar "%CLI_JAR%" ^ + %* + +endlocal +endlocal diff --git a/plugin/build.gradle b/plugin/build.gradle index 5e86de92119..0077cd1d8a1 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -64,6 +64,7 @@ configurations { } } } + bundledBin } dependencies { @@ -100,6 +101,9 @@ dependencies { // sql's server components and its transitive dependencies compile project(':x-pack-elasticsearch:sql:server') + bundledBin(project(':x-pack-elasticsearch:sql:cli')) { + transitive = false + } // common test deps testCompile 'org.elasticsearch:securemock:1.2' @@ -176,6 +180,12 @@ bundlePlugin { // We don't ship the individual nativeBundle licenses - instead // they get combined into the top level NOTICES file we ship exclude 'platform/licenses/**' + + // Include the SQL CLI jar in the bundled plugin + dependsOn configurations.bundledBin + from(configurations.bundledBin) { + into 'bin' + } } // add api jar for extension authors to compile against diff --git a/qa/vagrant/src/test/resources/packaging/tests/bootstrap_password.bash b/qa/vagrant/src/test/resources/packaging/tests/bootstrap_password.bash index 03e7d3e44ea..a4bf0067ffe 100644 --- a/qa/vagrant/src/test/resources/packaging/tests/bootstrap_password.bash +++ b/qa/vagrant/src/test/resources/packaging/tests/bootstrap_password.bash @@ -118,6 +118,33 @@ SETUP_OK curl -H "Authorization: Basic $basic" -XGET 'http://127.0.0.1:9200' | grep "You Know, for Search" done set -H +} +@test "[$GROUP] test sql-cli" { + password=$(grep "PASSWORD elastic = " /tmp/setup-passwords-output-with-bootstrap | sed "s/PASSWORD elastic = //") + curl -s -u "elastic:$password" -H "Content-Type: application/json" -XPUT 'localhost:9200/library/book/1?refresh&pretty' -d'{ + "name": "Ender'"'"'s Game", + "author": "Orson Scott Card", + "release_date": "1985-06-01", + "page_count": 324 + }' + + password=$(grep "PASSWORD elastic = " /tmp/setup-passwords-output-with-bootstrap | sed "s/PASSWORD elastic = //") + + run $ESHOME/bin/x-pack/sql-cli --debug true "http://elastic@127.0.0.1:9200" <