use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.
the class IndyRepositorySession method collectUploads.
/**
* Return list of output artifacts for promotion.
*
* @param report The tracking report that contains info about artifacts uploaded (output) from the build
* @return List of output artifacts meta data
* @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
* artifacts
*/
private Uploads collectUploads(TrackedContentDTO report) throws RepositoryManagerException {
List<Artifact> data;
List<String> promotion;
logger.info("BEGIN: Process artifacts uploaded from build");
userLog.info("Processing built artifacts");
StopWatch stopWatch = StopWatch.createStarted();
Set<TrackedContentEntryDTO> uploads = report.getUploads();
if (CollectionUtils.isEmpty(uploads)) {
data = Collections.emptyList();
promotion = Collections.emptyList();
} else {
data = new ArrayList<>();
Set<String> promotionSet = new HashSet<>();
IndyContentClientModule content;
try {
content = indy.content();
} catch (IndyClientException e) {
throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
}
for (TrackedContentEntryDTO upload : uploads) {
String path = upload.getPath();
StoreKey storeKey = upload.getStoreKey();
if (artifactFilter.acceptsForData(upload)) {
String identifier = computeIdentifier(upload);
String purl = computePurl(upload);
logger.info("Recording upload: {}", identifier);
RepositoryType repoType = toRepoType(storeKey.getPackageType());
TargetRepository targetRepository = getUploadsTargetRepository(repoType, content);
ArtifactQuality artifactQuality = getArtifactQuality(isTempBuild);
Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(upload.getMd5()).sha1(upload.getSha1()).sha256(upload.getSha256()).size(upload.getSize()).deployPath(upload.getPath()).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository).artifactQuality(artifactQuality).buildCategory(buildCategory);
Artifact artifact = validateArtifact(artifactBuilder.build());
data.add(artifact);
}
if (artifactFilter.acceptsForPromotion(upload, false)) {
promotionSet.add(path);
if (MAVEN_PKG_KEY.equals(storeKey.getPackageType()) && !isChecksum(path)) {
// add the standard checksums to ensure, they are promoted (Maven usually uses only one, so
// the other would be missing) but avoid adding checksums of checksums.
promotionSet.add(path + ".md5");
promotionSet.add(path + ".sha1");
}
}
}
promotion = new ArrayList<>(promotionSet);
}
logger.info("END: Process artifacts uploaded from build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
return new Uploads(data, promotion);
}
use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.
the class TemporaryBuildsCleanerTest method shouldReturnOnlyTopLevelTemporaryBuilds.
@Test
public void shouldReturnOnlyTopLevelTemporaryBuilds() throws Exception {
// with
// top level BR1
BuildRecord br1 = initBuildRecordBuilder().temporaryBuild(true).build();
br1 = buildRecordRepository.save(br1);
Artifact art1br1 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br1).build();
Artifact art2br1 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br1).build();
artifactRepository.save(art1br1);
artifactRepository.save(art2br1);
Set<Artifact> depArtBr2 = new HashSet<>();
// independent BR2
BuildRecord br2 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr2).build();
br2 = buildRecordRepository.save(br2);
Artifact art1br2 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br2).build();
Artifact art2br2 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br2).build();
artifactRepository.save(art1br2);
artifactRepository.save(art2br2);
Set<Artifact> depArtBr3 = new HashSet<>();
depArtBr3.add(art1br1);
depArtBr3.add(art1br2);
// create implicitly dependent BR3 (BR3 is dependent on BR1)
BuildRecord br3 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr3).build();
br3 = buildRecordRepository.save(br3);
Artifact art1br3 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br3).build();
Artifact art2br3 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br3).build();
artifactRepository.save(art1br3);
artifactRepository.save(art2br3);
Set<Artifact> depArtBr4 = new HashSet<>();
depArtBr4.add(art2br2);
depArtBr4.add(art1br3);
// create implicitly dependent BR4 (BR4 is dependent on BR2 and BR3)
BuildRecord br4 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr4).build();
br4 = buildRecordRepository.save(br4);
Artifact art1br4 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br4).build();
Artifact art2br4 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br4).build();
artifactRepository.save(art1br4);
artifactRepository.save(art2br4);
BuildRecord finalBr1 = br1;
Condition<Build> hasBr1 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr1.getId()))), "Is Br1 with id " + BuildMapper.idMapper.toDto(finalBr1.getId()));
BuildRecord finalBr2 = br2;
Condition<Build> hasBr2 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr2.getId()))), "Is Br2 with id " + BuildMapper.idMapper.toDto(finalBr2.getId()));
BuildRecord finalBr3 = br3;
Condition<Build> hasBr3 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr3.getId()))), "Is Br3 with id " + BuildMapper.idMapper.toDto(finalBr3.getId()));
BuildRecord finalBr4 = br4;
Condition<Build> hasBr4 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr4.getId()))), "Is Br4 with id " + BuildMapper.idMapper.toDto(finalBr4.getId()));
// when #1
Page<Build> builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
// then #1
assertThat(builds.getContent()).doNotHave(hasBr1).doNotHave(hasBr2).doNotHave(hasBr3).haveExactly(1, hasBr4);
// when #2
temporaryBuildsCleaner.deleteTemporaryBuild(br4.getId(), "");
builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
// then #2
assertThat(builds.getContent()).doNotHave(hasBr1).doNotHave(hasBr2).haveExactly(1, hasBr3).doNotHave(hasBr4);
// when #3
temporaryBuildsCleaner.deleteTemporaryBuild(br3.getId(), "");
builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
// then #3
assertThat(builds.getContent()).haveExactly(1, hasBr1).haveExactly(1, hasBr2).doNotHave(hasBr3).doNotHave(hasBr4);
}
use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.
the class ArtifactProviderTest method testStore.
@Test
public void testStore() {
TargetRepository repo = TargetRepository.refBuilder().identifier("repo-id").repositoryPath("/repo/path").repositoryType(RepositoryType.MAVEN).build();
final String identifier = "foo:bar:0.0.1";
Artifact artifact = Artifact.builder().identifier(identifier).artifactQuality(ArtifactQuality.NEW).buildCategory(BuildCategory.STANDARD).build();
Artifact stored = provider.store(artifact);
assertThat(stored.getIdentifier()).isEqualTo(identifier);
assertThat(stored.getId()).isNotNull();
Mockito.verify(repository).save(ArgumentMatchers.argThat(a -> identifier.equals(a.getIdentifier())));
}
use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.
the class ArtifactProviderImpl method validateProvidedArtifactQuality.
private ArtifactQuality validateProvidedArtifactQuality(String quality, boolean isLoggedInUserSystemUser) {
ArtifactQuality newQuality;
try {
newQuality = ArtifactQuality.valueOf(quality.toUpperCase());
} catch (IllegalArgumentException e) {
throw new InvalidEntityException("Artifact quality: " + quality + " does not exist.");
}
// User can specify NEW, TESTED, VERIFIED, DEPRECATED quality levels; admins can also specify DELETED and
// BLACKLISTED
EnumSet<ArtifactQuality> allowedQualities = isLoggedInUserSystemUser ? ADMIN_ALLOWED_ARTIFACT_QUALITIES : USER_ALLOWED_ARTIFACT_QUALITIES;
if (!allowedQualities.contains(newQuality)) {
throw new InvalidEntityException("Artifact quality level can be changed only to " + allowedQualities);
}
return newQuality;
}
use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.
the class ArtifactProviderImpl method createQualityLevelRevision.
@Override
public ArtifactRevision createQualityLevelRevision(String id, String quality, String reason) throws DTOValidationException {
boolean isLoggedInUserSystemUser = userService.hasLoggedInUserRole(SYSTEM_USER);
ArtifactQuality newQuality = validateProvidedArtifactQuality(quality, isLoggedInUserSystemUser);
org.jboss.pnc.dto.Artifact artifact = getSpecific(id);
if (artifact == null) {
throw new InvalidEntityException("Artifact with id: " + id + " does not exist.");
}
validateIfArtifactQualityIsModifiable(artifact, newQuality);
update(id, artifact.toBuilder().artifactQuality(newQuality).qualityLevelReason(reason).build());
ArtifactAudited latestRevision = artifactAuditedRepository.findLatestById(Integer.parseInt(id));
if (latestRevision == null) {
throw new RepositoryViolationException("Entity should exist in the DB");
}
if (DA_SYNCRONIZED_ARTIFACT_QUALITIES.contains(newQuality)) {
String jsonPayload = createBlacklistJSONPayload(artifact);
blacklistAsyncInvoker.notifyBlacklistToDA(jsonPayload);
}
return artifactRevisionMapper.toDTO(latestRevision);
}
Aggregations