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);
}
}
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;
}
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;
}
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());
}
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()));
}
Aggregations