Search in sources :

Example 1 with RestConnector

use of org.jboss.pnc.bpm.RestConnector in project pnc by project-ncl.

the class RestConnectorRequestSerializationTest method before.

@Before
public void before() {
    when(bpmConfig.getBpmNewBaseUrl()).thenReturn(wireMockServer.baseUrl());
    when(bpmConfig.getBpmNewDeploymentId()).thenReturn(DEPLOYMENT_ID);
    wireMockServer.stubFor(post(urlMatching(".*" + DEPLOYMENT_ID + ".*")).willReturn(aResponse().withStatus(201).withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody("1")));
    this.connector = new RestConnector(bpmConfig);
}
Also used : RestConnector(org.jboss.pnc.bpm.RestConnector) Before(org.junit.Before)

Example 2 with RestConnector

use of org.jboss.pnc.bpm.RestConnector in project pnc by project-ncl.

the class ProductMilestoneReleaseManager method triggerRHPAMRelease.

/**
 * Trigger the release using the new RHPAM server
 *
 * @param milestone milestone to be released
 * @param accessToken access token to use to submit request
 * @param milestoneReleaseId the milestone id
 */
private ProductMilestoneRelease triggerRHPAMRelease(ProductMilestone milestone, String accessToken, Long milestoneReleaseId) {
    ProductMilestoneRelease release = new ProductMilestoneRelease();
    release.setId(milestoneReleaseId);
    release.setStartingDate(new Date());
    release.setMilestone(milestone);
    try (RestConnector restConnector = new RestConnector(bpmConfig)) {
        MilestoneReleaseTask releaseTask = new MilestoneReleaseTask(milestone, accessToken);
        releaseTask.setTaskId(bpmManager.getNextTaskId());
        releaseTask.setGlobalConfig(globalConfig);
        releaseTask.setJsonEncodedProcessParameters(false);
        restConnector.startProcess(bpmConfig.getBpmNewReleaseProcessId(), releaseTask.getExtendedProcessParameters(), Numbers.decimalToBase32(milestoneReleaseId), accessToken);
        return release;
    } catch (CoreException | ProcessManagerException e) {
        log.error("Error trying to start brew push task for milestone: {}", milestone.getId(), e);
        userLog.error("Release process creation failed.", e);
        release.setStatus(MilestoneCloseStatus.SYSTEM_ERROR);
        release.setEndDate(new Date());
        return release;
    }
}
Also used : RestConnector(org.jboss.pnc.bpm.RestConnector) CoreException(org.jboss.pnc.spi.exception.CoreException) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) Date(java.util.Date)

Example 3 with RestConnector

use of org.jboss.pnc.bpm.RestConnector in project pnc by project-ncl.

the class ProductMilestoneReleaseManager method cancel.

public void cancel(ProductMilestone milestoneInDb, String accessToken, boolean useRHPAM) {
    if (!useRHPAM) {
        Collection<BpmTask> activeTasks = bpmManager.getActiveTasks();
        Optional<MilestoneReleaseTask> milestoneReleaseTask = activeTasks.stream().map(task -> (MilestoneReleaseTask) task).filter(task -> task.getMilestone().getId().equals(milestoneInDb.getId())).findAny();
        if (milestoneReleaseTask.isPresent()) {
            bpmManager.cancelTask(milestoneReleaseTask.get());
        }
    } else {
        RestConnector restConnector = new RestConnector(bpmConfig);
        restConnector.cancelByCorrelation(Numbers.decimalToBase32(milestoneInDb.getId()), accessToken);
    }
    ProductMilestoneRelease milestoneRelease = productMilestoneReleaseRepository.findLatestByMilestone(milestoneInDb);
    milestoneRelease.setStatus(MilestoneCloseStatus.CANCELED);
    productMilestoneReleaseRepository.save(milestoneRelease);
}
Also used : GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) BuildImportResultRest(org.jboss.pnc.bpm.model.causeway.BuildImportResultRest) Date(java.util.Date) CollectionUtils.ofNullableCollection(org.jboss.pnc.common.util.CollectionUtils.ofNullableCollection) LoggerFactory(org.slf4j.LoggerFactory) BpmTask(org.jboss.pnc.bpm.BpmTask) Function(java.util.function.Function) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) ProductMilestoneRepository(org.jboss.pnc.spi.datastore.repositories.ProductMilestoneRepository) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) BuildPushStatus(org.jboss.pnc.enums.BuildPushStatus) BpmManager(org.jboss.pnc.bpm.BpmManager) ProductMilestone(org.jboss.pnc.model.ProductMilestone) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) BpmEventType(org.jboss.pnc.bpm.BpmEventType) BuildImportStatus(org.jboss.pnc.bpm.model.causeway.BuildImportStatus) ProductVersion(org.jboss.pnc.model.ProductVersion) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) Logger(org.slf4j.Logger) Collection(java.util.Collection) RestConnector(org.jboss.pnc.bpm.RestConnector) BuildRecord(org.jboss.pnc.model.BuildRecord) NoEntityException(org.jboss.pnc.bpm.NoEntityException) MilestoneReleaseResultRest(org.jboss.pnc.bpm.model.causeway.MilestoneReleaseResultRest) ProductMilestoneReleaseRepository(org.jboss.pnc.spi.datastore.repositories.ProductMilestoneReleaseRepository) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildRecordPushResultRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordPushResultRepository) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) Optional(java.util.Optional) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) ProductMilestoneCloseResultMapper(org.jboss.pnc.mapper.api.ProductMilestoneCloseResultMapper) BpmModuleConfig(org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig) Sequence(org.jboss.pnc.common.concurrent.Sequence) Numbers(org.jboss.pnc.common.Numbers) MilestoneCloseStatus(org.jboss.pnc.enums.MilestoneCloseStatus) Base32LongID(org.jboss.pnc.model.Base32LongID) RestConnector(org.jboss.pnc.bpm.RestConnector) BpmTask(org.jboss.pnc.bpm.BpmTask) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease)

Example 4 with RestConnector

use of org.jboss.pnc.bpm.RestConnector in project pnc by project-ncl.

the class DeliverableAnalyzerManagerImpl method startAnalysis.

private void startAnalysis(String milestoneId, List<String> sourcesLink, Base32LongID operationId) {
    Request callback = operationsManager.getOperationCallback(operationId);
    String id = operationId.getId();
    try (RestConnector restConnector = new RestConnector(bpmConfig)) {
        AnalyzeDeliverablesBpmRequest bpmRequest = new AnalyzeDeliverablesBpmRequest(id, milestoneId, sourcesLink);
        AnalyzeDeliverablesTask analyzeTask = new AnalyzeDeliverablesTask(bpmRequest, callback);
        restConnector.startProcess(bpmConfig.getAnalyzeDeliverablesBpmProcessId(), analyzeTask, id, userService.currentUserToken());
        DeliverableAnalysisStatusChangedEvent analysisStatusChanged = DefaultDeliverableAnalysisStatusChangedEvent.started(id, milestoneId, sourcesLink);
        analysisStatusChangedEventNotifier.fire(analysisStatusChanged);
    } catch (ProcessManagerException e) {
        log.error("Error trying to start analysis of deliverables task for milestone: {}", milestoneId, e);
        throw new RuntimeException(e);
    }
}
Also used : RestConnector(org.jboss.pnc.bpm.RestConnector) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) AnalyzeDeliverablesTask(org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest) Request(org.jboss.pnc.api.dto.Request) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)

Example 5 with RestConnector

use of org.jboss.pnc.bpm.RestConnector in project pnc by project-ncl.

the class SCMRepositoryProviderImpl method startRCreationTask.

/**
 * @param externalURL
 * @param preBuildSyncEnabled
 * @param jobType
 * @param consumer
 * @param buildConfiguration required when repository is created as part of BC creation process
 * @return
 */
private Integer startRCreationTask(String externalURL, String revision, boolean preBuildSyncEnabled, JobNotificationType jobType, Consumer<RepositoryCreated> consumer, Optional<BuildConfiguration> buildConfiguration) {
    String userToken = userService.currentUserToken();
    org.jboss.pnc.bpm.model.RepositoryConfiguration repositoryConfiguration = org.jboss.pnc.bpm.model.RepositoryConfiguration.builder().externalUrl(externalURL).preBuildSyncEnabled(preBuildSyncEnabled).build();
    RepositoryCreationTask task;
    if (bpmConfig.isNewBpmForced() || userService.hasLoggedInUserRole(WORK_WITH_TECH_PREVIEW)) {
        RepositoryCreationProcess.RepositoryCreationProcessBuilder repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision);
        buildConfiguration.ifPresent(bc -> repositoryCreationProcess.buildConfiguration(bc));
        task = new RepositoryCreationTask(repositoryCreationProcess.build(), userToken);
        task.setTaskId(bpmManager.getNextTaskId());
        task.setGlobalConfig(globalConfig);
        task.setJsonEncodedProcessParameters(false);
        task.setJobType(jobType);
        RestConnector restConnector = new RestConnector(bpmConfig);
        try {
            Map<String, Object> processParameters = task.getExtendedProcessParameters();
            restConnector.startProcess(bpmConfig.getNewBcCreationProcessId(), processParameters, userToken);
        } catch (CoreException e) {
            throw new RuntimeException("Could not get process parameters: " + task, e);
        } catch (ProcessManagerException e) {
            throw new RuntimeException("Could not start BPM task using REST connector: " + task, e);
        }
    } else {
        // deprecated
        RepositoryCreationProcess repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision).build();
        task = new RepositoryCreationTask(repositoryCreationProcess, userToken);
        task.setJobType(jobType);
        Consumer<RepositoryCloneSuccess> successListener = event -> onRepoCloneSuccess(event.getData().getInternalUrl(), task.getTaskId(), consumer, jobType, externalURL, preBuildSyncEnabled);
        task.addListener(BpmEventType.RC_REPO_CLONE_SUCCESS, MDCWrappers.wrap(successListener));
        addErrorListeners(jobType, task);
        try {
            bpmManager.startTask(task);
        } catch (CoreException e) {
            throw new RuntimeException("Could not start BPM task: " + task, e);
        }
    }
    return task.getTaskId();
}
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) RestConnector(org.jboss.pnc.bpm.RestConnector) RepositoryCreationProcess(org.jboss.pnc.bpm.model.RepositoryCreationProcess) RepositoryCloneSuccess(org.jboss.pnc.bpm.model.RepositoryCloneSuccess) CoreException(org.jboss.pnc.spi.exception.CoreException) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) RepositoryCreationTask(org.jboss.pnc.bpm.task.RepositoryCreationTask)

Aggregations

RestConnector (org.jboss.pnc.bpm.RestConnector)5 ProcessManagerException (org.jboss.pnc.spi.exception.ProcessManagerException)4 CoreException (org.jboss.pnc.spi.exception.CoreException)3 Date (java.util.Date)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Stateless (javax.ejb.Stateless)2 Inject (javax.inject.Inject)2 BpmEventType (org.jboss.pnc.bpm.BpmEventType)2 BpmManager (org.jboss.pnc.bpm.BpmManager)2 MilestoneReleaseTask (org.jboss.pnc.bpm.task.MilestoneReleaseTask)2 GlobalModuleGroup (org.jboss.pnc.common.json.GlobalModuleGroup)2 BpmModuleConfig (org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1