Search in sources :

Example 11 with BuildConfigurationAudited

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

the class LocalBuildScheduler method startBuilding.

@Override
public void startBuilding(BuildTask buildTask) throws CoreException {
    Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
        try {
            log.debug("Received execution status update {}.", statusChangedEvent);
            if (statusChangedEvent.getNewStatus().isCompleted()) {
                BuildResult buildResult = statusChangedEvent.getBuildResult().get();
                log.debug("Notifying build execution completed {}.", statusChangedEvent);
                buildCoordinator.completeBuild(buildTask, buildResult);
            }
        } catch (Throwable t) {
            log.error("Failed to notify build completion.", t);
        }
    };
    String contentId = ContentIdentityManager.getBuildContentId(buildTask.getId());
    BuildConfigurationAudited configuration = buildTask.getBuildConfigurationAudited();
    BuildExecutionConfiguration buildExecutionConfiguration = BuildExecutionConfiguration.build(buildTask.getId(), contentId, buildTask.getUser().getId().toString(), configuration.getBuildScript(), configuration.getId().toString(), configuration.getName(), configuration.getRepositoryConfiguration().getInternalUrl(), configuration.getScmRevision(), null, configuration.getRepositoryConfiguration().getExternalUrl(), configuration.getRepositoryConfiguration().isPreBuildSyncEnabled(), configuration.getBuildEnvironment().getSystemImageId(), configuration.getBuildEnvironment().getSystemImageRepositoryUrl(), configuration.getBuildEnvironment().getSystemImageType(), configuration.getBuildType(), buildTask.getBuildOptions().isKeepPodOnFailure(), configuration.getGenericParameters(), buildTask.getBuildOptions().isTemporaryBuild(), TimeUtils.generateTimestamp(buildTask.getBuildOptions().isTimestampAlignment(), buildTask.getBuildSetTask().getStartTime()), configuration.isBrewPullActive(), configuration.getDefaultAlignmentParams(), buildTask.getBuildOptions().getAlignmentPreference());
    try {
        buildExecutor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, buildTask.getUser().getLoginToken());
    } catch (ExecutorException e) {
        throw new CoreException("Could not start build execution.", e);
    }
}
Also used : TimeUtils(org.jboss.pnc.common.util.TimeUtils) Logger(org.slf4j.Logger) BuildScheduler(org.jboss.pnc.coordinator.builder.BuildScheduler) ContentIdentityManager(org.jboss.pnc.model.utils.ContentIdentityManager) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) LoggerFactory(org.slf4j.LoggerFactory) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildResult(org.jboss.pnc.spi.BuildResult) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)

Example 12 with BuildConfigurationAudited

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

the class BuildRecordRepositoryImpl method fetchBuildConfigurationAudited.

private void fetchBuildConfigurationAudited(BuildRecord buildRecord) {
    Integer revision = buildRecord.getBuildConfigurationRev();
    BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(new IdRev(buildRecord.getBuildConfigurationId(), revision));
    buildRecord.setBuildConfigurationAudited(buildConfigurationAudited);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordPredicates.withBuildConfigurationIdRev(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigurationIdRev) IdRev(org.jboss.pnc.model.IdRev)

Example 13 with BuildConfigurationAudited

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

the class DefaultDatastore method getLatestBuildConfigurationAuditedLoadBCDependencies.

@Override
public BuildConfigurationAudited getLatestBuildConfigurationAuditedLoadBCDependencies(Integer buildConfigurationId) {
    BuildConfigurationAudited buildConfigurationAudited = getLatestBuildConfigurationAudited(buildConfigurationId);
    buildConfigurationAudited.setBuildConfiguration(buildConfigurationRepository.queryById(buildConfigurationAudited.getBuildConfiguration().getId()));
    buildConfigurationAudited.getBuildConfiguration().getIndirectDependencies();
    return buildConfigurationAudited;
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited)

Example 14 with BuildConfigurationAudited

use of org.jboss.pnc.model.BuildConfigurationAudited 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)

Example 15 with BuildConfigurationAudited

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

the class BuildBCRevisionFetcher method mapFromAuditedBuildConfig.

@BeforeMapping
public void mapFromAuditedBuildConfig(BuildRecord build, @MappingTarget Build.Builder dtoBuilder) {
    Integer id = build.getBuildConfigurationId();
    Integer revision = build.getBuildConfigurationRev();
    // If somebody before us already set the BCA we don't need to query it from DB again
    BuildConfigurationAudited bca = build.getBuildConfigurationAudited();
    if (bca == null) {
        bca = bcAuditedRepository.queryById(new IdRev(id, revision));
    }
    BuildConfigurationRevisionRef bcRevision = bcRevisionMapper.toRef(bca);
    ProjectRef project = projectMapper.toRef(bca.getProject());
    Environment environment = environmentMapper.toRef(bca.getBuildEnvironment());
    SCMRepository scmRepository = scmRepositoryMapper.toRef(bca.getRepositoryConfiguration());
    dtoBuilder.buildConfigRevision(bcRevision);
    dtoBuilder.project(project);
    dtoBuilder.environment(environment);
    dtoBuilder.scmRepository(scmRepository);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Environment(org.jboss.pnc.dto.Environment) IdRev(org.jboss.pnc.model.IdRev) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository) BeforeMapping(org.mapstruct.BeforeMapping)

Aggregations

BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)35 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 IdRev (org.jboss.pnc.model.IdRev)12 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)10 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)10 Test (org.junit.Test)8 HashSet (java.util.HashSet)7 BuildRecord (org.jboss.pnc.model.BuildRecord)6 Date (java.util.Date)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Map (java.util.Map)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Base32LongID (org.jboss.pnc.model.Base32LongID)4 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 Stateless (javax.ejb.Stateless)3