Search in sources :

Example 26 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestShardsAction method buildTable.

// package private for testing
Table buildTable(RestRequest request, ClusterStateResponse state, IndicesStatsResponse stats) {
    Table table = getTableWithHeader(request);
    for (ShardRouting shard : state.getState().routingTable().allShards()) {
        ShardStats shardStats = stats.asMap().get(shard);
        CommonStats commonStats = null;
        CommitStats commitStats = null;
        if (shardStats != null) {
            commonStats = shardStats.getStats();
            commitStats = shardStats.getCommitStats();
        }
        table.startRow();
        table.addCell(shard.getIndexName());
        table.addCell(shard.id());
        if (shard.primary()) {
            table.addCell("p");
        } else {
            table.addCell("r");
        }
        table.addCell(shard.state());
        table.addCell(getOrNull(commonStats, CommonStats::getDocs, DocsStats::getCount));
        table.addCell(getOrNull(commonStats, CommonStats::getStore, StoreStats::getSize));
        if (shard.assignedToNode()) {
            String ip = state.getState().nodes().get(shard.currentNodeId()).getHostAddress();
            String nodeId = shard.currentNodeId();
            StringBuilder name = new StringBuilder();
            name.append(state.getState().nodes().get(shard.currentNodeId()).getName());
            if (shard.relocating()) {
                String reloIp = state.getState().nodes().get(shard.relocatingNodeId()).getHostAddress();
                String reloNme = state.getState().nodes().get(shard.relocatingNodeId()).getName();
                String reloNodeId = shard.relocatingNodeId();
                name.append(" -> ");
                name.append(reloIp);
                name.append(" ");
                name.append(reloNodeId);
                name.append(" ");
                name.append(reloNme);
            }
            table.addCell(ip);
            table.addCell(nodeId);
            table.addCell(name);
        } else {
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
        }
        table.addCell(commitStats == null ? null : commitStats.getUserData().get(Engine.SYNC_COMMIT_ID));
        if (shard.unassignedInfo() != null) {
            table.addCell(shard.unassignedInfo().getReason());
            Instant unassignedTime = Instant.ofEpochMilli(shard.unassignedInfo().getUnassignedTimeInMillis());
            table.addCell(UnassignedInfo.DATE_TIME_FORMATTER.format(unassignedTime));
            table.addCell(TimeValue.timeValueMillis(System.currentTimeMillis() - shard.unassignedInfo().getUnassignedTimeInMillis()));
            table.addCell(shard.unassignedInfo().getDetails());
        } else {
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
        }
        if (shard.recoverySource() != null) {
            table.addCell(shard.recoverySource().getType().toString().toLowerCase(Locale.ROOT));
        } else {
            table.addCell(null);
        }
        table.addCell(getOrNull(commonStats, CommonStats::getCompletion, CompletionStats::getSize));
        table.addCell(getOrNull(commonStats, CommonStats::getFieldData, FieldDataStats::getMemorySize));
        table.addCell(getOrNull(commonStats, CommonStats::getFieldData, FieldDataStats::getEvictions));
        table.addCell(getOrNull(commonStats, CommonStats::getQueryCache, QueryCacheStats::getMemorySize));
        table.addCell(getOrNull(commonStats, CommonStats::getQueryCache, QueryCacheStats::getEvictions));
        table.addCell(getOrNull(commonStats, CommonStats::getFlush, FlushStats::getTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getFlush, FlushStats::getTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::current));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getCount));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getExistsTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getExistsCount));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getMissingTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getMissingCount));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getDeleteCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getDeleteTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getDeleteCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexFailedCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getCurrent));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getCurrentNumDocs));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getCurrentSize));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotalNumDocs));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotalSize));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getExternalTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getExternalTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getListeners));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getFetchCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getFetchTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getFetchCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, SearchStats::getOpenContexts));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getScrollCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getScrollTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getScrollCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getCount));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getZeroMemory));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getIndexWriterMemory));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getVersionMapMemory));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getBitsetMemory));
        table.addCell(getOrNull(shardStats, ShardStats::getSeqNoStats, SeqNoStats::getMaxSeqNo));
        table.addCell(getOrNull(shardStats, ShardStats::getSeqNoStats, SeqNoStats::getLocalCheckpoint));
        table.addCell(getOrNull(shardStats, ShardStats::getSeqNoStats, SeqNoStats::getGlobalCheckpoint));
        table.addCell(getOrNull(commonStats, CommonStats::getWarmer, WarmerStats::current));
        table.addCell(getOrNull(commonStats, CommonStats::getWarmer, WarmerStats::total));
        table.addCell(getOrNull(commonStats, CommonStats::getWarmer, WarmerStats::totalTime));
        table.addCell(getOrNull(shardStats, ShardStats::getDataPath, s -> s));
        table.addCell(getOrNull(shardStats, ShardStats::getStatePath, s -> s));
        table.endRow();
    }
    return table;
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) SeqNoStats(org.opensearch.index.seqno.SeqNoStats) Collections.unmodifiableList(java.util.Collections.unmodifiableList) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) SearchStats(org.opensearch.index.search.stats.SearchStats) Table(org.opensearch.common.Table) Function(java.util.function.Function) Strings(org.opensearch.common.Strings) MergeStats(org.opensearch.index.merge.MergeStats) RestActionListener(org.opensearch.rest.action.RestActionListener) RefreshStats(org.opensearch.index.refresh.RefreshStats) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) SegmentsStats(org.opensearch.index.engine.SegmentsStats) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) StoreStats(org.opensearch.index.store.StoreStats) CommitStats(org.opensearch.index.engine.CommitStats) RestResponseListener(org.opensearch.rest.action.RestResponseListener) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) DocsStats(org.opensearch.index.shard.DocsStats) FlushStats(org.opensearch.index.flush.FlushStats) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest) Instant(java.time.Instant) GetStats(org.opensearch.index.get.GetStats) RestResponse(org.opensearch.rest.RestResponse) WarmerStats(org.opensearch.index.warmer.WarmerStats) ShardRouting(org.opensearch.cluster.routing.ShardRouting) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) Engine(org.opensearch.index.engine.Engine) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) Table(org.opensearch.common.Table) CommitStats(org.opensearch.index.engine.CommitStats) Instant(java.time.Instant) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Example 27 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestTemplatesAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    final String matchPattern = request.hasParam("name") ? request.param("name") : null;
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().metadata(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestResponseListener<ClusterStateResponse>(channel) {

        @Override
        public RestResponse buildResponse(ClusterStateResponse clusterStateResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, clusterStateResponse, matchPattern), channel);
        }
    });
}
Also used : IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) NodeClient(org.opensearch.client.node.NodeClient) Metadata(org.opensearch.cluster.metadata.Metadata) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) Regex(org.opensearch.common.regex.Regex) RestResponse(org.opensearch.rest.RestResponse) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Map(java.util.Map) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest)

Example 28 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestThreadPoolAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.timeout(request.param("timeout"));
            nodesInfoRequest.clear().addMetrics(NodesInfoRequest.Metric.PROCESS.metricName(), NodesInfoRequest.Metric.THREAD_POOL.metricName());
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {

                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.timeout(request.param("timeout"));
                    nodesStatsRequest.clear().addMetric(NodesStatsRequest.Metric.THREAD_POOL.metricName());
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Collections.unmodifiableList(java.util.Collections.unmodifiableList) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) Table(org.opensearch.common.Table) HashMap(java.util.HashMap) Regex(org.opensearch.common.regex.Regex) HashSet(java.util.HashSet) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ThreadPoolInfo(org.opensearch.threadpool.ThreadPoolInfo) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest) Set(java.util.Set) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) RestResponse(org.opensearch.rest.RestResponse) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) TreeMap(java.util.TreeMap) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) NodesStatsRequest(org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest) Collections(java.util.Collections) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) NodesStatsRequest(org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 29 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestMasterAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestResponseListener<ClusterStateResponse>(channel) {

        @Override
        public RestResponse buildResponse(final ClusterStateResponse clusterStateResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, clusterStateResponse), channel);
        }
    });
}
Also used : ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) RestResponse(org.opensearch.rest.RestResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) Collections.singletonList(java.util.Collections.singletonList) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest)

Example 30 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class SniffConnectionStrategy method collectRemoteNodes.

private void collectRemoteNodes(Iterator<Supplier<DiscoveryNode>> seedNodes, ActionListener<Void> listener) {
    if (Thread.currentThread().isInterrupted()) {
        listener.onFailure(new InterruptedException("remote connect thread got interrupted"));
        return;
    }
    if (seedNodes.hasNext()) {
        final Consumer<Exception> onFailure = e -> {
            if (e instanceof ConnectTransportException || e instanceof IOException || e instanceof IllegalStateException) {
                // ISE if we fail the handshake with an version incompatible node
                if (seedNodes.hasNext()) {
                    logger.debug(() -> new ParameterizedMessage("fetching nodes from external cluster [{}] failed moving to next seed node", clusterAlias), e);
                    collectRemoteNodes(seedNodes, listener);
                    return;
                }
            }
            logger.warn(new ParameterizedMessage("fetching nodes from external cluster [{}] failed", clusterAlias), e);
            listener.onFailure(e);
        };
        final DiscoveryNode seedNode = seedNodes.next().get();
        logger.trace("[{}] opening transient connection to seed node: [{}]", clusterAlias, seedNode);
        final StepListener<Transport.Connection> openConnectionStep = new StepListener<>();
        try {
            connectionManager.openConnection(seedNode, null, openConnectionStep);
        } catch (Exception e) {
            onFailure.accept(e);
        }
        final StepListener<TransportService.HandshakeResponse> handshakeStep = new StepListener<>();
        openConnectionStep.whenComplete(connection -> {
            ConnectionProfile connectionProfile = connectionManager.getConnectionProfile();
            transportService.handshake(connection, connectionProfile.getHandshakeTimeout().millis(), getRemoteClusterNamePredicate(), handshakeStep);
        }, onFailure);
        final StepListener<Void> fullConnectionStep = new StepListener<>();
        handshakeStep.whenComplete(handshakeResponse -> {
            final DiscoveryNode handshakeNode = handshakeResponse.getDiscoveryNode();
            if (nodePredicate.test(handshakeNode) && shouldOpenMoreConnections()) {
                logger.trace("[{}] opening managed connection to seed node: [{}] proxy address: [{}]", clusterAlias, handshakeNode, proxyAddress);
                final DiscoveryNode handshakeNodeWithProxy = maybeAddProxyAddress(proxyAddress, handshakeNode);
                connectionManager.connectToNode(handshakeNodeWithProxy, null, transportService.connectionValidator(handshakeNodeWithProxy), fullConnectionStep);
            } else {
                fullConnectionStep.onResponse(null);
            }
        }, e -> {
            final Transport.Connection connection = openConnectionStep.result();
            final DiscoveryNode node = connection.getNode();
            logger.debug(() -> new ParameterizedMessage("[{}] failed to handshake with seed node: [{}]", clusterAlias, node), e);
            IOUtils.closeWhileHandlingException(connection);
            onFailure.accept(e);
        });
        fullConnectionStep.whenComplete(aVoid -> {
            if (remoteClusterName.get() == null) {
                TransportService.HandshakeResponse handshakeResponse = handshakeStep.result();
                assert handshakeResponse.getClusterName().value() != null;
                remoteClusterName.set(handshakeResponse.getClusterName());
            }
            final Transport.Connection connection = openConnectionStep.result();
            ClusterStateRequest request = new ClusterStateRequest();
            request.clear();
            request.nodes(true);
            // here we pass on the connection since we can only close it once the sendRequest returns otherwise
            // due to the async nature (it will return before it's actually sent) this can cause the request to fail
            // due to an already closed connection.
            ThreadPool threadPool = transportService.getThreadPool();
            ThreadContext threadContext = threadPool.getThreadContext();
            TransportService.ContextRestoreResponseHandler<ClusterStateResponse> responseHandler = new TransportService.ContextRestoreResponseHandler<>(threadContext.newRestorableContext(false), new SniffClusterStateResponseHandler(connection, listener, seedNodes));
            try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
                // we stash any context here since this is an internal execution and should not leak any
                // existing context information.
                threadContext.markAsSystemContext();
                transportService.sendRequest(connection, ClusterStateAction.NAME, request, TransportRequestOptions.EMPTY, responseHandler);
            }
        }, e -> {
            final Transport.Connection connection = openConnectionStep.result();
            final DiscoveryNode node = connection.getNode();
            logger.debug(() -> new ParameterizedMessage("[{}] failed to open managed connection to seed node: [{}]", clusterAlias, node), e);
            IOUtils.closeWhileHandlingException(openConnectionStep.result());
            onFailure.accept(e);
        });
    } else {
        listener.onFailure(new NoSeedNodeLeftException(clusterAlias));
    }
}
Also used : Arrays(java.util.Arrays) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) Version(org.opensearch.Version) StreamOutput(org.opensearch.common.io.stream.StreamOutput) Writeable(org.opensearch.common.io.stream.Writeable) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Supplier(java.util.function.Supplier) Strings(org.opensearch.common.Strings) HashSet(java.util.HashSet) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Booleans(org.opensearch.common.Booleans) Setting.intSetting(org.opensearch.common.settings.Setting.intSetting) ActionListener(org.opensearch.action.ActionListener) UUIDs(org.opensearch.common.UUIDs) StreamInput(org.opensearch.common.io.stream.StreamInput) Setting(org.opensearch.common.settings.Setting) SetOnce(org.apache.lucene.util.SetOnce) Iterator(java.util.Iterator) ClusterStateAction(org.opensearch.action.admin.cluster.state.ClusterStateAction) Predicate(java.util.function.Predicate) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) TransportAddress(org.opensearch.common.transport.TransportAddress) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) IOUtils(org.opensearch.core.internal.io.IOUtils) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) Stream(java.util.stream.Stream) ClusterName(org.opensearch.cluster.ClusterName) StepListener(org.opensearch.action.StepListener) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) IOException(java.io.IOException) IOException(java.io.IOException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) StepListener(org.opensearch.action.StepListener)

Aggregations

ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)57 Settings (org.opensearch.common.settings.Settings)20 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)19 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)19 List (java.util.List)16 NodeClient (org.opensearch.client.node.NodeClient)13 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)13 RestRequest (org.opensearch.rest.RestRequest)12 GET (org.opensearch.rest.RestRequest.Method.GET)12 RestResponse (org.opensearch.rest.RestResponse)12 Table (org.opensearch.common.Table)11 ClusterState (org.opensearch.cluster.ClusterState)10 RestResponseListener (org.opensearch.rest.action.RestResponseListener)10 MockTransportService (org.opensearch.test.transport.MockTransportService)9 SearchResponse (org.opensearch.action.search.SearchResponse)8 Client (org.opensearch.client.Client)8 ShardRouting (org.opensearch.cluster.routing.ShardRouting)8 Strings (org.opensearch.common.Strings)8 Arrays.asList (java.util.Arrays.asList)7 Collections.unmodifiableList (java.util.Collections.unmodifiableList)7