Search in sources :

Example 1 with AnalyzerConfig

use of com.epam.ta.reportportal.ws.model.project.AnalyzerConfig in project service-api by reportportal.

the class LogIndexerService method indexLaunchLogs.

@Override
@Transactional(readOnly = true)
public // TODO Probably we should implement AsyncLogIndexer and use this service as sync delegate with transaction
CompletableFuture<Long> indexLaunchLogs(Long projectId, Long launchId, AnalyzerConfig analyzerConfig) {
    return CompletableFuture.supplyAsync(() -> {
        try {
            indexerStatusCache.indexingStarted(projectId);
            Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, launchId));
            Optional<IndexLaunch> indexLaunch = launchPreparerService.prepare(launch, testItemRepository.findTestItemsByLaunchId(launch.getId()), analyzerConfig);
            return indexLaunch.map(it -> {
                LOGGER.info("Start indexing for {} launches", 1);
                Long indexed = indexerServiceClient.index(Lists.newArrayList(it));
                LOGGER.info("Indexed {} logs", indexed);
                return indexed;
            }).orElse(0L);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            throw new ReportPortalException(e.getMessage());
        } finally {
            indexerStatusCache.indexingFinished(projectId);
        }
    });
}
Also used : Async(org.springframework.scheduling.annotation.Async) IndexerStatusCache(com.epam.ta.reportportal.core.analyzer.auto.indexer.IndexerStatusCache) TestItem(com.epam.ta.reportportal.entity.item.TestItem) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) CompletableFuture(java.util.concurrent.CompletableFuture) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) Lists(com.google.common.collect.Lists) BatchLogIndexer(com.epam.ta.reportportal.core.analyzer.auto.indexer.BatchLogIndexer) Service(org.springframework.stereotype.Service) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TaskExecutor(org.springframework.core.task.TaskExecutor) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) LaunchPreparerService(com.epam.ta.reportportal.core.analyzer.auto.impl.preparer.LaunchPreparerService) Logger(org.slf4j.Logger) Launch(com.epam.ta.reportportal.entity.launch.Launch) LogIndexer(com.epam.ta.reportportal.core.analyzer.auto.LogIndexer) Collection(java.util.Collection) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) Collectors(java.util.stream.Collectors) List(java.util.List) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) CollectionUtils(org.springframework.util.CollectionUtils) IndexerServiceClient(com.epam.ta.reportportal.core.analyzer.auto.client.IndexerServiceClient) Optional(java.util.Optional) Transactional(org.springframework.transaction.annotation.Transactional) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) Launch(com.epam.ta.reportportal.entity.launch.Launch) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AnalyzerConfig

use of com.epam.ta.reportportal.ws.model.project.AnalyzerConfig in project service-api by reportportal.

the class SearchLogServiceImpl method composeRequest.

private Optional<SearchRq> composeRequest(SearchLogRq request, Project project, TestItem item, Launch launch) {
    SearchLogsMode searchMode = SearchLogsMode.fromString(request.getSearchMode()).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, request.getSearchMode()));
    SearchRq searchRq = new SearchRq();
    searchRq.setFilteredLaunchIds(searchCollectorFactory.getCollector(searchMode).collect(request.getFilterId(), launch));
    // TODO fix query - select messages from `Nested Step` descendants too
    List<String> logMessages = logRepository.findMessagesByLaunchIdAndItemIdAndPathAndLevelGte(launch.getId(), item.getItemId(), item.getPath(), LogLevel.ERROR_INT);
    if (CollectionUtils.isEmpty(logMessages)) {
        return Optional.empty();
    }
    searchRq.setLogMessages(logMessages);
    final AnalyzerConfig analyzerConfig = AnalyzerUtils.getAnalyzerConfig(project);
    searchRq.setAnalyzerConfig(analyzerConfig);
    searchRq.setLogLines(analyzerConfig.getNumberOfLogLines());
    searchRq.setItemId(item.getItemId());
    searchRq.setLaunchId(launch.getId());
    searchRq.setLaunchName(launch.getName());
    searchRq.setProjectId(project.getId());
    return Optional.of(searchRq);
}
Also used : SearchLogsMode(com.epam.ta.reportportal.core.analyzer.auto.strategy.search.SearchLogsMode) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) SearchRq(com.epam.ta.reportportal.ws.model.analyzer.SearchRq)

Example 3 with AnalyzerConfig

use of com.epam.ta.reportportal.ws.model.project.AnalyzerConfig in project service-api by reportportal.

the class LaunchAutoAnalysisStrategy method analyze.

public void analyze(AnalyzeLaunchRQ analyzeRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    expect(analyzerServiceAsync.hasAnalyzers(), Predicate.isEqual(true)).verify(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "There are no analyzer services are deployed.");
    AnalyzeMode analyzeMode = AnalyzeMode.fromString(analyzeRQ.getAnalyzerHistoryMode()).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, analyzeRQ.getAnalyzerHistoryMode()));
    Launch launch = launchRepository.findById(analyzeRQ.getLaunchId()).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, analyzeRQ.getLaunchId()));
    validateLaunch(launch, projectDetails);
    Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectDetails.getProjectId()));
    AnalyzerConfig analyzerConfig = getAnalyzerConfig(project);
    analyzerConfig.setAnalyzerMode(analyzeMode.getValue());
    List<Long> itemIds = collectItemsByModes(launch.getId(), analyzeRQ.getAnalyzeItemsModes(), project, user);
    eventPublisher.publishEvent(new AnalysisEvent(launch, itemIds, analyzerConfig));
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) AnalyzerUtils.getAnalyzerConfig(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils.getAnalyzerConfig) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) AnalysisEvent(com.epam.ta.reportportal.core.events.AnalysisEvent) AnalyzeMode(com.epam.ta.reportportal.entity.AnalyzeMode) Launch(com.epam.ta.reportportal.entity.launch.Launch)

Example 4 with AnalyzerConfig

use of com.epam.ta.reportportal.ws.model.project.AnalyzerConfig in project service-api by reportportal.

the class AnalyzerUtils method getAnalyzerConfig.

public static AnalyzerConfig getAnalyzerConfig(Project project) {
    Map<String, String> configParameters = ProjectUtils.getConfigParameters(project.getProjectAttributes());
    AnalyzerConfig analyzerConfig = new AnalyzerConfig();
    analyzerConfig.setIsAutoAnalyzerEnabled(BooleanUtils.toBoolean(configParameters.get(AUTO_ANALYZER_ENABLED.getAttribute())));
    analyzerConfig.setMinShouldMatch(Integer.valueOf(ofNullable(configParameters.get(MIN_SHOULD_MATCH.getAttribute())).orElse(MIN_SHOULD_MATCH.getDefaultValue())));
    analyzerConfig.setSearchLogsMinShouldMatch(Integer.valueOf(ofNullable(configParameters.get(SEARCH_LOGS_MIN_SHOULD_MATCH.getAttribute())).orElse(SEARCH_LOGS_MIN_SHOULD_MATCH.getDefaultValue())));
    analyzerConfig.setNumberOfLogLines(Integer.valueOf(ofNullable(configParameters.get(NUMBER_OF_LOG_LINES.getAttribute())).orElse(NUMBER_OF_LOG_LINES.getDefaultValue())));
    analyzerConfig.setIndexingRunning(BooleanUtils.toBoolean(configParameters.get(INDEXING_RUNNING.getAttribute())));
    analyzerConfig.setAnalyzerMode(configParameters.get(AUTO_ANALYZER_MODE.getAttribute()));
    analyzerConfig.setAllMessagesShouldMatch(BooleanUtils.toBoolean(configParameters.get(ALL_MESSAGES_SHOULD_MATCH.getAttribute())));
    return analyzerConfig;
}
Also used : AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig)

Example 5 with AnalyzerConfig

use of com.epam.ta.reportportal.ws.model.project.AnalyzerConfig in project service-api by reportportal.

the class LogIndexerServiceTest method testIndexWithZeroCount.

@Test
void testIndexWithZeroCount() {
    Long launchId = 2L;
    final IndexLaunch indexLaunch = new IndexLaunch();
    indexLaunch.setLaunchId(launchId);
    when(batchLogIndexer.index(eq(1L), any(AnalyzerConfig.class))).thenReturn(0L);
    Long result = logIndexerService.index(1L, analyzerConfig()).join();
    assertThat(result, org.hamcrest.Matchers.equalTo(0L));
    verify(indexerStatusCache, times(1)).indexingFinished(1L);
}
Also used : IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) Test(org.junit.jupiter.api.Test)

Aggregations

AnalyzerConfig (com.epam.ta.reportportal.ws.model.project.AnalyzerConfig)18 IndexLaunch (com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch)6 Test (org.junit.jupiter.api.Test)6 Launch (com.epam.ta.reportportal.entity.launch.Launch)5 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 Project (com.epam.ta.reportportal.entity.project.Project)4 Transactional (org.springframework.transaction.annotation.Transactional)4 LaunchPreparerService (com.epam.ta.reportportal.core.analyzer.auto.impl.preparer.LaunchPreparerService)3 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)3 TestItem (com.epam.ta.reportportal.entity.item.TestItem)3 IndexTestItem (com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem)3 Collectors (java.util.stream.Collectors)3 Async (org.springframework.scheduling.annotation.Async)3 LogIndexer (com.epam.ta.reportportal.core.analyzer.auto.LogIndexer)2 IndexerServiceClient (com.epam.ta.reportportal.core.analyzer.auto.client.IndexerServiceClient)2 GenerateClustersConfig (com.epam.ta.reportportal.core.analyzer.auto.client.model.cluster.GenerateClustersConfig)2 AnalyzerUtils.getAnalyzerConfig (com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils.getAnalyzerConfig)2 BatchLogIndexer (com.epam.ta.reportportal.core.analyzer.auto.indexer.BatchLogIndexer)2 IndexerStatusCache (com.epam.ta.reportportal.core.analyzer.auto.indexer.IndexerStatusCache)2 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)2