Search in sources :

Example 16 with BuildClient

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);
    }
}
Also used : InputStream(java.io.InputStream) BuildClient(org.jboss.pnc.client.BuildClient) ClientException(org.jboss.pnc.client.ClientException) IOException(java.io.IOException)

Example 17 with BuildClient

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);
    });
}
Also used : Response(javax.ws.rs.core.Response) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) InputStream(java.io.InputStream) BuildClient(org.jboss.pnc.client.BuildClient) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 18 with BuildClient

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));
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) ArtifactClient(org.jboss.pnc.client.ArtifactClient) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 19 with BuildClient

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");
}
Also used : InputStream(java.io.InputStream) BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 20 with BuildClient

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);
}
Also used : Configuration(org.jboss.pnc.client.Configuration) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

BuildClient (org.jboss.pnc.client.BuildClient)37 ContainerTest (org.jboss.pnc.test.category.ContainerTest)33 Test (org.junit.Test)33 Build (org.jboss.pnc.dto.Build)20 BuildsFilterParameters (org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)7 InputStream (java.io.InputStream)5 Artifact (org.jboss.pnc.dto.Artifact)5 InSequence (org.jboss.arquillian.junit.InSequence)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 ArtifactClient (org.jboss.pnc.client.ArtifactClient)3 BuildPushParameters (org.jboss.pnc.dto.requests.BuildPushParameters)3 Field (java.lang.reflect.Field)2 ApacheHttpClient43EngineWithRetry (org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry)2 ClientException (org.jboss.pnc.client.ClientException)2 Configuration (org.jboss.pnc.client.Configuration)2 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)2 BuildRef (org.jboss.pnc.dto.BuildRef)2 BeforeClass (org.junit.BeforeClass)2