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


Java ExceptionsHelper类代码示例

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


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

示例1: execute

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
@Override
public void execute(IngestDocument ingestDocument) {
    String value = ingestDocument.getFieldValue(field, String.class);

    DateTime dateTime = null;
    Exception lastException = null;
    for (Function<String, DateTime> dateParser : dateParsers) {
        try {
            dateTime = dateParser.apply(value);
        } catch (Exception e) {
            //try the next parser and keep track of the exceptions
            lastException = ExceptionsHelper.useOrSuppress(lastException, e);
        }
    }

    if (dateTime == null) {
        throw new IllegalArgumentException("unable to parse date [" + value + "]", lastException);
    }

    ingestDocument.setFieldValue(targetField, ISODateTimeFormat.dateTime().print(dateTime));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DateProcessor.java

示例2: assertThrows

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
public static void assertThrows(ActionFuture future, RestStatus status, String extraInfo) {
    boolean fail = false;
    extraInfo = extraInfo == null || extraInfo.isEmpty() ? "" : extraInfo + ": ";
    extraInfo += "expected a " + status + " status exception to be thrown";

    try {
        future.actionGet();
        fail = true;
    } catch (Exception e) {
        assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status));
    }
    // has to be outside catch clause to get a proper message
    if (fail) {
        throw new AssertionError(extraInfo);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ElasticsearchAssertions.java

示例3: snapshotShard

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
@Override
public void snapshotShard(IndexShard shard, SnapshotId snapshotId, IndexId indexId, IndexCommit snapshotIndexCommit, IndexShardSnapshotStatus snapshotStatus) {
    SnapshotContext snapshotContext = new SnapshotContext(shard, snapshotId, indexId, snapshotStatus);
    snapshotStatus.startTime(System.currentTimeMillis());

    try {
        snapshotContext.snapshot(snapshotIndexCommit);
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.DONE);
    } catch (Exception e) {
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.FAILURE);
        snapshotStatus.failure(ExceptionsHelper.detailedMessage(e));
        if (e instanceof IndexShardSnapshotFailedException) {
            throw (IndexShardSnapshotFailedException) e;
        } else {
            throw new IndexShardSnapshotFailedException(shard.shardId(), e);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:BlobStoreRepository.java

示例4: executeDfsPhase

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
public DfsSearchResult executeDfsPhase(ShardSearchRequest request, SearchTask task) throws IOException {
    final SearchContext context = createAndPutContext(request);
    context.incRef();
    try {
        context.setTask(task);
        contextProcessing(context);
        dfsPhase.execute(context);
        contextProcessedSuccessfully(context);
        return context.dfsResult();
    } catch (Exception e) {
        logger.trace("Dfs phase failed", e);
        processFailure(context, e);
        throw ExceptionsHelper.convertToRuntime(e);
    } finally {
        cleanContext(context);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SearchService.java

示例5: executeFetchPhase

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
private QueryFetchSearchResult executeFetchPhase(SearchContext context, SearchOperationListener operationListener,
                                                    long afterQueryTime) {
    operationListener.onPreFetchPhase(context);
    try {
        shortcutDocIdsToLoad(context);
        fetchPhase.execute(context);
        if (fetchPhaseShouldFreeContext(context)) {
            freeContext(context.id());
        } else {
            contextProcessedSuccessfully(context);
        }
    } catch (Exception e) {
        operationListener.onFailedFetchPhase(context);
        throw ExceptionsHelper.convertToRuntime(e);
    }
    operationListener.onFetchPhase(context, System.nanoTime() - afterQueryTime);
    return new QueryFetchSearchResult(context.queryResult(), context.fetchResult());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SearchService.java

示例6: executeQueryPhase

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
public ScrollQuerySearchResult executeQueryPhase(InternalScrollSearchRequest request, SearchTask task) {
    final SearchContext context = findContext(request.id());
    SearchOperationListener operationListener = context.indexShard().getSearchOperationListener();
    context.incRef();
    try {
        context.setTask(task);
        operationListener.onPreQueryPhase(context);
        long time = System.nanoTime();
        contextProcessing(context);
        processScroll(request, context);
        queryPhase.execute(context);
        contextProcessedSuccessfully(context);
        operationListener.onQueryPhase(context, System.nanoTime() - time);
        return new ScrollQuerySearchResult(context.queryResult(), context.shardTarget());
    } catch (Exception e) {
        operationListener.onFailedQueryPhase(context);
        logger.trace("Query phase failed", e);
        processFailure(context, e);
        throw ExceptionsHelper.convertToRuntime(e);
    } finally {
        cleanContext(context);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SearchService.java

示例7: validatePipeline

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
void validatePipeline(Map<DiscoveryNode, IngestInfo> ingestInfos, PutPipelineRequest request) throws Exception {
    if (ingestInfos.isEmpty()) {
        throw new IllegalStateException("Ingest info is empty");
    }

    Map<String, Object> pipelineConfig = XContentHelper.convertToMap(request.getSource(), false, request.getXContentType()).v2();
    Pipeline pipeline = factory.create(request.getId(), pipelineConfig, processorFactories);
    List<Exception> exceptions = new ArrayList<>();
    for (Processor processor : pipeline.flattenAllProcessors()) {
        for (Map.Entry<DiscoveryNode, IngestInfo> entry : ingestInfos.entrySet()) {
            if (entry.getValue().containsProcessor(processor.getType()) == false) {
                String message = "Processor type [" + processor.getType() + "] is not installed on node [" + entry.getKey() + "]";
                exceptions.add(ConfigurationUtils.newConfigurationException(processor.getType(), processor.getTag(), null, message));
            }
        }
    }
    ExceptionsHelper.rethrowAndSuppress(exceptions);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:PipelineStore.java

示例8: readProcessorConfigs

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
public static List<Processor> readProcessorConfigs(List<Map<String, Map<String, Object>>> processorConfigs,
                                                   Map<String, Processor.Factory> processorFactories) throws Exception {
    Exception exception = null;
    List<Processor> processors = new ArrayList<>();
    if (processorConfigs != null) {
        for (Map<String, Map<String, Object>> processorConfigWithKey : processorConfigs) {
            for (Map.Entry<String, Map<String, Object>> entry : processorConfigWithKey.entrySet()) {
                try {
                    processors.add(readProcessor(processorFactories, entry.getKey(), entry.getValue()));
                } catch (Exception e) {
                    exception = ExceptionsHelper.useOrSuppress(exception, e);
                }
            }
        }
    }

    if (exception != null) {
        throw exception;
    }

    return processors;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:ConfigurationUtils.java

示例9: shardOperation

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
@Override
protected FieldStatsShardResponse shardOperation(FieldStatsShardRequest request) {
    ShardId shardId = request.shardId();
    Map<String, FieldStats> fieldStats = new HashMap<>();
    IndexService indexServices = indicesService.indexServiceSafe(shardId.getIndex());
    MapperService mapperService = indexServices.mapperService();
    IndexShard shard = indexServices.shardSafe(shardId.id());
    try (Engine.Searcher searcher = shard.acquireSearcher("fieldstats")) {
        for (String field : request.getFields()) {
            MappedFieldType fieldType = mapperService.fullName(field);
            if (fieldType != null) {
                IndexReader reader = searcher.reader();
                Terms terms = MultiFields.getTerms(reader, field);
                if (terms != null) {
                    fieldStats.put(field, fieldType.stats(terms, reader.maxDoc()));
                }
            } else {
                throw new IllegalArgumentException("field [" + field + "] doesn't exist");
            }
        }
    } catch (IOException e) {
        throw ExceptionsHelper.convertToElastic(e);
    }
    return new FieldStatsShardResponse(shardId, fieldStats);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:TransportFieldStatsTransportAction.java

示例10: validateUpdate

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
/**
 * Validates the given settings by running it through all update listeners without applying it. This
 * method will not change any settings but will fail if any of the settings can't be applied.
 */
public synchronized Settings validateUpdate(Settings settings) {
    final Settings current = Settings.builder().put(this.settings).put(settings).build();
    final Settings previous = Settings.builder().put(this.settings).put(this.lastSettingsApplied).build();
    List<RuntimeException> exceptions = new ArrayList<>();
    for (SettingUpdater<?> settingUpdater : settingUpdaters) {
        try {
            // ensure running this through the updater / dynamic validator
            // don't check if the value has changed we wanna test this anyways
            settingUpdater.getValue(current, previous);
        } catch (RuntimeException ex) {
            exceptions.add(ex);
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex);
        }
    }
    // here we are exhaustive and record all settings that failed.
    ExceptionsHelper.rethrowAndSuppress(exceptions);
    return current;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:AbstractScopedSettings.java

示例11: toString

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
/**
 * Return a {@link String} that is the json representation of the provided {@link ToXContent}.
 * Wraps the output into an anonymous object.
 */
public static String toString(ToXContent toXContent) {
    try {
        XContentBuilder builder = JsonXContent.contentBuilder();
        if (toXContent.isFragment()) {
            builder.startObject();
        }
        toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
        if (toXContent.isFragment()) {
            builder.endObject();
        }
        return builder.string();
    } catch (IOException e) {
        return "Error building toString out of XContent: " + ExceptionsHelper.stackTrace(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:Strings.java

示例12: cleanupAfterError

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
private void cleanupAfterError(Exception exception) {
    if(snapshotCreated) {
        try {
            repositoriesService.repository(snapshot.snapshot().getRepository())
                               .finalizeSnapshot(snapshot.snapshot().getSnapshotId(),
                                                 snapshot.indices(),
                                                 snapshot.startTime(),
                                                 ExceptionsHelper.detailedMessage(exception),
                                                 0,
                                                 Collections.emptyList(),
                                                 snapshot.getRepositoryStateId());
        } catch (Exception inner) {
            inner.addSuppressed(exception);
            logger.warn((Supplier<?>) () -> new ParameterizedMessage("[{}] failed to close snapshot in repository", snapshot.snapshot()), inner);
        }
    }
    userCreateSnapshotListener.onFailure(e);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SnapshotsService.java

示例13: executeNextPhase

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
@Override
public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPhase) {
    /* This is the main search phase transition where we move to the next phase. At this point we check if there is
     * at least one successful operation left and if so we move to the next phase. If not we immediately fail the
     * search phase as "all shards failed"*/
    if (successfulOps.get() == 0) { // we have 0 successful results that means we shortcut stuff and return a failure
        if (logger.isDebugEnabled()) {
            final ShardOperationFailedException[] shardSearchFailures = ExceptionsHelper.groupBy(buildShardFailures());
            Throwable cause = ElasticsearchException.guessRootCauses(shardSearchFailures[0].getCause())[0];
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("All shards failed for phase: [{}]", getName()),
                cause);
        }
        onPhaseFailure(currentPhase, "all shards failed", null);
    } else {
        if (logger.isTraceEnabled()) {
            final String resultsFrom = results.getSuccessfulResults()
                .map(r -> r.shardTarget().toString()).collect(Collectors.joining(","));
            logger.trace("[{}] Moving to next phase: [{}], based on results from: {} (cluster state version: {})",
                currentPhase.getName(), nextPhase.getName(), resultsFrom, clusterStateVersion);
        }
        executePhase(nextPhase);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:AbstractSearchAsyncAction.java

示例14: toXContent

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.startArray(Fields.RESPONSES);
    for (Item item : items) {
        builder.startObject();
        if (item.isFailure()) {
            ElasticsearchException.generateFailureXContent(builder, params, item.getFailure(), true);
            builder.field(Fields.STATUS, ExceptionsHelper.status(item.getFailure()).getStatus());
        } else {
            item.getResponse().innerToXContent(builder, params);
            builder.field(Fields.STATUS, item.getResponse().status().getStatus());
        }
        builder.endObject();
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MultiSearchResponse.java

示例15: onResponse

import org.elasticsearch.ExceptionsHelper; //导入依赖的package包/类
/**
 * Notifies every given listener with the response passed to {@link #onResponse(Object)}. If a listener itself throws an exception
 * the exception is forwarded to {@link #onFailure(Exception)}. If in turn {@link #onFailure(Exception)} fails all remaining
 * listeners will be processed and the caught exception will be re-thrown.
 */
static <Response> void onResponse(Iterable<ActionListener<Response>> listeners, Response response) {
    List<Exception> exceptionList = new ArrayList<>();
    for (ActionListener<Response> listener : listeners) {
        try {
            listener.onResponse(response);
        } catch (Exception ex) {
            try {
                listener.onFailure(ex);
            } catch (Exception ex1) {
                exceptionList.add(ex1);
            }
        }
    }
    ExceptionsHelper.maybeThrowRuntimeAndSuppress(exceptionList);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ActionListener.java


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