From dev-return-40199-archive-asf-public=cust-asf.ponee.io@ignite.apache.org Mon Oct 8 10:43:36 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 780D118067A for ; Mon, 8 Oct 2018 10:43:35 +0200 (CEST) Received: (qmail 94851 invoked by uid 500); 8 Oct 2018 08:43:33 -0000 Mailing-List: contact dev-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list dev@ignite.apache.org Received: (qmail 93866 invoked by uid 99); 8 Oct 2018 08:43:32 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Oct 2018 08:43:32 +0000 From: GitBox To: dev@ignite.apache.org Subject: [GitHub] SomeFire commented on a change in pull request #25: IGNITE-9645 [TC Bot] Add comparison of failed tests lists in two date intervals Message-ID: <153898821176.31094.1512643134102720190.gitbox@gitbox.apache.org> Date: Mon, 08 Oct 2018 08:43:31 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit SomeFire commented on a change in pull request #25: IGNITE-9645 [TC Bot] Add comparison of failed tests lists in two date intervals URL: https://github.com/apache/ignite-teamcity-bot/pull/25#discussion_r223274311 ########## File path: ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/hist/BuildsHistory.java ########## @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.ci.web.model.hist; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.servlet.ServletContext; +import org.apache.ignite.ci.IAnalyticsEnabledTeamcity; +import org.apache.ignite.ci.ITcHelper; +import org.apache.ignite.ci.tcbot.chain.BuildChainProcessor; +import org.apache.ignite.ci.tcmodel.result.Build; +import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrence; +import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrences; +import org.apache.ignite.ci.user.ICredentialsProv; +import org.apache.ignite.ci.web.CtxListener; +import org.apache.ignite.ci.web.model.current.BuildStatisticsSummary; +import org.apache.ignite.ci.web.rest.exception.ServiceUnauthorizedException; +import org.apache.ignite.ci.web.rest.parms.FullQueryParams; + +import static com.google.common.base.Strings.isNullOrEmpty; +import static org.apache.ignite.ci.web.rest.build.GetBuildTestFailures.BUILDS_STATISTICS_SUMMARY_CACHE_NAME; + +/** + * Builds History: includes statistic for every build and merged failed unmuted tests in specified time interval. + */ + +public class BuildsHistory { + /** */ + private String srvId; + + /** */ + private String projectId; + + /** */ + private String buildTypeId; + + /** */ + private String branchName; + + /** */ + private Date sinceDateFilter; + + /** */ + private Date untilDateFilter; + + /** */ + private ObjectMapper objectMapper = new ObjectMapper(); + + /** */ + private Map> mergedTestsBySuites = new HashMap<>(); + + /** */ + public List buildsStatistics = new ArrayList<>(); + + /** */ + public String mergedTestsJson; + + /** */ + public void initialize(ICredentialsProv prov, ServletContext context) { + if (!prov.hasAccess(srvId)) + throw ServiceUnauthorizedException.noCreds(srvId); + + ITcHelper tcHelper = CtxListener.getTcHelper(context); + + IAnalyticsEnabledTeamcity teamcity = tcHelper.server(srvId, prov); + + int[] finishedBuildsIds = teamcity.getBuildNumbersFromHistory(buildTypeId, branchName, + sinceDateFilter, untilDateFilter); + + initBuildsStatistics(teamcity, prov, context, finishedBuildsIds); + + initBuildsMergedFailedTests(teamcity, finishedBuildsIds); + } + + /** */ + private void initBuildsStatistics(IAnalyticsEnabledTeamcity teamcity, ICredentialsProv prov, + ServletContext context, int[] buildIds) { + for (int buildId : buildIds) { + FullQueryParams buildParams = new FullQueryParams(); + + buildParams.setBuildId(buildId); + buildParams.setBranch(branchName); + buildParams.setServerId(srvId); + + BuildStatisticsSummary buildsStatistic = CtxListener.getBackgroundUpdater(context).get( + BUILDS_STATISTICS_SUMMARY_CACHE_NAME, prov, buildParams, + (k) -> { + BuildStatisticsSummary stat = new BuildStatisticsSummary(buildId); + + stat.initialize(teamcity); + + return stat; + }, false); + + if (buildsStatistic != null && !buildsStatistic.isFakeStub) + buildsStatistics.add(buildsStatistic); + } + } + + /** */ + private void initBuildsMergedFailedTests(IAnalyticsEnabledTeamcity teamcity, int[] buildIds) { + for (int buildId : buildIds) { + Build build = teamcity.getBuild(teamcity.getBuildHrefById(buildId)); + + TestOccurrences testOccurrences = teamcity.getFailedUnmutedTests(build.testOccurrences.href, + build.testOccurrences.failed, BuildChainProcessor.normalizeBranch(build.branchName)); + + for (TestOccurrence testOccurrence : testOccurrences.getTests()) { + String testName = testOccurrence.getName(); + + build = teamcity.getBuild(teamcity.getBuildHrefById(testOccurrence.getBuildId())); + + Set tests = mergedTestsBySuites.computeIfAbsent(build.buildTypeId, + k -> new HashSet<>()); + + if (!tests.add(testName)) + continue; + + FullQueryParams key = new FullQueryParams(); + + key.setServerId(srvId); + + key.setProjectId(projectId); + + key.setTestName(testOccurrence.getName()); + + key.setSuiteId(build.buildTypeId); + + teamcity.getTestRef(key); + } + } + + try { + mergedTestsJson = objectMapper.writeValueAsString(mergedTestsBySuites); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + /** */ + public BuildsHistory(Builder builder) { + this.srvId = builder.srvId; + Review comment: Redundant empty lines in the method, because all lines here are the same semantic units. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services