use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class StatusUpdatesTest method buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState.
@Test
@InSequence(10)
public void buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState() throws DatastoreException, InterruptedException, CoreException {
ObjectWrapper<BuildSetStatusChangedEvent> receivedBuildSetStatusChangedEvent = new ObjectWrapper<>();
Consumer<BuildSetStatusChangedEvent> statusUpdateListener = receivedBuildSetStatusChangedEvent::set;
testCDIBuildSetStatusChangedReceiver.addBuildSetStatusChangedEventListener(statusUpdateListener);
User user = User.Builder.newBuilder().id(1).username("test-user-1").build();
Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
}).getBuildTasks();
buildTasks.forEach((bt) -> {
buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE);
buildCoordinator.completeBuild(bt, createBuildResult());
});
this.waitForConditionWithTimeout(() -> buildTasks.stream().allMatch(task -> task.getStatus().isCompleted()), 4);
Assert.assertNotNull("Did not receive build set status update.", receivedBuildSetStatusChangedEvent.get());
Assert.assertEquals(BuildSetStatus.DONE, receivedBuildSetStatusChangedEvent.get().getNewStatus());
}
use of org.jboss.pnc.spi.coordinator.BuildTask 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.BuildTask in project pnc by project-ncl.
the class DefaultBuildCoordinator method handleErroneousFinish.
private void handleErroneousFinish(BuildTask failedTask) {
BuildSetTask taskSet = failedTask.getBuildSetTask();
if (taskSet != null) {
log.debug("Finishing tasks in set {}, after failedTask {}.", taskSet, failedTask);
taskSet.getBuildTasks().stream().filter(t -> isDependentOn(failedTask, t)).filter(t -> !t.getStatus().isCompleted()).forEach(t -> finishDueToFailedDependency(failedTask, t));
}
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class DefaultBuildCoordinator method isBuildConfigurationAlreadyInQueue.
private boolean isBuildConfigurationAlreadyInQueue(BuildTask buildTask) {
BuildConfigurationAudited buildConfigurationAudited = buildTask.getBuildConfigurationAudited();
Optional<BuildTask> unfinishedTask = buildQueue.getUnfinishedTask(buildConfigurationAudited);
if (unfinishedTask.isPresent()) {
log.debug("Task with the same buildConfigurationAudited is in the queue {}.", unfinishedTask.get());
return true;
} else {
return false;
}
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BpmBuildScheduler method cancel.
@Override
public boolean cancel(BuildTask buildTask) {
Map<String, String> genericParameters = buildTask.getBuildConfigurationAudited().getGenericParameters();
BpmBuildTask task = new BpmBuildTask(buildTask);
if (useNewProcessForBuild(genericParameters, bpmConfig.isNewBpmForced())) {
return restConnector.cancelByCorrelation(buildTask.getId(), task.getAccessToken());
} else {
Optional<BpmBuildTask> taskOptional = manager.getActiveTasks().stream().filter(bpmTask -> bpmTask instanceof BpmBuildTask).map(bpmTask -> (BpmBuildTask) bpmTask).filter(bpmTask -> bpmTask.getBuildTask().getId().equals(buildTask.getId())).findAny();
if (taskOptional.isPresent()) {
return manager.cancelTask(taskOptional.get());
} else {
return false;
}
}
}
Aggregations