use of jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder in project teamcity-rest by JetBrains.
the class BuildPromotionFinder method getBuildFilter.
@NotNull
private MultiCheckerFilter<SBuild> getBuildFilter(@NotNull final Locator locator) {
final MultiCheckerFilter<SBuild> result = new MultiCheckerFilter<SBuild>();
final String buildNumber = locator.getSingleDimensionValue(NUMBER);
if (buildNumber != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return buildNumber.equals(item.getBuildNumber());
}
});
}
final String status = locator.getSingleDimensionValue(STATUS);
if (status != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return status.equalsIgnoreCase(item.getStatusDescriptor().getStatus().getText());
}
});
}
final Boolean pinned = locator.getSingleDimensionValueAsBoolean(PINNED);
if (pinned != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return FilterUtil.isIncludedByBooleanFilter(pinned, item.isPinned());
}
});
}
final Boolean hanging = locator.getSingleDimensionValueAsBoolean(HANGING);
if (hanging != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
if (item.isFinished())
return !hanging;
return FilterUtil.isIncludedByBooleanFilter(hanging, ((SRunningBuild) item).isProbablyHanging());
}
});
}
if (locator.isUnused(AGENT_NAME)) {
final String agentName = locator.getSingleDimensionValue(AGENT_NAME);
if (agentName != null) {
final ValueCondition agentNameCondition = ParameterCondition.createValueCondition(agentName);
result.add(item -> agentNameCondition.matches(item.getAgentName()));
}
}
if (locator.isUnused(AGENT_TYPE_ID)) {
final Long agentTypeId = locator.getSingleDimensionValueAsLong(AGENT_TYPE_ID);
if (agentTypeId != null) {
result.add(item -> agentTypeId.intValue() == item.getAgent().getAgentTypeId());
}
}
// see also settings cut off date in main filter
final Date sinceDate = DataProvider.parseDate(locator.getSingleDimensionValue(SINCE_DATE));
if (sinceDate != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return sinceDate.before(item.getStartDate());
}
});
}
final Date untilDate = DataProvider.parseDate(locator.getSingleDimensionValue(UNTIL_DATE));
if (untilDate != null) {
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return !(untilDate.before(item.getStartDate()));
}
});
}
final List<String> statisticValues = locator.getDimensionValue(STATISTIC_VALUE);
if (!statisticValues.isEmpty()) {
final Matcher<ParametersProvider> parameterCondition = ParameterCondition.create(statisticValues);
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return parameterCondition.matches(new AbstractMapParametersProvider(Build.getBuildStatisticsValues(item)));
}
});
}
if (locator.isUnused(TEST_OCCURRENCE)) {
final String testOccurrence = locator.getSingleDimensionValue(TEST_OCCURRENCE);
if (testOccurrence != null) {
TestOccurrenceFinder testOccurrenceFinder = myServiceLocator.getSingletonService(TestOccurrenceFinder.class);
Set<Long> buildPromotionIds = testOccurrenceFinder.getItems(testOccurrence).myEntries.stream().map(sTestRun -> sTestRun.getBuild().getBuildPromotion().getId()).collect(Collectors.toSet());
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
return buildPromotionIds.contains(item.getBuildPromotion().getId());
}
});
}
}
final String test = locator.getSingleDimensionValue(TEST);
if (test != null) {
TestFinder testFinder = myServiceLocator.getSingletonService(TestFinder.class);
result.add(new FilterConditionChecker<SBuild>() {
public boolean isIncluded(@NotNull final SBuild item) {
String locator = new Locator(test).setDimension(TestFinder.BUILD, getLocator(item.getBuildPromotion())).setDimension(PagerData.COUNT, "1").getStringRepresentation();
return !testFinder.getItems(locator).myEntries.isEmpty();
}
});
}
return result;
}
use of jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder in project teamcity-rest by JetBrains.
the class BaseTestScopesCollectorTest method setUp.
@BeforeMethod(alwaysRun = true)
@Override
protected void setUp() throws Exception {
super.setUp();
myTimeCondition = new TimeCondition(myFixture);
myFixture.addService(myTimeCondition);
myPermissionChecker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
myFixture.addService(myPermissionChecker);
myProjectFinder = new ProjectFinder(myProjectManager, myPermissionChecker, myServer);
myFixture.addService(myProjectFinder);
myGroupFinder = new UserGroupFinder(getUserGroupManager());
myFixture.addService(myGroupFinder);
myUserFinder = new UserFinder(getUserModelEx(), myGroupFinder, myProjectFinder, myTimeCondition, myFixture.getRolesManager(), myPermissionChecker, myServer.getSecurityContext(), myServer);
myAgentFinder = new AgentFinder(myAgentManager, myFixture);
myFixture.addService(myAgentFinder);
myBuildTypeFinder = new BuildTypeFinder(myProjectManager, myProjectFinder, myAgentFinder, myPermissionChecker, myFixture);
myBranchFinder = new BranchFinder(myBuildTypeFinder, myFixture);
final VcsRootIdentifiersManagerImpl vcsRootIdentifiersManager = myFixture.getSingletonService(VcsRootIdentifiersManagerImpl.class);
myVcsRootFinder = new VcsRootFinder(myFixture.getVcsManager(), myProjectFinder, myBuildTypeFinder, myProjectManager, vcsRootIdentifiersManager, myPermissionChecker);
myFixture.addService(myVcsRootFinder);
myBuildPromotionFinder = new BuildPromotionFinder(myFixture.getBuildPromotionManager(), myFixture.getBuildQueue(), myServer, myVcsRootFinder, myProjectFinder, myBuildTypeFinder, myUserFinder, myAgentFinder, myBranchFinder, myTimeCondition, myPermissionChecker, null, myFixture);
myFixture.addService(myBuildPromotionFinder);
myBuildFinder = new BuildFinder(myFixture, myBuildTypeFinder, myProjectFinder, myUserFinder, myBuildPromotionFinder, myAgentFinder);
final TestName2Index testName2Index = myFixture.getSingletonService(TestName2Index.class);
final ProblemMutingService problemMutingService = myFixture.getSingletonService(ProblemMutingService.class);
myTestFinder = new TestFinder(myProjectFinder, myBuildTypeFinder, myBuildPromotionFinder, myFixture.getTestManager(), testName2Index, myFixture.getCurrentProblemsManager(), problemMutingService);
myFixture.addService(myTestFinder);
TestScopeFilterProducer testScopesFilterProducer = new TestScopeFilterProducer(myBuildTypeFinder);
final CurrentProblemsManager currentProblemsManager = myServer.getSingletonService(CurrentProblemsManager.class);
myTestOccurrenceFinder = new TestOccurrenceFinder(myServer.getSecurityContext(), myTestFinder, myBuildFinder, myBuildTypeFinder, myProjectFinder, myFixture.getTestsHistory(), currentProblemsManager, myBranchFinder, testScopesFilterProducer);
myFixture.addService(myTestOccurrenceFinder);
myTestScopesCollector = new TestScopesCollector(myTestOccurrenceFinder, testScopesFilterProducer);
}
use of jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder in project teamcity-rest by JetBrains.
the class BaseFinderTest method initFinders.
protected void initFinders() {
myVcsManager = myFixture.getVcsManager();
myFixture.addService(myVcsManager);
myFixture.addService(myProjectManager);
myPermissionChecker = new PermissionChecker(myServer.getSecurityContext(), myProjectManager);
myFixture.addService(myPermissionChecker);
myTimeCondition = new TimeCondition(myFixture);
myFixture.addService(myTimeCondition);
myProjectFinder = new ProjectFinder(myProjectManager, myPermissionChecker, myServer);
myFixture.addService(myProjectFinder);
myAgentFinder = new AgentFinder(myAgentManager, myFixture);
myFixture.addService(myAgentFinder);
myAgentPoolFinder = new AgentPoolFinder(myFixture.getAgentPoolManager(), myAgentFinder, myFixture);
myFixture.addService(myAgentPoolFinder);
myBuildTypeFinder = new BuildTypeFinder(myProjectManager, myProjectFinder, myAgentFinder, myPermissionChecker, myServer);
myFixture.addService(myBuildTypeFinder);
final VcsRootIdentifiersManagerImpl vcsRootIdentifiersManager = myFixture.getSingletonService(VcsRootIdentifiersManagerImpl.class);
myVcsRootFinder = new VcsRootFinder(myVcsManager, myProjectFinder, myBuildTypeFinder, myProjectManager, vcsRootIdentifiersManager, myPermissionChecker);
myFixture.addService(myVcsRootFinder);
myVcsRootInstanceFinder = new VcsRootInstanceFinder(myVcsRootFinder, myVcsManager, myProjectFinder, myBuildTypeFinder, myProjectManager, myFixture.getSingletonService(VersionedSettingsManager.class), myTimeCondition, myPermissionChecker, myServer);
myFixture.addService(myVcsRootInstanceFinder);
myGroupFinder = new UserGroupFinder(getUserGroupManager());
myFixture.addService(myGroupFinder);
myUserFinder = new UserFinder(getUserModelEx(), myGroupFinder, myProjectFinder, myTimeCondition, myFixture.getRolesManager(), myPermissionChecker, myServer.getSecurityContext(), myServer);
myFixture.addService(myUserFinder);
myBranchFinder = new BranchFinder(myBuildTypeFinder, myFixture);
myBuildPromotionFinder = new BuildPromotionFinder(myFixture.getBuildPromotionManager(), myFixture.getBuildQueue(), myServer, myVcsRootFinder, myProjectFinder, myBuildTypeFinder, myUserFinder, myAgentFinder, myBranchFinder, myTimeCondition, myPermissionChecker, null, myFixture);
myFixture.addService(myBuildPromotionFinder);
myBuildFinder = new BuildFinder(myServer, myBuildTypeFinder, myProjectFinder, myUserFinder, myBuildPromotionFinder, myAgentFinder);
myFixture.addService(myBuildFinder);
final TestName2Index testName2Index = myFixture.getSingletonService(TestName2Index.class);
final ProblemMutingService problemMutingService = myFixture.getSingletonService(ProblemMutingService.class);
myTestFinder = new TestFinder(myProjectFinder, myBuildTypeFinder, myBuildPromotionFinder, myFixture.getTestManager(), testName2Index, myFixture.getCurrentProblemsManager(), problemMutingService);
myFixture.addService(myTestFinder);
TestScopeFilterProducer filterProducer = new TestScopeFilterProducer(myBuildTypeFinder);
final CurrentProblemsManager currentProblemsManager = myServer.getSingletonService(CurrentProblemsManager.class);
myTestOccurrenceFinder = new TestOccurrenceFinder(myServer.getSecurityContext(), myTestFinder, myBuildFinder, myBuildTypeFinder, myProjectFinder, myFixture.getTestsHistory(), currentProblemsManager, myBranchFinder, filterProducer);
myFixture.addService(myTestOccurrenceFinder);
final BuildProblemManager buildProblemManager = myFixture.getSingletonService(BuildProblemManager.class);
myProblemFinder = new ProblemFinder(myProjectFinder, myBuildPromotionFinder, buildProblemManager, myProjectManager, myFixture, problemMutingService);
myFixture.addService(myProblemFinder);
myProblemOccurrenceFinder = new ProblemOccurrenceFinder(myProjectFinder, myBuildFinder, myProblemFinder, buildProblemManager, myProjectManager, myFixture);
myFixture.addService(myProblemOccurrenceFinder);
final ResponsibilityFacadeEx responsibilityFacade = myFixture.getResponsibilityFacadeEx();
myInvestigationFinder = new InvestigationFinder(myProjectFinder, myBuildTypeFinder, myProblemFinder, myTestFinder, myUserFinder, responsibilityFacade, responsibilityFacade, responsibilityFacade);
myFixture.addService(myInvestigationFinder);
myMuteFinder = new MuteFinder(myProjectFinder, myTimeCondition, myPermissionChecker, problemMutingService, (LowLevelProblemMutingServiceImpl) myFixture.getSingletonService(LowLevelProblemMutingService.class), myFixture);
myFixture.addService(myMuteFinder);
myQueuedBuildFinder = new QueuedBuildFinder(myServer.getQueue(), myProjectFinder, myBuildTypeFinder, myUserFinder, myAgentFinder, myAgentPoolFinder, myFixture.getBuildPromotionManager(), myServer);
myFixture.addService(myQueuedBuildFinder);
myChangeFinder = new ChangeFinder(myProjectFinder, myBuildFinder, myBuildPromotionFinder, myBuildTypeFinder, myVcsRootFinder, myVcsRootInstanceFinder, myUserFinder, myVcsManager, myFixture.getVcsHistory(), myBranchFinder, myFixture, myPermissionChecker);
myFixture.addService(myChangeFinder);
myFixture.addService(new HealthItemFinder(myFixture.getSingletonService(HealthStatusProvider.class), myFixture.getSingletonService(HealthStatusReportLocator.class), myFixture));
}
use of jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder in project teamcity-rest by JetBrains.
the class BuildPromotionFinder method getPrefilteredItems.
@NotNull
@Override
public ItemHolder<BuildPromotion> getPrefilteredItems(@NotNull Locator locator) {
if (!myPermissionChecker.hasPermissionInAnyProject(Permission.VIEW_PROJECT)) {
// TeamCity issue: should be handled in core. Do not spend any resources on user without permissions
return getItemHolder(Collections.emptyList());
}
final Boolean byPromotion = locator.getSingleDimensionValueAsBoolean(BY_PROMOTION);
if (byPromotion != null && !byPromotion) {
throw new BadRequestException("Found '" + BY_PROMOTION + "' locator set to 'false' which is not supported");
}
final String strob = locator.getSingleDimensionValue(STROB);
if (strob != null) {
final Locator strobLocator = new Locator(strob, BUILD_TYPE, BRANCH, STROB_BUILD_LOCATOR);
List<Locator> partialLocators = Collections.singletonList(Locator.createEmptyLocator());
partialLocators = getPartialLocatorsForStrobDimension(partialLocators, strobLocator, BUILD_TYPE, myBuildTypeFinder);
partialLocators = getPartialLocatorsForStrobDimension(partialLocators, strobLocator, BRANCH, myBranchFinder);
final String strobBuildLocator = strobLocator.getSingleDimensionValue(STROB_BUILD_LOCATOR);
final AggregatingItemHolder<BuildPromotion> strobResult = new AggregatingItemHolder<>();
for (Locator partialLocator : partialLocators) {
// limit to single item per strob item by default
partialLocator.setDimensionIfNotPresent(PagerData.COUNT, "1");
final String finalBuildLocator = Locator.createLocator(strobBuildLocator, partialLocator, new String[] {}).getStringRepresentation();
strobResult.add(getItemHolder(getItems(finalBuildLocator).myEntries));
}
strobLocator.checkLocatorFullyProcessed();
return strobResult;
}
setLocatorDefaults(locator);
final String equivalent = locator.getSingleDimensionValue(EQUIVALENT);
if (equivalent != null) {
final BuildPromotionEx build = (BuildPromotionEx) getItem(equivalent);
final List<BuildPromotionEx> result = build.getStartedEquivalentPromotions(-1);
final Set<BuildPromotion> convertedResult = new TreeSet<BuildPromotion>(BUILD_PROMOTIONS_COMPARATOR);
for (BuildPromotionEx item : result) {
convertedResult.add(item);
}
return getItemHolder(convertedResult);
}
final String metadata = locator.getSingleDimensionValue(METADATA);
if (metadata != null) {
final Iterator<BuildMetadataEntry> metadataEntries = getBuildMetadataEntryIterator(metadata);
return new ItemHolder<BuildPromotion>() {
@Override
public void process(@NotNull final ItemProcessor<BuildPromotion> processor) {
while (metadataEntries.hasNext()) {
BuildMetadataEntry metadataEntry = metadataEntries.next();
SBuild build = myBuildsManager.findBuildInstanceById(metadataEntry.getBuildId());
if (build != null && Build.canViewRuntimeData(myPermissionChecker, build.getBuildPromotion())) {
processor.processItem(build.getBuildPromotion());
}
}
}
};
}
final String graphLocator = locator.getSingleDimensionValue(ORDERED);
if (graphLocator != null) {
final GraphFinder<BuildPromotion> graphFinder = new BuildPromotionOrderedFinder(this);
// consider performance optimization by converting id to build only on actual retrieve (use GraphFinder<Int/buildId>)
return getItemHolder(graphFinder.getItems(graphLocator).myEntries);
}
final String snapshotDepDimension = locator.getSingleDimensionValue(SNAPSHOT_DEP);
if (snapshotDepDimension != null) {
return getItemHolder(getSnapshotRelatedBuilds(snapshotDepDimension));
}
final String artifactDepDimension = locator.getSingleDimensionValue(ARTIFACT_DEP);
if (artifactDepDimension != null) {
return getItemHolder(getArtifactRelatedBuilds(artifactDepDimension, locator));
}
final String snapshotDepProblem = locator.getSingleDimensionValue(SNAPSHOT_PROBLEM);
if (snapshotDepProblem != null) {
return getItemHolder(getSnapshotDepProblemBuilds(snapshotDepProblem));
}
final String number = locator.getSingleDimensionValue(NUMBER);
if (number != null) {
final String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
if (buildTypeLocator != null) {
final List<SBuildType> buildTypes = myBuildTypeFinder.getBuildTypes(null, buildTypeLocator);
final Set<BuildPromotion> builds = new TreeSet<BuildPromotion>(BUILD_PROMOTIONS_COMPARATOR);
for (SBuildType buildType : buildTypes) {
// todo: ensure due builds sorting
builds.addAll(BuildFinder.toBuildPromotions(myBuildsManager.findBuildInstancesByBuildNumber(buildType.getBuildTypeId(), number)));
}
return getItemHolder(builds);
} else {
// if build type is not specified, search by scanning (performance impact)
locator.markUnused(NUMBER, BUILD_TYPE);
}
}
if (locator.isAnyPresent(TAG) && TeamCityProperties.getBooleanOrTrue("rest.request.builds.prefilterByTag")) {
// using locator copy so that no dimensions are marked as used
Locator stateLocator = getStateLocator(new Locator(locator));
if (isStateIncluded(stateLocator, STATE_FINISHED)) {
// no sense in going further here if no finished builds are requested
// not marking as used to enforce filter processing later
final List<String> tagLocators = locator.lookupDimensionValue(TAG);
Stream<BuildPromotion> finishedBuilds = TagFinder.getPrefilteredFinishedBuildPromotions(tagLocators, myServiceLocator);
if (finishedBuilds != null) {
FilterConditionChecker<BuildPromotion> tagsFilter = getFilterByTag(tagLocators);
// After this point no other builds will be added
locator.markUsed(Collections.singleton(TAG));
Stream<BuildPromotion> queuedBuilds = Stream.empty();
if (isStateIncluded(stateLocator, STATE_QUEUED)) {
queuedBuilds = myBuildQueue.getItems().stream().map(SQueuedBuild::getBuildPromotion);
}
Stream<BuildPromotion> runningBuilds = Stream.empty();
if (isStateIncluded(stateLocator, STATE_RUNNING)) {
// BuildsManager.processBuilds could be used here instead of getting finished and running builds separately, but BuildQueryOptions support
// only exact tag name match, so we can't satisfy all possible TAG queriy conditions with it. To counter that we use
// TagFinder.getPrefilteredFinishedBuildPromotions to obtain a subset of required finished builds and BuildsManager.getRunningBuilds()
// to get all runing builds and later filter everything properly.
runningBuilds = myBuildsManager.getRunningBuilds().stream().map(SRunningBuild::getBuildPromotion);
}
// None of the concatenated streams were properly filtered, so let's filter them now.
// This hopefully allows for avoiding of hitting a lookupLimit because of a large queue.
Stream<BuildPromotion> allBuildsFilteredByTag = Stream.concat(Stream.concat(queuedBuilds, runningBuilds), finishedBuilds).filter(tagsFilter::isIncluded);
return processor -> allBuildsFilteredByTag.forEach(processor::processItem);
}
}
}
final String testOccurrence = locator.getSingleDimensionValue(TEST_OCCURRENCE);
if (testOccurrence != null) {
TestOccurrenceFinder testOccurrenceFinder = myServiceLocator.getSingletonService(TestOccurrenceFinder.class);
return FinderDataBinding.getItemHolder(testOccurrenceFinder.getItems(testOccurrence).myEntries.stream().map(sTestRun -> sTestRun.getBuild().getBuildPromotion()));
}
SBuildAgent agent;
final String agentLocator = locator.getSingleDimensionValue(AGENT);
if (agentLocator != null) {
List<SBuildAgent> agents = myAgentFinder.getItemsNotEmpty(agentLocator).myEntries;
if (agents.size() == 1) {
agent = agents.get(0);
} else {
// only if builds processor cannot handle this
Stream<BuildPromotion> result = Stream.empty();
Locator stateLocator = getStateLocator(locator);
if (isStateIncluded(stateLocator, STATE_QUEUED)) {
// todo: should sort backwards as currently the order does not seem right...
result = Stream.concat(result, myBuildQueue.getItems().stream().filter(build -> !CollectionsUtil.intersect(build.getCanRunOnAgents(), agents).isEmpty()).map(build -> build.getBuildPromotion()));
}
if (isStateIncluded(stateLocator, STATE_RUNNING)) {
// todo: address an issue when a build can appear twice in the output
// agent instance can be different when disconnecting, so need to check id
Set<Integer> agentIds = agents.stream().map(a -> a.getId()).collect(Collectors.toSet());
Set<String> agentNames = agents.stream().map(a -> a.getName()).collect(Collectors.toSet());
result = Stream.concat(result, myBuildsManager.getRunningBuilds().stream().filter(build -> {
SBuildAgent buildAgent = build.getAgent();
int agentId = buildAgent.getId();
return agentId > 0 ? agentIds.contains(agentId) : agentNames.contains(buildAgent.getName());
}).map(build -> build.getBuildPromotion()));
}
if (isStateIncluded(stateLocator, STATE_FINISHED)) {
// todo: optimize for user and canceled
Stream<BuildPromotion> finishedBuilds = StreamUtil.merge(agents.stream().map(a -> a.getBuildHistory(null, true).stream().map(b -> b.getBuildPromotion())), BUILD_PROMOTIONS_COMPARATOR);
result = Stream.concat(result, finishedBuilds);
}
return FinderDataBinding.getItemHolder(result);
}
} else {
agent = null;
}
// process by build states
final List<BuildPromotion> result = new ArrayList<BuildPromotion>();
Set<Long> includedPromotionIds = new HashSet<>();
@Nullable Set<SBuildType> buildTypes = getBuildTypes(locator);
String agentName;
String agentNameCondition = locator.lookupSingleDimensionValue(AGENT_NAME);
if (agentNameCondition != null) {
agentName = ParameterCondition.createValueCondition(agentNameCondition).getConstantValueIfSimpleEqualsCondition();
if (agentName != null)
locator.markUsed(Collections.singleton(AGENT_NAME));
} else {
agentName = null;
}
Long agentTypeId = locator.getSingleDimensionValueAsLong(AGENT_TYPE_ID);
Locator stateLocator = getStateLocator(locator);
if (isStateIncluded(stateLocator, STATE_QUEUED)) {
// todo: should sort backwards as currently the order does not seem right...
Stream<SQueuedBuild> builds = myBuildQueue.getItems().stream();
if (buildTypes != null) {
// make sure buildTypes retrieved from the locator are used
builds = builds.filter(qb -> buildTypes.contains(qb.getBuildPromotion().getParentBuildType()));
}
if (agentTypeId != null) {
builds = builds.filter(build -> build.getCanRunOnAgents().stream().anyMatch(a -> a.getAgentTypeId() == agentTypeId.intValue()));
}
if (agent != null) {
// todo: check
builds = builds.filter(build -> build.getCanRunOnAgents().stream().anyMatch(a -> a.equals(agent)));
}
if (agentName != null) {
builds = builds.filter(build -> build.getCanRunOnAgents().stream().anyMatch(a -> a.getName().equals(agentName)));
}
builds.map(b -> b.getBuildPromotion()).forEach(p -> {
if (includedPromotionIds.add(p.getId())) {
result.add(p);
}
});
}
if (isStateIncluded(stateLocator, STATE_RUNNING)) {
Stream<SRunningBuild> builds = myBuildsManager.getRunningBuilds().stream();
if (buildTypes != null) {
// make sure buildTypes retrieved from the locator are used
builds = builds.filter(b -> buildTypes.contains(b.getBuildPromotion().getParentBuildType()));
}
if (agentTypeId != null) {
builds = builds.filter(build -> build.getAgent().getAgentTypeId() == agentTypeId.intValue());
}
if (agent != null) {
builds = builds.filter(build -> {
SBuildAgent buildAgent = build.getAgent();
int agentId = buildAgent.getId();
return agentId > 0 ? agent.getId() == agentId : agent.getName().equals(buildAgent.getName());
});
}
if (agentName != null) {
builds = builds.filter(build -> build.getAgentName().equals(agentName));
}
builds.map(b -> b.getBuildPromotion()).forEach(p -> {
if (includedPromotionIds.add(p.getId())) {
result.add(p);
}
});
}
ItemHolder<BuildPromotion> finishedBuilds = null;
if (isStateIncluded(stateLocator, STATE_FINISHED)) {
final BuildQueryOptions options = new BuildQueryOptions();
if (buildTypes != null) {
options.setBuildTypeIds(buildTypes.stream().map(bt -> bt.getBuildTypeId()).collect(Collectors.toList()));
}
if (agentTypeId != null) {
options.setAgentTypeId(agentTypeId.intValue());
}
if (agent != null) {
options.setAgent(agent);
}
if (agentName != null) {
options.setAgentName(agentName);
}
final Boolean personal = locator.lookupSingleDimensionValueAsBoolean(PERSONAL);
if (personal == null || personal) {
final String userDimension = locator.getSingleDimensionValue(USER);
options.setIncludePersonal(true, userDimension == null ? null : myUserFinder.getItem(userDimension));
} else {
options.setIncludePersonal(false, null);
}
final Boolean failedToStart = locator.lookupSingleDimensionValueAsBoolean(FAILED_TO_START);
final Boolean canceled = locator.lookupSingleDimensionValueAsBoolean(CANCELED);
if (canceled == null || canceled || failedToStart == null || failedToStart) {
// also includes failed to start builds, TW-32060
options.setIncludeCanceled(true);
} else {
options.setIncludeCanceled(false);
}
final Boolean pinned = locator.getSingleDimensionValueAsBoolean(PINNED);
if (pinned != null) {
options.setPinStatus(pinned);
}
TagFinder.FilterOptions tagFilterOptions = TagFinder.getFilterOptions(locator.lookupDimensionValue(TAG), myServiceLocator);
if (tagFilterOptions != null) {
options.setTagName(tagFilterOptions.getTagName(), tagFilterOptions.getTagOwner());
}
// do not mark dimension as used as not all can be used from it
final String branchLocatorValue = locator.lookupSingleDimensionValue(BRANCH);
if (branchLocatorValue != null) {
BranchFinder.BranchFilterDetails branchFilterDetails;
try {
branchFilterDetails = myBranchFinder.getBranchFilterDetailsWithoutLocatorCheck(branchLocatorValue);
// parsed OK, setting options
if (branchFilterDetails.isAnyBranch()) {
options.setMatchAllBranches(true);
} else {
if (branchFilterDetails.isDefaultBranchOrNotBranched()) {
options.setMatchAllBranches(false);
options.setBranch(Branch.DEFAULT_BRANCH_NAME);
}
if (branchFilterDetails.getBranchName() != null) {
// causes a bug in certain cases, see https://youtrack.jetbrains.com/issue/TW-61530 however, no performant fix is possible so far
options.setMatchAllBranches(false);
options.setBranch(branchFilterDetails.getBranchName());
}
}
} catch (LocatorProcessException e) {
// not parsed, cannot extract name or default status
options.setMatchAllBranches(true);
}
} else {
options.setMatchAllBranches(true);
}
// running builds are retrieved separately and appear before finished ones
options.setIncludeRunning(false);
options.setOrderByChanges(false);
Long count = locator.getSingleDimensionValueAsLong(PagerData.COUNT);
if (count != null) {
options.setPageSize(count.intValue());
}
finishedBuilds = new ItemHolder<BuildPromotion>() {
public void process(@NotNull final ItemProcessor<BuildPromotion> processor) {
myBuildsManager.processBuilds(options, new ItemProcessor<SBuild>() {
public boolean processItem(SBuild item) {
// ignore already added builds
if (includedPromotionIds.contains(item.getBuildPromotion().getId()))
return true;
return processor.processItem(item.getBuildPromotion());
}
});
}
};
}
stateLocator.checkLocatorFullyProcessed();
final ItemHolder<BuildPromotion> finishedBuildsFinal = finishedBuilds;
return new ItemHolder<BuildPromotion>() {
public void process(@NotNull final ItemProcessor<BuildPromotion> processor) {
new CollectionItemHolder<BuildPromotion>(result).process(processor);
if (finishedBuildsFinal != null) {
finishedBuildsFinal.process(processor);
}
}
};
}
Aggregations