diff --git a/plugin/build.gradle b/plugin/build.gradle index 8a14c139f41..21313ae796d 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -16,7 +16,7 @@ es_meta_plugin { name = 'x-pack' description = 'Elasticsearch Expanded Pack Plugin' plugins = ['core', 'deprecation', 'graph', 'logstash', - 'ml', 'monitoring', 'security', 'upgrade', 'watcher'] + 'ml', 'monitoring', 'security', 'upgrade', 'watcher', 'sql'] } ext.expansions = [ @@ -155,5 +155,6 @@ run { setting 'xpack.security.enabled', 'true' setting 'xpack.monitoring.enabled', 'true' setting 'xpack.watcher.enabled', 'true' + setting 'xpack.sql.enabled', 'true' keystoreSetting 'bootstrap.password', 'password' } diff --git a/plugin/security/build.gradle b/plugin/security/build.gradle index b6398af804d..72ee2a0a5d6 100644 --- a/plugin/security/build.gradle +++ b/plugin/security/build.gradle @@ -26,6 +26,7 @@ dependencies { provided project(path: ':plugins:transport-nio', configuration: 'runtime') testCompile project(path: ':x-pack-elasticsearch:plugin:monitoring') + testCompile project(path: ':x-pack-elasticsearch:plugin:sql:sql-proto') testCompile project(path: ':x-pack-elasticsearch:plugin:core', configuration: 'testArtifacts') diff --git a/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java b/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java index 5c3a39b2e51..1b14e5a105d 100644 --- a/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java +++ b/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java @@ -64,11 +64,6 @@ import org.elasticsearch.xpack.security.user.SystemUser; import org.elasticsearch.xpack.security.user.User; import org.elasticsearch.xpack.security.user.XPackSecurityUser; import org.elasticsearch.xpack.security.user.XPackUser; -import org.elasticsearch.xpack.sql.plugin.SqlQueryAction; -import org.elasticsearch.xpack.sql.plugin.SqlClearCursorAction; -import org.elasticsearch.xpack.sql.plugin.SqlListColumnsAction; -import org.elasticsearch.xpack.sql.plugin.SqlListTablesAction; -import org.elasticsearch.xpack.sql.plugin.SqlTranslateAction; import java.util.Arrays; import java.util.Collections; @@ -483,10 +478,10 @@ public class AuthorizationService extends AbstractComponent { action.equals("indices:data/read/msearch/template") || action.equals("indices:data/read/search/template") || action.equals("indices:data/write/reindex") || - action.equals(SqlQueryAction.NAME) || - action.equals(SqlTranslateAction.NAME) || - action.equals(SqlListTablesAction.NAME) || - action.equals(SqlListColumnsAction.NAME) ; + action.equals("indices:data/read/sql") || + action.equals("indices:data/read/sql/translate") || + action.equals("indices:admin/sql/tables") || + action.equals("indices:admin/sql/columns") ; } private static boolean isTranslatedToBulkAction(String action) { @@ -505,7 +500,7 @@ public class AuthorizationService extends AbstractComponent { action.equals(SearchTransportService.QUERY_SCROLL_ACTION_NAME) || action.equals(SearchTransportService.FREE_CONTEXT_SCROLL_ACTION_NAME) || action.equals(ClearScrollAction.NAME) || - action.equals(SqlClearCursorAction.NAME) || + action.equals("indices:data/read/sql/close_cursor") || action.equals(SearchTransportService.CLEAR_SCROLL_CONTEXTS_ACTION_NAME); } diff --git a/plugin/security/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java b/plugin/security/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java index 1d72eeaf970..f4c36161878 100644 --- a/plugin/security/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java @@ -388,11 +388,11 @@ public class XPackLicenseStateTests extends ESTestCase { } public void testSqlAckAnyToTrialOrPlatinum() { - assertAckMesssages(XpackField.SQL, randomMode(), randomTrialOrPlatinumMode(), 0); + assertAckMesssages(XPackField.SQL, randomMode(), randomTrialOrPlatinumMode(), 0); } public void testSqlAckTrialOrPlatinumToNotTrialOrPlatinum() { - assertAckMesssages(XpackField.SQL, randomTrialOrPlatinumMode(), randomBasicStandardOrGold(), 1); + assertAckMesssages(XPackField.SQL, randomTrialOrPlatinumMode(), randomBasicStandardOrGold(), 1); } } diff --git a/plugin/sql/build.gradle b/plugin/sql/build.gradle index 591274fb868..d25f76535e6 100644 --- a/plugin/sql/build.gradle +++ b/plugin/sql/build.gradle @@ -1,3 +1,5 @@ +evaluationDependsOn(':x-pack-elasticsearch:plugin:core') + apply plugin: 'elasticsearch.esplugin' esplugin { name 'x-pack-sql' @@ -12,12 +14,20 @@ esplugin { archivesBaseName = 'x-pack-sql' +// TODO: enable this once we have tests +integTest.enabled = false + dependencies { provided "org.elasticsearch:elasticsearch:${version}" compile project(':x-pack-elasticsearch:plugin:sql:sql-proto') - compile "org.elasticsearch.plugin:x-pack-core:${version}" + provided "org.elasticsearch.plugin:x-pack-core:${version}" compile 'org.antlr:antlr4-runtime:4.5.3' testCompile "org.elasticsearch.test:framework:${version}" + testCompile project(path: ':x-pack-elasticsearch:plugin:core', configuration: 'testArtifacts') + testCompile project(path: ':x-pack-elasticsearch:plugin:security', configuration: 'testArtifacts') + testCompile project(path: ':modules:reindex', configuration: 'runtime') + testCompile project(path: ':modules:parent-join', configuration: 'runtime') + testCompile project(path: ':modules:analysis-common', configuration: 'runtime') } dependencyLicenses { @@ -29,9 +39,6 @@ dependencyLicenses { ignoreSha 'sql-proto' } -// TODO: Should we move integrations tests here? -integTest.enabled = false - /********************************************** * SQL Parser regeneration * **********************************************/ diff --git a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java index e130949360f..71d387f3475 100644 --- a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java +++ b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java @@ -30,6 +30,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.XPackField; import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.sql.analysis.index.IndexResolver; import org.elasticsearch.xpack.sql.execution.PlanExecutor; @@ -46,11 +47,15 @@ public class SqlPlugin extends Plugin implements ActionPlugin { private final SqlLicenseChecker sqlLicenseChecker; private IndexResolver indexResolver; - public SqlPlugin(boolean enabled, SqlLicenseChecker sqlLicenseChecker) { + SqlPlugin(boolean enabled, SqlLicenseChecker sqlLicenseChecker) { this.enabled = enabled; - XPackLicenseState licenseState = XPackPlugin.getSharedLicenseState(); - this.sqlLicenseChecker = new SqlLicenseChecker( + this.sqlLicenseChecker = sqlLicenseChecker; + } + + public SqlPlugin(Settings settings) { + this(XPackSettings.SQL_ENABLED.get(settings), new SqlLicenseChecker( (mode) -> { + XPackLicenseState licenseState = XPackPlugin.getSharedLicenseState(); switch (mode) { case JDBC: if (licenseState.isJdbcAllowed() == false) { @@ -66,7 +71,7 @@ public class SqlPlugin extends Plugin implements ActionPlugin { throw new IllegalArgumentException("Unknown SQL mode " + mode); } } - ); + )); } @Override @@ -90,18 +95,19 @@ public class SqlPlugin extends Plugin implements ActionPlugin { @Override public List getRestHandlers(Settings settings, RestController restController, - ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, - IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { + ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, + SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { if (false == enabled) { return emptyList(); } return Arrays.asList(new RestSqlQueryAction(settings, restController), - new RestSqlTranslateAction(settings, restController), - new RestSqlClearCursorAction(settings, restController), - new RestSqlListTablesAction(settings, restController), - new RestSqlListColumnsAction(settings, restController)); + new RestSqlTranslateAction(settings, restController), + new RestSqlClearCursorAction(settings, restController), + new RestSqlListTablesAction(settings, restController), + new RestSqlListColumnsAction(settings, restController)); } @Override @@ -111,9 +117,9 @@ public class SqlPlugin extends Plugin implements ActionPlugin { } return Arrays.asList(new ActionHandler<>(SqlQueryAction.INSTANCE, TransportSqlQueryAction.class), - new ActionHandler<>(SqlTranslateAction.INSTANCE, TransportSqlTranslateAction.class), - new ActionHandler<>(SqlClearCursorAction.INSTANCE, TransportSqlClearCursorAction.class), - new ActionHandler<>(SqlListTablesAction.INSTANCE, TransportSqlListTablesAction.class), - new ActionHandler<>(SqlListColumnsAction.INSTANCE, TransportSqlListColumnsAction.class)); + new ActionHandler<>(SqlTranslateAction.INSTANCE, TransportSqlTranslateAction.class), + new ActionHandler<>(SqlClearCursorAction.INSTANCE, TransportSqlClearCursorAction.class), + new ActionHandler<>(SqlListTablesAction.INSTANCE, TransportSqlListTablesAction.class), + new ActionHandler<>(SqlListColumnsAction.INSTANCE, TransportSqlListColumnsAction.class)); } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlIntegTestCase.java b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/AbstractSqlIntegTestCase.java similarity index 92% rename from plugin/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlIntegTestCase.java rename to plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/AbstractSqlIntegTestCase.java index ae25ed7ed38..22bc2b1ae28 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlIntegTestCase.java +++ b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/AbstractSqlIntegTestCase.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql; +package org.elasticsearch.xpack.sql.action; import org.elasticsearch.analysis.common.CommonAnalysisPlugin; import org.elasticsearch.common.settings.Settings; @@ -13,7 +13,6 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.discovery.TestZenDiscovery; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; -import org.elasticsearch.xpack.ml.MachineLearning; import java.util.Arrays; import java.util.Collection; @@ -33,7 +32,7 @@ public abstract class AbstractSqlIntegTestCase extends ESIntegTestCase { settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.GRAPH_ENABLED.getKey(), false); settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); - settings.put(MachineLearning.AUTODETECT_PROCESS.getKey(), false); + settings.put("xpack.ml.autodetect_process", false); return settings.build(); } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlActionIT.java b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java similarity index 97% rename from plugin/src/test/java/org/elasticsearch/xpack/sql/SqlActionIT.java rename to plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java index 7e90bf987bf..762231d65a3 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlActionIT.java +++ b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlActionIT.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql; +package org.elasticsearch.xpack.sql.action; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.WriteRequest; @@ -17,6 +17,7 @@ import org.elasticsearch.xpack.sql.plugin.SqlListTablesAction; import org.elasticsearch.xpack.sql.plugin.SqlListTablesResponse; import org.elasticsearch.xpack.sql.plugin.SqlQueryAction; import org.elasticsearch.xpack.sql.plugin.SqlQueryResponse; +import org.hamcrest.Matchers; import java.io.IOException; import java.sql.JDBCType; @@ -98,7 +99,7 @@ public class SqlActionIT extends AbstractSqlIntegTestCase { .indexPattern("bar").columnPattern("").mode(Mode.JDBC).get(); List columns = response.getColumns(); assertThat(columns, hasSize(2)); - assertThat(columns, contains( + assertThat(columns, Matchers.contains( new MetaColumnInfo("bar", "int_field", "integer", JDBCType.INTEGER, 10, 1), new MetaColumnInfo("bar", "str_field", "text", JDBCType.VARCHAR, Integer.MAX_VALUE, 2) )); @@ -107,7 +108,7 @@ public class SqlActionIT extends AbstractSqlIntegTestCase { .indexPattern("bar").columnPattern("").mode(Mode.PLAIN).get(); columns = response.getColumns(); assertThat(columns, hasSize(2)); - assertThat(columns, contains( + assertThat(columns, Matchers.contains( new MetaColumnInfo("bar", "int_field", "integer", null, 0, 1), new MetaColumnInfo("bar", "str_field", "text", null, 0, 2) )); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlClearCursorActionIT.java b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java similarity index 99% rename from plugin/src/test/java/org/elasticsearch/xpack/sql/SqlClearCursorActionIT.java rename to plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java index c0413bb20ea..7b747ffeb67 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlClearCursorActionIT.java +++ b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorActionIT.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql; +package org.elasticsearch.xpack.sql.action; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.index.IndexRequest; diff --git a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlDisabledIT.java b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java similarity index 97% rename from plugin/src/test/java/org/elasticsearch/xpack/sql/SqlDisabledIT.java rename to plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java index 9b41b6ce1f4..81a963cae00 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlDisabledIT.java +++ b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlDisabledIT.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql; +package org.elasticsearch.xpack.sql.action; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.XPackSettings; diff --git a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlLicenseIT.java b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java similarity index 97% rename from plugin/src/test/java/org/elasticsearch/xpack/sql/SqlLicenseIT.java rename to plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java index b77cb553445..336d861b02d 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlLicenseIT.java +++ b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlLicenseIT.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql; +package org.elasticsearch.xpack.sql.action; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.action.index.IndexRequest; @@ -17,6 +17,7 @@ import org.elasticsearch.license.License.OperationMode; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; +import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.xpack.sql.plugin.SqlListColumnsAction; import org.elasticsearch.xpack.sql.plugin.SqlListColumnsResponse; @@ -35,7 +36,6 @@ import java.util.Locale; import static org.elasticsearch.license.XPackLicenseStateTests.randomBasicStandardOrGold; import static org.elasticsearch.license.XPackLicenseStateTests.randomTrialBasicStandardGoldOrPlatinumMode; import static org.elasticsearch.license.XPackLicenseStateTests.randomTrialOrPlatinumMode; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; @@ -191,7 +191,7 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase { // TODO test SqlGetIndicesAction. Skipping for now because of lack of serialization support. private void setupTestIndex() { - assertAcked(client().admin().indices().prepareCreate("test").get()); + ElasticsearchAssertions.assertAcked(client().admin().indices().prepareCreate("test").get()); client().prepareBulk() .add(new IndexRequest("test", "doc", "1").source("data", "bar", "count", 42)) .add(new IndexRequest("test", "doc", "2").source("data", "baz", "count", 43)) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlTranslateActionIT.java b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java similarity index 97% rename from plugin/src/test/java/org/elasticsearch/xpack/sql/SqlTranslateActionIT.java rename to plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java index 738bb0d912c..5de9cfca97a 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/sql/SqlTranslateActionIT.java +++ b/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateActionIT.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.sql; +package org.elasticsearch.xpack.sql.action; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.WriteRequest; diff --git a/plugin/src/test/resources/rest-api-spec/test/xpack/10_basic.yml b/plugin/src/test/resources/rest-api-spec/test/xpack/10_basic.yml index b1a6d5d80dd..17051390c3d 100644 --- a/plugin/src/test/resources/rest-api-spec/test/xpack/10_basic.yml +++ b/plugin/src/test/resources/rest-api-spec/test/xpack/10_basic.yml @@ -15,5 +15,6 @@ - match: { nodes.$master.plugins.4.name: x-pack-ml } - match: { nodes.$master.plugins.5.name: x-pack-monitoring } - match: { nodes.$master.plugins.6.name: x-pack-security } - - match: { nodes.$master.plugins.7.name: x-pack-upgrade } - - match: { nodes.$master.plugins.8.name: x-pack-watcher } + - match: { nodes.$master.plugins.7.name: x-pack-sql } + - match: { nodes.$master.plugins.8.name: x-pack-upgrade } + - match: { nodes.$master.plugins.9.name: x-pack-watcher }