Search in sources :

Example 1 with RepositoryCreationResponse

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

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;
}
Also used : RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse)

Example 3 with RepositoryCreationResponse

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;
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationPredicates.withDependencyConfiguration(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withDependencyConfiguration) Notifier(org.jboss.pnc.spi.notifications.Notifier) Date(java.util.Date) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationPredicates.withScmRepositoryId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withScmRepositoryId) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationMapper(org.jboss.pnc.mapper.api.BuildConfigurationMapper) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) User(org.jboss.pnc.dto.User) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) BuildConfigurationRevisionMapper(org.jboss.pnc.mapper.api.BuildConfigurationRevisionMapper) SCMRepositoryProvider(org.jboss.pnc.facade.providers.api.SCMRepositoryProvider) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) WhenCreatingNew(org.jboss.pnc.dto.validation.groups.WhenCreatingNew) BuildRef(org.jboss.pnc.dto.BuildRef) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) ValidationBuilder(org.jboss.pnc.facade.validation.ValidationBuilder) Set(java.util.Set) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) Collectors(java.util.stream.Collectors) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) IdRev(org.jboss.pnc.model.IdRev) BuildConfigurationPredicates.withDependantConfiguration(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withDependantConfiguration) Objects(java.util.Objects) SequenceHandlerRepository(org.jboss.pnc.spi.datastore.repositories.SequenceHandlerRepository) List(java.util.List) ConflictedEntryValidator(org.jboss.pnc.facade.validation.ConflictedEntryValidator) RepositoryConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.RepositoryConfigurationRepository) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) BuildConfigurationPredicates.isNotArchived(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.isNotArchived) Optional(java.util.Optional) BuildConfigurationPredicates.withProductVersionId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProductVersionId) BuildConfigWithSCMRequest(org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest) ProjectRepository(org.jboss.pnc.spi.datastore.repositories.ProjectRepository) BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation) JobNotificationType(org.jboss.pnc.enums.JobNotificationType) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildEnvironmentRepository(org.jboss.pnc.spi.datastore.repositories.BuildEnvironmentRepository) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) HashSet(java.util.HashSet) UserMapper(org.jboss.pnc.mapper.api.UserMapper) SCMRepositoryMapper(org.jboss.pnc.mapper.api.SCMRepositoryMapper) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) BuildConfigurationProvider(org.jboss.pnc.facade.providers.api.BuildConfigurationProvider) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) WhenUpdating(org.jboss.pnc.dto.validation.groups.WhenUpdating) Logger(org.slf4j.Logger) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigurationPredicates.withProjectId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProjectId) Page(org.jboss.pnc.dto.response.Page) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildConfigurationWithLatestBuild(org.jboss.pnc.dto.BuildConfigurationWithLatestBuild) SCMRepository(org.jboss.pnc.dto.SCMRepository) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) MDCWrappers(org.jboss.pnc.common.concurrent.MDCWrappers) Comparator(java.util.Comparator) BuildConfigurationPredicates.withName(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withName) Collections(java.util.Collections) BuildConfigurationPredicates.withBuildConfigurationSetId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withBuildConfigurationSetId) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse)

Example 4 with RepositoryCreationResponse

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");
}
Also used : CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) SCMRepository(org.jboss.pnc.dto.SCMRepository) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with RepositoryCreationResponse

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!");
    }
}
Also used : RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) Test(org.junit.Test)

Aggregations

RepositoryCreationResponse (org.jboss.pnc.dto.response.RepositoryCreationResponse)6 SCMRepository (org.jboss.pnc.dto.SCMRepository)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 PermitAll (javax.annotation.security.PermitAll)1 Stateless (javax.ejb.Stateless)1 Inject (javax.inject.Inject)1 ClientException (org.jboss.pnc.client.ClientException)1 MDCWrappers (org.jboss.pnc.common.concurrent.MDCWrappers)1 MDCUtils (org.jboss.pnc.common.logging.MDCUtils)1