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;
}
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;
}
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);
});
}
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++;
}
}
}
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);
}
}
}
};
}
Aggregations