Search in sources :

Example 56 with BuildRecord

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

the class BuildRecordRepositoryImpl method getLatestSuccessfulBuildRecord.

@Override
public BuildRecord getLatestSuccessfulBuildRecord(IdRev idRev, boolean temporaryBuild) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.id.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationIdRev(idRev), withSuccess(), includeTemporary(idRev, temporaryBuild));
    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 57 with BuildRecord

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

the class DefaultDatastore method requiresRebuild.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean requiresRebuild(BuildConfigurationAudited buildConfigurationAudited, boolean checkImplicitDependencies, boolean temporaryBuild, AlignmentPreference alignmentPreference, Set<Integer> processedDependenciesCache, Consumer<BuildRecord> nonRebuildCauseSetter) {
    IdRev idRev = buildConfigurationAudited.getIdRev();
    // Step 1 - Check the existence of a build with the same revision
    BuildRecord latestSuccessfulBuildRecord = buildRecordRepository.getAnyLatestSuccessfulBuildRecordWithRevision(idRev, temporaryBuild);
    if (latestSuccessfulBuildRecord == null) {
        logger.debug("Rebuild of buildConfiguration.idRev: {} required as there is no successful BuildRecord.", idRev);
        return true;
    }
    // Step 2 - Check the existence of more recent builds with different revision
    if (!isLatestSuccessBRFromThisBCA(buildConfigurationAudited, temporaryBuild)) {
        return true;
    }
    // Step 3 - check implicit dependencies
    if (checkImplicitDependencies) {
        logger.debug("Checking if BCA: {} has implicit dependencies that need rebuild", idRev);
        boolean rebuild = hasARebuiltImplicitDependency(latestSuccessfulBuildRecord, temporaryBuild, alignmentPreference, processedDependenciesCache);
        logger.debug("Implicit dependency check for rebuild of buildConfiguration.idRev: {} required: {}.", idRev, rebuild);
        if (rebuild) {
            return true;
        }
    }
    // Step 4 - check explicit dependencies
    Set<BuildConfiguration> dependencies = buildConfigurationAudited.getBuildConfiguration().getDependencies();
    boolean rebuild = hasARebuiltExplicitDependency(latestSuccessfulBuildRecord, dependencies, temporaryBuild, alignmentPreference);
    logger.debug("Explicit dependency check for rebuild of buildConfiguration.idRev: {} required: {}.", idRev, rebuild);
    if (!rebuild) {
        nonRebuildCauseSetter.accept(latestSuccessfulBuildRecord);
    }
    return rebuild;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) IdRev(org.jboss.pnc.model.IdRev) BuildRecord(org.jboss.pnc.model.BuildRecord) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 58 with BuildRecord

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

the class DefaultDatastore method storeCompletedBuild.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public BuildRecord storeCompletedBuild(BuildRecord.Builder buildRecordBuilder, List<Artifact> builtArtifacts, List<Artifact> dependencies) {
    BuildRecord buildRecord = buildRecordBuilder.build(true);
    logger.debug("Storing completed build {}.", buildRecord);
    BuildRecord previouslySavedBuild = buildRecordRepository.queryById(buildRecord.getId());
    if (previouslySavedBuild != null) {
        throw new IllegalStateException("When trying to save build " + buildRecord + " previously saved build with status " + previouslySavedBuild.getStatus() + " was found.");
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Build Log: {}.", buildRecord.getBuildLog());
    }
    Map<TargetRepository.IdentifierPath, TargetRepository> repositoriesCache = new HashMap<>();
    Map<Artifact.IdentifierSha256, Artifact> artifactCache = new HashMap<>();
    /**
     * Built artifacts must be saved before the dependencies. In case an artifact is built and the dependency
     * (re-downloaded), it must be linked to built artifacts repository.
     */
    logger.debug("Saving built artifacts ...");
    final Set<Artifact> savedBuiltArtifacts = saveArtifacts(builtArtifacts, repositoriesCache, artifactCache);
    logger.debug("Saving dependencies ...");
    buildRecord.setDependencies(saveArtifacts(dependencies, repositoriesCache, artifactCache));
    logger.debug("Done saving artifacts.");
    logger.trace("Saving build record {}.", buildRecord);
    buildRecord = buildRecordRepository.save(buildRecord);
    logger.debug("Build record {} saved.", buildRecord.getId());
    ArtifactQuality quality = buildRecord.isTemporaryBuild() ? ArtifactQuality.TEMPORARY : ArtifactQuality.NEW;
    logger.trace("Setting artifacts as built and their quality to {}.", quality);
    for (Artifact builtArtifact : savedBuiltArtifacts) {
        builtArtifact.setBuildRecord(buildRecord);
        builtArtifact.setArtifactQuality(quality);
    }
    return buildRecord;
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository) HashMap(java.util.HashMap) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) BuildRecord(org.jboss.pnc.model.BuildRecord) Artifact(org.jboss.pnc.model.Artifact) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 59 with BuildRecord

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

the class TemporaryBuildsCleanerTest method shouldDeleteSingleTemporaryBuildSetTestWithOneBr.

@Test
public void shouldDeleteSingleTemporaryBuildSetTestWithOneBr() throws Exception {
    // given
    BuildConfigSetRecord buildConfigSetRecord = initBuildConfigSetRecordBuilder().temporaryBuild(true).build();
    buildConfigSetRecordRepository.save(buildConfigSetRecord);
    BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).buildConfigSetRecord(buildConfigSetRecord).build();
    buildRecordRepository.save(tempBr);
    // when
    temporaryBuildsCleaner.deleteTemporaryBuildConfigSetRecord(buildConfigSetRecord.getId(), "");
    // then
    assertNull(buildConfigSetRecordRepository.queryById(buildConfigSetRecord.getId()));
    assertNull(buildRecordRepository.queryById(tempBr.getId()).getBuildConfigSetRecord());
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 60 with BuildRecord

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

the class TemporaryBuildsCleanerTest method shouldDeleteTemporaryBuildWithArtifactsTest.

@Test
public void shouldDeleteTemporaryBuildWithArtifactsTest() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException, ValidationException {
    // given
    Artifact artifact1 = storeAndGetArtifact();
    Artifact artifact2 = storeAndGetArtifact();
    Artifact artifact3 = storeAndGetArtifact();
    Artifact artifact4 = storeAndGetArtifact();
    Set<Artifact> dependencies = new HashSet<>();
    dependencies.add(artifact3);
    dependencies.add(artifact4);
    BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).build();
    tempBr.setDependencies(dependencies);
    BuildRecord savedTempBr = buildRecordRepository.save(tempBr);
    artifact1.setBuildRecord(savedTempBr);
    artifactRepository.save(artifact1);
    artifact2.setBuildRecord(savedTempBr);
    artifactRepository.save(artifact2);
    List<BuildRecord> givenBuilds = buildRecordRepository.queryAll();
    int numberOfBuilds = givenBuilds.size();
    // when
    temporaryBuildsCleaner.deleteTemporaryBuild(tempBr.getId(), "");
    // then
    assertEquals(numberOfBuilds - 1, buildRecordRepository.queryAll().size());
    assertNull(buildRecordRepository.queryById(tempBr.getId()));
    assertNull(artifactRepository.queryById(artifact1.getId()));
    assertNull(artifactRepository.queryById(artifact2.getId()));
    assertNotNull(artifactRepository.queryById(artifact3.getId()));
    assertNotNull(artifactRepository.queryById(artifact4.getId()));
}
Also used : Artifact(org.jboss.pnc.model.Artifact) BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) 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