Search in sources :

Example 11 with ClientException

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

the class PncBuilder method getCountOfBuildConfigsForGroupBuild.

/**
 * Try to get the count of build configs for a group build's group config. Returns -1 if it couldn't do the request
 *
 * @param groupBuildId
 * @return count, -1 if an error happened
 */
int getCountOfBuildConfigsForGroupBuild(String groupBuildId) {
    try {
        GroupBuild gb = groupBuildClient.getSpecific(groupBuildId);
        GroupConfigurationRef gc = gb.getGroupConfig();
        return groupConfigClient.getBuildConfigs(gc.getId()).size();
    } catch (ClientException e) {
        log.warn("Failed to get count of build configs in the group build {}", groupBuildId, e);
        return -1;
    }
}
Also used : GroupConfigurationRef(org.jboss.pnc.dto.GroupConfigurationRef) GroupBuild(org.jboss.pnc.dto.GroupBuild) ClientException(org.jboss.pnc.client.ClientException)

Example 12 with ClientException

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

the class PncBuilder method verifyAllBuildsInGroupBuildInFinalStateWithProperCount.

/**
 * This check makes sure that even when a group build is marked as done, we also need to make sure all its builds
 * are also done (NCL-6044). We also make sure that the number of builds done is the same as the number of build
 * configs in the group build's group config (NCL-6041)
 *
 * This is done to handle a weird timing error which happens when a group build finishes, the group build status is
 * updated before the last individual build status is updated to their final state. This may cause inconsistency in
 * the last build data.
 *
 * This is especially true when the Group build status is NO_REBUILD_REQUIRED, where it is also essential that all
 * the individual builds are also in their final state (and logically NO_REBUILD_REQUIRED status) so that we can get
 * the no rebuild cause.
 *
 * @param groupBuildId the group build id
 * @return whether all the builds have a final status or not
 */
boolean verifyAllBuildsInGroupBuildInFinalStateWithProperCount(String groupBuildId) {
    // log set to info for CPaaS to detect infinite loop
    log.info("Checking if all builds in group build {} are in final state with proper count of builds ( {} )", groupBuildId, UrlGenerator.generateGroupBuildUrl(groupBuildId));
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setLatest(false);
    filter.setRunning(false);
    try {
        Collection<Build> builds = groupBuildClient.getBuilds(groupBuildId, filter).getAll();
        boolean allFinal = builds.stream().allMatch(b -> b.getStatus().isFinal());
        return allFinal && getCountOfBuildConfigsForGroupBuild(groupBuildId) == builds.size();
    } catch (ClientException e) {
        log.warn("Failed to check if all builds in group build {} have a final status. Assuming it is not finished", groupBuildId, e);
        return false;
    }
}
Also used : Build(org.jboss.pnc.dto.Build) GroupBuild(org.jboss.pnc.dto.GroupBuild) ClientException(org.jboss.pnc.client.ClientException) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Example 13 with ClientException

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

the class BuildConfigurationEndpointTest method testGetSupportedParameters.

@Test
public void testGetSupportedParameters() throws ClientException {
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asAnonymous());
    Set<Parameter> all = client.getSupportedParameters();
    assertThat(all).haveExactly(1, new Condition<>(p -> p.getName().equals(BuildConfigurationParameterKeys.ALIGNMENT_PARAMETERS.name()) && p.getDescription().startsWith("Additional parameters, which will be "), "has PME parameter")).size().isGreaterThanOrEqualTo(4);
}
Also used : PatchBuilderException(org.jboss.pnc.client.patch.PatchBuilderException) Arquillian(org.jboss.arquillian.junit.Arquillian) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) ClientErrorException(javax.ws.rs.ClientErrorException) ProjectClient(org.jboss.pnc.client.ProjectClient) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) BadRequestException(javax.ws.rs.BadRequestException) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) Deployments(org.jboss.pnc.integration.setup.Deployments) BuildConfigurationParameterKeys(org.jboss.pnc.api.constants.BuildConfigurationParameterKeys) BuildConfigurationPatchBuilder(org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder) AlignmentParameters(org.jboss.pnc.dto.response.AlignmentParameters) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) EnvironmentClient(org.jboss.pnc.client.EnvironmentClient) Parameter(org.jboss.pnc.dto.response.Parameter) Set(java.util.Set) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) List(java.util.List) BeforeClass(org.junit.BeforeClass) BuildConfigWithSCMRequest(org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest) RunWith(org.junit.runner.RunWith) ProductClient(org.jboss.pnc.client.ProductClient) DTOEntity(org.jboss.pnc.dto.DTOEntity) HashMap(java.util.HashMap) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Environment(org.jboss.pnc.dto.Environment) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ArrayList(java.util.ArrayList) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ProjectRef(org.jboss.pnc.dto.ProjectRef) BuildType(org.jboss.pnc.enums.BuildType) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) SCMRepositoryClient(org.jboss.pnc.client.SCMRepositoryClient) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationWithLatestBuild(org.jboss.pnc.dto.BuildConfigurationWithLatestBuild) SCMRepository(org.jboss.pnc.dto.SCMRepository) Ignore(org.junit.Ignore) Deployment(org.jboss.arquillian.container.test.api.Deployment) Condition(org.assertj.core.api.Condition) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Parameter(org.jboss.pnc.dto.response.Parameter) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 14 with ClientException

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

the class BuildTest method buildToFinish.

private Boolean buildToFinish(String buildId, EnumSet<BuildStatus> isIn, EnumSet<BuildStatus> isNotIn) {
    Build build = null;
    logger.debug("Waiting for build {} to finish", buildId);
    try {
        build = buildClient.getSpecific(buildId);
        assertThat(build).isNotNull();
        logger.debug("Gotten build with status: {}", build.getStatus());
        if (!build.getStatus().isFinal())
            return false;
    } catch (RemoteResourceNotFoundException e) {
        fail(String.format("Build with id:%s not present", buildId), e);
    } catch (ClientException e) {
        fail("Client has failed in an unexpected way.", e);
    }
    assertThat(build).isNotNull();
    assertThat(build.getStatus()).isNotNull();
    if (isIn != null && !isIn.isEmpty())
        assertThat(build.getStatus()).isIn(isIn);
    if (isNotIn != null && !isNotIn.isEmpty())
        assertThat(build.getStatus()).isNotIn(isNotIn);
    return true;
}
Also used : RemoteResourceNotFoundException(org.jboss.pnc.client.RemoteResourceNotFoundException) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) ClientException(org.jboss.pnc.client.ClientException)

Example 15 with ClientException

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

the class BuildTest method groupBuildToFinish.

private Boolean groupBuildToFinish(String groupBuildId, EnumSet<BuildStatus> isIn, EnumSet<BuildStatus> isNotIn) {
    if (isIn == null)
        isIn = EnumSet.noneOf(BuildStatus.class);
    if (isNotIn == null)
        isNotIn = EnumSet.noneOf(BuildStatus.class);
    GroupBuild build = null;
    logger.debug("Waiting for build {} to finish", groupBuildId);
    try {
        build = groupBuildClient.getSpecific(groupBuildId);
        assertThat(build).isNotNull();
        logger.debug("Gotten build with status: {}", build.getStatus());
        if (!build.getStatus().isFinal())
            return false;
    } catch (RemoteResourceNotFoundException e) {
        fail(String.format("Group Build with id:%s not present", groupBuildId), e);
    } catch (ClientException e) {
        fail("Client has failed in an unexpected way.", e);
    }
    assertThat(build.getStatus()).isNotIn(isNotIn).isIn(isIn);
    return true;
}
Also used : RemoteResourceNotFoundException(org.jboss.pnc.client.RemoteResourceNotFoundException) GroupBuild(org.jboss.pnc.dto.GroupBuild) ClientException(org.jboss.pnc.client.ClientException)

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