use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class ProjectBuilder method buildProject.
BuildTask buildProject(BuildConfiguration buildConfiguration, BuildCoordinator buildCoordinator, Consumer<BuildStatusChangedEvent> onStatusUpdate, BuildOptions buildOptions) throws BuildConflictException, InterruptedException, CoreException {
log.debug("Building project {}", buildConfiguration.getName());
List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
receivedStatuses.add(statusUpdate);
onStatusUpdate.accept(statusUpdate);
};
// Defines a number of callbacks, which are executed after buildStatus update
final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, N_STATUS_UPDATES_PER_TASK);
BuildSetTask taskSet = buildCoordinator.build(buildConfiguration, MockUser.newTestUser(1), buildOptions);
Set<BuildTask> buildTasks = taskSet.getBuildTasks();
assertThat(buildTasks).hasSize(1);
BuildTask buildTask = buildTasks.iterator().next();
log.info("Started build task {}", buildTask);
assertBuildStartedSuccessfully(buildTask);
waitForStatusUpdates(N_STATUS_UPDATES_PER_TASK, semaphore, "");
return buildTask;
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class ProjectWithFailedTransitiveDependenciesBuildTest method buildFailingProjectTestCase.
@Test
@InSequence(10)
public void buildFailingProjectTestCase() throws Exception {
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastore);
BuildCoordinatorBeans buildCoordinatorBeans = buildCoordinatorFactory.createBuildCoordinator(datastore);
BuildCoordinator coordinator = buildCoordinatorBeans.coordinator;
buildQueue = buildCoordinatorBeans.queue;
buildFailingProject(configurationBuilder.buildConfigurationSetWithFailedDependenciesAndDelay(1), 1, 2, coordinator);
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class CancelledBuildTest method cancelBuildingConfigSetTestCase.
@Test(timeout = 5_000)
public void cancelBuildingConfigSetTestCase() throws Exception {
// given
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
BuildConfigurationSet configurationSet = configurationBuilder.buildConfigurationSetForCancel(1);
List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
receivedStatuses.add(event);
if (event.getBuild().getBuildConfigRevision().getId().equals("2") && event.getNewStatus().equals(BuildStatus.BUILDING)) {
CompletableFuture.runAsync(() -> {
try {
// wait a bit for build execution to start
Thread.sleep(250);
// we need to get buildConfigSet id to cancel BuildGroup, it is not provided by event class
// directly, so we need to dit it up from buildTaskId that event provides
log.info("Cancelling ...");
coordinator.cancelSet(getBuildConfigSetId(coordinator, event.getBuild().getId()));
} catch (CoreException | InterruptedException e) {
log.error("Unable to cancel the build.", e);
Assert.fail("Unable to cancel the build.");
}
});
}
};
// when
BuildSetTask buildSetTask = buildProjects(configurationSet, coordinator, onStatusUpdate, 2);
// expect
List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
Assert.assertEquals("Incorrect number of build records in datastore: " + buildRecords, 3, buildRecords.size());
for (BuildRecord buildRecord : buildRecords) {
Assert.assertNotNull(buildRecord.getSubmitTime());
switch(buildRecord.getBuildConfigurationId()) {
case 1:
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
continue;
case 2:
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
break;
case 3:
Assert.assertEquals(BuildStatus.SUCCESS, buildRecord.getStatus());
break;
default:
Assert.fail("Invalid build configuration ID");
break;
}
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
}
// 3 is independent, 2 is dependent on 3, 1 is dependent on 2
for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
String buildTaskId = buildTask.getId();
switch(buildTask.getBuildConfigurationAudited().getId()) {
case 1:
// Building status is skipped (cancelled before it can start building)
assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
break;
case 2:
assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
break;
case 3:
assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.SUCCESS, buildTaskId);
break;
default:
break;
}
}
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator in project pnc by project-ncl.
the class CancelledBuildByBpmTest method buildSingleProjectTestCase.
@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
// given
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastoreMock);
SystemConfig systemConfig = createConfiguration();
BuildQueue queue = new BuildQueue(systemConfig);
BlockingQueue<BuildStatusChangedEvent> receivedStatuses = new ArrayBlockingQueue<>(5);
Consumer<BuildStatusChangedEvent> onStatusUpdate = receivedStatuses::add;
EventListener buildStatusChangedEventNotifier = new EventListener(onStatusUpdate);
BlockingQueue<BpmTask> task = new ArrayBlockingQueue<>(5);
Consumer<BpmTask> onBpmTaskCreated = task::add;
BuildSchedulerFactory buildSchedulerFactory = new BuildSchedulerFactory(onBpmTaskCreated);
BuildCoordinator coordinator = new DefaultBuildCoordinator(datastoreAdapter, buildStatusChangedEventNotifier, null, buildSchedulerFactory, queue, systemConfig, groupBuildMapper, buildMapper);
coordinator.start();
queue.initSemaphore();
coordinator.build(configurationBuilder.buildConfigurationToCancel(1, "c1-bpm"), MockUser.newTestUser(1), new BuildOptions());
waitForStatus(receivedStatuses, BuildStatus.BUILDING);
BpmTask bpmTask = task.poll(1, TimeUnit.SECONDS);
BuildResultRest result = new BuildResultRest();
result.setCompletionStatus(CompletionStatus.CANCELLED);
// when
bpmTask.notify(BUILD_COMPLETE, result);
waitForStatus(receivedStatuses, BuildStatus.CANCELLED);
// expect
List<BuildRecord> buildRecords = datastoreMock.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());
}
use of org.jboss.pnc.spi.coordinator.BuildCoordinator 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);
}
Aggregations