Search in sources :

Example 1 with CloseableConnection

use of org.opensearch.transport.CloseableConnection 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

DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)1 CloseableConnection (org.opensearch.transport.CloseableConnection)1 ConnectTransportException (org.opensearch.transport.ConnectTransportException)1 TransportException (org.opensearch.transport.TransportException)1 TransportRequest (org.opensearch.transport.TransportRequest)1 TransportRequestOptions (org.opensearch.transport.TransportRequestOptions)1