Search in sources :

Example 21 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getPreferredLatestSuccessfulBuildRecordWithBuildConfig.

@Override
public BuildRecord getPreferredLatestSuccessfulBuildRecordWithBuildConfig(Integer configurationId, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationId(configurationId), withSuccess(), includeTemporary(configurationId, temporaryBuild, alignmentPreference));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Example 22 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class DefaultDatastore method hasARebuiltExplicitDependency.

/**
 * Check is some of the dependencies defined on BuildConfiguration has newer version.
 */
private boolean hasARebuiltExplicitDependency(BuildRecord latestSuccessfulBuildRecord, Set<BuildConfiguration> dependencies, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
    for (BuildConfiguration dependencyBuildConfiguration : dependencies) {
        BuildRecord dependencyLatestSuccessfulBuildRecord = buildRecordRepository.getPreferredLatestSuccessfulBuildRecordWithBuildConfig(dependencyBuildConfiguration.getId(), temporaryBuild, alignmentPreference);
        if (dependencyLatestSuccessfulBuildRecord == null) {
            return true;
        }
        boolean newer = dependencyLatestSuccessfulBuildRecord.getEndTime().after(latestSuccessfulBuildRecord.getEndTime());
        if (newer) {
            return true;
        }
    }
    return false;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 23 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.

/**
 * @param buildConfigurationId
 * @return List of BuildRecords where only id is fetched
 */
private List<BuildRecord> getBuildRecords(Integer buildConfigurationId) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Base32LongID> query = cb.createQuery(Base32LongID.class);
    Root<BuildRecord> root = query.from(BuildRecord.class);
    query.select(root.get(BuildRecord_.id));
    query.where(cb.equal(root.get(BuildRecord_.buildConfigurationId), buildConfigurationId));
    List<Base32LongID> buildRecordIds = entityManager.createQuery(query).getResultList();
    return buildRecordIds.stream().map(id -> BuildRecord.Builder.newBuilder().id(id).build()).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) Project(org.jboss.pnc.model.Project) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) BuildRecord_(org.jboss.pnc.model.BuildRecord_) Set(java.util.Set) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) AuditReaderFactory(org.hibernate.envers.AuditReaderFactory) AuditEntity(org.hibernate.envers.query.AuditEntity) Base32LongID(org.jboss.pnc.model.Base32LongID) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 24 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.

/**
 * @param idRev
 * @return List of BuildRecords where only id is fetched
 */
private List<BuildRecord> getBuildRecords(IdRev idRev) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Base32LongID> query = cb.createQuery(Base32LongID.class);
    Root<BuildRecord> root = query.from(BuildRecord.class);
    query.select(root.get(BuildRecord_.id));
    query.where(cb.and(cb.equal(root.get(BuildRecord_.buildConfigurationId), idRev.getId()), cb.equal(root.get(BuildRecord_.buildConfigurationRev), idRev.getRev())));
    List<Base32LongID> buildRecordIds = entityManager.createQuery(query).getResultList();
    return buildRecordIds.stream().map(id -> BuildRecord.Builder.newBuilder().id(id).build()).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) Project(org.jboss.pnc.model.Project) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) BuildRecord_(org.jboss.pnc.model.BuildRecord_) Set(java.util.Set) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) AuditReaderFactory(org.hibernate.envers.AuditReaderFactory) AuditEntity(org.hibernate.envers.query.AuditEntity) Base32LongID(org.jboss.pnc.model.Base32LongID) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 25 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class TemporaryBuildsCleanerTest method shouldNotReturnWithNewNoRebuildRecord.

@Test
public void shouldNotReturnWithNewNoRebuildRecord() throws Exception {
    // given
    BuildRecord tempBr = initBuildRecordBuilder().submitTime(Date.from(Instant.now().minus(2, ChronoUnit.DAYS))).endTime(Date.from(Instant.now().minus(2, ChronoUnit.DAYS))).temporaryBuild(true).build();
    tempBr = buildRecordRepository.save(tempBr);
    BuildRecord tempNRRBr = initBuildRecordBuilder().status(BuildStatus.NO_REBUILD_REQUIRED).noRebuildCause(tempBr).temporaryBuild(true).build();
    tempNRRBr = buildRecordRepository.save(tempNRRBr);
    // when
    Page<Build> builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, Date.from(Instant.now().minus(1, ChronoUnit.DAYS)).getTime());
    // then
    assertThat(builds.getContent()).extracting("id", String.class).doesNotContain(BuildMapper.idMapper.toDto(tempBr.getId()), BuildMapper.idMapper.toDto(tempNRRBr.getId()));
}
Also used : Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10