Search in sources :

Example 1 with RepositoryCreationFailure

use of org.jboss.pnc.dto.notification.RepositoryCreationFailure 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 RepositoryCreationFailure

use of org.jboss.pnc.dto.notification.RepositoryCreationFailure in project pnc by project-ncl.

the class SCMRepositoryProviderImpl method onRepoCloneSuccess.

private void onRepoCloneSuccess(String internalScmUrl, Integer taskId, Consumer<RepositoryCreated> consumer, JobNotificationType jobType, String externalURL, boolean preBuildSyncEnabled) {
    RepositoryConfiguration existing = repository.queryByPredicates(withExactInternalScmRepoUrl(internalScmUrl));
    if (existing != null) {
        RepositoryCreationFailure error = new RepositoryCreationFailure(jobType, RC_REPO_CREATION_CONFLICT, existing, taskId.toString());
        notifier.sendMessage(error);
    } else {
        SCMRepository scmRepo = createSCMRepositoryFromValues(externalURL, internalScmUrl, preBuildSyncEnabled);
        RepositoryCreated notification = new RepositoryCreated(taskId, Integer.parseInt(scmRepo.getId()));
        consumer.accept(notification);
    }
}
Also used : RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository) RepositoryCreationFailure(org.jboss.pnc.dto.notification.RepositoryCreationFailure)

Example 3 with RepositoryCreationFailure

use of org.jboss.pnc.dto.notification.RepositoryCreationFailure in project pnc by project-ncl.

the class SCMRepositoryProviderImpl method repositoryCreationCompleted.

@Override
public void repositoryCreationCompleted(RepositoryCreationResult result) {
    if (result.getStatus().isSuccess()) {
        Consumer<RepositoryCreated> onRepositoryCreated = event -> {
            log.debug("Repository created: {}", event);
            if (result.getJobType().equals(JobNotificationType.BUILD_CONFIG_CREATION)) {
                buildConfigurationProvider.createBuildConfigurationWithRepository(result.getTaskId().toString(), event.getRepositoryId(), result.getBuildConfiguration());
            }
            notifySCMRepositoryCreated(event);
        };
        onRepoCloneSuccess(result.getInternalScmUrl(), result.getTaskId(), onRepositoryCreated, result.getJobType(), result.getExternalUrl(), result.isPreBuildSyncEnabled());
    } else {
        String eventType;
        if (!result.isRepoCreatedSuccessfully()) {
            eventType = BpmEventType.RC_REPO_CREATION_ERROR.toString();
        } else {
            eventType = BpmEventType.RC_REPO_CLONE_ERROR.toString();
        }
        org.jboss.pnc.bpm.model.RepositoryConfiguration repositoryConfiguration = org.jboss.pnc.bpm.model.RepositoryConfiguration.builder().externalUrl(result.getExternalUrl()).preBuildSyncEnabled(result.isPreBuildSyncEnabled()).build();
        RepositoryCreationProcess repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).build();
        notifier.sendMessage(new RepositoryCreationFailure(result.getJobType(), eventType, repositoryCreationProcess, result.getTaskId().toString()));
    }
}
Also used : GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) RepositoryCreationProcess(org.jboss.pnc.bpm.model.RepositoryCreationProcess) Notifier(org.jboss.pnc.spi.notifications.Notifier) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.jboss.pnc.common.util.StringUtils) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) RepositoryCreationTask(org.jboss.pnc.bpm.task.RepositoryCreationTask) UrlUtils(org.jboss.pnc.common.util.UrlUtils) SCMRepositoryProvider(org.jboss.pnc.facade.providers.api.SCMRepositoryProvider) BpmEventType(org.jboss.pnc.bpm.BpmEventType) RepourClient(org.jboss.pnc.facade.util.RepourClient) INTERNAL_REPOSITORY_NAME(org.jboss.pnc.constants.Patterns.INTERNAL_REPOSITORY_NAME) SCM_REPOSITORY_CREATION(org.jboss.pnc.enums.JobNotificationType.SCM_REPOSITORY_CREATION) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) BpmStringMapNotificationRest(org.jboss.pnc.bpm.model.BpmStringMapNotificationRest) RepositoryCreationResult(org.jboss.pnc.dto.tasks.RepositoryCreationResult) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) RepositoryConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.RepositoryConfigurationRepository) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) Optional(java.util.Optional) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) Pattern(java.util.regex.Pattern) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) RepositoryConfigurationPredicates(org.jboss.pnc.spi.datastore.predicates.RepositoryConfigurationPredicates) JobNotificationType(org.jboss.pnc.enums.JobNotificationType) RepositoryCloneSuccess(org.jboss.pnc.bpm.model.RepositoryCloneSuccess) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) SCMRepositoryMapper(org.jboss.pnc.mapper.api.SCMRepositoryMapper) BuildConfigurationProvider(org.jboss.pnc.facade.providers.api.BuildConfigurationProvider) SCMRepositoryCreationSuccess(org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess) BpmManager(org.jboss.pnc.bpm.BpmManager) WORK_WITH_TECH_PREVIEW(org.jboss.pnc.facade.providers.api.UserRoles.WORK_WITH_TECH_PREVIEW) RepositoryCreationFailure(org.jboss.pnc.dto.notification.RepositoryCreationFailure) Logger(org.slf4j.Logger) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) RestConnector(org.jboss.pnc.bpm.RestConnector) RepositoryConfigurationPredicates.withExactInternalScmRepoUrl(org.jboss.pnc.spi.datastore.predicates.RepositoryConfigurationPredicates.withExactInternalScmRepoUrl) Configuration(org.jboss.pnc.common.Configuration) ScmModuleConfig(org.jboss.pnc.common.json.moduleconfig.ScmModuleConfig) Page(org.jboss.pnc.dto.response.Page) Consumer(java.util.function.Consumer) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) SCMRepository(org.jboss.pnc.dto.SCMRepository) MDCWrappers(org.jboss.pnc.common.concurrent.MDCWrappers) BpmModuleConfig(org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig) RepositoryCreationProcess(org.jboss.pnc.bpm.model.RepositoryCreationProcess) RepositoryCreationFailure(org.jboss.pnc.dto.notification.RepositoryCreationFailure)

Aggregations

RepositoryCreationFailure (org.jboss.pnc.dto.notification.RepositoryCreationFailure)3 SCMRepository (org.jboss.pnc.dto.SCMRepository)2 SCMRepositoryCreationSuccess (org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess)2 RepositoryCreationResponse (org.jboss.pnc.dto.response.RepositoryCreationResponse)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Pattern (java.util.regex.Pattern)1 PermitAll (javax.annotation.security.PermitAll)1 Stateless (javax.ejb.Stateless)1 Inject (javax.inject.Inject)1 BpmEventType (org.jboss.pnc.bpm.BpmEventType)1 BpmManager (org.jboss.pnc.bpm.BpmManager)1 RestConnector (org.jboss.pnc.bpm.RestConnector)1 BpmStringMapNotificationRest (org.jboss.pnc.bpm.model.BpmStringMapNotificationRest)1 RepositoryCloneSuccess (org.jboss.pnc.bpm.model.RepositoryCloneSuccess)1 RepositoryCreationProcess (org.jboss.pnc.bpm.model.RepositoryCreationProcess)1