diff --git a/build.gradle b/build.gradle index 3751e4bd76..a756577fa9 100644 --- a/build.gradle +++ b/build.gradle @@ -14,16 +14,15 @@ */ buildscript { - ext { - // When upgrading to version after 7.3.0, must remove also - // project substitution from configurations.all (line 39) - es_version = System.getProperty("es.version", "7.6.1") + es_version = "7.6.1" } - // This isn't applying from repositories.gradle so repeating it here + repositories { mavenCentral() - } + maven { url "https://plugins.gradle.org/m2/" } + jcenter() + } dependencies { classpath "org.elasticsearch.gradle:build-tools:${es_version}" @@ -37,18 +36,6 @@ plugins { id "io.freefair.lombok" version "5.0.0-rc4" } -/* -Temporary fix, must be removed after 7.3.0 See -https://github.com/elastic/elasticsearch/issues/45073 - -Also must remove include ':rest-api-spec' from settings.gradle -*/ -configurations.all { - resolutionStrategy.dependencySubstitution { - substitute project(':rest-api-spec') with module ("org.elasticsearch:rest-api-spec:${es_version}") - } -} - // Repository on root level is for dependencies that project code depends on. And this block must be placed after plugins{} repositories { mavenCentral() // For Elastic Libs that you can use to get started coding until open ES libs are available @@ -59,10 +46,24 @@ ext { isSnapshot = "true" == System.getProperty("build.snapshot", "true") } -version = "${opendistroVersion}.0" +allprojects { + version = "${opendistroVersion}.0" + + plugins.withId('java') { + sourceCompatibility = targetCompatibility = "1.8" + } +} apply plugin: 'elasticsearch.esplugin' apply plugin: 'elasticsearch.testclusters' +// Todo, removed after migrate SQL to subProject +project('plugin') { + apply plugin: 'elasticsearch.esplugin' +} +// Todo, removed after migrate SQL to subProject +project('integ-test') { + apply plugin: 'elasticsearch.testclusters' +} apply plugin: 'jacoco' if (!System.properties.containsKey('tests.rest.cluster') && !System.properties.containsKey('tests.cluster')){ apply from: 'build-tools/sqlplugin-coverage.gradle' @@ -291,7 +292,7 @@ afterEvaluate { maintainer 'OpenDistro for Elasticsearch Team ' url 'https://opendistro.github.io/elasticsearch/downloads' summary ''' - SQL plugin for OpenDistro for Elasticsearch. + SQL plugin for OpenDistro for Elasticsearch. Reference documentation can be found at https://opendistro.github.io/for-elasticsearch-docs/. '''.stripIndent().replace('\n', ' ').trim() } diff --git a/integ-test/build.gradle b/integ-test/build.gradle new file mode 100644 index 0000000000..ae58d9dd19 --- /dev/null +++ b/integ-test/build.gradle @@ -0,0 +1,40 @@ +apply plugin: 'elasticsearch.build' +apply plugin: 'elasticsearch.rest-test' +apply plugin: 'java' + +ext { + projectSubstitutions = [:] + licenseFile = rootProject.file('LICENSE.TXT') + noticeFile = rootProject.file('NOTICE') +} + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'org.elasticsearch.test', name: 'framework', version: '7.6.1' + testCompile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.6.1' + testCompile group: 'junit', name: 'junit', version: '4.12' + testCompile group: 'org.hamcrest', name: 'hamcrest', version: '2.1' + testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.11.1' +} + +dependencyLicenses.enabled = false +testingConventions.enabled = false +checkstyleTest.ignoreFailures = true + +tasks.integTest.dependsOn(':plugin:bundlePlugin') +testClusters.integTest { + testDistribution='oss' + plugin file(tasks.getByPath(':plugin:bundlePlugin').archiveFile) +} + +integTest.runner { + systemProperty 'tests.security.manager', 'false' + systemProperty('project.root', project.rootDir.absolutePath) + + if (System.getProperty("test.debug") != null) { + jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' + } +} \ No newline at end of file diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/PPLPluginIT.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/PPLPluginIT.java new file mode 100644 index 0000000000..07129630df --- /dev/null +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/PPLPluginIT.java @@ -0,0 +1,32 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.ppl; + +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; +import org.elasticsearch.test.rest.ESRestTestCase; + +import java.io.IOException; + +import static org.hamcrest.Matchers.is; + +public class PPLPluginIT extends ESRestTestCase { + + public void testQueryEndpointShouldOK() throws IOException { + Response response = client().performRequest(new Request("POST", "/_opendistro/_ppl")); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + } +} diff --git a/plugin/build.gradle b/plugin/build.gradle new file mode 100644 index 0000000000..6897cb7eba --- /dev/null +++ b/plugin/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'java' +apply plugin: 'idea' + +ext { + projectSubstitutions = [:] + licenseFile = rootProject.file('LICENSE.TXT') + noticeFile = rootProject.file('NOTICE') +} + +repositories { + mavenCentral() +} + +esplugin { + name 'opendistro_sql' + description 'Open Distro for Elasticsearch SQL' + classname 'com.amazon.opendistroforelasticsearch.sql.plugin.SQLPlugin' +} + +test.enabled = false +integTest.enabled = false +dependencyLicenses.enabled = false + +dependencies { + compile project(":ppl") +} \ No newline at end of file diff --git a/plugin/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/SQLPlugin.java b/plugin/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/SQLPlugin.java new file mode 100644 index 0000000000..1c92af4046 --- /dev/null +++ b/plugin/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/SQLPlugin.java @@ -0,0 +1,45 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.plugin; + +import com.amazon.opendistroforelasticsearch.sql.plugin.rest.RestPPLQueryAction; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestHandler; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Supplier; + +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) { + return Arrays.asList( + new RestPPLQueryAction(restController) + ); + } +} diff --git a/plugin/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/rest/RestPPLQueryAction.java b/plugin/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/rest/RestPPLQueryAction.java new file mode 100644 index 0000000000..86bb34081d --- /dev/null +++ b/plugin/src/main/java/com/amazon/opendistroforelasticsearch/sql/plugin/rest/RestPPLQueryAction.java @@ -0,0 +1,60 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.plugin.rest; + +import com.amazon.opendistroforelasticsearch.sql.ppl.PPLService; +import com.amazon.opendistroforelasticsearch.sql.ppl.ResponseListener; +import com.amazon.opendistroforelasticsearch.sql.ppl.domain.PPLQueryRequest; +import com.amazon.opendistroforelasticsearch.sql.ppl.domain.PPLQueryResponse; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; + +import java.io.IOException; + +import static org.elasticsearch.rest.RestStatus.OK; + +public class RestPPLQueryAction extends BaseRestHandler { + public static final String QUERY_API_ENDPOINT = "/_opendistro/_ppl"; + + public RestPPLQueryAction(RestController restController) { + super(); + restController.registerHandler(RestRequest.Method.POST, QUERY_API_ENDPOINT, this); + } + + @Override + public String getName() { + return "ppl_query_action"; + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + PPLService pplService = new PPLService(); + return channel -> pplService.execute(new PPLQueryRequest(), new ResponseListener() { + @Override + public void onResponse(PPLQueryResponse pplQueryResponse) { + channel.sendResponse(new BytesRestResponse(OK, "application/json; charset=UTF-8", "ok")); + } + + @Override + public void onFailure(Exception e) { + channel.sendResponse(new BytesRestResponse(OK, "application/json; charset=UTF-8", "error")); + } + }); + } +} diff --git a/ppl/build.gradle b/ppl/build.gradle new file mode 100644 index 0000000000..f481795a62 --- /dev/null +++ b/ppl/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'java' + id "io.freefair.lombok" +} + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/ppl/lombok.config b/ppl/lombok.config new file mode 100644 index 0000000000..6aa51d71ec --- /dev/null +++ b/ppl/lombok.config @@ -0,0 +1,2 @@ +# This file is generated by the 'io.freefair.lombok' Gradle plugin +config.stopBubbling = true diff --git a/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/PPLService.java b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/PPLService.java new file mode 100644 index 0000000000..97afcdac96 --- /dev/null +++ b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/PPLService.java @@ -0,0 +1,28 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.ppl; + +import com.amazon.opendistroforelasticsearch.sql.ppl.domain.PPLQueryRequest; +import com.amazon.opendistroforelasticsearch.sql.ppl.domain.PPLQueryResponse; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class PPLService { + + public void execute(PPLQueryRequest request, ResponseListener listener) { + listener.onResponse(new PPLQueryResponse()); + } +} diff --git a/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/ResponseListener.java b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/ResponseListener.java new file mode 100644 index 0000000000..63fe7a179e --- /dev/null +++ b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/ResponseListener.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.ppl; + +public interface ResponseListener { + + void onResponse(Response response); + + void onFailure(Exception e); +} diff --git a/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/domain/PPLQueryRequest.java b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/domain/PPLQueryRequest.java new file mode 100644 index 0000000000..8301ec9fab --- /dev/null +++ b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/domain/PPLQueryRequest.java @@ -0,0 +1,19 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.ppl.domain; + +public class PPLQueryRequest { +} diff --git a/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/domain/PPLQueryResponse.java b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/domain/PPLQueryResponse.java new file mode 100644 index 0000000000..d7da904314 --- /dev/null +++ b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/domain/PPLQueryResponse.java @@ -0,0 +1,19 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ + +package com.amazon.opendistroforelasticsearch.sql.ppl.domain; + +public class PPLQueryResponse { +} diff --git a/settings.gradle b/settings.gradle index 8bece21c25..54e60e757a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,5 +15,6 @@ rootProject.name = 'opendistro-sql' - -include ':rest-api-spec' \ No newline at end of file +include 'plugin' +include 'ppl' +include 'integ-test'