use of org.jboss.pnc.spi.datastore.DatastoreException 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.datastore.DatastoreException 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.spi.datastore.DatastoreException 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);
}
use of org.jboss.pnc.spi.datastore.DatastoreException in project pnc by project-ncl.
the class DefaultBuildCoordinator method processBuildTask.
private void processBuildTask(BuildTask task) {
try {
// process only tasks with status ENQUEUED
synchronized (task) {
if (task.getStatus() != BuildCoordinationStatus.ENQUEUED) {
log.debug("Skipping the execution of build task {} as it has been processed already. Status: {}.", task.getId(), task.getStatus());
return;
}
if (!task.getBuildOptions().isForceRebuild() && !datastoreAdapter.requiresRebuild(task, new HashSet<>())) {
completeNoBuild(task, CompletionStatus.NO_REBUILD_REQUIRED);
return;
}
task.setStartTime(new Date());
updateBuildTaskStatus(task, BuildCoordinationStatus.BUILDING);
}
buildScheduler.startBuilding(task);
} catch (CoreException | ExecutorException e) {
log.debug(" Build coordination task failed. Setting it as SYSTEM_ERROR.", e);
updateBuildTaskStatus(task, BuildCoordinationStatus.SYSTEM_ERROR, e.getMessage());
try {
datastoreAdapter.storeResult(task, Optional.empty(), e);
} catch (DatastoreException e1) {
log.error("Unable to store error [" + e.getMessage() + "] of build coordination task [" + task.getId() + "].", e1);
}
} catch (Error error) {
log.error("Build coordination task failed with error! Setting it as SYSTEM_ERROR.", error);
log.error("The system probably is in an invalid state!");
updateBuildTaskStatus(task, BuildCoordinationStatus.SYSTEM_ERROR, error.getMessage());
try {
datastoreAdapter.storeResult(task, Optional.empty(), error);
} catch (DatastoreException e1) {
log.error("Unable to store error [" + error.getMessage() + "] of build coordination task [" + task.getId() + "].", e1);
}
throw error;
} finally {
ProcessStageUtils.logProcessStageEnd(BuildCoordinationStatus.ENQUEUED.toString());
}
}
use of org.jboss.pnc.spi.datastore.DatastoreException in project pnc by project-ncl.
the class StatusUpdatesTest method BuildTaskCallbacksShouldBeCalled.
@Test
@InSequence(30)
public void BuildTaskCallbacksShouldBeCalled() throws DatastoreException, CoreException {
User user = User.Builder.newBuilder().id(3).username("test-user-3").build();
Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
}).getBuildTasks();
Set<String> tasksIds = buildTasks.stream().map((BuildTask::getId)).collect(Collectors.toSet());
Set<String> receivedUpdatesForId = new HashSet<>();
Consumer<BuildStatusChangedEvent> statusChangeEventConsumer = (statusChangedEvent) -> {
receivedUpdatesForId.add(statusChangedEvent.getBuild().getId());
};
tasksIds.forEach((id) -> buildStatusNotifications.subscribe(new BuildCallBack(id, statusChangeEventConsumer)));
buildTasks.forEach((bt) -> buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE));
System.out.println("Received updates: " + receivedUpdatesForId);
tasksIds.forEach((id) -> Assert.assertTrue("Did not receive update for task " + id, receivedUpdatesForId.contains(id)));
}
Aggregations