Java Code Examples for org.elasticsearch.ExceptionsHelper#unwrapCause()
The following examples show how to use
org.elasticsearch.ExceptionsHelper#unwrapCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportClientNodesService.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void onFailure(Throwable e) { if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) { int i = ++this.i; if (i >= nodes.size()) { listener.onFailure(new NoNodeAvailableException("None of the configured nodes were available: " + nodes, e)); } else { try { callback.doWithNode(nodes.get((index + i) % nodes.size()), this); } catch(final Throwable t) { // this exception can't come from the TransportService as it doesn't throw exceptions at all listener.onFailure(t); } } } else { listener.onFailure(e); } }
Example 2
Source File: TransportClient.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override public void onFailure(Throwable e) { if (ExceptionsHelper.unwrapCause(e) instanceof ConnectTransportException) { int n = ++this.n; if (n >= nodes.size()) { listener.onFailure(new NoNodeAvailableException("none of the configured nodes were available: " + nodes, e)); } else { try { logger.warn("retrying on anoher node (n={}, nodes={})", n, nodes.size()); callback.doWithNode(nodes.get((index + n) % nodes.size()), this); } catch (final Throwable t) { listener.onFailure(t); } } } else { listener.onFailure(e); } }
Example 3
Source File: ReplicationOperation.java From crate with Apache License 2.0 | 6 votes |
private void onNoLongerPrimary(Exception failure) { final Throwable cause = ExceptionsHelper.unwrapCause(failure); final boolean nodeIsClosing = cause instanceof NodeClosedException || (cause instanceof TransportException && "TransportService is closed stopped can't send request".equals(cause.getMessage())); final String message; if (nodeIsClosing) { message = String.format(Locale.ROOT, "node with primary [%s] is shutting down while failing replica shard", primary.routingEntry()); // We prefer not to fail the primary to avoid unnecessary warning log // when the node with the primary shard is gracefully shutting down. } else { if (Assertions.ENABLED) { if (failure instanceof ShardStateAction.NoLongerPrimaryShardException == false) { throw new AssertionError("unexpected failure", failure); } } // we are no longer the primary, fail ourselves and start over message = String.format(Locale.ROOT, "primary shard [%s] was demoted while failing replica shard", primary.routingEntry()); primary.failShard(message, failure); } finishAsFailed(new RetryOnPrimaryException(primary.routingEntry().shardId(), message, failure)); }
Example 4
Source File: StopDetectorTransportAction.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override protected void doExecute(Task task, ActionRequest actionRequest, ActionListener<StopDetectorResponse> listener) { StopDetectorRequest request = StopDetectorRequest.fromActionRequest(actionRequest); String adID = request.getAdID(); try { DiscoveryNode[] dataNodes = nodeFilter.getEligibleDataNodes(); DeleteModelRequest modelDeleteRequest = new DeleteModelRequest(adID, dataNodes); client.execute(DeleteModelAction.INSTANCE, modelDeleteRequest, ActionListener.wrap(response -> { if (response.hasFailures()) { LOG.warn("Cannot delete all models of detector {}", adID); for (FailedNodeException failedNodeException : response.failures()) { LOG.warn("Deleting models of node has exception", failedNodeException); } // if customers are using an updated detector and we haven't deleted old // checkpoints, customer would have trouble listener.onResponse(new StopDetectorResponse(false)); } else { LOG.info("models of detector {} get deleted", adID); listener.onResponse(new StopDetectorResponse(true)); } }, exception -> { LOG.error(new ParameterizedMessage("Deletion of detector [{}] has exception.", adID), exception); listener.onResponse(new StopDetectorResponse(false)); })); } catch (Exception e) { LOG.error("Fail to stop detector " + adID, e); Throwable cause = ExceptionsHelper.unwrapCause(e); listener.onFailure(new InternalFailure(adID, cause)); } }
Example 5
Source File: AnomalyResultTransportAction.java From anomaly-detection with Apache License 2.0 | 5 votes |
void handleExecuteException(Exception ex, ActionListener<AnomalyResultResponse> listener, String adID) { if (ex instanceof ClientException) { listener.onFailure(ex); } else if (ex instanceof AnomalyDetectionException) { listener.onFailure(new InternalFailure((AnomalyDetectionException) ex)); } else { Throwable cause = ExceptionsHelper.unwrapCause(ex); listener.onFailure(new InternalFailure(adID, cause)); } }
Example 6
Source File: AnomalyResultTransportAction.java From anomaly-detection with Apache License 2.0 | 5 votes |
private void handlePredictionFailure(Exception e, String adID, String nodeID, AtomicReference<AnomalyDetectionException> failure) { LOG.error(new ParameterizedMessage("Received an error from node {} while fetching anomaly grade for {}", nodeID, adID), e); if (e == null) { return; } Throwable cause = ExceptionsHelper.unwrapCause(e); if (hasConnectionIssue(cause)) { handleConnectionException(nodeID); } else { findException(cause, adID, failure); } }
Example 7
Source File: ShardSearchFailure.java From Elasticsearch with Apache License 2.0 | 5 votes |
public ShardSearchFailure(Throwable t, @Nullable SearchShardTarget shardTarget) { Throwable actual = ExceptionsHelper.unwrapCause(t); if (actual != null && actual instanceof SearchException) { this.shardTarget = ((SearchException) actual).shard(); } else if (shardTarget != null) { this.shardTarget = shardTarget; } status = ExceptionsHelper.status(actual); this.reason = ExceptionsHelper.detailedMessage(t); this.cause = actual; }
Example 8
Source File: TransportReplicationAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected boolean isConflictException(Throwable e) { Throwable cause = ExceptionsHelper.unwrapCause(e); // on version conflict or document missing, it means // that a new change has crept into the replica, and it's fine if (cause instanceof VersionConflictEngineException) { return true; } if (cause instanceof DocumentAlreadyExistsException) { return true; } return false; }
Example 9
Source File: TransportActions.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static boolean isShardNotAvailableException(Throwable t) { Throwable actual = ExceptionsHelper.unwrapCause(t); if (actual instanceof ShardNotFoundException || actual instanceof IndexNotFoundException || actual instanceof IllegalIndexShardStateException || actual instanceof NoShardAvailableActionException || actual instanceof UnavailableShardsException || actual instanceof AlreadyClosedException) { return true; } return false; }
Example 10
Source File: Retry.java From Elasticsearch with Apache License 2.0 | 5 votes |
private boolean canRetry(BulkResponse bulkItemResponses) { if (!backoff.hasNext()) { return false; } for (BulkItemResponse bulkItemResponse : bulkItemResponses) { if (bulkItemResponse.isFailed()) { Throwable cause = bulkItemResponse.getFailure().getCause(); Throwable rootCause = ExceptionsHelper.unwrapCause(cause); if (!rootCause.getClass().equals(retryOnThrowable)) { return false; } } } return true; }
Example 11
Source File: TransportReplicaShardIngestAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
boolean ignoreReplicaException(Throwable e) { if (TransportActions.isShardNotAvailableException(e)) { return true; } Throwable cause = ExceptionsHelper.unwrapCause(e); return cause instanceof VersionConflictEngineException; }
Example 12
Source File: TransportActions.java From crate with Apache License 2.0 | 5 votes |
public static boolean isShardNotAvailableException(final Throwable e) { final Throwable actual = ExceptionsHelper.unwrapCause(e); return (actual instanceof ShardNotFoundException || actual instanceof IndexNotFoundException || actual instanceof IllegalIndexShardStateException || actual instanceof NoShardAvailableActionException || actual instanceof UnavailableShardsException || actual instanceof AlreadyClosedException); }
Example 13
Source File: KerberizedClient.java From elasticsearch-shield-kerberos-realm with Apache License 2.0 | 4 votes |
@Override public void onFailure(final Throwable e) { final Throwable cause = ExceptionsHelper.unwrapCause(e); if (cause instanceof ElasticsearchSecurityException) { final ElasticsearchSecurityException securityException = (ElasticsearchSecurityException) cause; if (++count > 100) { inner.onFailure(new ElasticsearchException("kerberos loop", cause)); return; } else { String negotiateHeaderValue = null; final List<String> headers = securityException.getHeader(KrbConstants.WWW_AUTHENTICATE); if (headers == null || headers.isEmpty()) { inner.onFailure(new ElasticsearchException("no auth header", cause)); return; } else if (headers.size() == 1) { negotiateHeaderValue = headers.get(0).trim(); } else { for (final String header : headers) { if (header != null && header.toLowerCase(Locale.ENGLISH).startsWith(KrbConstants.NEGOTIATE)) { negotiateHeaderValue = header.trim(); break; } } } if (negotiateHeaderValue == null) { inner.onFailure(new ElasticsearchException("no negotiate auth header")); return; } byte[] challenge = null; try { if (negotiateHeaderValue.length() > (KrbConstants.NEGOTIATE.length() + 1)) { challenge = DatatypeConverter .parseBase64Binary(negotiateHeaderValue.substring(KrbConstants.NEGOTIATE.length() + 2)); } byte[] data = null; if (challenge == null) { logger.debug("challenge is null"); data = context.initSecContext(new byte[0], 0, 0); request.putHeader("Authorization", "Negotiate " + DatatypeConverter.printBase64Binary(data)); } else { logger.debug("challenge is not null"); data = context.initSecContext(challenge, 0, challenge.length); request.putHeader("Authorization", "Negotiate " + DatatypeConverter.printBase64Binary(data)); addAdditionalHeader(request, count, data); } KerberizedClient.this.doExecute(action, request, this); } catch (final Exception e1) { inner.onFailure(e); return; } } } else { inner.onFailure(e); return; } }