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);
}
});
}
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);
}
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
}
}
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);
}
}
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);
}
}
Aggregations