Search in sources :

Example 1 with TransportRequestOptions

use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.

the class DedicatedClusterSnapshotRestoreIT method testAbortWaitsOnDataNode.

public void testAbortWaitsOnDataNode() throws Exception {
    internalCluster().startMasterOnlyNode();
    final String dataNodeName = internalCluster().startDataOnlyNode();
    final String indexName = "test-index";
    createIndex(indexName);
    index(indexName, "_doc", "some_id", "foo", "bar");
    final String otherDataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    createRepository(repoName, "mock");
    blockAllDataNodes(repoName);
    final String snapshotName = "test-snap";
    final ActionFuture<CreateSnapshotResponse> snapshotResponse = startFullSnapshot(repoName, snapshotName);
    waitForBlock(dataNodeName, repoName, TimeValue.timeValueSeconds(30L));
    final AtomicBoolean blocked = new AtomicBoolean(true);
    final TransportService transportService = internalCluster().getInstance(TransportService.class, otherDataNode);
    transportService.addMessageListener(new TransportMessageListener() {

        @Override
        public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions finalOptions) {
            if (blocked.get() && action.equals(SnapshotsService.UPDATE_SNAPSHOT_STATUS_ACTION_NAME)) {
                throw new AssertionError("Node had no assigned shard snapshots so it shouldn't send out shard state updates");
            }
        }
    });
    logger.info("--> abort snapshot");
    final ActionFuture<AcknowledgedResponse> deleteResponse = startDeleteSnapshot(repoName, snapshotName);
    awaitClusterState(otherDataNode, state -> state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).entries().stream().anyMatch(entry -> entry.state() == SnapshotsInProgress.State.ABORTED));
    assertFalse("delete should not be able to finish until data node is unblocked", deleteResponse.isDone());
    blocked.set(false);
    unblockAllDataNodes(repoName);
    assertAcked(deleteResponse.get());
    assertThat(snapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.FAILED));
}
Also used : RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) CheckedFunction(org.opensearch.common.CheckedFunction) Matchers.not(org.hamcrest.Matchers.not) ClusterScope(org.opensearch.test.OpenSearchIntegTestCase.ClusterScope) Version(org.opensearch.Version) SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) Strings(org.opensearch.common.Strings) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) RecoveryState(org.opensearch.indices.recovery.RecoveryState) SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) OpenSearchAssertions.assertRequestBuilderThrows(org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows) Client(org.opensearch.client.Client) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Settings(org.opensearch.common.settings.Settings) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) Scope(org.opensearch.test.OpenSearchIntegTestCase.Scope) TransportService(org.opensearch.transport.TransportService) RetentionLeaseActions(org.opensearch.index.seqno.RetentionLeaseActions) UncheckedIOException(java.io.UncheckedIOException) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Priority(org.opensearch.common.Priority) Node(org.opensearch.node.Node) ParseField(org.opensearch.common.ParseField) Writeable(org.opensearch.common.io.stream.Writeable) MockTransportService(org.opensearch.test.transport.MockTransportService) ArrayList(java.util.ArrayList) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) ClusterState(org.opensearch.cluster.ClusterState) BusyMasterServiceDisruption(org.opensearch.test.disruption.BusyMasterServiceDisruption) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Matchers.hasSize(org.hamcrest.Matchers.hasSize) AbstractRestChannel(org.opensearch.rest.AbstractRestChannel) Environment(org.opensearch.env.Environment) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Files(java.nio.file.Files) RETAIN_ALL(org.opensearch.index.seqno.RetentionLeaseActions.RETAIN_ALL) IOException(java.io.IOException) TransportMessageListener(org.opensearch.transport.TransportMessageListener) Plugin(org.opensearch.plugins.Plugin) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) ClusterService(org.opensearch.cluster.service.ClusterService) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) BlobStoreRepository(org.opensearch.repositories.blobstore.BlobStoreRepository) NodeRoles.nonMasterNode(org.opensearch.test.NodeRoles.nonMasterNode) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) XContentParser(org.opensearch.common.xcontent.XContentParser) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Locale(java.util.Locale) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Collection(java.util.Collection) RestStatus(org.opensearch.rest.RestStatus) ServiceDisruptionScheme(org.opensearch.test.disruption.ServiceDisruptionScheme) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SnapshotStats(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats) RestGetRepositoriesAction(org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalTestCluster(org.opensearch.test.InternalTestCluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) PeerRecoveryTargetService(org.opensearch.indices.recovery.PeerRecoveryTargetService) StreamInput(org.opensearch.common.io.stream.StreamInput) SettingsFilter(org.opensearch.common.settings.SettingsFilter) OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Setting(org.opensearch.common.settings.Setting) TransportRequest(org.opensearch.transport.TransportRequest) RestRequest(org.opensearch.rest.RestRequest) IntHashSet(com.carrotsearch.hppc.IntHashSet) IntSet(com.carrotsearch.hppc.IntSet) RestClusterStateAction(org.opensearch.rest.action.admin.cluster.RestClusterStateAction) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) OpenSearchAssertions.assertFutureThrows(org.opensearch.test.hamcrest.OpenSearchAssertions.assertFutureThrows) RestResponse(org.opensearch.rest.RestResponse) ActionFuture(org.opensearch.action.ActionFuture) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Sets(org.opensearch.common.util.set.Sets) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) NamedDiff(org.opensearch.cluster.NamedDiff) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) TransportService(org.opensearch.transport.TransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) TransportMessageListener(org.opensearch.transport.TransportMessageListener)

Example 2 with TransportRequestOptions

use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.

the class RemoteRecoveryTargetHandler method receiveFileInfo.

@Override
public void receiveFileInfo(List<String> phase1FileNames, List<Long> phase1FileSizes, List<String> phase1ExistingFileNames, List<Long> phase1ExistingFileSizes, int totalTranslogOps, ActionListener<Void> listener) {
    final String action = PeerRecoveryTargetService.Actions.FILES_INFO;
    final long requestSeqNo = requestSeqNoGenerator.getAndIncrement();
    RecoveryFilesInfoRequest request = new RecoveryFilesInfoRequest(recoveryId, requestSeqNo, shardId, phase1FileNames, phase1FileSizes, phase1ExistingFileNames, phase1ExistingFileSizes, totalTranslogOps);
    final TransportRequestOptions options = TransportRequestOptions.builder().withTimeout(recoverySettings.internalActionTimeout()).build();
    final Writeable.Reader<TransportResponse.Empty> reader = in -> TransportResponse.Empty.INSTANCE;
    final ActionListener<TransportResponse.Empty> responseListener = ActionListener.map(listener, r -> null);
    executeRetryableAction(action, request, options, responseListener, reader);
}
Also used : CancellableThreads(org.opensearch.common.util.CancellableThreads) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) BytesReference(org.opensearch.common.bytes.BytesReference) ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchException(org.opensearch.OpenSearchException) RetryableAction(org.opensearch.action.support.RetryableAction) Writeable(org.opensearch.common.io.stream.Writeable) ConcurrentCollections(org.opensearch.common.util.concurrent.ConcurrentCollections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) LegacyESVersion(org.opensearch.LegacyESVersion) Map(java.util.Map) Translog(org.opensearch.index.translog.Translog) ActionListener(org.opensearch.action.ActionListener) StoreFileMetadata(org.opensearch.index.store.StoreFileMetadata) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) TimeValue(org.opensearch.common.unit.TimeValue) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler) RemoteTransportException(org.opensearch.transport.RemoteTransportException) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) ExceptionsHelper(org.opensearch.ExceptionsHelper) ReplicationTracker(org.opensearch.index.seqno.ReplicationTracker) IOException(java.io.IOException) TransportResponse(org.opensearch.transport.TransportResponse) Store(org.opensearch.index.store.Store) TransportService(org.opensearch.transport.TransportService) SendRequestTransportException(org.opensearch.transport.SendRequestTransportException) ShardId(org.opensearch.index.shard.ShardId) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) ActionListenerResponseHandler(org.opensearch.action.ActionListenerResponseHandler) ConnectTransportException(org.opensearch.transport.ConnectTransportException) LogManager(org.apache.logging.log4j.LogManager) RateLimiter(org.apache.lucene.store.RateLimiter) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Writeable(org.opensearch.common.io.stream.Writeable)

Example 3 with TransportRequestOptions

use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.

the class RemoteRecoveryTargetHandler method cleanFiles.

@Override
public void cleanFiles(int totalTranslogOps, long globalCheckpoint, Store.MetadataSnapshot sourceMetadata, ActionListener<Void> listener) {
    final String action = PeerRecoveryTargetService.Actions.CLEAN_FILES;
    final long requestSeqNo = requestSeqNoGenerator.getAndIncrement();
    final RecoveryCleanFilesRequest request = new RecoveryCleanFilesRequest(recoveryId, requestSeqNo, shardId, sourceMetadata, totalTranslogOps, globalCheckpoint);
    final TransportRequestOptions options = TransportRequestOptions.builder().withTimeout(recoverySettings.internalActionTimeout()).build();
    final Writeable.Reader<TransportResponse.Empty> reader = in -> TransportResponse.Empty.INSTANCE;
    final ActionListener<TransportResponse.Empty> responseListener = ActionListener.map(listener, r -> null);
    executeRetryableAction(action, request, options, responseListener, reader);
}
Also used : CancellableThreads(org.opensearch.common.util.CancellableThreads) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) BytesReference(org.opensearch.common.bytes.BytesReference) ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchException(org.opensearch.OpenSearchException) RetryableAction(org.opensearch.action.support.RetryableAction) Writeable(org.opensearch.common.io.stream.Writeable) ConcurrentCollections(org.opensearch.common.util.concurrent.ConcurrentCollections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) LegacyESVersion(org.opensearch.LegacyESVersion) Map(java.util.Map) Translog(org.opensearch.index.translog.Translog) ActionListener(org.opensearch.action.ActionListener) StoreFileMetadata(org.opensearch.index.store.StoreFileMetadata) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) TimeValue(org.opensearch.common.unit.TimeValue) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler) RemoteTransportException(org.opensearch.transport.RemoteTransportException) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) ExceptionsHelper(org.opensearch.ExceptionsHelper) ReplicationTracker(org.opensearch.index.seqno.ReplicationTracker) IOException(java.io.IOException) TransportResponse(org.opensearch.transport.TransportResponse) Store(org.opensearch.index.store.Store) TransportService(org.opensearch.transport.TransportService) SendRequestTransportException(org.opensearch.transport.SendRequestTransportException) ShardId(org.opensearch.index.shard.ShardId) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) ActionListenerResponseHandler(org.opensearch.action.ActionListenerResponseHandler) ConnectTransportException(org.opensearch.transport.ConnectTransportException) LogManager(org.apache.logging.log4j.LogManager) RateLimiter(org.apache.lucene.store.RateLimiter) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Writeable(org.opensearch.common.io.stream.Writeable)

Example 4 with TransportRequestOptions

use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.

the class TransportSearchActionTests method testBuildConnectionLookup.

public void testBuildConnectionLookup() {
    Function<String, DiscoveryNode> localNodes = (nodeId) -> new DiscoveryNode("local-" + nodeId, new TransportAddress(TransportAddress.META_ADDRESS, 1024), Version.CURRENT);
    BiFunction<String, String, DiscoveryNode> remoteNodes = (clusterAlias, nodeId) -> new DiscoveryNode("remote-" + nodeId, new TransportAddress(TransportAddress.META_ADDRESS, 2048), Version.CURRENT);
    BiFunction<String, DiscoveryNode, Transport.Connection> nodeToConnection = (clusterAlias, node) -> new Transport.Connection() {

        @Override
        public DiscoveryNode getNode() {
            return node;
        }

        @Override
        public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws TransportException {
        }

        @Override
        public void addCloseListener(ActionListener<Void> listener) {
        }

        @Override
        public boolean isClosed() {
            return false;
        }

        @Override
        public void close() {
        }
    };
    {
        BiFunction<String, String, Transport.Connection> connectionLookup = TransportSearchAction.buildConnectionLookup(null, localNodes, remoteNodes, nodeToConnection);
        Transport.Connection localConnection = connectionLookup.apply(null, randomAlphaOfLengthBetween(5, 10));
        assertThat(localConnection.getNode().getId(), startsWith("local-"));
        Transport.Connection remoteConnection = connectionLookup.apply(randomAlphaOfLengthBetween(5, 10), randomAlphaOfLengthBetween(5, 10));
        assertThat(remoteConnection.getNode().getId(), startsWith("remote-"));
    }
    {
        String requestClusterAlias = randomAlphaOfLengthBetween(5, 10);
        BiFunction<String, String, Transport.Connection> connectionLookup = TransportSearchAction.buildConnectionLookup(requestClusterAlias, localNodes, remoteNodes, nodeToConnection);
        Transport.Connection localConnection = connectionLookup.apply(requestClusterAlias, randomAlphaOfLengthBetween(5, 10));
        assertThat(localConnection.getNode().getId(), startsWith("local-"));
    }
}
Also used : Arrays(java.util.Arrays) SearchContext(org.opensearch.search.internal.SearchContext) BiFunction(java.util.function.BiFunction) TestThreadPool(org.opensearch.threadpool.TestThreadPool) SortBuilders(org.opensearch.search.sort.SortBuilders) Version(org.opensearch.Version) ClusterSearchShardsResponse(org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Strings(org.opensearch.common.Strings) Transport(org.opensearch.transport.Transport) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) LatchedActionListener(org.opensearch.action.LatchedActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalAggregations(org.opensearch.search.aggregations.InternalAggregations) AliasFilter(org.opensearch.search.internal.AliasFilter) Map(java.util.Map) ActionListener(org.opensearch.action.ActionListener) Scroll(org.opensearch.search.Scroll) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) OpenSearchAssertions.awaitLatch(org.opensearch.test.hamcrest.OpenSearchAssertions.awaitLatch) InternalAggregationTestCase.emptyReduceContextBuilder(org.opensearch.test.InternalAggregationTestCase.emptyReduceContextBuilder) Index(org.opensearch.index.Index) SearchHit(org.opensearch.search.SearchHit) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) RemoteTransportException(org.opensearch.transport.RemoteTransportException) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) InnerHitBuilder(org.opensearch.index.query.InnerHitBuilder) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) RestStatus(org.opensearch.rest.RestStatus) TransportService(org.opensearch.transport.TransportService) OriginalIndices(org.opensearch.action.OriginalIndices) Tuple(org.opensearch.common.collect.Tuple) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) NodeDisconnectedException(org.opensearch.transport.NodeDisconnectedException) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) CollapseBuilder(org.opensearch.search.collapse.CollapseBuilder) TermsQueryBuilder(org.opensearch.index.query.TermsQueryBuilder) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) TransportException(org.opensearch.transport.TransportException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RemoteClusterServiceTests(org.opensearch.transport.RemoteClusterServiceTests) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) GroupShardsIteratorTests(org.opensearch.cluster.routing.GroupShardsIteratorTests) HashMap(java.util.HashMap) SearchHits(org.opensearch.search.SearchHits) IndicesOptions(org.opensearch.action.support.IndicesOptions) MockTransportService(org.opensearch.test.transport.MockTransportService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) ClusterBlocks(org.opensearch.cluster.block.ClusterBlocks) QueryBuilders(org.opensearch.index.query.QueryBuilders) SetOnce(org.apache.lucene.util.SetOnce) RemoteClusterService(org.opensearch.transport.RemoteClusterService) TransportRequest(org.opensearch.transport.TransportRequest) TransportConnectionListener(org.opensearch.transport.TransportConnectionListener) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse) ClusterSearchShardsGroup(org.opensearch.action.admin.cluster.shards.ClusterSearchShardsGroup) TotalHits(org.apache.lucene.search.TotalHits) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) GroupShardsIterator(org.opensearch.cluster.routing.GroupShardsIterator) TestShardRouting(org.opensearch.cluster.routing.TestShardRouting) SearchShardTarget(org.opensearch.search.SearchShardTarget) RemoteClusterConnectionTests(org.opensearch.transport.RemoteClusterConnectionTests) ClusterName(org.opensearch.cluster.ClusterName) OriginalIndicesTests(org.opensearch.action.OriginalIndicesTests) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) TransportAddress(org.opensearch.common.transport.TransportAddress) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) BiFunction(java.util.function.BiFunction) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Transport(org.opensearch.transport.Transport)

Example 5 with TransportRequestOptions

use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.

the class DisruptableMockTransport method openConnection.

@Override
public void openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Connection> listener) {
    final Optional<DisruptableMockTransport> optionalMatchingTransport = getDisruptableMockTransport(node.getAddress());
    if (optionalMatchingTransport.isPresent()) {
        final DisruptableMockTransport matchingTransport = optionalMatchingTransport.get();
        final ConnectionStatus connectionStatus = getConnectionStatus(matchingTransport.getLocalNode());
        if (connectionStatus != ConnectionStatus.CONNECTED) {
            listener.onFailure(new ConnectTransportException(node, "node [" + node + "] is [" + connectionStatus + "] not [CONNECTED]"));
        } else {
            listener.onResponse(new CloseableConnection() {

                @Override
                public DiscoveryNode getNode() {
                    return node;
                }

                @Override
                public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws TransportException {
                    onSendRequest(requestId, action, request, matchingTransport);
                }
            });
        }
    } else {
        listener.onFailure(new ConnectTransportException(node, "node " + node + " does not exist"));
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) ConnectTransportException(org.opensearch.transport.ConnectTransportException) CloseableConnection(org.opensearch.transport.CloseableConnection) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) ConnectTransportException(org.opensearch.transport.ConnectTransportException) TransportException(org.opensearch.transport.TransportException)

Aggregations

TransportRequestOptions (org.opensearch.transport.TransportRequestOptions)9 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)8 IOException (java.io.IOException)7 TimeValue (org.opensearch.common.unit.TimeValue)7 ConnectTransportException (org.opensearch.transport.ConnectTransportException)7 TransportService (org.opensearch.transport.TransportService)7 List (java.util.List)6 ShardId (org.opensearch.index.shard.ShardId)6 Map (java.util.Map)5 Consumer (java.util.function.Consumer)5 OpenSearchException (org.opensearch.OpenSearchException)5 ActionListener (org.opensearch.action.ActionListener)5 CircuitBreakingException (org.opensearch.common.breaker.CircuitBreakingException)5 Writeable (org.opensearch.common.io.stream.Writeable)5 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)5 RetentionLeases (org.opensearch.index.seqno.RetentionLeases)5 ThreadPool (org.opensearch.threadpool.ThreadPool)5 RemoteTransportException (org.opensearch.transport.RemoteTransportException)5 TransportRequest (org.opensearch.transport.TransportRequest)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4