use of org.jboss.pnc.client.BuildClient in project bacon by project-ncl.
the class PncBuild method getBuildLog.
/**
* Get the build log of the build on demand and result if cached. If the method is called again, the cached content
* will be served if not null
*
* @return the logs of the build
*/
public List<String> getBuildLog() {
// use cached buildLog if present
if (buildLog != null) {
return buildLog;
}
try (BuildClient buildClient = new BuildClient(PncClientHelper.getPncConfiguration())) {
Optional<InputStream> maybeBuildLogs = buildClient.getBuildLogs(id);
if (maybeBuildLogs.isPresent()) {
try (InputStream inputStream = maybeBuildLogs.get()) {
buildLog = readLog(inputStream);
}
} else {
log.debug("Couldn't find logs for build id: {} ( {} )", id, UrlGenerator.generateBuildUrl(id));
buildLog = Collections.emptyList();
}
return buildLog;
} catch (ClientException | IOException e) {
throw new RuntimeException("Failed to get build log for " + id + " (" + UrlGenerator.generateBuildUrl(id) + ")", e);
}
}
use of org.jboss.pnc.client.BuildClient in project bacon by project-ncl.
the class SourcesGenerator method downloadSourcesFromBuilds.
private void downloadSourcesFromBuilds(Map<String, PncBuild> builds, File workDir, File contentsDir) {
builds.values().forEach(build -> {
URI url = gerritSnapshotDownloadUrl(build.getInternalScmUrl(), build.getScmRevision());
File targetPath = new File(workDir, build.getName() + ".tar.gz");
try (BuildClient client = CREATOR.newClient();
Response response = client.getInternalScmArchiveLink(build.getId())) {
InputStream in = (InputStream) response.getEntity();
Files.copy(in, targetPath.toPath());
} catch (IOException | RemoteResourceException e) {
throw new RuntimeException(e);
}
Collection<String> untaredFiles = FileUtils.untar(targetPath, contentsDir);
List<String> topLevelDirectories = untaredFiles.stream().filter(this::isNotANestedFile).collect(Collectors.toList());
if (topLevelDirectories.size() != 1) {
throw new RuntimeException("Found more than one top-level directory (" + topLevelDirectories.size() + ") untared for build " + build + ", the untared archive: " + targetPath.getAbsolutePath() + ", the top level directories:" + topLevelDirectories);
}
String topLevelDirectoryName = untaredFiles.iterator().next();
File topLevelDirectory = new File(contentsDir, topLevelDirectoryName);
File properTopLevelDirectory = new File(contentsDir, build.getName());
topLevelDirectory.renameTo(properTopLevelDirectory);
});
}
use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldModifyBuiltArtifactQualityLevels.
@Test
public void shouldModifyBuiltArtifactQualityLevels() throws RemoteResourceException {
BuildClient client = new BuildClient(RestClientConfiguration.asSystem());
String buildRecordId = build3Id;
String REASON = "This artifact has become old enough";
ArtifactClient artifactClient = new ArtifactClient(RestClientConfiguration.asSystem());
Artifact newArtifact = artifactClient.create(Artifact.builder().artifactQuality(ArtifactQuality.NEW).buildCategory(BuildCategory.STANDARD).filename("builtArtifactInsertNew.jar").identifier("integration-test:built-artifact-new:jar:1.0").targetRepository(artifactClient.getSpecific("100").getTargetRepository()).md5("insert-md5-22").sha1("insert-22").sha256("insert-22").size(10L).build());
client.setBuiltArtifacts(build3Id, Collections.singletonList(newArtifact.getId()));
client.createBuiltArtifactsQualityLevelRevisions(buildRecordId, "BLACKListed", REASON);
RemoteCollection<Artifact> artifacts = client.getBuiltArtifacts(buildRecordId);
for (Artifact artifact : artifacts) {
assertThat(artifact.getArtifactQuality()).isEqualTo(ArtifactQuality.BLACKLISTED);
assertThat(artifact.getQualityLevelReason()).isEqualTo(REASON);
assertThat(artifact.getModificationUser().getUsername()).isEqualTo("system");
}
Build withAttribute = client.getSpecific(buildRecordId);
assertThat(withAttribute.getAttributes()).contains(entry(Attributes.BLACKLIST_REASON, REASON));
}
use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldGetBuildLogs.
@Test
public void shouldGetBuildLogs() throws ClientException, IOException {
// when
BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
Optional<InputStream> stream = client.getBuildLogs(buildId);
// then
assertThat(stream).isPresent();
String log = IoUtils.readStreamAsString(stream.get());
// from DatabaseDataInitializer
assertThat(log).contains("demo log");
}
use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldFailGetAllWithLargePage.
@Test
public void shouldFailGetAllWithLargePage() throws RemoteResourceException {
final Configuration clientConfig = RestClientConfiguration.asAnonymous();
Configuration largePageConfig = Configuration.builder().basicAuth(clientConfig.getBasicAuth()).bearerToken(clientConfig.getBearerToken()).host(clientConfig.getHost()).pageSize(MAX_PAGE_SIZE + 1).port(clientConfig.getPort()).protocol(clientConfig.getProtocol()).build();
BuildClient client = new BuildClient(largePageConfig);
assertThatThrownBy(() -> client.getAll(null, null)).hasCauseInstanceOf(BadRequestException.class);
}
Aggregations