Search in sources :

Example 6 with ClientException

use of org.jboss.pnc.client.ClientException in project bacon by project-ncl.

the class PncEntitiesImporter method setBrewTagPrefix.

/**
 * Override the default brewTagPrefix for the product version with the one specified in the pig configuration This
 * only happens if the brewTagPrefix in the pig configuration is not null/empty
 */
private void setBrewTagPrefix(ProductVersion productVersion) {
    String brewTagPrefix = pigConfiguration.getBrewTagPrefix();
    if (brewTagPrefix != null && !brewTagPrefix.isEmpty()) {
        log.info("Updating the product version's brewTagPrefix with: {}", brewTagPrefix);
        Map<String, String> attributes = productVersion.getAttributes();
        attributes.put(Attributes.BREW_TAG_PREFIX, brewTagPrefix);
        ProductVersion update = productVersion.toBuilder().attributes(attributes).build();
        try {
            versionClient.update(productVersion.getId(), update);
        } catch (ClientException e) {
            throw new RuntimeException("Failed to update the brew tag prefix of the product version", e);
        }
    }
}
Also used : ProductVersion(org.jboss.pnc.dto.ProductVersion) ClientException(org.jboss.pnc.client.ClientException)

Example 7 with ClientException

use of org.jboss.pnc.client.ClientException in project bacon by project-ncl.

the class PncEntitiesImporter method updateBuildConfig.

private BuildConfiguration updateBuildConfig(BuildConfigData data, BuildConfiguration existing) {
    String configId = data.getId();
    BuildConfiguration buildConfiguration = generatePncBuildConfig(data.getNewConfig(), existing);
    try {
        buildConfigClient.update(configId, buildConfiguration);
        return buildConfigClient.getSpecific(configId);
    } catch (ClientException e) {
        throw new RuntimeException("Failed to update build configuration " + configId, e);
    }
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) ClientException(org.jboss.pnc.client.ClientException)

Example 8 with ClientException

use of org.jboss.pnc.client.ClientException in project bacon by project-ncl.

the class PncEntitiesImporter method generateProduct.

private Product generateProduct() {
    ProductConfig productConfig = pigConfiguration.getProduct();
    Product product = Product.builder().name(productConfig.getName()).abbreviation(productConfig.getAbbreviation()).build();
    try {
        return productClient.createNew(product);
    } catch (ClientException e) {
        throw new RuntimeException("Failed to create the product", e);
    }
}
Also used : ProductConfig(org.jboss.pnc.bacon.pig.impl.config.ProductConfig) Product(org.jboss.pnc.dto.Product) ClientException(org.jboss.pnc.client.ClientException)

Example 9 with ClientException

use of org.jboss.pnc.client.ClientException 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 10 with ClientException

use of org.jboss.pnc.client.ClientException in project bacon by project-ncl.

the class BuildInfoCollector method getLatestBuild.

public PncBuild getLatestBuild(String configId, BuildSearchType searchType) {
    try {
        BuildsFilterParameters filter = new BuildsFilterParameters();
        Optional<String> queryParam;
        switch(searchType) {
            case ANY:
                queryParam = query("status==%s", BuildStatus.SUCCESS);
                break;
            case PERMANENT:
                queryParam = query("status==%s;temporaryBuild==%s", BuildStatus.SUCCESS, false);
                break;
            case TEMPORARY:
                // NCL-5943 Cannot ignore permanent(regular) builds because they cause NO_REBUILD_REQUIRED even for
                // temporary builds. That means "latest build" for a temporary build can be permanent(regular).
                queryParam = query("status==%s", BuildStatus.SUCCESS);
                break;
            default:
                queryParam = Optional.empty();
        }
        // Note: sort by id not allowed
        Iterator<Build> buildIterator = buildConfigClient.getBuilds(configId, filter, of("=desc=submitTime"), queryParam).iterator();
        if (!buildIterator.hasNext()) {
            throw new NoSuccessfulBuildException(configId);
        }
        Build build = buildIterator.next();
        PncBuild result = new PncBuild(build);
        result.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(build.getId())));
        return result;
    } catch (ClientException e) {
        throw new RuntimeException("Failed to get latest successful build for " + configId, e);
    }
}
Also used : GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) ClientException(org.jboss.pnc.client.ClientException) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Aggregations

ClientException (org.jboss.pnc.client.ClientException)19 GroupBuild (org.jboss.pnc.dto.GroupBuild)6 ContainerTest (org.jboss.pnc.test.category.ContainerTest)6 Test (org.junit.Test)6 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)4 Build (org.jboss.pnc.dto.Build)4 BadRequestException (javax.ws.rs.BadRequestException)3 ClientErrorException (javax.ws.rs.ClientErrorException)3 InSequence (org.jboss.arquillian.junit.InSequence)3 ProductClient (org.jboss.pnc.client.ProductClient)3 RemoteResourceNotFoundException (org.jboss.pnc.client.RemoteResourceNotFoundException)3 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)3 BuildsFilterParameters (org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)3 Iterator (java.util.Iterator)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Condition (org.assertj.core.api.Condition)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 Arquillian (org.jboss.arquillian.junit.Arquillian)2