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));
}
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);
}
}
});
}
}
Aggregations