Search in sources :

Example 31 with GetSettingsResponse

use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.

the class RestIndicesAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, IndicesOptions.strictExpand());
    final boolean local = request.paramAsBoolean("local", false);
    final TimeValue masterNodeTimeout = request.paramAsTime("master_timeout", DEFAULT_MASTER_NODE_TIMEOUT);
    final boolean includeUnloadedSegments = request.paramAsBoolean("include_unloaded_segments", false);
    return channel -> {
        final ActionListener<Table> listener = ActionListener.notifyOnce(new RestResponseListener<Table>(channel) {

            @Override
            public RestResponse buildResponse(final Table table) throws Exception {
                return RestTable.buildResponse(table, channel);
            }
        });
        sendGetSettingsRequest(indices, indicesOptions, local, masterNodeTimeout, client, new ActionListener<GetSettingsResponse>() {

            @Override
            public void onResponse(final GetSettingsResponse getSettingsResponse) {
                final GroupedActionListener<ActionResponse> groupedListener = createGroupedListener(request, 4, listener);
                groupedListener.onResponse(getSettingsResponse);
                // The list of indices that will be returned is determined by the indices returned from the Get Settings call.
                // All the other requests just provide additional detail, and wildcards may be resolved differently depending on the
                // type of request in the presence of security plugins (looking at you, ClusterHealthRequest), so
                // force the IndicesOptions for all the sub-requests to be as inclusive as possible.
                final IndicesOptions subRequestIndicesOptions = IndicesOptions.lenientExpandHidden();
                // Indices that were successfully resolved during the get settings request might be deleted when the subsequent cluster
                // state, cluster health and indices stats requests execute. We have to distinguish two cases:
                // 1) the deleted index was explicitly passed as parameter to the /_cat/indices request. In this case we want the
                // subsequent requests to fail.
                // 2) the deleted index was resolved as part of a wildcard or _all. In this case, we want the subsequent requests not to
                // fail on the deleted index (as we want to ignore wildcards that cannot be resolved).
                // This behavior can be ensured by letting the cluster state, cluster health and indices stats requests re-resolve the
                // index names with the same indices options that we used for the initial cluster state request (strictExpand).
                sendIndicesStatsRequest(indices, subRequestIndicesOptions, includeUnloadedSegments, client, ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure));
                sendClusterStateRequest(indices, subRequestIndicesOptions, local, masterNodeTimeout, client, ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure));
                sendClusterHealthRequest(indices, subRequestIndicesOptions, local, masterNodeTimeout, client, ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure));
            }

            @Override
            public void onFailure(final Exception e) {
                listener.onFailure(e);
            }
        });
    };
}
Also used : CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) Collections.unmodifiableList(java.util.Collections.unmodifiableList) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ZonedDateTime(java.time.ZonedDateTime) DEFAULT_MASTER_NODE_TIMEOUT(org.opensearch.action.support.master.MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT) Table(org.opensearch.common.Table) IndicesOptions(org.opensearch.action.support.IndicesOptions) Function(java.util.function.Function) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) Strings(org.opensearch.common.Strings) HashSet(java.util.HashSet) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ActionListener(org.opensearch.action.ActionListener) ActionResponse(org.opensearch.action.ActionResponse) ZoneOffset(java.time.ZoneOffset) IndexStats(org.opensearch.action.admin.indices.stats.IndexStats) DateFormatter(org.opensearch.common.time.DateFormatter) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterHealthStatus(org.opensearch.cluster.health.ClusterHealthStatus) ClusterIndexHealth(org.opensearch.cluster.health.ClusterIndexHealth) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Collection(java.util.Collection) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) IndexSettings(org.opensearch.index.IndexSettings) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ClusterHealthRequest(org.opensearch.action.admin.cluster.health.ClusterHealthRequest) Collections(java.util.Collections) Table(org.opensearch.common.Table) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ActionResponse(org.opensearch.action.ActionResponse) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) ActionListener(org.opensearch.action.ActionListener) IndicesOptions(org.opensearch.action.support.IndicesOptions) TimeValue(org.opensearch.common.unit.TimeValue)

Aggregations

GetSettingsResponse (org.opensearch.action.admin.indices.settings.get.GetSettingsResponse)31 Settings (org.opensearch.common.settings.Settings)14 Matchers.containsString (org.hamcrest.Matchers.containsString)10 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)8 IndexSettings (org.opensearch.index.IndexSettings)7 Sort (org.apache.lucene.search.Sort)4 SortField (org.apache.lucene.search.SortField)4 SortedSetSortField (org.apache.lucene.search.SortedSetSortField)4 IndicesStatsResponse (org.opensearch.action.admin.indices.stats.IndicesStatsResponse)4 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)4 Version (org.opensearch.Version)3 ActionListener (org.opensearch.action.ActionListener)3 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)3 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)3 CommonStats (org.opensearch.action.admin.indices.stats.CommonStats)3 Client (org.opensearch.client.Client)3 ClusterState (org.opensearch.cluster.ClusterState)3 TermsQueryBuilder (org.opensearch.index.query.TermsQueryBuilder)3 SeqNoStats (org.opensearch.index.seqno.SeqNoStats)3 IOException (java.io.IOException)2