Search in sources :

Example 6 with RemoteTransportException

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

the class ElasticsearchExceptionTests method testStatus.

public void testStatus() {
    ElasticsearchException exception = new ElasticsearchException("test");
    assertThat(exception.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
    exception = new ElasticsearchException("test", new RuntimeException());
    assertThat(exception.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
    exception = new ElasticsearchException("test", new ResourceNotFoundException("test"));
    assertThat(exception.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
    exception = new RemoteTransportException("test", new ResourceNotFoundException("test"));
    assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
    exception = new RemoteTransportException("test", new ResourceAlreadyExistsException("test"));
    assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
    exception = new RemoteTransportException("test", new IllegalArgumentException("foobar"));
    assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
    exception = new RemoteTransportException("test", new IllegalStateException("foobar"));
    assertThat(exception.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
}
Also used : RemoteTransportException(org.elasticsearch.transport.RemoteTransportException)

Example 7 with RemoteTransportException

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

the class ShardStateAction method sendShardAction.

private void sendShardAction(final String actionName, final ClusterState currentState, final ShardEntry shardEntry, final Listener listener) {
    ClusterStateObserver observer = new ClusterStateObserver(currentState, clusterService, null, logger, threadPool.getThreadContext());
    DiscoveryNode masterNode = currentState.nodes().getMasterNode();
    Predicate<ClusterState> changePredicate = MasterNodeChangePredicate.build(currentState);
    if (masterNode == null) {
        logger.warn("{} no master known for action [{}] for shard entry [{}]", shardEntry.shardId, actionName, shardEntry);
        waitForNewMasterAndRetry(actionName, observer, shardEntry, listener, changePredicate);
    } else {
        logger.debug("{} sending [{}] to [{}] for shard entry [{}]", shardEntry.shardId, actionName, masterNode.getId(), shardEntry);
        transportService.sendRequest(masterNode, actionName, shardEntry, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

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

            @Override
            public void handleException(TransportException exp) {
                if (isMasterChannelException(exp)) {
                    waitForNewMasterAndRetry(actionName, observer, shardEntry, listener, changePredicate);
                } else {
                    logger.warn((Supplier<?>) () -> new ParameterizedMessage("{} unexpected failure while sending request [{}] to [{}] for shard entry [{}]", shardEntry.shardId, actionName, masterNode, shardEntry), exp);
                    listener.onFailure(exp instanceof RemoteTransportException ? (Exception) (exp.getCause() instanceof Exception ? exp.getCause() : new ElasticsearchException(exp.getCause())) : exp);
                }
            }
        });
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ElasticsearchException(org.elasticsearch.ElasticsearchException) TransportResponse(org.elasticsearch.transport.TransportResponse) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) TransportException(org.elasticsearch.transport.TransportException) ElasticsearchException(org.elasticsearch.ElasticsearchException) NodeClosedException(org.elasticsearch.node.NodeClosedException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) NodeDisconnectedException(org.elasticsearch.transport.NodeDisconnectedException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) TransportException(org.elasticsearch.transport.TransportException) NotMasterException(org.elasticsearch.cluster.NotMasterException) IOException(java.io.IOException) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EmptyTransportResponseHandler(org.elasticsearch.transport.EmptyTransportResponseHandler)

Aggregations

RemoteTransportException (org.elasticsearch.transport.RemoteTransportException)7 IOException (java.io.IOException)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2 IndexInput (org.apache.lucene.store.IndexInput)2 RateLimiter (org.apache.lucene.store.RateLimiter)2 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)2 ParsingException (org.elasticsearch.common.ParsingException)2 StopWatch (org.elasticsearch.common.StopWatch)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)2 IndexShardClosedException (org.elasticsearch.index.shard.IndexShardClosedException)2 Store (org.elasticsearch.index.store.Store)2 StoreFileMetaData (org.elasticsearch.index.store.StoreFileMetaData)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1