Search in sources :

Example 66 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class BuildProviderImplTest method testGetLatestRunningBuild.

@Test
public void testGetLatestRunningBuild() {
    // Prepare
    mockBuildTask();
    mockBuildTask();
    mockBuildRecord();
    BuildTask latestRunning = mockBuildTask();
    mockBuildRecord();
    // When
    BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", true, true, "");
    Page<Build> builds = provider.getBuilds(pageInfo);
    // Verify
    assertEquals(1, builds.getTotalHits());
    assertEquals(latestRunning.getId(), builds.getContent().iterator().next().getId());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) Test(org.junit.Test)

Example 67 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class BuildProviderImplTest method testBuildIterator.

public void testBuildIterator() {
    SortInfo sortInfo = mock(SortInfo.class);
    Predicate<BuildRecord> predicate = mock(Predicate.class);
    mockRepository(sortInfo, predicate);
    BuildProviderImpl.BuildIterator bit;
    List<Integer> ret;
    bit = provider.new BuildIterator(1, 10, 1, sortInfo, predicate);
    ret = new ArrayList<>();
    while (bit.hasNext()) {
        Build next = bit.next();
        System.out.println("next: " + next);
        ret.add(Integer.valueOf(next.getId()));
    }
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
    bit = provider.new BuildIterator(1, 10, 10, sortInfo, predicate);
    ret = new ArrayList<>();
    while (bit.hasNext()) {
        ret.add(Integer.valueOf(bit.next().getId()));
    }
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
    bit = provider.new BuildIterator(1, 10, 100, sortInfo, predicate);
    ret = new ArrayList<>();
    while (bit.hasNext()) {
        ret.add(Integer.valueOf(bit.next().getId()));
    }
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
    bit = provider.new BuildIterator(7, 12, 100, sortInfo, predicate);
    ret = new ArrayList<>();
    while (bit.hasNext()) {
        ret.add(Integer.valueOf(bit.next().getId()));
    }
    assertEquals(Arrays.asList(7, 8, 9, 10, 11, 12), ret);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo)

Example 68 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class BuildProviderImplTest method testPage.

private void testPage(int idx, int size, Base32LongID... ids) {
    BuildPageInfo pageInfo = new BuildPageInfo(idx, size, "", "", false, false, "");
    Page<Build> builds = provider.getBuilds(pageInfo);
    Iterator<Build> it = builds.getContent().iterator();
    for (Base32LongID id : ids) {
        assertEquals(BuildMapper.idMapper.toDto(id), it.next().getId());
    }
    assertFalse(it.hasNext());
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo)

Example 69 with Build

use of org.jboss.pnc.dto.Build in project pnc by project-ncl.

the class DefaultBuildCoordinator method cancelSet.

@Override
public boolean cancelSet(int buildSetTaskId) {
    BuildConfigSetRecord record = datastoreAdapter.getBuildCongigSetRecordById(buildSetTaskId);
    if (record == null) {
        log.error("Could not find buildConfigSetRecord with id : {}", buildSetTaskId);
        return false;
    }
    log.debug("Cancelling Build Configuration Set: {}", buildSetTaskId);
    getSubmittedBuildTasks().stream().filter(Objects::nonNull).filter(t -> t.getBuildSetTask() != null && t.getBuildSetTask().getId().equals(buildSetTaskId)).forEach(buildTask -> {
        try {
            MDCUtils.addBuildContext(getMDCMeta(buildTask));
            log.debug("Received cancel request for buildTaskId: {}.", buildTask.getId());
            cancel(buildTask.getId());
        } catch (CoreException e) {
            log.error("Unable to cancel the build [" + buildTask.getId() + "].", e);
        } finally {
            MDCUtils.removeBuildContext();
        }
    });
    record.setStatus(BuildStatus.CANCELLED);
    record.setEndTime(Date.from(Instant.now()));
    try {
        datastoreAdapter.saveBuildConfigSetRecord(record);
    } catch (DatastoreException e) {
        log.error("Failed to update BuildConfigSetRecord (id: {} ) with status CANCELLED", record.getId(), e);
    }
    return true;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) ScheduledFuture(java.util.concurrent.ScheduledFuture) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) GroupBuildMapper(org.jboss.pnc.mapper.api.GroupBuildMapper) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Map(java.util.Map) CollectionUtils.hasCycle(org.jboss.pnc.common.util.CollectionUtils.hasCycle) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) EnumMap(java.util.EnumMap) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) Objects(java.util.Objects) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) PostConstruct(javax.annotation.PostConstruct) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) RepourResult(org.jboss.pnc.spi.repour.RepourResult) Quicksort(org.jboss.pnc.common.util.Quicksort) ExecutorService(java.util.concurrent.ExecutorService) Event(javax.enterprise.event.Event) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildRecord(org.jboss.pnc.model.BuildRecord) ProcessStageUtils(org.jboss.pnc.common.util.ProcessStageUtils) PollingMonitor(org.jboss.pnc.common.monitor.PollingMonitor) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) Sequence(org.jboss.pnc.common.concurrent.Sequence) CoreException(org.jboss.pnc.spi.exception.CoreException) Objects(java.util.Objects) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 70 with Build

use of org.jboss.pnc.dto.Build 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)71 Test (org.junit.Test)52 ContainerTest (org.jboss.pnc.test.category.ContainerTest)35 BuildClient (org.jboss.pnc.client.BuildClient)20 BuildRecord (org.jboss.pnc.model.BuildRecord)18 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)16 BuildStatus (org.jboss.pnc.enums.BuildStatus)15 GroupBuild (org.jboss.pnc.dto.GroupBuild)14 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)14 ArrayList (java.util.ArrayList)12 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)11 HashSet (java.util.HashSet)10 List (java.util.List)10 Set (java.util.Set)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Date (java.util.Date)9 Page (org.jboss.pnc.dto.response.Page)9 BuildMapper (org.jboss.pnc.mapper.api.BuildMapper)9 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)9