use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class IndyRepositorySession method processDownloads.
/**
* Promote all build dependencies NOT ALREADY CAPTURED to the hosted repository holding store for the shared imports
* and return dependency artifacts meta data.
*
* @param report The tracking report that contains info about artifacts downloaded by the build
* @param promote flag if collected dependencies should be promoted
* @return List of dependency artifacts meta data
* @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
* artifacts
* @throws PromotionValidationException when the promotion process results in an error due to validation failure
*/
private List<Artifact> processDownloads(final TrackedContentDTO report, final boolean promote) throws RepositoryManagerException, PromotionValidationException {
List<Artifact> deps;
logger.info("BEGIN: Process artifacts downloaded by build");
userLog.info("Processing dependencies");
StopWatch stopWatch = StopWatch.createStarted();
Set<TrackedContentEntryDTO> downloads = report.getDownloads();
if (CollectionUtils.isEmpty(downloads)) {
deps = Collections.emptyList();
} else {
deps = collectDownloadedArtifacts(report);
if (promote) {
Map<StoreKey, Map<StoreKey, Set<String>>> depMap = collectDownloadsPromotionMap(downloads);
promoteDownloads(depMap);
}
}
logger.info("END: Process artifacts downloaded by build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
return deps;
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class IndyRepositorySession method extractBuildArtifacts.
/**
* Retrieve tracking report from repository manager. Add each tracked download to the dependencies of the build
* result. Add each tracked upload to the built artifacts of the build result. Promote uploaded artifacts to the
* product-level storage. Finally delete the group associated with the completed build.
*
* @param liveBuild {@inheritDoc} - if true, the promotion of the collected artifacts and dependencies is done,
* tracking report is sealed and the build group is removed, if false it only reads the data without any
* actions
*/
@Override
public RepositoryManagerResult extractBuildArtifacts(final boolean liveBuild) throws RepositoryManagerException {
TrackedContentDTO report = sealAndGetTrackingReport(liveBuild);
Comparator<Artifact> comp = (one, two) -> one.getIdentifier().compareTo(two.getIdentifier());
Uploads uploads = collectUploads(report);
List<Artifact> uploadedArtifacts = uploads.getData();
Collections.sort(uploadedArtifacts, comp);
List<Artifact> downloadedArtifacts = null;
String log = "";
CompletionStatus status = CompletionStatus.SUCCESS;
try {
downloadedArtifacts = processDownloads(report, liveBuild);
Collections.sort(downloadedArtifacts, comp);
} catch (PromotionValidationException ex) {
status = CompletionStatus.FAILED;
log = ex.getMessage();
logger.warn("Dependencies promotion failed. Error(s): {}", log);
userLog.error("Dependencies promotion failed. Error(s): {}", log);
}
if (liveBuild) {
deleteBuildGroup();
}
// if the promotion of dependencies succeeded...
if (status == CompletionStatus.SUCCESS) {
logger.info("Returning built artifacts / dependencies:\nUploads:\n {}\n\nDownloads:\n {}\n\n", StringUtils.join(uploads.getData(), "\n "), StringUtils.join(downloadedArtifacts, "\n "));
if (liveBuild) {
logger.info("BEGIN: promotion to build content set");
StopWatch stopWatch = StopWatch.createStarted();
try {
promoteToBuildContentSet(uploads.getPromotion());
} catch (PromotionValidationException ex) {
status = CompletionStatus.FAILED;
log = ex.getMessage();
logger.warn("Built artifact promotion failed. Error(s): {}", log);
userLog.error("Built artifact promotion failed. Error(s): {}", log);
}
logger.info("END: promotion to build content set, took: {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
stopWatch.reset();
}
}
if (status == CompletionStatus.FAILED) {
// prevent saving artifacts and dependencies to a failed build
downloadedArtifacts = Collections.emptyList();
uploadedArtifacts = Collections.emptyList();
}
return new IndyRepositoryManagerResult(uploadedArtifacts, downloadedArtifacts, buildContentId, log, status);
}
use of org.jboss.pnc.model.Artifact 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.model.Artifact in project pnc by project-ncl.
the class TemporaryBuildsCleanerTest method shouldNotDeleteNonTemporaryArtifacts.
@Test
public void shouldNotDeleteNonTemporaryArtifacts() {
// given
Artifact artifact = initArtifactBuilder().artifactQuality(ArtifactQuality.NEW).build();
artifactRepository.save(artifact);
Set<Artifact> builtArtifacts = new HashSet<>();
builtArtifacts.add(artifact);
BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).build();
BuildRecord savedTempBr = buildRecordRepository.save(tempBr);
artifact.setBuildRecord(savedTempBr);
artifactRepository.save(artifact);
// when - then
try {
temporaryBuildsCleaner.deleteTemporaryBuild(tempBr.getId(), "");
} catch (Exception ex) {
logger.info("Received exception:", ex);
if (ex.getCause().getClass().equals(PersistenceException.class)) {
return;
}
}
fail("Deletion of non-temporary artifacts should be prohibited");
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class DownloadTwoThenVerifyExtractedArtifactsContainThemTest method extractBuildArtifacts_ContainsTwoDownloads.
@Test
public void extractBuildArtifacts_ContainsTwoDownloads() throws Exception {
String pomPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
String jarPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.jar";
String pomContent = "This is a pom test " + System.currentTimeMillis();
String jarContent = "This is a jar test " + System.currentTimeMillis();
// setup the expectation that the remote repo pointing at this server will request this file...and define its
// content.
server.expect(server.formatUrl(STORE, pomPath), 200, pomContent);
server.expect(server.formatUrl(STORE, jarPath), 200, jarContent);
// create a dummy non-chained build execution and repo session based on it
BuildExecution execution = new TestBuildExecution();
RepositorySession rc = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
assertThat(rc, notNullValue());
String baseUrl = rc.getConnectionInfo().getDependencyUrl();
// download the two files via the repo session's dependency URL, which will proxy the test http server
// using the expectations above
assertThat(download(UrlUtils.buildUrl(baseUrl, pomPath)), equalTo(pomContent));
assertThat(download(UrlUtils.buildUrl(baseUrl, jarPath)), equalTo(jarContent));
// extract the build artifacts, which should contain the two imported deps.
// This will also trigger promoting imported artifacts into the shared-imports hosted repo
RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
List<Artifact> deps = repositoryManagerResult.getDependencies();
System.out.println(deps);
assertThat(deps, notNullValue());
assertThat("Expected 2 dependencies, got: " + deps, deps.size(), equalTo(2));
ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
Set<String> refs = new HashSet<>();
refs.add(new SimpleArtifactRef(pvr, "pom", null).toString());
refs.add(new SimpleArtifactRef(pvr, "jar", null).toString());
// check that both files are in the dep artifacts list using getIdentifier() to match on GAVT[C]
for (Artifact artifact : deps) {
assertThat(artifact + " is not in the expected list of deps: " + refs, refs.contains(artifact.getIdentifier()), equalTo(true));
}
Indy indy = driver.getIndy(accessToken);
// check that the new imports are available from shared-imports
assertAvailableInSharedImports(indy, pomContent, pomPath);
assertAvailableInSharedImports(indy, jarContent, jarPath);
}
Aggregations