Skip to content

Commit

Permalink
refactor and merge req/response model
Browse files Browse the repository at this point in the history
Signed-off-by: Zhongnan Su <[email protected]>
  • Loading branch information
zhongnansu committed May 31, 2022
1 parent d852466 commit ea32529
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 529 deletions.
11 changes: 0 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ buildscript {
// 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT (opensearch_build)
opensearch_build += "-SNAPSHOT"
}
common_utils_version = System.getProperty("common_utils.version", opensearch_build)
kotlin_version = System.getProperty("kotlin.version", "1.4.32")
}

repositories {
Expand All @@ -30,8 +28,6 @@ buildscript {

dependencies {
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}"
}
}

Expand All @@ -43,9 +39,6 @@ plugins {
id 'jacoco'
}

apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.allopen'

// Repository on root level is for dependencies that project code depends on. And this block must be placed after plugins{}
repositories {
mavenLocal()
Expand All @@ -66,10 +59,6 @@ allprojects {
plugins.withId('java') {
sourceCompatibility = targetCompatibility = "11"
}

plugins.withId('org.jetbrains.kotlin.jvm') {
compileKotlin.kotlinOptions.jvmTarget = compileTestKotlin.kotlinOptions.jvmTarget = "1.8"
}
}

subprojects {
Expand Down
14 changes: 1 addition & 13 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,8 @@ dependencies {
api project(":ppl")
api project(':legacy')
api project(':opensearch')
api "org.opensearch:common-utils:${common_utils_version}"
api "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
api "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
}

configurations.all {
if (it.state != Configuration.State.UNRESOLVED) return
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
force "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
}
}

ext {
projectSubstitutions = [:]
Expand Down Expand Up @@ -116,14 +106,12 @@ dependencyLicenses.enabled = false
// enable testingConventions check will cause errors like: "Classes ending with [Tests] must subclass [LuceneTestCase]"
testingConventions.enabled = false

// TODO: need to verify the thirdParty
// TODO: need to verify the thirdPartyAudi
// currently it complains missing classes like ibatis, mysql etc, should not be a problem
thirdPartyAudit.enabled = false


apply plugin: 'nebula.ospackage'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.allopen'
validateNebulaPom.enabled = false

// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
Expand Down
64 changes: 6 additions & 58 deletions plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
package org.opensearch.sql.plugin;

import com.google.common.collect.ImmutableList;

import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -20,7 +17,6 @@
import org.opensearch.action.ActionResponse;
import org.opensearch.action.ActionType;
import org.opensearch.client.Client;
import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.cluster.service.ClusterService;
Expand All @@ -32,8 +28,6 @@
import org.opensearch.common.settings.SettingsFilter;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.commons.sql.action.SQLActions;
import org.opensearch.commons.sql.action.TransportQueryResponse;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.plugins.ActionPlugin;
Expand All @@ -48,30 +42,22 @@
import org.opensearch.sql.legacy.esdomain.LocalClusterState;
import org.opensearch.sql.legacy.executor.AsyncRestExecutor;
import org.opensearch.sql.legacy.metrics.Metrics;
import org.opensearch.sql.legacy.plugin.OpenSearchSQLPluginConfig;
import org.opensearch.sql.legacy.plugin.RestSqlAction;
import org.opensearch.sql.legacy.plugin.RestSqlStatsAction;
import org.opensearch.sql.opensearch.security.SecurityAccess;
import org.opensearch.sql.opensearch.setting.LegacyOpenDistroSettings;
import org.opensearch.sql.opensearch.setting.OpenSearchSettings;
import org.opensearch.sql.opensearch.storage.script.ExpressionScriptEngine;
import org.opensearch.sql.opensearch.storage.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.plugin.rest.OpenSearchPluginConfig;
import org.opensearch.sql.plugin.rest.RestPPLQueryAction;
import org.opensearch.sql.plugin.rest.RestPPLStatsAction;
import org.opensearch.sql.plugin.rest.RestQuerySettingsAction;
import org.opensearch.sql.plugin.transport.PPLQueryHelper;
import org.opensearch.sql.plugin.transport.SQLQueryHelper;
import org.opensearch.sql.plugin.transport.TransportQueryAction;
import org.opensearch.sql.ppl.PPLService;
import org.opensearch.sql.ppl.config.PPLServiceConfig;
import org.opensearch.sql.sql.SQLService;
import org.opensearch.sql.sql.config.SQLServiceConfig;
import org.opensearch.sql.plugin.transport.PPLQueryAction;
import org.opensearch.sql.plugin.transport.TransportPPLQueryAction;
import org.opensearch.sql.plugin.transport.TransportPPLQueryResponse;
import org.opensearch.threadpool.ExecutorBuilder;
import org.opensearch.threadpool.FixedExecutorBuilder;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.watcher.ResourceWatcherService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class SQLPlugin extends Plugin implements ActionPlugin, ScriptPlugin {

Expand Down Expand Up @@ -104,7 +90,7 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
Metrics.getInstance().registerDefaultMetrics();

return Arrays.asList(
new RestPPLQueryAction(restController, clusterService, pluginSettings, settings),
new RestPPLQueryAction(pluginSettings, settings),
new RestSqlAction(settings, clusterService, pluginSettings),
new RestSqlStatsAction(settings, restController),
new RestPPLStatsAction(settings, restController),
Expand All @@ -120,8 +106,8 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
return Arrays
.asList(
new ActionHandler<>(
new ActionType<>(SQLActions.SEND_SQL_QUERY_NAME, TransportQueryResponse::new),
TransportQueryAction.class
new ActionType<>(PPLQueryAction.NAME, TransportPPLQueryResponse::new),
TransportPPLQueryAction.class
)
);
}
Expand All @@ -145,50 +131,12 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
LocalClusterState.state().setClusterService(clusterService);
LocalClusterState.state().setPluginSettings((OpenSearchSettings) pluginSettings);

PPLQueryHelper.getInstance().setPplService(createPPLService((NodeClient) client));
SQLQueryHelper.getInstance().setSqlService(createSQLService((NodeClient) client));

return super
.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService,
contentRegistry, environment, nodeEnvironment, namedWriteableRegistry,
indexNameResolver, repositoriesServiceSupplier);
}

private <T> T doPrivileged(PrivilegedExceptionAction<T> action) {
try {
return SecurityAccess.doPrivileged(action);
} catch (IOException e) {
throw new IllegalStateException("Failed to perform privileged action", e);
}
}


private PPLService createPPLService(NodeClient client) {
return doPrivileged(() -> {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.registerBean(ClusterService.class, () -> clusterService);
context.registerBean(NodeClient.class, () -> client);
context.registerBean(org.opensearch.sql.common.setting.Settings.class, () -> pluginSettings);
context.register(OpenSearchPluginConfig.class);
context.register(PPLServiceConfig.class);
context.refresh();
return context.getBean(PPLService.class);
});
}

private SQLService createSQLService(NodeClient client) {
return doPrivileged(() -> {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.registerBean(ClusterService.class, () -> clusterService);
context.registerBean(NodeClient.class, () -> client);
context.registerBean(org.opensearch.sql.common.setting.Settings.class, () -> pluginSettings);
context.register(OpenSearchSQLPluginConfig.class);
context.register(SQLServiceConfig.class);
context.refresh();
return context.getBean(SQLService.class);
});
}

@Override
public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
return Collections.singletonList(
Expand Down
Loading

0 comments on commit ea32529

Please sign in to comment.