Search in sources :

Example 16 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class TransportCancelTasksAction method sendSetBanRequest.

private void sendSetBanRequest(DiscoveryNodes nodes, BanParentTaskRequest request, ActionListener<Void> listener) {
    for (ObjectObjectCursor<String, DiscoveryNode> node : nodes.getNodes()) {
        logger.trace("Sending ban for tasks with the parent [{}] to the node [{}], ban [{}]", request.parentTaskId, node.key, request.ban);
        transportService.sendRequest(node.value, BAN_PARENT_ACTION_NAME, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleResponse(TransportResponse.Empty response) {
                listener.onResponse(null);
            }

            @Override
            public void handleException(TransportException exp) {
                logger.warn("Cannot send ban for tasks with the parent [{}] to the node [{}]", request.parentTaskId, node.key);
                listener.onFailure(exp);
            }
        });
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) EmptyTransportResponseHandler(org.elasticsearch.transport.EmptyTransportResponseHandler) TransportResponse(org.elasticsearch.transport.TransportResponse) TransportException(org.elasticsearch.transport.TransportException)

Example 17 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class TransportGetTaskAction method runOnNodeWithTaskIfPossible.

/**
     * Executed on the coordinating node to forward execution of the remaining work to the node that matches that requested
     * {@link TaskId#getNodeId()}. If the node isn't in the cluster then this will just proceed to
     * {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} on this node.
     */
private void runOnNodeWithTaskIfPossible(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
    TransportRequestOptions.Builder builder = TransportRequestOptions.builder();
    if (request.getTimeout() != null) {
        builder.withTimeout(request.getTimeout());
    }
    builder.withCompress(false);
    DiscoveryNode node = clusterService.state().nodes().get(request.getTaskId().getNodeId());
    if (node == null) {
        // Node is no longer part of the cluster! Try and look the task up from the results index.
        getFinishedTaskFromIndex(thisTask, request, ActionListener.wrap(listener::onResponse, e -> {
            if (e instanceof ResourceNotFoundException) {
                e = new ResourceNotFoundException("task [" + request.getTaskId() + "] belongs to the node [" + request.getTaskId().getNodeId() + "] which isn't part of the cluster and there is no record of the task", e);
            }
            listener.onFailure(e);
        }));
        return;
    }
    GetTaskRequest nodeRequest = request.nodeRequest(clusterService.localNode().getId(), thisTask.getId());
    transportService.sendRequest(node, GetTaskAction.NAME, nodeRequest, builder.build(), new TransportResponseHandler<GetTaskResponse>() {

        @Override
        public GetTaskResponse newInstance() {
            return new GetTaskResponse();
        }

        @Override
        public void handleResponse(GetTaskResponse response) {
            listener.onResponse(response);
        }

        @Override
        public void handleException(TransportException exp) {
            listener.onFailure(exp);
        }

        @Override
        public String executor() {
            return ThreadPool.Names.SAME;
        }
    });
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) ClusterService(org.elasticsearch.cluster.service.ClusterService) TaskId(org.elasticsearch.tasks.TaskId) Inject(org.elasticsearch.common.inject.Inject) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) TaskResult(org.elasticsearch.tasks.TaskResult) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) HandledTransportAction(org.elasticsearch.action.support.HandledTransportAction) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) TaskInfo(org.elasticsearch.tasks.TaskInfo) GetRequest(org.elasticsearch.action.get.GetRequest) ActionFilters(org.elasticsearch.action.support.ActionFilters) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) XContentParser(org.elasticsearch.common.xcontent.XContentParser) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportListTasksAction.waitForCompletionTimeout(org.elasticsearch.action.admin.cluster.node.tasks.list.TransportListTasksAction.waitForCompletionTimeout) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Task(org.elasticsearch.tasks.Task) TransportException(org.elasticsearch.transport.TransportException) ActionListener(org.elasticsearch.action.ActionListener) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) TransportException(org.elasticsearch.transport.TransportException)

Example 18 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class PublishClusterStateAction method sendCommitToNode.

private void sendCommitToNode(final DiscoveryNode node, final ClusterState clusterState, final SendingController sendingController) {
    try {
        logger.trace("sending commit for cluster state (uuid: [{}], version [{}]) to [{}]", clusterState.stateUUID(), clusterState.version(), node);
        TransportRequestOptions options = TransportRequestOptions.builder().withType(TransportRequestOptions.Type.STATE).build();
        // no need to put a timeout on the options here, because we want the response to eventually be received
        // and not log an error if it arrives after the timeout
        transportService.sendRequest(node, COMMIT_ACTION_NAME, new CommitClusterStateRequest(clusterState.stateUUID()), options, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleResponse(TransportResponse.Empty response) {
                if (sendingController.getPublishingTimedOut()) {
                    logger.debug("node {} responded to cluster state commit [{}]", node, clusterState.version());
                }
                sendingController.getPublishResponseHandler().onResponse(node);
            }

            @Override
            public void handleException(TransportException exp) {
                logger.debug((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("failed to commit cluster state (uuid [{}], version [{}]) to {}", clusterState.stateUUID(), clusterState.version(), node), exp);
                sendingController.getPublishResponseHandler().onFailure(node, exp);
            }
        });
    } catch (Exception t) {
        logger.warn((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("error sending cluster state commit (uuid [{}], version [{}]) to {}", clusterState.stateUUID(), clusterState.version(), node), t);
        sendingController.getPublishResponseHandler().onFailure(node, t);
    }
}
Also used : TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EmptyTransportResponseHandler(org.elasticsearch.transport.EmptyTransportResponseHandler) TransportResponse(org.elasticsearch.transport.TransportResponse) TransportException(org.elasticsearch.transport.TransportException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Example 19 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class Netty4ScheduledPingTests method testScheduledPing.

public void testScheduledPing() throws Exception {
    ThreadPool threadPool = new TestThreadPool(getClass().getName());
    Settings settings = Settings.builder().put(TcpTransport.PING_SCHEDULE.getKey(), "5ms").put(TransportSettings.PORT.getKey(), 0).put("cluster.name", "test").build();
    CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
    NamedWriteableRegistry registry = new NamedWriteableRegistry(Collections.emptyList());
    final Netty4Transport nettyA = new Netty4Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), BigArrays.NON_RECYCLING_INSTANCE, registry, circuitBreakerService);
    MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, null);
    serviceA.start();
    serviceA.acceptIncomingRequests();
    final Netty4Transport nettyB = new Netty4Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), BigArrays.NON_RECYCLING_INSTANCE, registry, circuitBreakerService);
    MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, null);
    serviceB.start();
    serviceB.acceptIncomingRequests();
    DiscoveryNode nodeA = serviceA.getLocalDiscoNode();
    DiscoveryNode nodeB = serviceB.getLocalDiscoNode();
    serviceA.connectToNode(nodeB);
    serviceB.connectToNode(nodeA);
    assertBusy(new Runnable() {

        @Override
        public void run() {
            assertThat(nettyA.getPing().getSuccessfulPings(), greaterThan(100L));
            assertThat(nettyB.getPing().getSuccessfulPings(), greaterThan(100L));
        }
    });
    assertThat(nettyA.getPing().getFailedPings(), equalTo(0L));
    assertThat(nettyB.getPing().getFailedPings(), equalTo(0L));
    serviceA.registerRequestHandler("sayHello", TransportRequest.Empty::new, ThreadPool.Names.GENERIC, new TransportRequestHandler<TransportRequest.Empty>() {

        @Override
        public void messageReceived(TransportRequest.Empty request, TransportChannel channel) {
            try {
                channel.sendResponse(TransportResponse.Empty.INSTANCE, TransportResponseOptions.EMPTY);
            } catch (IOException e) {
                logger.error("Unexpected failure", e);
                fail(e.getMessage());
            }
        }
    });
    int rounds = scaledRandomIntBetween(100, 5000);
    for (int i = 0; i < rounds; i++) {
        serviceB.submitRequest(nodeA, "sayHello", TransportRequest.Empty.INSTANCE, TransportRequestOptions.builder().withCompress(randomBoolean()).build(), new TransportResponseHandler<TransportResponse.Empty>() {

            @Override
            public TransportResponse.Empty newInstance() {
                return TransportResponse.Empty.INSTANCE;
            }

            @Override
            public String executor() {
                return ThreadPool.Names.GENERIC;
            }

            @Override
            public void handleResponse(TransportResponse.Empty response) {
            }

            @Override
            public void handleException(TransportException exp) {
                logger.error("Unexpected failure", exp);
                fail("got exception instead of a response: " + exp.getMessage());
            }
        }).txGet();
    }
    assertBusy(() -> {
        assertThat(nettyA.getPing().getSuccessfulPings(), greaterThan(200L));
        assertThat(nettyB.getPing().getSuccessfulPings(), greaterThan(200L));
    });
    assertThat(nettyA.getPing().getFailedPings(), equalTo(0L));
    assertThat(nettyB.getPing().getFailedPings(), equalTo(0L));
    Releasables.close(serviceA, serviceB);
    terminate(threadPool);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequest(org.elasticsearch.transport.TransportRequest) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) IOException(java.io.IOException) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TransportResponse(org.elasticsearch.transport.TransportResponse) TransportException(org.elasticsearch.transport.TransportException) NetworkService(org.elasticsearch.common.network.NetworkService) TransportChannel(org.elasticsearch.transport.TransportChannel) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) TransportSettings(org.elasticsearch.transport.TransportSettings) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 20 with TransportException

use of org.elasticsearch.transport.TransportException in project elasticsearch by elastic.

the class FailAndRetryMockTransport method getConnection.

@Override
public Connection getConnection(DiscoveryNode node) {
    return new Connection() {

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

        @Override
        public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException {
            //we make sure that nodes get added to the connected ones when calling addTransportAddress, by returning proper nodes info
            if (connectMode) {
                if (TransportLivenessAction.NAME.equals(action)) {
                    TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId);
                    transportResponseHandler.handleResponse(new LivenessResponse(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY), node));
                } else if (ClusterStateAction.NAME.equals(action)) {
                    TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId);
                    ClusterState clusterState = getMockClusterState(node);
                    transportResponseHandler.handleResponse(new ClusterStateResponse(clusterName, clusterState, 0L));
                } else {
                    throw new UnsupportedOperationException("Mock transport does not understand action " + action);
                }
                return;
            }
            //once nodes are connected we'll just return errors for each sendRequest call
            triedNodes.add(node);
            if (random.nextInt(100) > 10) {
                connectTransportExceptions.incrementAndGet();
                throw new ConnectTransportException(node, "node not available");
            } else {
                if (random.nextBoolean()) {
                    failures.incrementAndGet();
                    //throw whatever exception that is not a subclass of ConnectTransportException
                    throw new IllegalStateException();
                } else {
                    TransportResponseHandler transportResponseHandler = transportServiceAdapter.onResponseReceived(requestId);
                    if (random.nextBoolean()) {
                        successes.incrementAndGet();
                        transportResponseHandler.handleResponse(newResponse());
                    } else {
                        failures.incrementAndGet();
                        transportResponseHandler.handleException(new TransportException("transport exception"));
                    }
                }
            }
        }

        @Override
        public void close() throws IOException {
        }
    };
}
Also used : LivenessResponse(org.elasticsearch.action.admin.cluster.node.liveness.LivenessResponse) ClusterState(org.elasticsearch.cluster.ClusterState) TransportRequest(org.elasticsearch.transport.TransportRequest) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) TransportException(org.elasticsearch.transport.TransportException)

Aggregations

TransportException (org.elasticsearch.transport.TransportException)21 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)11 IOException (java.io.IOException)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)8 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)7 EmptyTransportResponseHandler (org.elasticsearch.transport.EmptyTransportResponseHandler)7 TransportResponse (org.elasticsearch.transport.TransportResponse)7 ClusterState (org.elasticsearch.cluster.ClusterState)6 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Supplier (org.apache.logging.log4j.util.Supplier)5 ConnectTransportException (org.elasticsearch.transport.ConnectTransportException)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)3 CountDown (org.elasticsearch.common.util.concurrent.CountDown)3 ShardId (org.elasticsearch.index.shard.ShardId)3 TransportRequestOptions (org.elasticsearch.transport.TransportRequestOptions)3 TransportResponseHandler (org.elasticsearch.transport.TransportResponseHandler)3