use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.
the class TemporaryBuildsCleanerAsyncInvoker method deleteTemporaryBuildConfigSetRecord.
/**
* Deletes a temporary BuildConfigSetRecord.
*
* @param buildConfigSetRecordId ID of the BuildConfigSetRecord to be deleted
* @param authToken Bearer token
* @param onComplete Operation to be executed after deletion operation
* @return True if the build exists and deletion started otherwise, false is build doesn't exist
* @throws ValidationException Thrown when build cannot be deleted
*/
public boolean deleteTemporaryBuildConfigSetRecord(Integer buildConfigSetRecordId, String authToken, Consumer<Result> onComplete) throws ValidationException {
BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(buildConfigSetRecordId);
if (buildConfigSetRecord == null) {
return false;
}
if (!buildConfigSetRecord.isTemporaryBuild()) {
throw new ValidationException("Only deletion of the temporary builds is allowed");
}
executorService.submit(() -> {
try {
Result result = temporaryBuildsCleaner.deleteTemporaryBuildConfigSetRecord(buildConfigSetRecordId, authToken);
onComplete.accept(result);
} catch (ValidationException e) {
logger.error("Failed to delete temporary buildConfigSetRecord.id: " + buildConfigSetRecordId + ".", e);
onComplete.accept(new Result(buildConfigSetRecordId.toString(), ResultStatus.FAILED, "Failed to delete temporary buildConfigSetRecord."));
}
});
return true;
}
use of org.jboss.pnc.model.BuildConfigSetRecord 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.model.BuildConfigSetRecord 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.model.BuildConfigSetRecord in project pnc by project-ncl.
the class BuildTasksInitializer method initBuildSetTask.
private BuildSetTask initBuildSetTask(BuildConfigurationSet buildConfigurationSet, User user, BuildOptions buildOptions) throws CoreException {
BuildConfigSetRecord buildConfigSetRecord = BuildConfigSetRecord.Builder.newBuilder().buildConfigurationSet(buildConfigurationSet).user(user).startTime(new Date()).status(org.jboss.pnc.enums.BuildStatus.BUILDING).temporaryBuild(buildOptions.isTemporaryBuild()).alignmentPreference(buildOptions.getAlignmentPreference()).build();
final BuildConfigSetRecord configSetRecord;
try {
configSetRecord = saveBuildConfigSetRecord(buildConfigSetRecord);
} catch (DatastoreException e) {
log.error("Failed to store build config set record: " + e);
throw new CoreException(e);
}
return BuildSetTask.Builder.newBuilder().buildConfigSetRecord(configSetRecord).buildOptions(buildOptions).build();
}
use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.
the class DefaultBuildCoordinator method updateBuildSetTaskStatus.
private void updateBuildSetTaskStatus(BuildSetTask buildSetTask, BuildSetStatus status, String description) {
log.info("Setting new status {} on buildSetTask.id {}. Description: {}.", status, buildSetTask.getId(), description);
BuildSetStatus oldStatus = buildSetTask.getStatus();
Optional<BuildConfigSetRecord> buildConfigSetRecord = buildSetTask.getBuildConfigSetRecord();
// Completed BuildSets are updated using BuildSetTask#taskStatusUpdatedToFinalState()
if (buildConfigSetRecord.isPresent() && REJECTED_STATES.containsKey(status)) {
buildConfigSetRecord.get().setStatus(REJECTED_STATES.get(status));
try {
datastoreAdapter.saveBuildConfigSetRecord(buildConfigSetRecord.get());
} catch (DatastoreException de) {
log.warn("Failed to update build config set record to REJECTED status: " + de);
}
}
buildConfigSetRecord.ifPresent(record -> sendSetStatusChangeEvent(buildSetTask, status, oldStatus, record, description));
buildSetTask.setStatus(status);
buildSetTask.setStatusDescription(description);
}
Aggregations