Search in sources :

Example 1 with BuildSetStatusChangedEvent

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));
}
Also used : HashSet(java.util.HashSet) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Observes(javax.enterprise.event.Observes) LoggerFactory(org.slf4j.LoggerFactory) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Set(java.util.Set) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Collectors(java.util.stream.Collectors) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent)

Example 2 with 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());
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) LoggerFactory(org.slf4j.LoggerFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) CoreException(org.jboss.pnc.spi.exception.CoreException) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IndyRepositoryManagerResult(org.jboss.pnc.indyrepositorymanager.IndyRepositoryManagerResult) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) RunWith(org.junit.runner.RunWith) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BuildCoordinatorDeployments(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildTasksInitializer(org.jboss.pnc.coordinator.builder.BuildTasksInitializer) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) Assert(org.junit.Assert) Sequence(org.jboss.pnc.common.concurrent.Sequence) Collections(java.util.Collections) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with BuildSetStatusChangedEvent

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);
}
Also used : BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent)

Example 4 with BuildSetStatusChangedEvent

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);
}
Also used : GroupBuild(org.jboss.pnc.dto.GroupBuild) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 5 with BuildSetStatusChangedEvent

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;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) Inject(javax.inject.Inject) TestCDIBuildSetStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildSetStatusChangedReceiver) Assert.fail(org.junit.Assert.fail) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Before(org.junit.Before) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) TestCDIBuildStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildStatusChangedReceiver) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) MockUser(org.jboss.pnc.mock.model.MockUser) CoreException(org.jboss.pnc.spi.exception.CoreException) Dependent(javax.enterprise.context.Dependent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArtifactBuilder(org.jboss.pnc.mock.model.builders.ArtifactBuilder) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Semaphore(java.util.concurrent.Semaphore)

Aggregations

BuildSetStatusChangedEvent (org.jboss.pnc.spi.events.BuildSetStatusChangedEvent)8 HashSet (java.util.HashSet)4 Set (java.util.Set)4 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)4 Test (org.junit.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 BuildStatus (org.jboss.pnc.enums.BuildStatus)3 RebuildMode (org.jboss.pnc.enums.RebuildMode)3 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)3 BuildOptions (org.jboss.pnc.spi.BuildOptions)3 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)3 Collections (java.util.Collections)2 Optional (java.util.Optional)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2