Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

[PPL] init basic codebase structure #409

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment on lines -19 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing about this PR, but I wonder if another PR is needed to remove these deprecated in master as well. I can run some tests and help with that.

}
// 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}"
Expand All @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -291,7 +292,7 @@ afterEvaluate {
maintainer 'OpenDistro for Elasticsearch Team <[email protected]>'
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()
}
Expand Down
40 changes: 40 additions & 0 deletions integ-test/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
26 changes: 26 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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<RestHandler> getRestHandlers(Settings settings, RestController restController,
ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings,
SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(
new RestPPLQueryAction(restController)
);
}
}
Original file line number Diff line number Diff line change
@@ -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<PPLQueryResponse>() {
@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"));
}
});
}
}
12 changes: 12 additions & 0 deletions ppl/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id 'java'
id "io.freefair.lombok"
}

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
2 changes: 2 additions & 0 deletions ppl/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
Original file line number Diff line number Diff line change
@@ -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<PPLQueryResponse> listener) {
listener.onResponse(new PPLQueryResponse());
}
}
Original file line number Diff line number Diff line change
@@ -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<Response> {

void onResponse(Response response);

void onFailure(Exception e);
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Loading