Skip to content

Commit

Permalink
move pplenabled to transportaction
Browse files Browse the repository at this point in the history
Signed-off-by: zane-neo <[email protected]>
  • Loading branch information
zane-neo committed Nov 24, 2023
1 parent 4af150e commit 647176e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public List<RestHandler> getRestHandlers(
Metrics.getInstance().registerDefaultMetrics();

return Arrays.asList(
new RestPPLQueryAction(pluginSettings, settings),
new RestPPLQueryAction(),
new RestSqlAction(settings, injector),
new RestSqlStatsAction(settings, restController),
new RestPPLStatsAction(settings, restController),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,9 @@ public class RestPPLQueryAction extends BaseRestHandler {

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

private final Supplier<Boolean> pplEnabled;

/** Constructor of RestPPLQueryAction. */
public RestPPLQueryAction(
Settings pluginSettings, org.opensearch.common.settings.Settings clusterSettings) {
public RestPPLQueryAction() {
super();
this.pplEnabled =
() ->
MULTI_ALLOW_EXPLICIT_INDEX.get(clusterSettings)
&& (Boolean) pluginSettings.getSettingValue(Settings.Key.PPL_ENABLED);
}

private static boolean isClientError(Exception e) {
Expand Down Expand Up @@ -104,17 +97,6 @@ protected Set<String> responseParams() {

@Override
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);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

package org.opensearch.sql.plugin.transport;

import static org.opensearch.rest.BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX;
import static org.opensearch.sql.protocol.response.format.JsonResponseFormatter.Style.PRETTY;

import java.util.Locale;
import java.util.Optional;
import java.util.function.Supplier;

import org.opensearch.action.ActionRequest;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
Expand All @@ -19,6 +22,7 @@
import org.opensearch.common.inject.ModulesBuilder;
import org.opensearch.core.action.ActionListener;
import org.opensearch.sql.common.response.ResponseListener;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.common.utils.QueryContext;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasources.service.DataSourceServiceImpl;
Expand Down Expand Up @@ -47,14 +51,18 @@ public class TransportPPLQueryAction

private final Injector injector;

private final Supplier<Boolean> pplEnabled;

/** Constructor of TransportPPLQueryAction. */
@Inject
public TransportPPLQueryAction(
TransportService transportService,
ActionFilters actionFilters,
NodeClient client,
ClusterService clusterService,
DataSourceServiceImpl dataSourceService) {
DataSourceServiceImpl dataSourceService,
Settings pluginSettings,
org.opensearch.common.settings.Settings clusterSettings) {
super(PPLQueryAction.NAME, transportService, actionFilters, TransportPPLQueryRequest::new);

ModulesBuilder modules = new ModulesBuilder();
Expand All @@ -67,6 +75,10 @@ public TransportPPLQueryAction(
b.bind(DataSourceService.class).toInstance(dataSourceService);
});
this.injector = modules.createInjector();
this.pplEnabled =
() ->
MULTI_ALLOW_EXPLICIT_INDEX.get(clusterSettings)
&& (Boolean) pluginSettings.getSettingValue(Settings.Key.PPL_ENABLED);
}

/**
Expand All @@ -76,6 +88,12 @@ public TransportPPLQueryAction(
@Override
protected void doExecute(
Task task, ActionRequest request, ActionListener<TransportPPLQueryResponse> listener) {
if (!pplEnabled.get()) {
listener.onFailure(new IllegalAccessException(
"Either plugins.ppl.enabled or rest.action.multi.allow_explicit_index setting is"
+ " false"));
return;
}
Metrics.getInstance().getNumericalMetric(MetricName.PPL_REQ_TOTAL).increment();
Metrics.getInstance().getNumericalMetric(MetricName.PPL_REQ_COUNT_TOTAL).increment();

Expand Down

0 comments on commit 647176e

Please sign in to comment.