use of org.jboss.pnc.dto.response.RepositoryCreationResponse 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.dto.response.RepositoryCreationResponse in project pnc by project-ncl.
the class SCMRepositoryEndpointImpl method createNew.
@Override
public RepositoryCreationResponse createNew(CreateAndSyncSCMRequest request) {
ValidationBuilder.validateObject(request, WhenCreatingNew.class).validateNotEmptyArgument().validateAnnotations();
RepositoryCreationResponse responseDTO = scmRepositoryProvider.createSCMRepository(request.getScmUrl(), request.getPreBuildSyncEnabled());
if (responseDTO.getRepository() == null) {
// not in database, it is being created, return 202
servletResponse.setStatus(Response.Status.ACCEPTED.getStatusCode());
} else {
// created, return 201
servletResponse.setStatus(Response.Status.CREATED.getStatusCode());
}
servletResponse.setContentType(MediaType.APPLICATION_JSON);
try {
servletResponse.flushBuffer();
} catch (Exception e) {
throw new RuntimeException(e);
}
return responseDTO;
}
use of org.jboss.pnc.dto.response.RepositoryCreationResponse in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method createWithScm.
@Override
public BuildConfigCreationResponse createWithScm(BuildConfigWithSCMRequest request) {
ValidationBuilder.validateObject(request, WhenCreatingNew.class).validateNotEmptyArgument().validateAnnotations();
BuildConfiguration buildConfiguration = request.getBuildConfig();
validateBeforeSaving(buildConfiguration.toBuilder().scmRepository(FAKE_REPOSITORY).build());
Long buildConfigurationId = sequenceHandlerRepository.getNextID(org.jboss.pnc.model.BuildConfiguration.SEQUENCE_NAME);
MDCUtils.addProcessContext(buildConfigurationId.toString());
BuildConfiguration newBuildConfigurationWithId = buildConfiguration.toBuilder().id(buildConfigurationId.toString()).build();
RepositoryCreationResponse rcResponse = scmRepositoryProvider.createSCMRepository(request.getScmUrl(), request.getBuildConfig().getScmRevision(), request.getPreBuildSyncEnabled(), JobNotificationType.BUILD_CONFIG_CREATION, // consumer is deprecated with new stateless approach
MDCWrappers.wrap(event -> {
createBuildConfigurationWithRepository(event.getTaskId() == null ? null : event.getTaskId().toString(), event.getRepositoryId(), newBuildConfigurationWithId);
}), Optional.of(newBuildConfigurationWithId));
BuildConfigCreationResponse response;
if (rcResponse.getTaskId() == null) {
// scm is internal, not running a RepositoryCreationTask.
// onRCCreationSuccess already called with id = rcResponse.getRepository().getId()
org.jboss.pnc.model.BuildConfiguration buildConfigurationFromDB = repository.queryByPredicates(withName(newBuildConfigurationWithId.getName()), isNotArchived());
response = new BuildConfigCreationResponse(mapper.toDTO(buildConfigurationFromDB));
} else {
response = new BuildConfigCreationResponse(rcResponse.getTaskId().toString());
}
MDCUtils.removeProcessContext();
return response;
}
use of org.jboss.pnc.dto.response.RepositoryCreationResponse in project pnc by project-ncl.
the class SCMRepositoryEndpointTest method shouldCreateNewWithInternalUrl.
@Test
public void shouldCreateNewWithInternalUrl() throws ClientException {
// With
SCMRepository repository = SCMRepository.builder().internalUrl("ssh://git@github.com:22/newUser/newRepo.git").preBuildSyncEnabled(false).build();
CreateAndSyncSCMRequest request = CreateAndSyncSCMRequest.builder().scmUrl(repository.getInternalUrl()).preBuildSyncEnabled(repository.getPreBuildSyncEnabled()).build();
// When
RepositoryCreationResponse response = repositoryClient.createNew(request);
// Then
assertThat(response).isNotNull();
assertThat(response.getRepository().getId()).isNotNull();
SCMRepository refreshed = repositoryClient.getSpecific(response.getRepository().getId());
assertThat(refreshed).isEqualToIgnoringGivenFields(repository, "id");
}
use of org.jboss.pnc.dto.response.RepositoryCreationResponse in project pnc by project-ncl.
the class SCMRepositoryProviderTest method testCreateSCMRepository.
@Test
public void testCreateSCMRepository() throws ConfigurationParseException {
// when
when(configuration.getModuleConfig(any())).thenReturn(scmModuleConfig);
when(scmModuleConfig.getInternalScmAuthority()).thenReturn("github.com");
RepositoryCreationResponse response = provider.createSCMRepository("git+ssh://github.com/project-ncl/cleaner.git", true);
// then
// NCL-5989 don't send WS message if repository is created immediately (happens with internal url)
// verify(notifier, times(1)).sendMessage(any());
assertThat(response).isNotNull();
if (response.getRepository() == null && response.getTaskId() == null) {
Assert.fail("Both repository and task id cannot be null!");
}
}
Aggregations