当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionsHelper.unwrapCause方法代码示例

本文整理汇总了Java中org.elasticsearch.ExceptionsHelper.unwrapCause方法的典型用法代码示例。如果您正苦于以下问题:Java ExceptionsHelper.unwrapCause方法的具体用法?Java ExceptionsHelper.unwrapCause怎么用?Java ExceptionsHelper.unwrapCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.ExceptionsHelper的用法示例。


在下文中一共展示了ExceptionsHelper.unwrapCause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBadPercents

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testBadPercents() throws Exception {
    double[] badPercents = {-1.0, 110.0};

    try {
        client().prepareSearch("idx")
                .addAggregation(terms("terms").field("tag").subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                .addAggregation(percentilesBucket("percentiles_bucket", "terms>sum")
                        .percents(badPercents)).execute().actionGet();

        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:PercentilesBucketIT.java

示例2: testIndexIntoDefaultMapping

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testIndexIntoDefaultMapping() throws Throwable {
    // 1. test implicit index creation
    ExecutionException e = expectThrows(ExecutionException.class, () -> {
        client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "1").setSource("{}", XContentType.JSON).execute().get();
    });
    Throwable throwable = ExceptionsHelper.unwrapCause(e.getCause());
    if (throwable instanceof IllegalArgumentException) {
        assertEquals("It is forbidden to index into the default mapping [_default_]", throwable.getMessage());
    } else {
        throw e;
    }

    // 2. already existing index
    IndexService indexService = createIndex("index2");
    e = expectThrows(ExecutionException.class, () -> {
        client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "2").setSource().execute().get();
    });
    throwable = ExceptionsHelper.unwrapCause(e.getCause());
    if (throwable instanceof IllegalArgumentException) {
        assertEquals("It is forbidden to index into the default mapping [_default_]", throwable.getMessage());
    } else {
        throw e;
    }
    assertFalse(indexService.mapperService().hasMapping(MapperService.DEFAULT_MAPPING));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:MapperServiceTests.java

示例3: onFailure

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:TransportClientNodesService.java

示例4: ShardSearchFailure

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public ShardSearchFailure(Exception e, @Nullable SearchShardTarget shardTarget) {
    final Throwable actual = ExceptionsHelper.unwrapCause(e);
    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(e);
    this.cause = actual;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:ShardSearchFailure.java

示例5: toXContent

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    Throwable ex = ExceptionsHelper.unwrapCause(this);
    if (ex != this) {
        generateThrowableXContent(builder, params, this);
    } else {
        // We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause
        // (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to
        // be rendered twice (one in the "cause" field, one in "failed_shards")
        innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), getMetadata(), super.getCause());
    }
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SearchPhaseExecutionException.java

示例6: isShardNotAvailableException

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TransportActions.java

示例7: canRetry

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
private boolean canRetry(BulkResponse bulkItemResponses) {
    if (!backoff.hasNext()) {
        return false;
    }
    for (BulkItemResponse bulkItemResponse : bulkItemResponses) {
        if (bulkItemResponse.isFailed()) {
            final Throwable cause = bulkItemResponse.getFailure().getCause();
            final Throwable rootCause = ExceptionsHelper.unwrapCause(cause);
            if (!rootCause.getClass().equals(retryOnThrowable)) {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:Retry.java

示例8: testSingleValueAggDerivative_invalidPath

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testSingleValueAggDerivative_invalidPath() throws Exception {
    try {
        client().prepareSearch("idx")
                .addAggregation(
                        histogram("histo")
                                .field(SINGLE_VALUED_FIELD_NAME)
                                .interval(interval)
                                .subAggregation(
                                        filters("filters", QueryBuilders.termQuery("tag", "foo")).subAggregation(
                                                sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                                .subAggregation(derivative("deriv", "filters>get>sum"))).execute().actionGet();
        fail("Expected an Exception but didn't get one");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:DerivativeIT.java

示例9: testBadPercents_asSubAgg

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testBadPercents_asSubAgg() throws Exception {
    double[] badPercents = {-1.0, 110.0};

    try {
        client()
            .prepareSearch("idx")
            .addAggregation(
                    terms("terms")
                            .field("tag")
                            .order(Terms.Order.term(true))
                            .subAggregation(
                                    histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                                            .extendedBounds(minRandomValue, maxRandomValue))
                            .subAggregation(percentilesBucket("percentiles_bucket", "histo>_count")
                                    .percents(badPercents))).execute().actionGet();

        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:PercentilesBucketIT.java

示例10: testBadSigmaAsSubAgg

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
public void testBadSigmaAsSubAgg() throws Exception {
    try {
        SearchResponse response = client()
                .prepareSearch("idx")
                .addAggregation(
                        terms("terms")
                                .field("tag")
                                .order(Order.term(true))
                                .subAggregation(
                                        histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                                                .extendedBounds(minRandomValue, maxRandomValue)
                                                .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME)))
                                .subAggregation(extendedStatsBucket("extended_stats_bucket", "histo>sum")
                                        .sigma(-1.0))).execute().actionGet();
        fail("Illegal sigma was provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:ExtendedStatsBucketIT.java

示例11: ShardSearchFailure

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:ShardSearchFailure.java

示例12: isConflictException

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:TransportReplicationAction.java

示例13: isShardNotAvailableException

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:TransportActions.java

示例14: canRetry

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:Retry.java

示例15: isConflictException

import org.elasticsearch.ExceptionsHelper; //导入方法依赖的package包/类
private static boolean isConflictException(final Exception e) {
    return ExceptionsHelper.unwrapCause(e) instanceof VersionConflictEngineException;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:TransportShardBulkAction.java


注:本文中的org.elasticsearch.ExceptionsHelper.unwrapCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。