Skip to content

Commit 66d4e9e

Browse files
authored
Create separate transport action for render search template action (#11170)
Signed-off-by: Craig Perkins <[email protected]>
1 parent 2798114 commit 66d4e9e

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
@@ -120,6 +120,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
120120
- Allow changing number of replicas of searchable snapshot index ([#11317](https://github.com/opensearch-project/OpenSearch/pull/11317))
121121
- Adding slf4j license header to LoggerMessageFormat.java ([#11069](https://github.com/opensearch-project/OpenSearch/pull/11069))
122122
- [BWC and API enforcement] Introduce checks for enforcing the API restrictions ([#11175](https://github.com/opensearch-project/OpenSearch/pull/11175))
123+
- Create separate transport action for render search template action ([#11170](https://github.com/opensearch-project/OpenSearch/pull/11170))
123124

124125
### Dependencies
125126
- Bump Lucene from 9.7.0 to 9.8.0 ([10276](https://github.com/opensearch-project/OpenSearch/pull/10276))

modules/lang-mustache/src/main/java/org/opensearch/script/mustache/MustacheModulePlugin.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)