Search in sources :

Example 1 with ClientException

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

the class AdvancedSCMRepositoryClient method createNewAndWait.

/**
 * If the scm repository is already created and present in the Orch database, a RemoteResourceException is thrown.
 * It's recommended that you check the presence of the repository before creating it.
 *
 * @param request scm to create
 * @return CompletableFuture of the result, whether it was successful or not
 * @throws RemoteResourceException Most likely thrown if repository already exists
 * @throws ClientException if the response from the server is strange: both task id and scm repository is null
 */
public CompletableFuture<SCMCreationResult> createNewAndWait(CreateAndSyncSCMRequest request) throws RemoteResourceException, ClientException {
    RepositoryCreationResponse response = super.createNew(request);
    if (response.getTaskId() == null) {
        if (response.getRepository() != null) {
            // if repository is internal, it'll get created immediately. Just wrap the results into the
            // CompletableFuture
            SCMRepositoryCreationSuccess dto = new SCMRepositoryCreationSuccess(response.getRepository(), null);
            return CompletableFuture.completedFuture(new SCMCreationResult(true, dto, null));
        } else {
            throw new ClientException("Something went wrong on creation of repository. task id and repository are both null");
        }
    }
    webSocketClient.connect("ws://" + configuration.getHost() + BASE_PATH + "/notifications").join();
    // if bpm task called, listen to either creation or failure events
    return CompletableFuture.anyOf(waitForScmCreationFailure(webSocketClient, response.getTaskId().toString()), waitForScmCreationSuccess(webSocketClient, response.getTaskId().toString())).thenApply(a -> {
        if (a instanceof SCMRepositoryCreationSuccess) {
            return new SCMCreationResult(true, (SCMRepositoryCreationSuccess) a, null);
        } else if (a instanceof RepositoryCreationFailure) {
            return new SCMCreationResult(false, null, (RepositoryCreationFailure) a);
        } else {
            return new SCMCreationResult(false, null, null);
        }
    });
}
Also used : ClientException(org.jboss.pnc.client.ClientException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) SCMRepositoryCreationSuccess(org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess) RepositoryCreationFailure(org.jboss.pnc.dto.notification.RepositoryCreationFailure)

Example 2 with ClientException

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

the class ArtifactEndpointTest method shouldFailToSaveArtifact.

@Test
public void shouldFailToSaveArtifact() {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asUser());
    Artifact artifact = Artifact.builder().filename("builtArtifactInsert.jar").identifier("integration-test:built-artifact-insert:jar:1.0").targetRepository(targetRepositoryRef).buildCategory(BuildCategory.STANDARD).md5("insert-md5-1").sha1("insert-1").sha256("insert-1").build();
    Exception caught = null;
    try {
        client.create(artifact);
    } catch (ClientException e) {
        caught = e;
    }
    Assertions.assertThat(caught).isNotNull();
    Assertions.assertThat(caught.getCause()).isInstanceOf(javax.ws.rs.ForbiddenException.class);
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) ClientException(org.jboss.pnc.client.ClientException) Artifact(org.jboss.pnc.dto.Artifact) ClientErrorException(javax.ws.rs.ClientErrorException) ClientException(org.jboss.pnc.client.ClientException) BadRequestException(javax.ws.rs.BadRequestException) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with ClientException

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

the class ProductEndpointTest method shouldFailToAddConflictingProduct.

@Test
@InSequence(30)
public void shouldFailToAddConflictingProduct() throws URISyntaxException, ClientException {
    ProductClient client = new ProductClient(RestClientConfiguration.asUser());
    Product product = Product.builder().name("The Same Thing").abbreviation("TST").description("Let's keep doing the same thing over and over. Nobody will notice.").build();
    Product created = client.createNew(product);
    assertThat(created.getId()).isNotEmpty();
    try {
        client.createNew(product);
        fail("Exception should be thrown");
    } catch (ClientException ex) {
    // OK
    }
}
Also used : ProductClient(org.jboss.pnc.client.ProductClient) Product(org.jboss.pnc.dto.Product) ClientException(org.jboss.pnc.client.ClientException) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 4 with ClientException

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

the class PncBuilder method run.

private GroupBuild run(GroupConfigurationRef group, boolean tempBuild, boolean tempBuildTS, RebuildMode rebuildMode, boolean dryRun) {
    log.info("Performing builds of group config {} in PNC ( {} )", group.getId(), UrlGenerator.generateGroupConfigUrl(group.getId()));
    if (tempBuildTS)
        log.warn("Temporary builds with timestamp alignment are not supported, running temporary builds instead...");
    GroupBuildParameters buildParams = new GroupBuildParameters();
    buildParams.setRebuildMode(rebuildMode);
    buildParams.setTemporaryBuild(tempBuild);
    if (dryRun) {
        buildParams.setTemporaryBuild(true);
        buildParams.setAlignmentPreference(AlignmentPreference.PREFER_PERSISTENT);
    }
    GroupBuildRequest request = GroupBuildRequest.builder().build();
    try {
        return groupConfigClient.trigger(group.getId(), buildParams, request);
    } catch (ClientException e) {
        throw new RuntimeException("Failed to trigger build group " + group.getId(), e);
    }
}
Also used : GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) ClientException(org.jboss.pnc.client.ClientException)

Example 5 with ClientException

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

the class PncEntitiesImporter method createRepository.

private SCMRepository createRepository(BuildConfig buildConfig) {
    String scmUrl = buildConfig.getScmUrl();
    CreateAndSyncSCMRequest createRepoRequest = CreateAndSyncSCMRequest.builder().preBuildSyncEnabled(true).scmUrl(scmUrl).build();
    try {
        CompletableFuture<AdvancedSCMRepositoryClient.SCMCreationResult> response = repoClient.createNewAndWait(createRepoRequest);
        log.info("Waiting for repository creation of '{}'", scmUrl);
        SleepUtils.waitFor(response::isDone, 10, true);
        AdvancedSCMRepositoryClient.SCMCreationResult result = response.join();
        log.info("{}", result.toString());
        if (result.isSuccess()) {
            return result.getScmRepositoryCreationSuccess().getScmRepository();
        } else {
            throw new RuntimeException("Error on creation of repository: " + result.getRepositoryCreationFailure());
        }
    } catch (ClientException e) {
        throw new RuntimeException("Failed to trigger repository creation for " + scmUrl, e);
    }
}
Also used : CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) ClientException(org.jboss.pnc.client.ClientException) AdvancedSCMRepositoryClient(org.jboss.pnc.restclient.AdvancedSCMRepositoryClient)

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