Search in sources :

Example 21 with BuildConfiguration

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

the class BuildConfigurationAuditedRepositoryMock method save.

public BuildConfigurationAudited save(BuildConfigurationAudited entity) {
    IdRev idRev = entity.getIdRev();
    if (idRev == null) {
        throw new IllegalStateException("auto-setting " + this.getClass().getSimpleName() + " entity id is not supported");
    }
    BuildConfiguration buildConfiguration = entity.getBuildConfiguration();
    Integer newRev = idSequence.getAndIncrement();
    BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, newRev);
    getOptionalById(idRev).ifPresent(data::remove);
    data.add(entity);
    return entity;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IdRev(org.jboss.pnc.model.IdRev)

Example 22 with BuildConfiguration

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

the class DatastoreMock method storeCompletedBuild.

@Override
public BuildRecord storeCompletedBuild(BuildRecord.Builder buildRecordBuilder, List<Artifact> builtArtifacts, List<Artifact> dependencies) {
    buildRecordBuilder.dependencies(dependencies);
    BuildRecord buildRecord = Mockito.spy(buildRecordBuilder.build());
    Mockito.when(buildRecord.getBuiltArtifacts()).thenReturn(new HashSet<>(builtArtifacts));
    BuildConfiguration buildConfiguration = buildRecord.getBuildConfigurationAudited().getBuildConfiguration();
    log.info("Storing build " + buildConfiguration);
    synchronized (this) {
        boolean exists = getBuildRecords().stream().anyMatch(br -> br.equals(buildRecord));
        if (exists) {
            throw new PersistenceException("Unique constraint violation, the record with id [" + buildRecord.getId() + "] already exists.");
        }
        buildRecords.add(buildRecord);
    }
    return buildRecord;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) PersistenceException(javax.persistence.PersistenceException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 23 with BuildConfiguration

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

the class DatastoreMock method getLatestBuildConfigurationAuditedLoadBCDependencies.

@Override
public BuildConfigurationAudited getLatestBuildConfigurationAuditedLoadBCDependencies(Integer buildConfigurationId) {
    BuildConfiguration buildConfig = buildConfigurations.get(buildConfigurationId);
    int rev = buildConfigAuditedRevSequence.incrementAndGet();
    BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfig).rev(rev).build();
    return buildConfigurationAudited;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited)

Example 24 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration 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 25 with BuildConfiguration

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

the class BuildConfigurationAuditedRepositoryImpl method queryById.

@Override
public Map<IdRev, BuildConfigurationAudited> queryById(Set<IdRev> idRevs) {
    logger.trace("Querying for BuildConfigurationAudited.idRevs: {}.", idRevs);
    List<String> idRevConcatenated = idRevs.stream().map(idRev -> idRev.getId() + "-" + idRev.getRev()).collect(Collectors.toList());
    // WORKAROUND: as I cannot concatenate AuditEntity property to match
    // `AuditEntity.property("id")-AuditEntity.property("rev")` in idRevConcatenated list
    // I can query all BuildConfigurationAudited with the only id and later on filter id and rev
    List<Integer> bcaRevIds = idRevs.stream().map(IdRev::getRev).collect(Collectors.toList());
    // Getting all revisions of BuildConfiguration with specified list of IDs
    List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(AuditEntity.revisionNumber().in(bcaRevIds)).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
    return result.stream().filter(res -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) res[1];
        return idRevConcatenated.contains(buildConfiguration.getId() + "-" + revisionEntity.getId());
    }).peek(res -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
        // preload generic parameters
        buildConfiguration.getGenericParameters().forEach((k, v) -> k.equals(null));
    }).map(res -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) res[1];
        return BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, revisionEntity.getId());
    }).collect(Collectors.toMap(BuildConfigurationAudited::getIdRev, bca -> bca));
}
Also used : 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) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity)

Aggregations

BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)65 Test (org.junit.Test)23 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)11 HashSet (java.util.HashSet)10 BuildRecord (org.jboss.pnc.model.BuildRecord)9 Project (org.jboss.pnc.model.Project)9 BuildOptions (org.jboss.pnc.spi.BuildOptions)9 BuildResult (org.jboss.pnc.spi.BuildResult)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 List (java.util.List)8 Set (java.util.Set)8 Inject (javax.inject.Inject)8 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)8 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)8 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)8 IdRev (org.jboss.pnc.model.IdRev)7 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)7 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)7 Collectors (java.util.stream.Collectors)5