use of org.jboss.pnc.spi.events.BuildSetStatusChangedEvent in project pnc by project-ncl.
the class BuildSetStatusNotifications method observeEvent.
public void observeEvent(@Observes BuildSetStatusChangedEvent event) {
log.debug("Observed BuildSetStatusChangedEvent {}.", event);
// Avoid CDI runtime issue NCL-1505
BuildSetStatusChangedEvent buildSetStatusChangedEvent = event;
Predicate<BuildSetCallBack> filterSubscribersMatchingTaskId = (callBackUrl) -> callBackUrl.getBuildSetConfigurationId().equals(Integer.valueOf(buildSetStatusChangedEvent.getBuildSetConfigurationId()));
Set<BuildSetCallBack> matchingTask = subscribers.stream().filter(filterSubscribersMatchingTaskId).collect(Collectors.toSet());
log.debug("Notifying {} of {} total subscribers with event {}.", matchingTask.size(), subscribers.size(), buildSetStatusChangedEvent);
matchingTask.forEach((buildSetCallBack) -> {
log.trace("Executing buildSetCallBack for buildSetConfigurationId {} with {}.", buildSetCallBack.getBuildSetConfigurationId(), buildSetStatusChangedEvent);
buildSetCallBack.callback(buildSetStatusChangedEvent);
});
matchingTask.forEach((buildSetCallBack) -> removeListenersOfCompletedTasks(buildSetCallBack, buildSetStatusChangedEvent));
}
use of org.jboss.pnc.spi.events.BuildSetStatusChangedEvent 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.events.BuildSetStatusChangedEvent in project pnc by project-ncl.
the class DefaultBuildCoordinator method sendSetStatusChangeEvent.
private void sendSetStatusChangeEvent(BuildSetTask buildSetTask, BuildSetStatus status, BuildSetStatus oldStatus, BuildConfigSetRecord record, String description) {
BuildSetStatusChangedEvent event = new DefaultBuildSetStatusChangedEvent(oldStatus, status, groupBuildMapper.toDTO(record), description);
log.debug("Notifying build set status update {}.", event);
buildSetStatusChangedEventNotifier.fire(event);
}
use of org.jboss.pnc.spi.events.BuildSetStatusChangedEvent in project pnc by project-ncl.
the class WebSocketsNotificationTest method shouldReceiveBuildSetStatusChangeNotification.
@Test
@InSequence(3)
public void shouldReceiveBuildSetStatusChangeNotification() throws Exception {
// given
GroupBuild groupBuild = GroupBuild.builder().id("1").groupConfig(GroupConfigurationRef.refBuilder().id("1").name("BuildSet1").build()).startTime(Instant.ofEpochMilli(1453118400000L)).endTime(Instant.ofEpochMilli(1453122000000L)).user(User.builder().id("1").username("user1").build()).status(BuildStatus.SUCCESS).build();
BuildSetStatusChangedEvent buildStatusChangedEvent = new DefaultBuildSetStatusChangedEvent(BuildSetStatus.NEW, BuildSetStatus.DONE, groupBuild, "description");
String groupBuildString = mapperProvider.getMapper().writeValueAsString(groupBuild);
String expectedJsonResponse = "{\"groupBuild\":" + groupBuildString + ",\"job\":\"GROUP_BUILD\",\"notificationType\":\"GROUP_BUILD_STATUS_CHANGED\",\"progress\":\"FINISHED\",\"oldProgress\":\"IN_PROGRESS\",\"message\":null}";
// when
buildSetStatusNotificationEvent.fire(buildStatusChangedEvent);
// then
Wait.forCondition(() -> isReceived(expectedJsonResponse), 15, ChronoUnit.SECONDS);
}
use of org.jboss.pnc.spi.events.BuildSetStatusChangedEvent 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;
}
Aggregations