Search in sources :

Example 1 with DEFAULT_MASTER_NODE_TIMEOUT

use of org.opensearch.action.support.master.MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT 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);
    TimeValue clusterManagerTimeout = request.paramAsTime("cluster_manager_timeout", DEFAULT_MASTER_NODE_TIMEOUT);
    // Remove the if condition and statements inside after removing MASTER_ROLE.
    if (request.hasParam("master_timeout")) {
        deprecationLogger.deprecate("cat_indices_master_timeout_parameter", MASTER_TIMEOUT_DEPRECATED_MESSAGE);
        if (request.hasParam("cluster_manager_timeout")) {
            throw new OpenSearchParseException(DUPLICATE_PARAMETER_ERROR_MESSAGE);
        }
        clusterManagerTimeout = request.paramAsTime("master_timeout", DEFAULT_MASTER_NODE_TIMEOUT);
    }
    final TimeValue clusterManagerNodeTimeout = clusterManagerTimeout;
    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, clusterManagerNodeTimeout, 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, clusterManagerNodeTimeout, client, ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure));
                sendClusterHealthRequest(indices, subRequestIndicesOptions, local, clusterManagerNodeTimeout, 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) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) 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) OpenSearchParseException(org.opensearch.OpenSearchParseException) 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) OpenSearchParseException(org.opensearch.OpenSearchParseException) OpenSearchParseException(org.opensearch.OpenSearchParseException) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) ActionListener(org.opensearch.action.ActionListener) IndicesOptions(org.opensearch.action.support.IndicesOptions) TimeValue(org.opensearch.common.unit.TimeValue)

Aggregations

Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 OpenSearchParseException (org.opensearch.OpenSearchParseException)1 ActionListener (org.opensearch.action.ActionListener)1 ActionResponse (org.opensearch.action.ActionResponse)1 ClusterHealthRequest (org.opensearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)1