Skip to content

Commit ebace1f

Browse files
More implementation of TransportIndicesResolvingAction
1 parent dd9620b commit ebace1f

File tree

6 files changed

+50
-32
lines changed

6 files changed

+50
-32
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.opensearch.script.mustache;
1010

11+
import org.opensearch.action.search.TransportSearchAction;
1112
import org.opensearch.action.support.ActionFilters;
1213
import org.opensearch.common.inject.Inject;
1314
import org.opensearch.core.xcontent.NamedXContentRegistry;
@@ -23,8 +24,9 @@ public TransportRenderSearchTemplateAction(
2324
ActionFilters actionFilters,
2425
ScriptService scriptService,
2526
NamedXContentRegistry xContentRegistry,
26-
NodeClient client
27+
NodeClient client,
28+
TransportSearchAction transportSearchAction
2729
) {
28-
super(RenderSearchTemplateAction.NAME, transportService, actionFilters, scriptService, xContentRegistry, client);
30+
super(RenderSearchTemplateAction.NAME, transportService, actionFilters, scriptService, xContentRegistry, client, transportSearchAction);
2931
}
3032
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434

3535
import org.opensearch.action.search.SearchRequest;
3636
import org.opensearch.action.search.SearchResponse;
37+
import org.opensearch.action.search.TransportSearchAction;
3738
import org.opensearch.action.support.ActionFilters;
3839
import org.opensearch.action.support.HandledTransportAction;
40+
import org.opensearch.action.support.TransportIndicesResolvingAction;
41+
import org.opensearch.cluster.metadata.ResolvedIndices;
3942
import org.opensearch.common.inject.Inject;
4043
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
4144
import org.opensearch.core.action.ActionListener;
@@ -57,27 +60,29 @@
5760
import java.io.IOException;
5861
import java.util.Collections;
5962

60-
public class TransportSearchTemplateAction extends HandledTransportAction<SearchTemplateRequest, SearchTemplateResponse> {
61-
// TODO: can we reuse implementation in TransportIndicesResolvingAction from TransportSearchAction?
62-
// TransportIndicesResolvingAction implement the interface
63+
public class TransportSearchTemplateAction extends HandledTransportAction<SearchTemplateRequest, SearchTemplateResponse> implements
64+
TransportIndicesResolvingAction<SearchTemplateRequest> {
6365
private static final String TEMPLATE_LANG = MustacheScriptEngine.NAME;
6466

6567
protected final ScriptService scriptService;
6668
protected final NamedXContentRegistry xContentRegistry;
6769
protected final NodeClient client;
70+
private final TransportSearchAction transportSearchAction;
6871

6972
@Inject
7073
public TransportSearchTemplateAction(
7174
TransportService transportService,
7275
ActionFilters actionFilters,
7376
ScriptService scriptService,
7477
NamedXContentRegistry xContentRegistry,
75-
NodeClient client
78+
NodeClient client,
79+
TransportSearchAction transportSearchAction
7680
) {
7781
super(SearchTemplateAction.NAME, transportService, actionFilters, SearchTemplateRequest::new);
7882
this.scriptService = scriptService;
7983
this.xContentRegistry = xContentRegistry;
8084
this.client = client;
85+
this.transportSearchAction = transportSearchAction;
8186
}
8287

8388
public TransportSearchTemplateAction(
@@ -86,12 +91,14 @@ public TransportSearchTemplateAction(
8691
ActionFilters actionFilters,
8792
ScriptService scriptService,
8893
NamedXContentRegistry xContentRegistry,
89-
NodeClient client
94+
NodeClient client,
95+
TransportSearchAction transportSearchAction
9096
) {
9197
super(actionName, transportService, actionFilters, SearchTemplateRequest::new);
9298
this.scriptService = scriptService;
9399
this.xContentRegistry = xContentRegistry;
94100
this.client = client;
101+
this.transportSearchAction = transportSearchAction;
95102
}
96103

97104
@Override
@@ -181,4 +188,10 @@ private static void checkRestTotalHitsAsInt(SearchRequest searchRequest, SearchS
181188
}
182189
}
183190
}
191+
192+
@Override
193+
public ResolvedIndices resolveIndices(SearchTemplateRequest request) {
194+
SearchRequest searchRequest = request.getRequest();
195+
return transportSearchAction.resolveIndices(searchRequest);
196+
}
184197
}

server/src/main/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamAction.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,8 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
239239
}
240240

241241
static ClusterState removeDataStream(MetadataDeleteIndexService deleteIndexService, ClusterState currentState, Request request) {
242-
Set<String> dataStreams = new HashSet<>();
243-
Set<String> snapshottingDataStreams = new HashSet<>();
244-
for (String name : request.names) {
245-
for (String dataStreamName : currentState.metadata().dataStreams().keySet()) {
246-
if (Regex.simpleMatch(name, dataStreamName)) {
247-
dataStreams.add(dataStreamName);
248-
}
249-
}
250-
251-
snapshottingDataStreams.addAll(SnapshotsService.snapshottingDataStreams(currentState, dataStreams));
252-
}
242+
Set<String> dataStreams = resolveDataStreams(currentState, request);
243+
Set<String> snapshottingDataStreams = new HashSet<>(SnapshotsService.snapshottingDataStreams(currentState, dataStreams));
253244

254245
if (snapshottingDataStreams.isEmpty() == false) {
255246
throw new SnapshotInProgressException(
@@ -279,25 +270,29 @@ static ClusterState removeDataStream(MetadataDeleteIndexService deleteIndexServi
279270
return deleteIndexService.deleteIndices(currentState, backingIndicesToRemove);
280271
}
281272

282-
@Override
283-
protected ClusterBlockException checkBlock(Request request, ClusterState state) {
284-
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
285-
}
286-
287-
@Override
288-
public ResolvedIndices resolveIndices(Request request) {
289-
ClusterState currentState = clusterService.state();
273+
private static Set<String> resolveDataStreams(ClusterState currentState, Request request) {
290274
Set<String> dataStreams = new HashSet<>();
291275
for (String name : request.names) {
292276
for (String dataStreamName : currentState.metadata().dataStreams().keySet()) {
293277
if (Regex.simpleMatch(name, dataStreamName)) {
294278
dataStreams.add(dataStreamName);
295279
}
296280
}
297-
298281
}
282+
return dataStreams;
283+
}
284+
285+
@Override
286+
public ResolvedIndices resolveIndices(Request request) {
287+
ClusterState currentState = clusterService.state();
288+
Set<String> dataStreams = resolveDataStreams(currentState, request);
299289
return ResolvedIndices.of(dataStreams);
300290
}
291+
292+
@Override
293+
protected ClusterBlockException checkBlock(Request request, ClusterState state) {
294+
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
295+
}
301296
}
302297

303298
}

server/src/main/java/org/opensearch/action/admin/indices/mapping/put/TransportAutoPutMappingAction.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
package org.opensearch.action.admin.indices.mapping.put;
3333

3434
import org.opensearch.action.support.ActionFilters;
35+
import org.opensearch.action.support.TransportIndicesResolvingAction;
3536
import org.opensearch.action.support.clustermanager.AcknowledgedResponse;
3637
import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction;
3738
import org.opensearch.cluster.ClusterState;
3839
import org.opensearch.cluster.block.ClusterBlockException;
3940
import org.opensearch.cluster.block.ClusterBlockLevel;
4041
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
4142
import org.opensearch.cluster.metadata.MetadataMappingService;
43+
import org.opensearch.cluster.metadata.ResolvedIndices;
4244
import org.opensearch.cluster.service.ClusterService;
4345
import org.opensearch.common.inject.Inject;
4446
import org.opensearch.core.action.ActionListener;
@@ -55,9 +57,8 @@
5557
*
5658
* @opensearch.internal
5759
*/
58-
public class TransportAutoPutMappingAction extends TransportClusterManagerNodeAction<PutMappingRequest, AcknowledgedResponse> {
59-
// TODO: Q do we need here extensions related to TransportIndicesResolvingAction
60-
// implementation may relay on TransportPutMappingAction
60+
public class TransportAutoPutMappingAction extends TransportClusterManagerNodeAction<PutMappingRequest, AcknowledgedResponse> implements
61+
TransportIndicesResolvingAction<PutMappingRequest> {
6162

6263
private final MetadataMappingService metadataMappingService;
6364

@@ -118,4 +119,9 @@ protected void clusterManagerOperation(
118119
TransportPutMappingAction.performMappingUpdate(concreteIndices, request, listener, metadataMappingService);
119120
}
120121

122+
@Override
123+
public ResolvedIndices resolveIndices(PutMappingRequest request) {
124+
Index[] indices = TransportPutMappingAction.resolveIndices(clusterService.state(), request, this.indexNameExpressionResolver);
125+
return ResolvedIndices.of(indices);
126+
}
121127
}

server/src/main/java/org/opensearch/action/admin/indices/tiering/TransportHotToWarmTieringAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
public class TransportHotToWarmTieringAction extends TransportClusterManagerNodeAction<TieringIndexRequest, HotToWarmTieringResponse> implements
4545
TransportIndicesResolvingAction<TieringIndexRequest> {
4646

47-
// TODO: implementation of TransportIndicesResolvingAction should be simple here
48-
4947
private static final Logger logger = LogManager.getLogger(TransportHotToWarmTieringAction.class);
5048
private final ClusterInfoService clusterInfoService;
5149
private final DiskThresholdSettings diskThresholdSettings;
@@ -119,6 +117,7 @@ private Index[] resolveIndices(ClusterState state, TieringIndexRequest request)
119117

120118
@Override
121119
public ResolvedIndices resolveIndices(TieringIndexRequest request) {
120+
// forces annotation @ExperimentalApi in ResolvedIndices
122121
return ResolvedIndices.of(resolveIndices(clusterService.state(), request));
123122
}
124123
}

server/src/main/java/org/opensearch/cluster/metadata/ResolvedIndices.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package org.opensearch.cluster.metadata;
1010

1111
import org.opensearch.action.OriginalIndices;
12+
import org.opensearch.common.annotation.ExperimentalApi;
1213
import org.opensearch.core.index.Index;
1314

1415
import java.util.Arrays;
@@ -36,6 +37,7 @@
3637
* just taken without further evaluation</li>
3738
* </ul>
3839
*/
40+
@ExperimentalApi
3941
public class ResolvedIndices {
4042

4143
public static ResolvedIndices of(String... indices) {
@@ -116,6 +118,7 @@ public boolean isEmpty() {
116118
/**
117119
* Encapsulates the local (i.e., non-remote) indices referenced by the respective request.
118120
*/
121+
@ExperimentalApi
119122
public static class Local {
120123
private final Set<String> names;
121124
private final OriginalIndices originalIndices;

0 commit comments

Comments
 (0)