Skip to content

Commit 69e6bba

Browse files
committed
Create separate transport action for render search template action (opensearch-project#11170)
Signed-off-by: Craig Perkins <[email protected]> (cherry picked from commit 66d4e9e)
1 parent 7f7aa05 commit 69e6bba

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3333
- Allow changing number of replicas of searchable snapshot index ([#11317](https://github.com/opensearch-project/OpenSearch/pull/11317))
3434
- [BWC and API enforcement] Introduce checks for enforcing the API restrictions ([#11175](https://github.com/opensearch-project/OpenSearch/pull/11175))
3535
- Maintainer approval check ([#11378](https://github.com/opensearch-project/OpenSearch/pull/11378))
36+
- Create separate transport action for render search template action ([#11170](https://github.com/opensearch-project/OpenSearch/pull/11170))
3637

3738
### Dependencies
3839
- Bumps jetty version to 9.4.52.v20230823 to fix GMS-2023-1857 ([#9822](https://github.com/opensearch-project/OpenSearch/pull/9822))

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MustachePlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<
6565
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
6666
return Arrays.asList(
6767
new ActionHandler<>(SearchTemplateAction.INSTANCE, TransportSearchTemplateAction.class),
68+
new ActionHandler<>(RenderSearchTemplateAction.INSTANCE, TransportRenderSearchTemplateAction.class),
6869
new ActionHandler<>(MultiSearchTemplateAction.INSTANCE, TransportMultiSearchTemplateAction.class)
6970
);
7071
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.script.mustache;
10+
11+
import org.opensearch.action.ActionType;
12+
13+
public class RenderSearchTemplateAction extends ActionType<SearchTemplateResponse> {
14+
15+
public static final RenderSearchTemplateAction INSTANCE = new RenderSearchTemplateAction();
16+
public static final String NAME = "indices:data/read/search/template/render";
17+
18+
private RenderSearchTemplateAction() {
19+
super(NAME, SearchTemplateResponse::new);
20+
}
21+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
8181
renderRequest.setScript(id);
8282
}
8383

84-
return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
84+
return channel -> client.execute(RenderSearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
8585
}
8686
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.script.mustache;
10+
11+
import org.opensearch.action.support.ActionFilters;
12+
import org.opensearch.client.node.NodeClient;
13+
import org.opensearch.common.inject.Inject;
14+
import org.opensearch.core.xcontent.NamedXContentRegistry;
15+
import org.opensearch.script.ScriptService;
16+
import org.opensearch.transport.TransportService;
17+
18+
public class TransportRenderSearchTemplateAction extends TransportSearchTemplateAction {
19+
20+
@Inject
21+
public TransportRenderSearchTemplateAction(
22+
TransportService transportService,
23+
ActionFilters actionFilters,
24+
ScriptService scriptService,
25+
NamedXContentRegistry xContentRegistry,
26+
NodeClient client
27+
) {
28+
super(RenderSearchTemplateAction.NAME, transportService, actionFilters, scriptService, xContentRegistry, client);
29+
}
30+
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
6161

6262
private static final String TEMPLATE_LANG = MustacheScriptEngine.NAME;
6363

64-
private final ScriptService scriptService;
65-
private final NamedXContentRegistry xContentRegistry;
66-
private final NodeClient client;
64+
protected final ScriptService scriptService;
65+
protected final NamedXContentRegistry xContentRegistry;
66+
protected final NodeClient client;
6767

6868
@Inject
6969
public TransportSearchTemplateAction(
@@ -79,6 +79,20 @@ public TransportSearchTemplateAction(
7979
this.client = client;
8080
}
8181

82+
public TransportSearchTemplateAction(
83+
String actionName,
84+
TransportService transportService,
85+
ActionFilters actionFilters,
86+
ScriptService scriptService,
87+
NamedXContentRegistry xContentRegistry,
88+
NodeClient client
89+
) {
90+
super(actionName, transportService, actionFilters, SearchTemplateRequest::new);
91+
this.scriptService = scriptService;
92+
this.xContentRegistry = xContentRegistry;
93+
this.client = client;
94+
}
95+
8296
@Override
8397
protected void doExecute(Task task, SearchTemplateRequest request, ActionListener<SearchTemplateResponse> listener) {
8498
final SearchTemplateResponse response = new SearchTemplateResponse();

0 commit comments

Comments
 (0)