Skip to content

Commit

Permalink
Dev/sl google java format15 (#341)
Browse files Browse the repository at this point in the history
* Spotless apply on 'datasources/**/*.java',
                                      'core/**/*.java',
                                      'docs/**/*.java',
                                      'doctest/**/*.java',
                                      'relase-notes/**/*.java',
                                      'spark/**/*.java'

Signed-off-by: Mitchell Gale <[email protected]>

* Added more directories to build.gradle

Signed-off-by: Mitchell Gale <[email protected]>

* spotless apply for plugin.

Signed-off-by: Mitchell Gale <[email protected]>

* Adding checkstyle ignorefailures.

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
MitchellGale authored Aug 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 491a73b commit 9718680
Showing 37 changed files with 566 additions and 583 deletions.
17 changes: 11 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -84,10 +84,16 @@ repositories {
spotless {
java {
target fileTree('.') {
include 'common/**/*.java',
'datasources/**/*.java',
include 'datasources/**/*.java',
'core/**/*.java',
'ppl/**/*.java'
'common/**/*.java',
'docs/**/*.java',
'doctest/**/*.java',
'relase-notes/**/*.java',
'spark/**/*.java',
'ppl/**/*.java',
'spark/**/*.java',
'plugin/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
@@ -116,9 +122,8 @@ allprojects {
sourceCompatibility = targetCompatibility = "11"
}
configurations.all {
resolutionStrategy.force "com.squareup.okio:okio:3.5.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0"
}
}

3 changes: 3 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -85,6 +85,9 @@ publishing {
}
}

checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true

javadoc.enabled = false
loggerUsageCheck.enabled = false
dependencyLicenses.enabled = false
77 changes: 42 additions & 35 deletions plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java
Original file line number Diff line number Diff line change
@@ -94,10 +94,10 @@ public class SQLPlugin extends Plugin implements ActionPlugin, ScriptPlugin {
private static final Logger LOGGER = LogManager.getLogger(SQLPlugin.class);

private ClusterService clusterService;
/**
* Settings should be inited when bootstrap the plugin.
*/

/** Settings should be inited when bootstrap the plugin. */
private org.opensearch.sql.common.setting.Settings pluginSettings;

private NodeClient client;
private DataSourceServiceImpl dataSourceService;
private Injector injector;
@@ -134,23 +134,28 @@ public List<RestHandler> getRestHandlers(
new RestDataSourceQueryAction());
}

/**
* Register action and handler so that transportClient can find proxy for action.
*/
/** Register action and handler so that transportClient can find proxy for action. */
@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(
new ActionHandler<>(
new ActionType<>(PPLQueryAction.NAME, TransportPPLQueryResponse::new),
TransportPPLQueryAction.class),
new ActionHandler<>(new ActionType<>(TransportCreateDataSourceAction.NAME,
CreateDataSourceActionResponse::new), TransportCreateDataSourceAction.class),
new ActionHandler<>(new ActionType<>(TransportGetDataSourceAction.NAME,
GetDataSourceActionResponse::new), TransportGetDataSourceAction.class),
new ActionHandler<>(new ActionType<>(TransportUpdateDataSourceAction.NAME,
UpdateDataSourceActionResponse::new), TransportUpdateDataSourceAction.class),
new ActionHandler<>(new ActionType<>(TransportDeleteDataSourceAction.NAME,
DeleteDataSourceActionResponse::new), TransportDeleteDataSourceAction.class));
new ActionHandler<>(
new ActionType<>(
TransportCreateDataSourceAction.NAME, CreateDataSourceActionResponse::new),
TransportCreateDataSourceAction.class),
new ActionHandler<>(
new ActionType<>(TransportGetDataSourceAction.NAME, GetDataSourceActionResponse::new),
TransportGetDataSourceAction.class),
new ActionHandler<>(
new ActionType<>(
TransportUpdateDataSourceAction.NAME, UpdateDataSourceActionResponse::new),
TransportUpdateDataSourceAction.class),
new ActionHandler<>(
new ActionType<>(
TransportDeleteDataSourceAction.NAME, DeleteDataSourceActionResponse::new),
TransportDeleteDataSourceAction.class));
}

@Override
@@ -176,11 +181,12 @@ public Collection<Object> createComponents(

ModulesBuilder modules = new ModulesBuilder();
modules.add(new OpenSearchPluginModule());
modules.add(b -> {
b.bind(NodeClient.class).toInstance((NodeClient) client);
b.bind(org.opensearch.sql.common.setting.Settings.class).toInstance(pluginSettings);
b.bind(DataSourceService.class).toInstance(dataSourceService);
});
modules.add(
b -> {
b.bind(NodeClient.class).toInstance((NodeClient) client);
b.bind(org.opensearch.sql.common.setting.Settings.class).toInstance(pluginSettings);
b.bind(DataSourceService.class).toInstance(dataSourceService);
});

injector = modules.createInjector();
return ImmutableList.of(dataSourceService);
@@ -212,30 +218,31 @@ public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<
}

private DataSourceServiceImpl createDataSourceService() {
String masterKey = OpenSearchSettings
.DATASOURCE_MASTER_SECRET_KEY.get(clusterService.getSettings());
String masterKey =
OpenSearchSettings.DATASOURCE_MASTER_SECRET_KEY.get(clusterService.getSettings());
if (StringUtils.isEmpty(masterKey)) {
LOGGER.warn("Master key is a required config for using create and update datasource APIs. "
+ "Please set plugins.query.datasources.encryption.masterkey config "
+ "in opensearch.yml in all the cluster nodes. "
+ "More details can be found here: "
+ "https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/"
+ "admin/datasources.rst#master-key-config-for-encrypting-credential-information");
LOGGER.warn(
"Master key is a required config for using create and update datasource APIs. "
+ "Please set plugins.query.datasources.encryption.masterkey config "
+ "in opensearch.yml in all the cluster nodes. "
+ "More details can be found here: "
+ "https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/"
+ "admin/datasources.rst#master-key-config-for-encrypting-credential-information");
}
DataSourceMetadataStorage dataSourceMetadataStorage
= new OpenSearchDataSourceMetadataStorage(client, clusterService,
new EncryptorImpl(masterKey));
DataSourceUserAuthorizationHelper dataSourceUserAuthorizationHelper
= new DataSourceUserAuthorizationHelperImpl(client);
DataSourceMetadataStorage dataSourceMetadataStorage =
new OpenSearchDataSourceMetadataStorage(
client, clusterService, new EncryptorImpl(masterKey));
DataSourceUserAuthorizationHelper dataSourceUserAuthorizationHelper =
new DataSourceUserAuthorizationHelperImpl(client);
return new DataSourceServiceImpl(
new ImmutableSet.Builder<DataSourceFactory>()
.add(new OpenSearchDataSourceFactory(
new OpenSearchNodeClient(this.client), pluginSettings))
.add(
new OpenSearchDataSourceFactory(
new OpenSearchNodeClient(this.client), pluginSettings))
.add(new PrometheusStorageFactory(pluginSettings))
.add(new SparkStorageFactory(this.client, pluginSettings))
.build(),
dataSourceMetadataStorage,
dataSourceUserAuthorizationHelper);
}

}
Original file line number Diff line number Diff line change
@@ -45,8 +45,7 @@ public class OpenSearchPluginModule extends AbstractModule {
BuiltinFunctionRepository.getInstance();

@Override
protected void configure() {
}
protected void configure() {}

@Provides
public OpenSearchClient openSearchClient(NodeClient nodeClient) {
@@ -59,8 +58,8 @@ public StorageEngine storageEngine(OpenSearchClient client, Settings settings) {
}

@Provides
public ExecutionEngine executionEngine(OpenSearchClient client, ExecutionProtector protector,
PlanSerializer planSerializer) {
public ExecutionEngine executionEngine(
OpenSearchClient client, ExecutionProtector protector, PlanSerializer planSerializer) {
return new OpenSearchExecutionEngine(client, protector, planSerializer);
}

@@ -95,18 +94,15 @@ public SQLService sqlService(QueryManager queryManager, QueryPlanFactory queryPl
return new SQLService(new SQLSyntaxParser(), queryManager, queryPlanFactory);
}

/**
* {@link QueryPlanFactory}.
*/
/** {@link QueryPlanFactory}. */
@Provides
public QueryPlanFactory queryPlanFactory(DataSourceService dataSourceService,
ExecutionEngine executionEngine) {
public QueryPlanFactory queryPlanFactory(
DataSourceService dataSourceService, ExecutionEngine executionEngine) {
Analyzer analyzer =
new Analyzer(
new ExpressionAnalyzer(functionRepository), dataSourceService, functionRepository);
Planner planner = new Planner(LogicalPlanOptimizer.create());
QueryService queryService = new QueryService(
analyzer, executionEngine, planner);
QueryService queryService = new QueryService(analyzer, executionEngine, planner);
return new QueryPlanFactory(queryService);
}
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.plugin.request;

import java.util.Map;
@@ -15,9 +14,7 @@
import org.opensearch.sql.protocol.response.format.Format;
import org.opensearch.sql.protocol.response.format.JsonResponseFormatter;

/**
* Factory of {@link PPLQueryRequest}.
*/
/** Factory of {@link PPLQueryRequest}. */
public class PPLQueryRequestFactory {
private static final String PPL_URL_PARAM_KEY = "ppl";
private static final String PPL_FIELD_NAME = "query";
@@ -28,6 +25,7 @@ public class PPLQueryRequestFactory {

/**
* Build {@link PPLQueryRequest} from {@link RestRequest}.
*
* @param request {@link PPLQueryRequest}
* @return {@link RestRequest}
*/
@@ -63,8 +61,12 @@ private static PPLQueryRequest parsePPLRequestFromPayload(RestRequest restReques
} catch (JSONException e) {
throw new IllegalArgumentException("Failed to parse request payload", e);
}
PPLQueryRequest pplRequest = new PPLQueryRequest(jsonContent.getString(PPL_FIELD_NAME),
jsonContent, restRequest.path(), format.getFormatName());
PPLQueryRequest pplRequest =
new PPLQueryRequest(
jsonContent.getString(PPL_FIELD_NAME),
jsonContent,
restRequest.path(),
format.getFormatName());
// set sanitize option if csv format
if (format.equals(Format.CSV)) {
pplRequest.sanitize(getSanitizeOption(restRequest.params()));
Original file line number Diff line number Diff line change
@@ -102,14 +102,17 @@ protected Set<String> responseParams() {
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient nodeClient) {
// TODO: need move to transport Action
if (!pplEnabled.get()) {
return channel -> reportError(channel, new IllegalAccessException(
"Either plugins.ppl.enabled or rest.action.multi.allow_explicit_index setting is false"),
BAD_REQUEST);
return channel ->
reportError(
channel,
new IllegalAccessException(
"Either plugins.ppl.enabled or rest.action.multi.allow_explicit_index setting is"
+ " false"),
BAD_REQUEST);
}

TransportPPLQueryRequest transportPPLQueryRequest = new TransportPPLQueryRequest(
PPLQueryRequestFactory.getPPLRequest(request)
);
TransportPPLQueryRequest transportPPLQueryRequest =
new TransportPPLQueryRequest(PPLQueryRequestFactory.getPPLRequest(request));

return channel ->
nodeClient.execute(
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.plugin.rest;

import static org.opensearch.core.rest.RestStatus.SERVICE_UNAVAILABLE;
@@ -26,17 +25,14 @@
import org.opensearch.sql.legacy.executor.format.ErrorMessageFactory;
import org.opensearch.sql.legacy.metrics.Metrics;

/**
* PPL Node level status.
*/
/** PPL Node level status. */
public class RestPPLStatsAction extends BaseRestHandler {

private static final Logger LOG = LogManager.getLogger(RestPPLStatsAction.class);

/**
* API endpoint path.
*/
/** API endpoint path. */
public static final String PPL_STATS_API_ENDPOINT = "/_plugins/_ppl/stats";

public static final String PPL_LEGACY_STATS_API_ENDPOINT = "/_opendistro/_ppl/stats";

public RestPPLStatsAction(Settings settings, RestController restController) {
@@ -70,13 +66,18 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
QueryContext.addRequestId();

try {
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK,
Metrics.getInstance().collectToJSON()));
return channel ->
channel.sendResponse(
new BytesRestResponse(RestStatus.OK, Metrics.getInstance().collectToJSON()));
} catch (Exception e) {
LOG.error("Failed during Query PPL STATS Action.", e);

return channel -> channel.sendResponse(new BytesRestResponse(SERVICE_UNAVAILABLE,
ErrorMessageFactory.createErrorMessage(e, SERVICE_UNAVAILABLE.getStatus()).toString()));
return channel ->
channel.sendResponse(
new BytesRestResponse(
SERVICE_UNAVAILABLE,
ErrorMessageFactory.createErrorMessage(e, SERVICE_UNAVAILABLE.getStatus())
.toString()));
}
}

Loading

0 comments on commit 9718680

Please sign in to comment.