Search in sources :

Example 16 with BuildStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildStatusChangedEvent 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)

Example 17 with BuildStatusChangedEvent

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

the class BuildStatusNotifications method observeEvent.

public void observeEvent(@Observes BuildStatusChangedEvent event) {
    log.debug("Observed new status changed event {}.", event);
    // Avoid CDI runtime issue issue NCL-1505
    BuildStatusChangedEvent buildStatusChangedEvent = event;
    Predicate<BuildCallBack> filterSubscribersMatchingTaskId = (callBackUrl) -> callBackUrl.getBuildTaskId().equals(buildStatusChangedEvent.getBuild().getId());
    Set<BuildCallBack> matchingTasks = subscribers.stream().filter(filterSubscribersMatchingTaskId).collect(Collectors.toSet());
    matchingTasks.forEach((buildCallBack) -> removeListenersOfCompletedTasks(buildCallBack, buildStatusChangedEvent));
    matchingTasks.forEach((buildCallBack) -> buildCallBack.callback(buildStatusChangedEvent));
    log.debug("Status changed event processed {}.", event);
}
Also used : HashSet(java.util.HashSet) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Observes(javax.enterprise.event.Observes) LoggerFactory(org.slf4j.LoggerFactory) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Set(java.util.Set) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Collectors(java.util.stream.Collectors) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent)

Aggregations

BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)17 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)9 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)9 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)9 Test (org.junit.Test)9 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 BuildOptions (org.jboss.pnc.spi.BuildOptions)7 Inject (javax.inject.Inject)6 BuildStatus (org.jboss.pnc.enums.BuildStatus)6 BuildRecord (org.jboss.pnc.model.BuildRecord)6 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 List (java.util.List)5 Consumer (java.util.function.Consumer)5 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)5 CoreException (org.jboss.pnc.spi.exception.CoreException)5 Set (java.util.Set)4 Deployment (org.jboss.arquillian.container.test.api.Deployment)4