Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/sl google java format15 #341

Merged
merged 4 commits into from
Aug 16, 2023
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
17 changes: 11 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Comment on lines +90 to +92

Choose a reason for hiding this comment

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

There are no java files here

'spark/**/*.java',
'ppl/**/*.java',
'spark/**/*.java',
'plugin/**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
Expand Down Expand Up @@ -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"
}
}

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

checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true

javadoc.enabled = false
loggerUsageCheck.enabled = false
dependencyLicenses.enabled = false
Expand Down
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Up @@ -45,8 +45,7 @@ public class OpenSearchPluginModule extends AbstractModule {
BuiltinFunctionRepository.getInstance();

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

@Provides
public OpenSearchClient openSearchClient(NodeClient nodeClient) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.plugin.request;

import java.util.Map;
Expand All @@ -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";
Expand All @@ -28,6 +25,7 @@ public class PPLQueryRequestFactory {

/**
* Build {@link PPLQueryRequest} from {@link RestRequest}.
*
* @param request {@link PPLQueryRequest}
* @return {@link RestRequest}
*/
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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()));
}
}

Expand Down
Loading
Loading