diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportRenderSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportRenderSearchTemplateAction.java index abd5d768f4a11..28a411d010543 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportRenderSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportRenderSearchTemplateAction.java @@ -8,6 +8,7 @@ package org.opensearch.script.mustache; +import org.opensearch.action.search.TransportSearchAction; import org.opensearch.action.support.ActionFilters; import org.opensearch.common.inject.Inject; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -23,8 +24,17 @@ public TransportRenderSearchTemplateAction( ActionFilters actionFilters, ScriptService scriptService, NamedXContentRegistry xContentRegistry, - NodeClient client + NodeClient client, + TransportSearchAction transportSearchAction ) { - super(RenderSearchTemplateAction.NAME, transportService, actionFilters, scriptService, xContentRegistry, client); + super( + RenderSearchTemplateAction.NAME, + transportService, + actionFilters, + scriptService, + xContentRegistry, + client, + transportSearchAction + ); } } diff --git a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportSearchTemplateAction.java index e24f3c0d7d560..75101349dcdb4 100644 --- a/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/opensearch/script/mustache/TransportSearchTemplateAction.java @@ -34,8 +34,11 @@ import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; +import org.opensearch.action.search.TransportSearchAction; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; +import org.opensearch.action.support.TransportIndicesResolvingAction; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.common.inject.Inject; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.action.ActionListener; @@ -57,13 +60,15 @@ import java.io.IOException; import java.util.Collections; -public class TransportSearchTemplateAction extends HandledTransportAction { - +public class TransportSearchTemplateAction extends HandledTransportAction + implements + TransportIndicesResolvingAction { private static final String TEMPLATE_LANG = MustacheScriptEngine.NAME; protected final ScriptService scriptService; protected final NamedXContentRegistry xContentRegistry; protected final NodeClient client; + private final TransportSearchAction transportSearchAction; @Inject public TransportSearchTemplateAction( @@ -71,12 +76,14 @@ public TransportSearchTemplateAction( ActionFilters actionFilters, ScriptService scriptService, NamedXContentRegistry xContentRegistry, - NodeClient client + NodeClient client, + TransportSearchAction transportSearchAction ) { super(SearchTemplateAction.NAME, transportService, actionFilters, SearchTemplateRequest::new); this.scriptService = scriptService; this.xContentRegistry = xContentRegistry; this.client = client; + this.transportSearchAction = transportSearchAction; } public TransportSearchTemplateAction( @@ -85,12 +92,14 @@ public TransportSearchTemplateAction( ActionFilters actionFilters, ScriptService scriptService, NamedXContentRegistry xContentRegistry, - NodeClient client + NodeClient client, + TransportSearchAction transportSearchAction ) { super(actionName, transportService, actionFilters, SearchTemplateRequest::new); this.scriptService = scriptService; this.xContentRegistry = xContentRegistry; this.client = client; + this.transportSearchAction = transportSearchAction; } @Override @@ -180,4 +189,10 @@ private static void checkRestTotalHitsAsInt(SearchRequest searchRequest, SearchS } } } + + @Override + public ResolvedIndices resolveIndices(SearchTemplateRequest request) { + SearchRequest searchRequest = request.getRequest(); + return transportSearchAction.resolveIndices(searchRequest); + } } diff --git a/modules/reindex/src/main/java/org/opensearch/index/reindex/TransportDeleteByQueryAction.java b/modules/reindex/src/main/java/org/opensearch/index/reindex/TransportDeleteByQueryAction.java index f50680777fcb8..b61004fc0e806 100644 --- a/modules/reindex/src/main/java/org/opensearch/index/reindex/TransportDeleteByQueryAction.java +++ b/modules/reindex/src/main/java/org/opensearch/index/reindex/TransportDeleteByQueryAction.java @@ -32,8 +32,12 @@ package org.opensearch.index.reindex; +import org.opensearch.action.search.SearchRequest; +import org.opensearch.action.search.TransportSearchAction; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; +import org.opensearch.action.support.TransportIndicesResolvingAction; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; @@ -45,12 +49,15 @@ import org.opensearch.transport.client.Client; import org.opensearch.transport.client.ParentTaskAssigningClient; -public class TransportDeleteByQueryAction extends HandledTransportAction { +public class TransportDeleteByQueryAction extends HandledTransportAction + implements + TransportIndicesResolvingAction { private final ThreadPool threadPool; private final Client client; private final ScriptService scriptService; private final ClusterService clusterService; + private final TransportSearchAction transportSearchAction; @Inject public TransportDeleteByQueryAction( @@ -59,7 +66,8 @@ public TransportDeleteByQueryAction( Client client, TransportService transportService, ScriptService scriptService, - ClusterService clusterService + ClusterService clusterService, + TransportSearchAction transportSearchAction ) { super( DeleteByQueryAction.NAME, @@ -71,6 +79,7 @@ public TransportDeleteByQueryAction( this.client = client; this.scriptService = scriptService; this.clusterService = clusterService; + this.transportSearchAction = transportSearchAction; } @Override @@ -94,4 +103,10 @@ public void doExecute(Task task, DeleteByQueryRequest request, ActionListener { +public class TransportUpdateByQueryAction extends HandledTransportAction + implements + TransportIndicesResolvingAction { private final ThreadPool threadPool; private final Client client; private final ScriptService scriptService; private final ClusterService clusterService; + private final TransportSearchAction transportSearchAction; @Inject public TransportUpdateByQueryAction( @@ -69,7 +75,8 @@ public TransportUpdateByQueryAction( Client client, TransportService transportService, ScriptService scriptService, - ClusterService clusterService + ClusterService clusterService, + TransportSearchAction transportSearchAction ) { super( UpdateByQueryAction.NAME, @@ -81,6 +88,7 @@ public TransportUpdateByQueryAction( this.client = client; this.scriptService = scriptService; this.clusterService = clusterService; + this.transportSearchAction = transportSearchAction; } @Override @@ -106,6 +114,11 @@ protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener ); } + @Override + public ResolvedIndices resolveIndices(UpdateByQueryRequest request) { + return transportSearchAction.resolveIndices(request.getSearchRequest()); + } + /** * Simple implementation of update-by-query using scrolling and bulk. */ diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/UpdateByQueryWithScriptTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/UpdateByQueryWithScriptTests.java index ce982dcb6bd34..56e3e9cbe311a 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/UpdateByQueryWithScriptTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/UpdateByQueryWithScriptTests.java @@ -79,6 +79,7 @@ protected TransportUpdateByQueryAction.AsyncIndexBySearchAction action(ScriptSer null, transportService, scriptService, + null, null ); return new TransportUpdateByQueryAction.AsyncIndexBySearchAction( diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java index 11323499efd8b..3c4f12c0ca5b7 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java @@ -33,11 +33,13 @@ package org.opensearch.action.admin.cluster.shards; import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.routing.GroupShardsIterator; import org.opensearch.cluster.routing.ShardIterator; @@ -65,7 +67,7 @@ */ public class TransportClusterSearchShardsAction extends TransportClusterManagerNodeReadAction< ClusterSearchShardsRequest, - ClusterSearchShardsResponse> { + ClusterSearchShardsResponse> implements TransportIndicesResolvingAction { private final IndicesService indicesService; @@ -99,8 +101,7 @@ protected String executor() { @Override protected ClusterBlockException checkBlock(ClusterSearchShardsRequest request, ClusterState state) { - return state.blocks() - .indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, resolveIndices(state, request)); } @Override @@ -115,7 +116,7 @@ protected void clusterManagerOperation( final ActionListener listener ) { ClusterState clusterState = clusterService.state(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); + String[] concreteIndices = resolveIndices(clusterState, request); Map> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices()); Map indicesAndFilters = new HashMap<>(); Set indicesAndAliases = indexNameExpressionResolver.resolveExpressions(clusterState, request.indices()); @@ -155,4 +156,13 @@ protected void clusterManagerOperation( } listener.onResponse(new ClusterSearchShardsResponse(groupResponses, nodes, indicesAndFilters)); } + + private String[] resolveIndices(ClusterState clusterState, ClusterSearchShardsRequest request) { + return indexNameExpressionResolver.concreteIndexNames(clusterState, request); + } + + @Override + public ResolvedIndices resolveIndices(ClusterSearchShardsRequest request) { + return ResolvedIndices.of(resolveIndices(clusterService.state(), request)); + } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java index 6b582396c2733..c83bca7ab9ad3 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java @@ -33,11 +33,13 @@ package org.opensearch.action.admin.cluster.snapshots.create; import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; @@ -57,7 +59,9 @@ * * @opensearch.internal */ -public class TransportCreateSnapshotAction extends TransportClusterManagerNodeAction { +public class TransportCreateSnapshotAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private final SnapshotsService snapshotsService; private final RepositoriesService repositoriesService; @@ -121,4 +125,9 @@ protected void clusterManagerOperation( snapshotsService.createSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse())); } } + + @Override + public ResolvedIndices resolveIndices(CreateSnapshotRequest request) { + return snapshotsService.resolveIndices(request); + } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java b/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java index 4f4e3bd481ee7..b8935e5c63c39 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java @@ -32,6 +32,7 @@ package org.opensearch.action.admin.indices.alias.get; import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; @@ -39,6 +40,7 @@ import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.logging.DeprecationLogger; @@ -65,7 +67,9 @@ * * @opensearch.internal */ -public class TransportGetAliasesAction extends TransportClusterManagerNodeReadAction { +public class TransportGetAliasesAction extends TransportClusterManagerNodeReadAction + implements + TransportIndicesResolvingAction { private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TransportGetAliasesAction.class); private final SystemIndices systemIndices; @@ -195,4 +199,12 @@ private static void checkSystemAliasAccess(GetAliasesRequest request, SystemIndi ); } } + + @Override + public ResolvedIndices resolveIndices(GetAliasesRequest request) { + ClusterState state = this.clusterService.state(); + try (ThreadContext.StoredContext ignore = threadPool.getThreadContext().newStoredContext(false)) { + return ResolvedIndices.of(indexNameExpressionResolver.concreteIndexNames(state, request)); + } + } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/close/TransportCloseIndexAction.java b/server/src/main/java/org/opensearch/action/admin/indices/close/TransportCloseIndexAction.java index 4a0822a9bb754..fb25978fc768f 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/close/TransportCloseIndexAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/close/TransportCloseIndexAction.java @@ -37,12 +37,14 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.DestructiveOperations; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.MetadataIndexStateService; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.settings.ClusterSettings; @@ -67,7 +69,9 @@ * * @opensearch.internal */ -public class TransportCloseIndexAction extends TransportClusterManagerNodeAction { +public class TransportCloseIndexAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private static final Logger logger = LogManager.getLogger(TransportCloseIndexAction.class); @@ -159,7 +163,7 @@ protected void clusterManagerOperation( final ClusterState state, final ActionListener listener ) throws Exception { - final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = resolveIndices(state, request); if (concreteIndices == null || concreteIndices.length == 0) { listener.onResponse(new CloseIndexResponse(true, false, Collections.emptyList())); return; @@ -177,6 +181,15 @@ protected void clusterManagerOperation( })); } + private Index[] resolveIndices(ClusterState state, CloseIndexRequest request) { + return indexNameExpressionResolver.concreteIndices(state, request); + } + + @Override + public ResolvedIndices resolveIndices(CloseIndexRequest request) { + return ResolvedIndices.of(resolveIndices(clusterService.state(), request)); + } + /** * Reject close index request if cluster mode is [MIXED] and migration direction is [RemoteStore] * @throws IllegalStateException if cluster mode is [MIXED] and migration direction is [RemoteStore] diff --git a/server/src/main/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamAction.java b/server/src/main/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamAction.java index 9db621b1a5367..8d4ed21eacf3d 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamAction.java @@ -38,6 +38,7 @@ import org.opensearch.action.IndicesRequest; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.IndicesOptions; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.AcknowledgedResponse; import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; @@ -49,6 +50,7 @@ import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.metadata.MetadataDeleteIndexService; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterManagerTaskThrottler; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Priority; @@ -169,7 +171,9 @@ public IndicesRequest indices(String... indices) { * * @opensearch.internal */ - public static class TransportAction extends TransportClusterManagerNodeAction { + public static class TransportAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private final MetadataDeleteIndexService deleteIndexService; private final ClusterManagerTaskThrottler.ThrottlingKey removeDataStreamTaskKey; @@ -235,17 +239,8 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS } static ClusterState removeDataStream(MetadataDeleteIndexService deleteIndexService, ClusterState currentState, Request request) { - Set dataStreams = new HashSet<>(); - Set snapshottingDataStreams = new HashSet<>(); - for (String name : request.names) { - for (String dataStreamName : currentState.metadata().dataStreams().keySet()) { - if (Regex.simpleMatch(name, dataStreamName)) { - dataStreams.add(dataStreamName); - } - } - - snapshottingDataStreams.addAll(SnapshotsService.snapshottingDataStreams(currentState, dataStreams)); - } + Set dataStreams = resolveDataStreams(currentState, request); + Set snapshottingDataStreams = new HashSet<>(SnapshotsService.snapshottingDataStreams(currentState, dataStreams)); if (snapshottingDataStreams.isEmpty() == false) { throw new SnapshotInProgressException( @@ -275,6 +270,25 @@ static ClusterState removeDataStream(MetadataDeleteIndexService deleteIndexServi return deleteIndexService.deleteIndices(currentState, backingIndicesToRemove); } + private static Set resolveDataStreams(ClusterState currentState, Request request) { + Set dataStreams = new HashSet<>(); + for (String name : request.names) { + for (String dataStreamName : currentState.metadata().dataStreams().keySet()) { + if (Regex.simpleMatch(name, dataStreamName)) { + dataStreams.add(dataStreamName); + } + } + } + return dataStreams; + } + + @Override + public ResolvedIndices resolveIndices(Request request) { + ClusterState currentState = clusterService.state(); + Set dataStreams = resolveDataStreams(currentState, request); + return ResolvedIndices.of(dataStreams); + } + @Override protected ClusterBlockException checkBlock(Request request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java index 53dbb86233803..3aaaf05b6e501 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java @@ -34,8 +34,10 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; @@ -55,7 +57,9 @@ * * @opensearch.internal */ -public class TransportGetFieldMappingsAction extends HandledTransportAction { +public class TransportGetFieldMappingsAction extends HandledTransportAction + implements + TransportIndicesResolvingAction { private final ClusterService clusterService; private final TransportGetFieldMappingsIndexAction shardAction; @@ -78,7 +82,7 @@ public TransportGetFieldMappingsAction( @Override protected void doExecute(Task task, GetFieldMappingsRequest request, final ActionListener listener) { ClusterState clusterState = clusterService.state(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); + String[] concreteIndices = resolveIndices(request, clusterState); final AtomicInteger indexCounter = new AtomicInteger(); final AtomicInteger completionCounter = new AtomicInteger(concreteIndices.length); final AtomicReferenceArray indexResponses = new AtomicReferenceArray<>(concreteIndices.length); @@ -110,6 +114,15 @@ public void onFailure(Exception e) { } } + private String[] resolveIndices(GetFieldMappingsRequest request, ClusterState clusterState) { + return indexNameExpressionResolver.concreteIndexNames(clusterState, request); + } + + @Override + public ResolvedIndices resolveIndices(GetFieldMappingsRequest request) { + return ResolvedIndices.of(resolveIndices(request, clusterService.state())); + } + private GetFieldMappingsResponse merge(AtomicReferenceArray indexResponses) { Map> mergedResponses = new HashMap<>(); for (int i = 0; i < indexResponses.length(); i++) { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/TransportAutoPutMappingAction.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/TransportAutoPutMappingAction.java index f50acb6e2d56e..cafccb18821d4 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/TransportAutoPutMappingAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/TransportAutoPutMappingAction.java @@ -32,6 +32,7 @@ package org.opensearch.action.admin.indices.mapping.put; import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.AcknowledgedResponse; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; import org.opensearch.cluster.ClusterState; @@ -39,6 +40,7 @@ import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.MetadataMappingService; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; @@ -55,7 +57,9 @@ * * @opensearch.internal */ -public class TransportAutoPutMappingAction extends TransportClusterManagerNodeAction { +public class TransportAutoPutMappingAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private final MetadataMappingService metadataMappingService; @@ -116,4 +120,9 @@ protected void clusterManagerOperation( TransportPutMappingAction.performMappingUpdate(concreteIndices, request, listener, metadataMappingService); } + @Override + public ResolvedIndices resolveIndices(PutMappingRequest request) { + Index[] indices = TransportPutMappingAction.resolveIndices(clusterService.state(), request, this.indexNameExpressionResolver); + return ResolvedIndices.of(indices); + } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/readonly/TransportAddIndexBlockAction.java b/server/src/main/java/org/opensearch/action/admin/indices/readonly/TransportAddIndexBlockAction.java index 33efa8e691794..538daf135b55c 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/readonly/TransportAddIndexBlockAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/readonly/TransportAddIndexBlockAction.java @@ -37,12 +37,14 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.DestructiveOperations; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.MetadataIndexStateService; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; @@ -65,7 +67,9 @@ * * @opensearch.internal */ -public class TransportAddIndexBlockAction extends TransportClusterManagerNodeAction { +public class TransportAddIndexBlockAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private static final Logger logger = LogManager.getLogger(TransportAddIndexBlockAction.class); @@ -135,7 +139,7 @@ protected void clusterManagerOperation( final ClusterState state, final ActionListener listener ) throws Exception { - final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = resolveIndices(state, request); if (concreteIndices == null || concreteIndices.length == 0) { listener.onResponse(new AddIndexBlockResponse(true, false, Collections.emptyList())); return; @@ -150,4 +154,13 @@ protected void clusterManagerOperation( delegatedListener.onFailure(t); })); } + + private Index[] resolveIndices(ClusterState state, AddIndexBlockRequest request) { + return indexNameExpressionResolver.concreteIndices(state, request); + } + + @Override + public ResolvedIndices resolveIndices(AddIndexBlockRequest request) { + return ResolvedIndices.of(resolveIndices(this.clusterService.state(), request)); + } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java b/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java index fad504a476511..609f8484818d6 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java @@ -36,6 +36,7 @@ import org.apache.lucene.util.CollectionUtil; import org.opensearch.action.FailedNodeException; import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; import org.opensearch.cluster.ClusterManagerMetrics; import org.opensearch.cluster.ClusterState; @@ -45,6 +46,7 @@ import org.opensearch.cluster.health.ClusterShardHealth; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.routing.IndexRoutingTable; @@ -84,7 +86,7 @@ */ public class TransportIndicesShardStoresAction extends TransportClusterManagerNodeReadAction< IndicesShardStoresRequest, - IndicesShardStoresResponse> { + IndicesShardStoresResponse> implements TransportIndicesResolvingAction { private static final Logger logger = LogManager.getLogger(TransportIndicesShardStoresAction.class); @@ -133,7 +135,7 @@ protected void clusterManagerOperation( ) { final RoutingTable routingTables = state.routingTable(); final RoutingNodes routingNodes = state.getRoutingNodes(); - final String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); + final String[] concreteIndices = resolveIndices(state, request); final Set> shardsToFetch = new HashSet<>(); logger.trace("using cluster state version [{}] to determine shards", state.version()); @@ -161,10 +163,18 @@ protected void clusterManagerOperation( new AsyncShardStoresInfoFetches(state.nodes(), routingNodes, shardsToFetch, listener, clusterManagerMetrics).start(); } + private String[] resolveIndices(ClusterState state, IndicesShardStoresRequest request) { + return indexNameExpressionResolver.concreteIndexNames(state, request); + } + + @Override + public ResolvedIndices resolveIndices(IndicesShardStoresRequest request) { + return ResolvedIndices.of(resolveIndices(clusterService.state(), request)); + } + @Override protected ClusterBlockException checkBlock(IndicesShardStoresRequest request, ClusterState state) { - return state.blocks() - .indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, resolveIndices(state, request)); } /** diff --git a/server/src/main/java/org/opensearch/action/admin/indices/streamingingestion/resume/TransportResumeIngestionAction.java b/server/src/main/java/org/opensearch/action/admin/indices/streamingingestion/resume/TransportResumeIngestionAction.java index dea46c7cf6b23..fc4bb2f1c145b 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/streamingingestion/resume/TransportResumeIngestionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/streamingingestion/resume/TransportResumeIngestionAction.java @@ -15,12 +15,14 @@ import org.opensearch.action.admin.indices.streamingingestion.state.UpdateIngestionStateResponse; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.DestructiveOperations; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.MetadataStreamingIngestionStateService; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.core.action.ActionListener; @@ -38,7 +40,9 @@ * * @opensearch.experimental */ -public class TransportResumeIngestionAction extends TransportClusterManagerNodeAction { +public class TransportResumeIngestionAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private static final Logger logger = LogManager.getLogger(TransportResumeIngestionAction.class); @@ -106,7 +110,7 @@ protected void clusterManagerOperation( final ClusterState state, final ActionListener listener ) throws Exception { - final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = resolveIndices(state, request); if (concreteIndices == null || concreteIndices.length == 0) { listener.onResponse(new ResumeIngestionResponse(true, false, new IngestionStateShardFailure[0], "")); return; @@ -173,4 +177,13 @@ private UpdateIngestionStateRequest getIngestionResumeRequest(String[] indices, return updateIngestionStateRequest; } + + private Index[] resolveIndices(ClusterState state, ResumeIngestionRequest request) { + return indexNameExpressionResolver.concreteIndices(state, request); + } + + @Override + public ResolvedIndices resolveIndices(ResumeIngestionRequest request) { + return ResolvedIndices.of(resolveIndices(clusterService.state(), request)); + } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/tiering/TransportHotToWarmTieringAction.java b/server/src/main/java/org/opensearch/action/admin/indices/tiering/TransportHotToWarmTieringAction.java index 8d1ab0bb37cdd..7352e1ab254cf 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/tiering/TransportHotToWarmTieringAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/tiering/TransportHotToWarmTieringAction.java @@ -11,12 +11,14 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; import org.opensearch.cluster.ClusterInfoService; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.routing.allocation.DiskThresholdSettings; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.annotation.ExperimentalApi; @@ -39,7 +41,9 @@ * @opensearch.experimental */ @ExperimentalApi -public class TransportHotToWarmTieringAction extends TransportClusterManagerNodeAction { +public class TransportHotToWarmTieringAction extends TransportClusterManagerNodeAction + implements + TransportIndicesResolvingAction { private static final Logger logger = LogManager.getLogger(TransportHotToWarmTieringAction.class); private final ClusterInfoService clusterInfoService; @@ -90,7 +94,7 @@ protected void clusterManagerOperation( ClusterState state, ActionListener listener ) throws Exception { - Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + Index[] concreteIndices = resolveIndices(state, request); if (concreteIndices == null || concreteIndices.length == 0) { listener.onResponse(new HotToWarmTieringResponse(true)); return; @@ -107,4 +111,14 @@ protected void clusterManagerOperation( return; } } + + private Index[] resolveIndices(ClusterState state, TieringIndexRequest request) { + return indexNameExpressionResolver.concreteIndices(state, request); + } + + @Override + public ResolvedIndices resolveIndices(TieringIndexRequest request) { + // forces annotation @ExperimentalApi in ResolvedIndices + return ResolvedIndices.of(resolveIndices(clusterService.state(), request)); + } } diff --git a/server/src/main/java/org/opensearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java b/server/src/main/java/org/opensearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java index 52937182e6a63..c5cbc05c1f040 100644 --- a/server/src/main/java/org/opensearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java +++ b/server/src/main/java/org/opensearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java @@ -41,10 +41,12 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.ChannelActionListener; import org.opensearch.action.support.HandledTransportAction; +import org.opensearch.action.support.TransportIndicesResolvingAction; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.routing.FailAwareWeightedRouting; @@ -93,7 +95,7 @@ */ public class TransportFieldCapabilitiesIndexAction extends HandledTransportAction< FieldCapabilitiesIndexRequest, - FieldCapabilitiesIndexResponse> { + FieldCapabilitiesIndexResponse> implements TransportIndicesResolvingAction { private static final Logger logger = LogManager.getLogger(TransportFieldCapabilitiesIndexAction.class); @@ -213,6 +215,11 @@ private ClusterBlockException checkRequestBlock(ClusterState state, String concr return state.blocks().indexBlockedException(ClusterBlockLevel.READ, concreteIndex); } + @Override + public ResolvedIndices resolveIndices(FieldCapabilitiesIndexRequest request) { + return ResolvedIndices.of(request.indices()); + } + /** * An action that executes on each shard sequentially until it finds one that can match the provided * {@link FieldCapabilitiesIndexRequest#indexFilter()}. In which case the shard is used diff --git a/server/src/main/java/org/opensearch/action/search/CreatePitController.java b/server/src/main/java/org/opensearch/action/search/CreatePitController.java index 87eb27bdb8255..1e23d18530672 100644 --- a/server/src/main/java/org/opensearch/action/search/CreatePitController.java +++ b/server/src/main/java/org/opensearch/action/search/CreatePitController.java @@ -15,6 +15,7 @@ import org.opensearch.action.StepListener; import org.opensearch.action.support.GroupedActionListener; import org.opensearch.cluster.ClusterState; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; @@ -86,11 +87,7 @@ public void executeCreatePit( StepListener createPitListener, ActionListener updatePitIdListener ) { - SearchRequest searchRequest = new SearchRequest(request.getIndices()); - searchRequest.preference(request.getPreference()); - searchRequest.routing(request.getRouting()); - searchRequest.indicesOptions(request.getIndicesOptions()); - searchRequest.allowPartialSearchResults(request.shouldAllowPartialPitCreation()); + SearchRequest searchRequest = request.toSearchRequest(); SearchTask searchTask = searchRequest.createTask( task.getId(), task.getType(), @@ -326,4 +323,10 @@ public void onFailure(Exception e) { } pitService.deletePitContexts(nodeToContextsMap, deleteListener); } + + ResolvedIndices resolveIndices(CreatePitRequest request) { + SearchRequest searchRequest = request.toSearchRequest(); + searchRequest.setCcsMinimizeRoundtrips(false); + return transportSearchAction.resolveIndices(searchRequest); + } } diff --git a/server/src/main/java/org/opensearch/action/search/CreatePitRequest.java b/server/src/main/java/org/opensearch/action/search/CreatePitRequest.java index 840d4becda714..f6791da13a328 100644 --- a/server/src/main/java/org/opensearch/action/search/CreatePitRequest.java +++ b/server/src/main/java/org/opensearch/action/search/CreatePitRequest.java @@ -196,4 +196,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } return builder; } + + SearchRequest toSearchRequest() { + SearchRequest searchRequest = new SearchRequest(this.getIndices()); + searchRequest.preference(this.getPreference()); + searchRequest.routing(this.getRouting()); + searchRequest.indicesOptions(this.getIndicesOptions()); + searchRequest.allowPartialSearchResults(this.shouldAllowPartialPitCreation()); + return searchRequest; + } } diff --git a/server/src/main/java/org/opensearch/action/search/TransportCreatePitAction.java b/server/src/main/java/org/opensearch/action/search/TransportCreatePitAction.java index baa113997f243..e15d216bdabe0 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportCreatePitAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportCreatePitAction.java @@ -12,6 +12,8 @@ import org.opensearch.action.StepListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; +import org.opensearch.action.support.TransportIndicesResolvingAction; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.unit.TimeValue; @@ -32,7 +34,9 @@ /** * Transport action for creating PIT reader context */ -public class TransportCreatePitAction extends HandledTransportAction { +public class TransportCreatePitAction extends HandledTransportAction + implements + TransportIndicesResolvingAction { public static final String CREATE_PIT_ACTION = "create_pit"; private final TransportService transportService; @@ -76,6 +80,11 @@ protected void doExecute(Task task, CreatePitRequest request, ActionListener, Response extends ActionResponse> extends - TransportClusterManagerNodeReadAction { + TransportClusterManagerNodeReadAction + implements + TransportIndicesResolvingAction { public TransportClusterInfoAction( String actionName, @@ -73,16 +77,24 @@ protected String executor() { @Override protected ClusterBlockException checkBlock(Request request, ClusterState state) { - return state.blocks() - .indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request)); + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, resolveIndices(state, request)); } @Override protected final void clusterManagerOperation(final Request request, final ClusterState state, final ActionListener listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); + String[] concreteIndices = resolveIndices(state, request); doClusterManagerOperation(request, concreteIndices, state, listener); } + private String[] resolveIndices(ClusterState state, Request request) { + return indexNameExpressionResolver.concreteIndexNames(state, request); + } + + @Override + public ResolvedIndices resolveIndices(Request request) { + return ResolvedIndices.of(resolveIndices(clusterService.state(), request)); + } + protected abstract void doClusterManagerOperation( Request request, String[] concreteIndices, diff --git a/server/src/main/java/org/opensearch/cluster/metadata/ResolvedIndices.java b/server/src/main/java/org/opensearch/cluster/metadata/ResolvedIndices.java index b505b3e63bf65..1f7d522ebc904 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ResolvedIndices.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ResolvedIndices.java @@ -9,6 +9,7 @@ package org.opensearch.cluster.metadata; import org.opensearch.action.OriginalIndices; +import org.opensearch.common.annotation.PublicApi; import org.opensearch.core.index.Index; import java.util.Arrays; @@ -36,7 +37,9 @@ * just taken without further evaluation * */ +@PublicApi(since = "3.2.0") public class ResolvedIndices { + public static ResolvedIndices of(String... indices) { return new ResolvedIndices( new Local(Collections.unmodifiableSet(new HashSet<>(Arrays.asList(indices))), null, false), @@ -111,6 +114,7 @@ public boolean isEmpty() { /** * Encapsulates the local (i.e., non-remote) indices referenced by the respective request. */ + @PublicApi(since = "3.2.0") public static class Local { private final Set names; private final OriginalIndices originalIndices; diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java b/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java index c5470a3cea517..c30015a11195d 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java @@ -68,6 +68,7 @@ import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.metadata.RepositoriesMetadata; +import org.opensearch.cluster.metadata.ResolvedIndices; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.routing.IndexRoutingTable; @@ -355,7 +356,7 @@ public ClusterState execute(ClusterState currentState) { ); ensureBelowConcurrencyLimit(repositoryName, snapshotName, snapshots, deletionsInProgress); // Store newSnapshot here to be processed in clusterStateProcessed - List indices = Arrays.asList(indexNameExpressionResolver.concreteIndexNames(currentState, request)); + List indices = Arrays.asList(resolveIndices(currentState, request)); final List dataStreams = indexNameExpressionResolver.dataStreamNames( currentState, @@ -456,6 +457,22 @@ public TimeValue timeout() { }, "create_snapshot [" + snapshotName + ']', listener::onFailure); } + private String[] resolveIndices(ClusterState currentState, CreateSnapshotRequest request) { + return indexNameExpressionResolver.concreteIndexNames(currentState, request); + } + + public ResolvedIndices resolveIndices(CreateSnapshotRequest request) { + ClusterState currentState = clusterService.state(); + final List dataStreams = indexNameExpressionResolver.dataStreamNames( + currentState, + request.indicesOptions(), + request.indices() + ); + List result = new ArrayList<>(dataStreams); + result.addAll(Arrays.asList(resolveIndices(currentState, request))); + return ResolvedIndices.of(result); + } + /** * Initializes the snapshotting process for clients when Snapshot v2 is enabled. This method is responsible for taking * a shallow snapshot and pinning the snapshot timestamp.The entire process is executed on the cluster manager node.