Search in sources :

Example 1 with DefaultBuildStatusChangedEvent

use of org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent in project pnc by project-ncl.

the class WebSocketsNotificationTest method shouldReceiveBuildStatusChangeNotification.

@Test
@InSequence(2)
public void shouldReceiveBuildStatusChangeNotification() throws Exception {
    // given
    Build build = BuildMock.newBuild(BuildStatus.SUCCESS, "Build1");
    BuildStatusChangedEvent buildStatusChangedEvent = new DefaultBuildStatusChangedEvent(build, BuildStatus.NEW, build.getStatus());
    String buildString = mapperProvider.getMapper().writeValueAsString(build);
    String expectedJsonResponse = "{\"oldStatus\":\"NEW\",\"build\":" + buildString + ",\"job\":\"BUILD\",\"notificationType\":\"BUILD_STATUS_CHANGED\",\"progress\":\"FINISHED\",\"oldProgress\":\"PENDING\",\"message\":null}";
    // when
    buildStatusNotificationEvent.fire(buildStatusChangedEvent);
    // then
    Wait.forCondition(() -> isReceived(expectedJsonResponse), 15, ChronoUnit.SECONDS);
}
Also used : GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with DefaultBuildStatusChangedEvent

use of org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent in project pnc by project-ncl.

the class ProcessProgressNotificationTest method shouldSubscribeToProcessUpdatesNotification.

@Test
public void shouldSubscribeToProcessUpdatesNotification() throws Exception {
    // given
    Integer taskId = 1;
    Build build = BuildMock.newBuild(taskId, BuildStatus.SUCCESS, "Build1");
    BuildStatusChangedEvent buildStatusChangedEvent = new DefaultBuildStatusChangedEvent(build, BuildStatus.NEW, build.getStatus());
    // when
    buildStatusNotificationEvent.fire(buildStatusChangedEvent);
    ProgressUpdatesRequest progressUpdatesRequest = new ProgressUpdatesRequest(Action.SUBSCRIBE, "component-build", taskId.toString());
    String text = JsonOutputConverterMapper.apply(new TypedMessage<>(MessageType.PROCESS_UPDATES, progressUpdatesRequest));
    logger.info("Sending test message:" + text);
    asyncRemote.sendText(text);
    waitForMessages(1);
    // then
    logger.info("Received: " + notificationCollector.getMessages().get(0));
    assertTrue(notificationCollector.getMessages().get(0).startsWith("{\"oldStatus\":\"NEW\",\"build\":{\"id\":\"1\",\"submitTime\":null,\"startTime\":null,\"endTime\":null,\"progress\":null,\"status\":\"SUCCESS\","));
}
Also used : Build(org.jboss.pnc.dto.Build) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) ProgressUpdatesRequest(org.jboss.pnc.notification.ProgressUpdatesRequest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with DefaultBuildStatusChangedEvent

use of org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent in project pnc by project-ncl.

the class DefaultBuildCoordinator method updateBuildTaskStatus.

private void updateBuildTaskStatus(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
    BuildCoordinationStatus oldStatus = task.getStatus();
    // REJECTED_ALREADY_BUILT -> DONE
    if (status.isCompleted() && !oldStatus.isCompleted()) {
        markFinished(task, status, statusDescription);
    } else {
        task.setStatus(status);
        task.setStatusDescription(statusDescription);
    }
    Build build = buildMapper.fromBuildTask(task);
    BuildStatusChangedEvent buildStatusChanged = new DefaultBuildStatusChangedEvent(build, BuildStatus.fromBuildCoordinationStatus(oldStatus), BuildStatus.fromBuildCoordinationStatus(status));
    log.debug("Updated build task {} status to {}; old coord status: {}, new coord status: {}", task.getId(), buildStatusChanged, oldStatus, status);
    userLog.info("Build status updated to {}; previous: {}", status, oldStatus);
    BuildStatus oldBuildStatus = BuildStatus.fromBuildCoordinationStatus(oldStatus);
    BuildStatus newBuildStatus = BuildStatus.fromBuildCoordinationStatus(status);
    if ((oldBuildStatus != newBuildStatus) && !(oldBuildStatus.isFinal() && newBuildStatus.isFinal())) {
        // only fire notification when BuildStatus changes
        // and avoid firing the notification when old and new statuses are final (NCL-5885)
        buildStatusChangedEventNotifier.fire(buildStatusChanged);
        log.debug("Fired buildStatusChangedEventNotifier after task {} status update to {}.", task.getId(), status);
    }
}
Also used : BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Build(org.jboss.pnc.dto.Build) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) BuildStatus(org.jboss.pnc.enums.BuildStatus)

Aggregations

Build (org.jboss.pnc.dto.Build)3 DefaultBuildStatusChangedEvent (org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent)3 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)3 ContainerTest (org.jboss.pnc.test.category.ContainerTest)2 Test (org.junit.Test)2 InSequence (org.jboss.arquillian.junit.InSequence)1 GroupBuild (org.jboss.pnc.dto.GroupBuild)1 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)1 BuildStatus (org.jboss.pnc.enums.BuildStatus)1 ProgressUpdatesRequest (org.jboss.pnc.notification.ProgressUpdatesRequest)1