use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class SkippingBuiltConfigsTest method shouldTriggerTheSameBuildConfigurationWithNewRevision.
@Test
public void shouldTriggerTheSameBuildConfigurationWithNewRevision() throws Exception {
coordinator.start();
buildRecordRepository.clear();
// given
BuildConfiguration testConfiguration = config("shouldRejectBCWithNewRevision");
BuildOptions buildOptions = new BuildOptions();
buildOptions.setBuildDependencies(false);
// when
coordinator.build(testConfiguration, user, buildOptions);
BuildConfiguration updatedConfiguration = updateConfiguration(testConfiguration);
BuildSetTask buildSetTask;
boolean rejected = false;
try {
buildSetTask = coordinator.build(updatedConfiguration, user, buildOptions);
} catch (BuildConflictException e) {
rejected = true;
}
// then
Assert.assertFalse("The task was rejected.", rejected);
waitForEmptyBuildQueue();
assertThat(getNonRejectedBuildRecords().size()).isEqualTo(2);
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class BuildTasksInitializer method fillBuildTaskSet.
/**
* Creates build tasks and sets up the appropriate dependency relations
*
* @param buildSetTask The build set task which will contain the build tasks. This must already have initialized the
* BuildConfigSet, BuildConfigSetRecord, Milestone, etc.
*/
private void fillBuildTaskSet(BuildSetTask buildSetTask, User user, Supplier<String> buildTaskIdProvider, ProductMilestone productMilestone, Set<BuildConfigurationAudited> toBuild, Set<BuildTask> alreadySubmittedBuildTasks, BuildOptions buildOptions) {
for (BuildConfigurationAudited buildConfigAudited : toBuild) {
Optional<BuildTask> taskOptional = alreadySubmittedBuildTasks.stream().filter(bt -> bt.getBuildConfigurationAudited().equals(buildConfigAudited)).findAny();
BuildTask buildTask;
if (taskOptional.isPresent()) {
buildTask = taskOptional.get();
log.debug("Linking BuildConfigurationAudited {} to existing task {}.", buildConfigAudited, buildTask);
} else {
String buildId = buildTaskIdProvider.get();
String buildContentId = ContentIdentityManager.getBuildContentId(buildId);
// Used only for this operation inside the loop
MDCUtils.addBuildContext(buildContentId, buildOptions.isTemporaryBuild(), ExpiresDate.getTemporaryBuildExpireDate(temporaryBuildLifespanDays, buildOptions.isTemporaryBuild()), user.getId().toString());
try {
Optional<String> requestContext = MDCUtils.getRequestContext();
buildTask = BuildTask.build(buildConfigAudited, buildSetTask.getBuildOptions(), user, buildId, buildSetTask, buildSetTask.getStartTime(), productMilestone, buildContentId, requestContext);
log.debug("Created new buildTask {} for BuildConfigurationAudited {}.", buildTask, buildConfigAudited);
} finally {
MDCUtils.removeBuildContext();
}
}
buildSetTask.addBuildTask(buildTask);
}
// Loop again to set dependencies
for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
for (BuildTask checkDepBuildTask : buildSetTask.getBuildTasks()) {
if (buildTask.hasDirectConfigDependencyOn(checkDepBuildTask)) {
buildTask.addDependency(checkDepBuildTask);
}
}
}
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class BuildTasksInitializer method createBuildSetTask.
public BuildSetTask createBuildSetTask(BuildConfigurationAudited buildConfigurationAudited, User user, BuildOptions buildOptions, Supplier<String> buildTaskIdProvider, Set<BuildTask> submittedBuildTasks) {
BuildSetTask buildSetTask = BuildSetTask.Builder.newBuilder().buildOptions(buildOptions).startTime(new Date()).build();
Set<BuildConfigurationAudited> toBuild = new HashSet<>();
collectBuildTasks(buildConfigurationAudited, buildOptions, toBuild);
log.debug("Collected build tasks for the BuildConfigurationAudited: {}. Collected: {}.", buildConfigurationAudited, toBuild.stream().map(BuildConfigurationAudited::toString).collect(Collectors.joining(", ")));
fillBuildTaskSet(buildSetTask, user, buildTaskIdProvider, buildConfigurationAudited.getBuildConfiguration().getCurrentProductMilestone(), toBuild, submittedBuildTasks, buildOptions);
return buildSetTask;
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class DefaultBuildCoordinator method build.
/**
* Run a set of builds. Only the current/latest version of builds in the given set will be executed. The order of
* execution is determined by the dependency relations between the build configurations.
*
* @param buildConfigurationSet The set of builds to be executed.
* @param user The user who triggered the build.
* @param buildOptions Customization of a build specified by user
*
* @return The new build set task
* @throws CoreException Thrown if there is a problem initializing the build
*/
@Override
@Deprecated
public BuildSetTask build(BuildConfigurationSet buildConfigurationSet, User user, BuildOptions buildOptions) throws CoreException {
synchronized (buildMethodLock) {
BuildSetTask buildSetTask = buildTasksInitializer.createBuildSetTask(buildConfigurationSet, user, buildOptions, this::buildRecordIdSupplier, buildQueue.getUnfinishedTasks());
updateBuildSetTaskStatus(buildSetTask, BuildSetStatus.NEW);
validateAndEnqueueBuildConfigurationSetTasks(buildConfigurationSet, buildOptions, buildSetTask);
return buildSetTask;
}
}
use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.
the class DefaultBuildCoordinator method build0.
private BuildSetTask build0(User user, BuildOptions buildOptions, BuildConfigurationAudited buildConfigurationAudited) throws BuildConflictException {
synchronized (buildMethodLock) {
checkNotRunning(buildConfigurationAudited);
BuildSetTask buildSetTask = buildTasksInitializer.createBuildSetTask(buildConfigurationAudited, user, buildOptions, this::buildRecordIdSupplier, buildQueue.getUnfinishedTasks());
buildQueue.enqueueTaskSet(buildSetTask);
buildSetTask.getBuildTasks().stream().sorted(this::dependantsFirst).forEach(this::addTaskToBuildQueue);
return buildSetTask;
}
}
Aggregations