use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class BuildProviderImplTest method shouldGetGraphWithDependencies.
@Test
public void shouldGetGraphWithDependencies() {
// With
Integer buildSetTaskId = 1;
BuildSetTask buildSetTask = mock(BuildSetTask.class);
when(buildSetTask.getId()).thenReturn(buildSetTaskId);
BuildTask task = mockBuildTaskWithSet(buildSetTask);
BuildTask taskDep = mockBuildTaskWithSet(buildSetTask);
BuildTask taskDepDep = mockBuildTaskWithSet(buildSetTask);
when(task.getDependencies()).thenReturn(asSet(taskDep));
when(taskDep.getDependencies()).thenReturn(asSet(taskDepDep));
// When
Graph<Build> graph = provider.getBuildGraphForGroupBuild(Integer.toString(buildSetTaskId));
// Then
assertThat(graph.getVertices()).hasSize(3);
List<String> buildTaskIDsOrderedByBCName = Stream.of(task, taskDep, taskDepDep).sorted(Comparator.comparing(t -> t.getBuildConfigurationAudited().getName())).map(t -> t.getId()).collect(Collectors.toList());
assertThat(graph.getVertices().values().stream().map(Vertex::getName)).containsExactlyElementsOf(buildTaskIDsOrderedByBCName);
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class DefaultBuildCoordinatorTest method testBuildBuildConfigurationSet.
@Test
public void testBuildBuildConfigurationSet() throws BuildConflictException, CoreException, DatastoreException {
BuildConfigurationAudited bca = mockDatastoreWithBCAudited(BC_1, 5);
BuildConfigurationAudited bcaDep = mockDatastoreWithBCAudited(BC_2, 2);
BuildConfigurationAudited bca3 = mockDatastoreWithBCAudited(BC_3, 9);
when(datastore.getBuildConfigurations(BCS)).thenReturn(BCS.getBuildConfigurations());
BuildSetTask buildSetTask = coordinator.build(BCS, USER, BUILD_OPTIONS);
assertEquals(2, buildSetTask.getBuildTasks().size());
assertNotNull(buildSetTask.getBuildTask(bca));
// Dependencies outside group are not build
assertNull(buildSetTask.getBuildTask(bcaDep));
assertNotNull(buildSetTask.getBuildTask(bca3));
assertSame(BUILD_OPTIONS, buildSetTask.getBuildOptions());
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class BuildCoordinationTest method buildConfigSetRecordShouldBeMarkedFailedOnFailure.
@Test
public void buildConfigSetRecordShouldBeMarkedFailedOnFailure() throws CoreException, TimeoutException, InterruptedException {
BuildConfigurationSet buildConfigurationSet = TestEntitiesFactory.newBuildConfigurationSet();
testProjectConfigurationBuilder.buildConfigurationWithDependenciesThatFail(buildConfigurationSet);
ObjectWrapper<BuildSetStatus> lastBuildSetStatus = registerCallback(buildConfigurationSet);
BuildOptions buildOptions = new BuildOptions();
buildOptions.setRebuildMode(RebuildMode.FORCE);
BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, TestEntitiesFactory.newUser(), buildOptions);
Wait.forCondition(lastBuildSetStatus::isSet, 5, ChronoUnit.SECONDS);
// check the result
Assert.assertEquals(BuildSetStatus.DONE, lastBuildSetStatus.get());
datastoreMock.getBuildConfigSetRecordById(buildConfigurationSet.getId());
Optional<BuildConfigSetRecord> maybeSetRecord = buildSetTask.getBuildConfigSetRecord();
assertThat(maybeSetRecord.isPresent()).isTrue();
Assert.assertEquals(BuildStatus.FAILED, maybeSetRecord.get().getStatus());
Collection<BuildStatus> statuses = getBuildStatuses();
// dependent build failed with
Assert.assertTrue(statuses.contains(BuildStatus.REJECTED_FAILED_DEPENDENCIES));
// system error
Assert.assertFalse(statuses.contains(BuildStatus.SYSTEM_ERROR));
assertEmptyQueue();
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class BuildTasksInitializer method createBuildSetTask.
/**
* Create a BuildSetTask of BuildConfigurations contained in the BuildConfigurationSet.
*
* A specific revision of the BuildConfigurations contained in the set is used, if it's available in the
* buildConfigurationAuditedsMap parameter. If it's not available, latest revision of the BuildConfiguration is
* used.
*
* @param buildConfigurationSet BuildConfigurationSet to be built
* @param buildConfigurationAuditedsMap A map BuildConfiguration::id:BuildConfigurationAudited of specific revisions
* of BuildConfigurations contained in the buildConfigurationSet
* @param user A user, who triggered the build
* @param buildOptions Build options
* @param buildTaskIdProvider Provider to get build task ID
* @param submittedBuildTasks Already submitted build tasks
* @return Prepared BuildSetTask
* @throws CoreException Thrown if the BuildConfigSetRecord cannot be stored
*/
public BuildSetTask createBuildSetTask(BuildConfigurationSet buildConfigurationSet, Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap, User user, BuildOptions buildOptions, Supplier<String> buildTaskIdProvider, Set<BuildTask> submittedBuildTasks) throws CoreException {
BuildSetTask buildSetTask = initBuildSetTask(buildConfigurationSet, user, buildOptions);
Set<BuildConfigurationAudited> buildConfigurationAuditeds = new HashSet<>();
for (BuildConfiguration buildConfiguration : datastoreAdapter.getBuildConfigurations(buildConfigurationSet)) {
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedsMap.get(buildConfiguration.getId());
if (buildConfigurationAudited == null) {
buildConfigurationAudited = datastoreAdapter.getLatestBuildConfigurationAuditedInitializeBCDependencies(buildConfiguration.getId());
}
buildConfigurationAuditeds.add(buildConfigurationAudited);
}
// initializeBuildTasksInSet
log.debug("Initializing BuildTasks In Set for BuildConfigurationAuditeds: {}.", buildConfigurationAuditeds.stream().map(BuildConfigurationAudited::toString).collect(Collectors.joining("; ")));
fillBuildTaskSet(buildSetTask, user, buildTaskIdProvider, buildConfigurationSet.getCurrentProductMilestone(), buildConfigurationAuditeds, submittedBuildTasks, buildOptions);
return buildSetTask;
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class DefaultBuildCoordinator method markFinished.
private synchronized void markFinished(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
log.debug("Finishing buildTask {}. Setting status {}.", task, status);
buildQueue.removeTask(task);
task.setStatus(status);
task.setStatusDescription(statusDescription);
switch(status) {
case DONE:
case REJECTED_ALREADY_BUILT:
buildQueue.executeNewReadyTasks();
break;
case REJECTED:
case REJECTED_FAILED_DEPENDENCIES:
case SYSTEM_ERROR:
case DONE_WITH_ERRORS:
case CANCELLED:
handleErroneousFinish(task);
break;
default:
throw new IllegalArgumentException("Unhandled build task status: " + task.getStatus() + ". Build task: " + task);
}
BuildSetTask buildSetTask = task.getBuildSetTask();
if (buildSetTask != null && buildSetTask.isFinished()) {
completeBuildSetTask(buildSetTask);
}
}
Aggregations