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

Create separate transport action for render search template action #11170

Merged
merged 3 commits into from
Dec 12, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Allow changing number of replicas of searchable snapshot index ([#11317](https://github.com/opensearch-project/OpenSearch/pull/11317))
- Adding slf4j license header to LoggerMessageFormat.java ([#11069](https://github.com/opensearch-project/OpenSearch/pull/11069))
- [BWC and API enforcement] Introduce checks for enforcing the API restrictions ([#11175](https://github.com/opensearch-project/OpenSearch/pull/11175))
- Create separate transport action for render search template action ([#11170](https://github.com/opensearch-project/OpenSearch/pull/11170))

### Dependencies
- Bump Lucene from 9.7.0 to 9.8.0 ([10276](https://github.com/opensearch-project/OpenSearch/pull/10276))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(
new ActionHandler<>(SearchTemplateAction.INSTANCE, TransportSearchTemplateAction.class),
new ActionHandler<>(RenderSearchTemplateAction.INSTANCE, TransportRenderSearchTemplateAction.class),
new ActionHandler<>(MultiSearchTemplateAction.INSTANCE, TransportMultiSearchTemplateAction.class)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.script.mustache;

import org.opensearch.action.ActionType;

public class RenderSearchTemplateAction extends ActionType<SearchTemplateResponse> {

public static final RenderSearchTemplateAction INSTANCE = new RenderSearchTemplateAction();

Check warning on line 15 in modules/lang-mustache/src/main/java/org/opensearch/script/mustache/RenderSearchTemplateAction.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/RenderSearchTemplateAction.java#L15

Added line #L15 was not covered by tests
public static final String NAME = "indices:data/read/search/template/render";

private RenderSearchTemplateAction() {
super(NAME, SearchTemplateResponse::new);
}

Check warning on line 20 in modules/lang-mustache/src/main/java/org/opensearch/script/mustache/RenderSearchTemplateAction.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/RenderSearchTemplateAction.java#L19-L20

Added lines #L19 - L20 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@
renderRequest.setScript(id);
}

return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
return channel -> client.execute(RenderSearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));

Check warning on line 84 in modules/lang-mustache/src/main/java/org/opensearch/script/mustache/RestRenderSearchTemplateAction.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/RestRenderSearchTemplateAction.java#L84

Added line #L84 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.script.mustache;

import org.opensearch.action.support.ActionFilters;
import org.opensearch.client.node.NodeClient;
import org.opensearch.common.inject.Inject;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.script.ScriptService;
import org.opensearch.transport.TransportService;

public class TransportRenderSearchTemplateAction extends TransportSearchTemplateAction {

@Inject
public TransportRenderSearchTemplateAction(
TransportService transportService,
ActionFilters actionFilters,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
NodeClient client
) {
super(RenderSearchTemplateAction.NAME, transportService, actionFilters, scriptService, xContentRegistry, client);
}

Check warning on line 29 in modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportRenderSearchTemplateAction.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportRenderSearchTemplateAction.java#L28-L29

Added lines #L28 - L29 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@

private static final String TEMPLATE_LANG = MustacheScriptEngine.NAME;

private final ScriptService scriptService;
private final NamedXContentRegistry xContentRegistry;
private final NodeClient client;
protected final ScriptService scriptService;
protected final NamedXContentRegistry xContentRegistry;
protected final NodeClient client;

@Inject
public TransportSearchTemplateAction(
Expand All @@ -79,6 +79,20 @@
this.client = client;
}

public TransportSearchTemplateAction(
String actionName,
TransportService transportService,
ActionFilters actionFilters,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
NodeClient client
) {
super(actionName, transportService, actionFilters, SearchTemplateRequest::new);
this.scriptService = scriptService;
this.xContentRegistry = xContentRegistry;
this.client = client;
}

Check warning on line 94 in modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportSearchTemplateAction.java

View check run for this annotation

Codecov / codecov/patch

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportSearchTemplateAction.java#L90-L94

Added lines #L90 - L94 were not covered by tests

@Override
protected void doExecute(Task task, SearchTemplateRequest request, ActionListener<SearchTemplateResponse> listener) {
final SearchTemplateResponse response = new SearchTemplateResponse();
Expand Down
Loading