use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class GroupConfigurationEndpointImpl method triggerBuild.
private GroupBuild triggerBuild(String groupConfigId, Optional<GroupBuildRequest> buildConfigRevisions, GroupBuildParameters buildParams) {
try {
BuildOptions buildOptions = toBuildOptions(buildParams);
int groupBuildId = buildTriggerer.triggerGroupBuild(Integer.parseInt(groupConfigId), buildConfigRevisions, buildOptions);
return groupBuildProvider.getSpecific(Integer.toString(groupBuildId));
} catch (BuildConflictException ex) {
throw new AlreadyRunningException(ex, ex.getBuildTaskId());
} catch (CoreException ex) {
throw new RuntimeException(ex);
}
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class CancelledBuildTest method buildSingleProjectTestCase.
@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
// given
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastore);
BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastore).coordinator;
List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
receivedStatuses.add(event);
if (event.getNewStatus().equals(BuildStatus.BUILDING)) {
CompletableFuture.runAsync(() -> {
try {
// wait a bit for build execution to start
Thread.sleep(250);
coordinator.cancel(event.getBuild().getId());
} catch (CoreException | InterruptedException e) {
log.error("Unable to cancel the build.", e);
Assert.fail("Unable to cancel the build.");
}
});
}
};
// when
BuildTask buildTask = buildProject(configurationBuilder.buildConfigurationToCancel(1, "c1-java"), coordinator, onStatusUpdate);
// expect
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
Assert.assertNotNull(buildRecord.getSubmitTime());
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
String buildTaskId = buildTask.getId();
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
}
use of org.jboss.pnc.spi.exception.CoreException 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)));
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class ProjectBuilder method buildProjectsAndWaitForUpdates.
private BuildSetTask buildProjectsAndWaitForUpdates(BuildConfigurationSet buildConfigurationSet, BuildCoordinator buildCoordinator, int nStatusUpdates, Consumer<BuildStatusChangedEvent> onStatusUpdate, List<BuildStatusChangedEvent> receivedStatuses, List<BuildSetStatusChangedEvent> receivedSetStatuses) throws InterruptedException, CoreException {
Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
log.debug("Received status change event [" + (i++) + "]: {}.", statusUpdate);
receivedStatuses.add(statusUpdate);
onStatusUpdate.accept(statusUpdate);
};
final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, nStatusUpdates);
final Semaphore buildSetSemaphore = registerBuildSetListeners(receivedSetStatuses, BUILD_SET_STATUS_UPDATES);
BuildOptions buildOptions = new BuildOptions();
buildOptions.setRebuildMode(RebuildMode.FORCE);
BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, MockUser.newTestUser(1), buildOptions);
assertBuildStartedSuccessfully(buildSetTask);
log.info("Waiting to receive all {} status updates...", nStatusUpdates);
waitForStatusUpdates(nStatusUpdates, semaphore, "");
log.debug("All status updates should be received. Semaphore has {} free entries.", semaphore.availablePermits());
log.info("Waiting to receive all {} build set status updates...", BUILD_SET_STATUS_UPDATES);
waitForStatusUpdates(BUILD_SET_STATUS_UPDATES, buildSetSemaphore, "build set task: " + buildSetTask);
log.debug("All status updates should be received. Semaphore has {} free entries.", semaphore.availablePermits());
return buildSetTask;
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class ReadDependenciesTest method createDependenciesTestCase.
@Test
public void createDependenciesTestCase() throws DatastoreException {
BuildConfigurationSet buildConfigurationSet = configurationBuilder.buildConfigurationSet(1);
User user = User.Builder.newBuilder().id(1).username("test-user").build();
BuildSetTask buildSetTask = null;
try {
buildSetTask = createBuildSetTask(buildConfigurationSet, user);
} catch (CoreException e) {
Assert.fail(e.getMessage());
}
Assert.assertEquals("Missing build tasks in set.", 5, buildSetTask.getBuildTasks().size());
BuildTask buildTask2 = buildSetTask.getBuildTasks().stream().filter(task -> task.getBuildConfigurationAudited().getId().equals(2)).findFirst().get();
Assert.assertEquals("Wrong number of dependencies.", 2, buildTask2.getDependencies().size());
}
Aggregations