Search in sources :

Example 1 with BuildProblem

use of jetbrains.buildServer.serverSide.problems.BuildProblem in project teamcity-rest by JetBrains.

the class ProblemFinder method getProblemsByBuilds.

@NotNull
private Set<ProblemWrapper> getProblemsByBuilds(@NotNull final String buildLocator) {
    LinkedHashSet<ProblemWrapper> result = new LinkedHashSet<>();
    List<BuildPromotion> builds = myBuildPromotionFinder.getItems(buildLocator).myEntries;
    for (BuildPromotion build : builds) {
        result.addAll(CollectionsUtil.convertCollection(ProblemOccurrenceFinder.getProblemOccurrences(build), new Converter<ProblemWrapper, BuildProblem>() {

            @Override
            public ProblemWrapper createFrom(@NotNull final BuildProblem buildProblem) {
                return new ProblemWrapper(buildProblem.getId(), buildProblem.getBuildProblemData(), myServiceLocator);
            }
        }));
    }
    return result;
}
Also used : BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) Converter(jetbrains.buildServer.util.Converter) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BuildProblem

use of jetbrains.buildServer.serverSide.problems.BuildProblem in project teamcity-rest by JetBrains.

the class ProblemOccurrenceFinder method findSingleItem.

@Override
public BuildProblem findSingleItem(@NotNull final Locator locator) {
    // todo: searching occurrence by id does not work: review!!!
    // dimension-specific item search
    String buildDimension = locator.getSingleDimensionValue(BUILD);
    if (buildDimension != null) {
        List<BuildPromotion> builds = myBuildFinder.getBuilds(null, buildDimension).myEntries;
        if (builds.size() != 1) {
            return null;
        }
        final BuildPromotion build = builds.get(0);
        String problemDimension = locator.getSingleDimensionValue(PROBLEM);
        if (problemDimension != null) {
            Long problemId = ProblemFinder.getProblemIdByLocator(new Locator(problemDimension));
            if (problemId == null) {
                problemId = myProblemFinder.getItem(problemDimension).getId();
            }
            final BuildProblem item = findProblem(build, problemId);
            if (item != null) {
                return item;
            }
            // message might be incorrect: uses promotion id
            throw new NotFoundException("No problem with id '" + problemId + "' found in build with id " + build.getId());
        } else {
            locator.markUnused(BUILD, PROBLEM);
        }
    }
    return null;
}
Also used : ServiceLocator(jetbrains.buildServer.ServiceLocator) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem)

Example 3 with BuildProblem

use of jetbrains.buildServer.serverSide.problems.BuildProblem in project teamcity-rest by JetBrains.

the class Build method getProblemOccurrences.

@XmlElement(name = "problemOccurrences")
public ProblemOccurrences getProblemOccurrences() {
    return ValueWithDefault.decideDefault(myFields.isIncluded("problemOccurrences", false), () -> {
        final List<BuildProblem> problemOccurrences = ProblemOccurrenceFinder.getProblemOccurrences(myBuildPromotion);
        if (problemOccurrences.size() == 0)
            return null;
        int newProblemsCount = 0;
        int mutedProblemsCount = 0;
        for (BuildProblem problem : problemOccurrences) {
            if (problem.isMutedInBuild())
                mutedProblemsCount++;
            final Boolean isNew = ((BuildProblemImpl) problem).isNew();
            if (isNew != null && isNew)
                newProblemsCount++;
        }
        final Fields problemOccurrencesFields = myFields.getNestedField("problemOccurrences");
        final List<BuildProblem> problems = ValueWithDefault.decideDefault(problemOccurrencesFields.isIncluded("problemOccurrence", false), problemOccurrences);
        return new ProblemOccurrences(problems, problemOccurrences.size(), null, null, newProblemsCount, null, mutedProblemsCount, ProblemOccurrenceRequest.getHref(myBuildPromotion), null, problemOccurrencesFields, myBeanContext);
    });
}
Also used : ProblemOccurrences(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrences) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) BuildProblemImpl(jetbrains.buildServer.serverSide.impl.problems.BuildProblemImpl) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 4 with BuildProblem

use of jetbrains.buildServer.serverSide.problems.BuildProblem in project teamcity-rest by JetBrains.

the class ChangeStatus method initCounters.

private void initCounters() {
    // This is heavily inspired by ChangeDetailsCalculator, but with some simplifications, so not reusing it here.
    SecurityContext context = myBeanContext.getSingletonService(SecurityContext.class);
    SUser self = (SUser) context.getAuthorityHolder().getAssociatedUser();
    myCriticalCollector = new BuildsCollector(myFields.getNestedField("criticalBuilds"));
    myCompilationErrorCollector = new BuildsCollector(myFields.getNestedField("compilationErrorBuilds"));
    myNewTestsFailedCollector = new BuildsCollector(myFields.getNestedField("newTestsFailedBuilds"));
    myNotCriticalCollector = new BuildsCollector(myFields.getNestedField("notCriticalBuilds"));
    final boolean includePersonalBuilds = self != null && StringUtil.isTrue(self.getPropertyValue(StandardProperties.SHOW_ALL_PERSONAL_BUILDS));
    for (BuildTypeChangeStatus status : myChangeStatus.getBuildTypesStatus().values()) {
        final SBuild firstBuild = status.getFirstBuild();
        if (firstBuild == null) {
            SQueuedBuild queued = status.getQueuedBuild();
            if (queued != null && (includePersonalBuilds || !queued.isPersonal())) {
                myQueuedBuildsCount++;
            }
            if (status.getQueuedBuild() == null) {
                myPendingCount++;
            }
            continue;
        }
        if (firstBuild.isPersonal() && !includePersonalBuilds) {
            continue;
        }
        if (firstBuild.getCanceledInfo() != null) {
            myCancelledCount++;
            continue;
        }
        if (firstBuild.isFinished()) {
            myFinishedBuildsCount++;
            if (status.isSuccessful()) {
                mySuccessfulBuildsCount++;
                // no need to count problems, as our build is green
                continue;
            }
        } else {
            myRunningBuildsCount++;
            Status runningBuildStatus = firstBuild.getBuildStatus();
            if (runningBuildStatus.isSuccessful()) {
                myRunningSuccessfullyCount++;
                // no need to count problems, as our build is green
                continue;
            }
        }
        myFailedBuildsCount++;
        String statusText = BuildStatusText.getBuildStatus(firstBuild, self);
        final BuildPromotionEx buildPromo = (BuildPromotionEx) firstBuild.getBuildPromotion();
        switch(statusText) {
            case BuildStatusText.NEW_TESTS_FAILED:
                myNewTestsFailedCollector.put(buildPromo);
                break;
            case BuildStatusText.CRITICAL_PROBLEM:
                myCriticalCollector.put(buildPromo);
                break;
            case BuildStatusText.COMPILATION_ERROR:
                myCompilationErrorCollector.put(buildPromo);
                break;
            default:
                myNotCriticalCollector.put(buildPromo);
        }
        for (BuildProblem problem : buildPromo.getBuildProblems()) {
            if (problem.isMutedInBuild())
                continue;
            if (problem.getBuildProblemData().getType().equals(BuildProblemData.TC_FAILED_TESTS_TYPE) || ErrorData.isSnapshotDependencyError(problem.getBuildProblemData().getType()))
                continue;
            myTotalProblemCount++;
        }
    }
}
Also used : Status(jetbrains.buildServer.messages.Status) BuildTypeChangeStatus(jetbrains.buildServer.vcs.BuildTypeChangeStatus) SUser(jetbrains.buildServer.users.SUser) BuildTypeChangeStatus(jetbrains.buildServer.vcs.BuildTypeChangeStatus) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem)

Example 5 with BuildProblem

use of jetbrains.buildServer.serverSide.problems.BuildProblem in project teamcity-rest by JetBrains.

the class ProblemOccurrenceFinder method getProblemOccurrences.

@NotNull
private static ItemHolder<BuildProblem> getProblemOccurrences(@NotNull final Long problemId, @NotNull final ServiceLocator serviceLocator, @NotNull final BuildFinder buildFinder) {
    // todo: TeamCity API (VB): how to do this?
    final ArrayList<Long> buildIds = new ArrayList<Long>();
    try {
        // final SQLRunner sqlRunner = myServiceLocator.getSingletonService(SQLRunner.class);
        // workaround for http://youtrack.jetbrains.com/issue/TW-25260
        final SQLRunnerEx sqlRunner = serviceLocator.getSingletonService(BuildServerEx.class).getSQLRunner();
        sqlRunner.withDB(new DBActionNoResults() {

            public void run(final DBFunctions dbf) throws DBException {
                dbf.queryForTuples(new Object() {

                    public void getBuildProblem(String build_state_id) throws IOException {
                        try {
                            // do nothing within database connection
                            buildIds.add(Long.valueOf(build_state_id));
                        } catch (NumberFormatException e) {
                            LOG.infoAndDebugDetails("Non-number build promotion id " + build_state_id + " retrieved from the database for problemId: " + problemId + ", ignoring.", e);
                        }
                    }
                }, "getBuildProblem", "select build_state_id from build_problem where problem_id = ? order by build_state_id desc", problemId);
            }
        });
    } catch (Exception e) {
        throw new OperationException("Error performing database query: " + e.toString(), e);
    }
    return new ItemHolder<BuildProblem>() {

        @Override
        public void process(@NotNull final ItemProcessor<BuildProblem> processor) {
            for (Long buildId : buildIds) {
                try {
                    final BuildPromotion buildByPromotionId = buildFinder.getBuildByPromotionId(Long.valueOf(buildId));
                    if (buildByPromotionId.getBuildType() == null) {
                    // missing build type, skip. Workaround for http://youtrack.jetbrains.com/issue/TW-34733
                    } else {
                        final BuildProblem problem = findProblem(buildByPromotionId, problemId);
                        if (problem != null) {
                            processor.processItem(problem);
                        }
                    }
                } catch (RuntimeException e) {
                    // addressing TW-41636
                    LOG.infoAndDebugDetails("Error getting problems for build promotion with id " + buildId + ", problemId: " + problemId + ", ignoring. Cause", e);
                }
            }
        }
    };
}
Also used : DBException(jetbrains.buildServer.serverSide.db.DBException) DBFunctions(jetbrains.buildServer.serverSide.db.DBFunctions) AggregatingItemHolder(jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder) DBActionNoResults(jetbrains.buildServer.serverSide.db.DBActionNoResults) NotNull(org.jetbrains.annotations.NotNull) SQLRunnerEx(jetbrains.buildServer.serverSide.db.SQLRunnerEx) IOException(java.io.IOException) DBException(jetbrains.buildServer.serverSide.db.DBException) ItemProcessor(jetbrains.buildServer.util.ItemProcessor) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuildProblem (jetbrains.buildServer.serverSide.problems.BuildProblem)6 NotNull (org.jetbrains.annotations.NotNull)3 IOException (java.io.IOException)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 Status (jetbrains.buildServer.messages.Status)1 AggregatingItemHolder (jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder)1 ProblemOccurrences (jetbrains.buildServer.server.rest.model.problem.ProblemOccurrences)1 BuildPromotion (jetbrains.buildServer.serverSide.BuildPromotion)1 SecurityContext (jetbrains.buildServer.serverSide.auth.SecurityContext)1 DBActionNoResults (jetbrains.buildServer.serverSide.db.DBActionNoResults)1 DBException (jetbrains.buildServer.serverSide.db.DBException)1 DBFunctions (jetbrains.buildServer.serverSide.db.DBFunctions)1 SQLRunnerEx (jetbrains.buildServer.serverSide.db.SQLRunnerEx)1 BuildProblemImpl (jetbrains.buildServer.serverSide.impl.problems.BuildProblemImpl)1 SUser (jetbrains.buildServer.users.SUser)1 Converter (jetbrains.buildServer.util.Converter)1 ItemProcessor (jetbrains.buildServer.util.ItemProcessor)1 BuildTypeChangeStatus (jetbrains.buildServer.vcs.BuildTypeChangeStatus)1