Search in sources :

Example 1 with MilestoneReleaseTask

use of org.jboss.pnc.bpm.task.MilestoneReleaseTask 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 2 with MilestoneReleaseTask

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

the class ProductMilestoneReleaseManager method triggerRelease.

@Deprecated
private ProductMilestoneRelease triggerRelease(ProductMilestone milestone, String accessToken, Long milestoneReleaseId) {
    ProductMilestoneRelease release = new ProductMilestoneRelease();
    release.setId(milestoneReleaseId);
    release.setStartingDate(new Date());
    release.setMilestone(milestone);
    try {
        MilestoneReleaseTask releaseTask = new MilestoneReleaseTask(milestone, accessToken);
        Integer id = milestone.getId();
        releaseTask.<MilestoneReleaseResultRest>addListener(BpmEventType.BREW_IMPORT, r -> onPushResult(id, r));
        release.setStatus(MilestoneCloseStatus.IN_PROGRESS);
        bpmManager.startTask(releaseTask);
        userLog.info("Release process started.");
        productMilestoneCloseResultEvent.fire(mapper.toDTO(release));
        return release;
    } catch (CoreException 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());
        productMilestoneCloseResultEvent.fire(mapper.toDTO(release));
        return release;
    }
}
Also used : MilestoneReleaseResultRest(org.jboss.pnc.bpm.model.causeway.MilestoneReleaseResultRest) CoreException(org.jboss.pnc.spi.exception.CoreException) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) Date(java.util.Date)

Example 3 with MilestoneReleaseTask

use of org.jboss.pnc.bpm.task.MilestoneReleaseTask 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)

Aggregations

Date (java.util.Date)3 MilestoneReleaseTask (org.jboss.pnc.bpm.task.MilestoneReleaseTask)3 ProductMilestoneRelease (org.jboss.pnc.model.ProductMilestoneRelease)3 CoreException (org.jboss.pnc.spi.exception.CoreException)3 RestConnector (org.jboss.pnc.bpm.RestConnector)2 MilestoneReleaseResultRest (org.jboss.pnc.bpm.model.causeway.MilestoneReleaseResultRest)2 ProcessManagerException (org.jboss.pnc.spi.exception.ProcessManagerException)2 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Stateless (javax.ejb.Stateless)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 BpmEventType (org.jboss.pnc.bpm.BpmEventType)1 BpmManager (org.jboss.pnc.bpm.BpmManager)1 BpmTask (org.jboss.pnc.bpm.BpmTask)1 NoEntityException (org.jboss.pnc.bpm.NoEntityException)1 BuildImportResultRest (org.jboss.pnc.bpm.model.causeway.BuildImportResultRest)1 BuildImportStatus (org.jboss.pnc.bpm.model.causeway.BuildImportStatus)1 Numbers (org.jboss.pnc.common.Numbers)1