Search in sources :

Example 6 with ProductMilestoneRelease

use of org.jboss.pnc.model.ProductMilestoneRelease 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 7 with ProductMilestoneRelease

use of org.jboss.pnc.model.ProductMilestoneRelease in project pnc by project-ncl.

the class ProductMilestoneReleaseManager method updateRelease.

/**
 * @param milestone
 * @param status
 * @return null if ProductMilestoneRelease is not found
 */
private Optional<ProductMilestoneRelease> updateRelease(ProductMilestone milestone, MilestoneCloseStatus status) {
    ProductMilestoneRelease release = productMilestoneReleaseRepository.findLatestByMilestone(milestone);
    if (release == null) {
        log.error("No milestone release found for milestone {}", milestone.getId());
        return Optional.empty();
    }
    if (status != MilestoneCloseStatus.IN_PROGRESS) {
        release.setEndDate(new Date());
    }
    release.setStatus(status);
    return Optional.of(productMilestoneReleaseRepository.save(release));
}
Also used : ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) Date(java.util.Date)

Example 8 with ProductMilestoneRelease

use of org.jboss.pnc.model.ProductMilestoneRelease in project pnc by project-ncl.

the class ProductMilestoneProviderImpl method doCloseMilestone.

private ProductMilestoneCloseResult doCloseMilestone(String id, Long milestoneReleaseId) {
    org.jboss.pnc.model.ProductMilestone milestoneInDb = repository.queryById(Integer.valueOf(id));
    if (milestoneInDb.getEndDate() != null) {
        userLog.info("Milestone is already closed: no more modifications allowed");
        throw new RepositoryViolationException("Milestone is already closed! No more modifications allowed");
    }
    if (milestoneInDb.getPerformedBuilds().size() == 0) {
        throw new InvalidEntityException("No builds were performed in milestone!");
    } else {
        Optional<ProductMilestoneRelease> inProgress = releaseManager.getInProgress(milestoneInDb);
        if (inProgress.isPresent()) {
            userLog.warn("Milestone close is already in progress.");
            return milestoneReleaseMapper.toDTO(inProgress.get());
        } else {
            log.debug("Milestone's 'end date' set; no release of the milestone in progress: will start release");
            boolean useRHPAM = bpmConfig.isNewBpmForced() || userService.hasLoggedInUserRole(WORK_WITH_TECH_PREVIEW);
            log.debug("Using RHPAM server: {}", useRHPAM);
            ProductMilestoneRelease milestoneReleaseDb = releaseManager.startRelease(milestoneInDb, userService.currentUserToken(), useRHPAM, milestoneReleaseId);
            ProductMilestoneCloseResult milestoneCloseResult = milestoneReleaseMapper.toDTO(milestoneReleaseDb);
            return milestoneCloseResult;
        }
    }
}
Also used : RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease)

Aggregations

ProductMilestoneRelease (org.jboss.pnc.model.ProductMilestoneRelease)8 Date (java.util.Date)5 MilestoneReleaseTask (org.jboss.pnc.bpm.task.MilestoneReleaseTask)3 ProductMilestone (org.jboss.pnc.model.ProductMilestone)3 NoEntityException (org.jboss.pnc.bpm.NoEntityException)2 RestConnector (org.jboss.pnc.bpm.RestConnector)2 BuildImportResultRest (org.jboss.pnc.bpm.model.causeway.BuildImportResultRest)2 MilestoneReleaseResultRest (org.jboss.pnc.bpm.model.causeway.MilestoneReleaseResultRest)2 ProductMilestoneCloseResult (org.jboss.pnc.dto.ProductMilestoneCloseResult)2 ProductVersion (org.jboss.pnc.model.ProductVersion)2 CoreException (org.jboss.pnc.spi.exception.CoreException)2 Instant (java.time.Instant)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Stateless (javax.ejb.Stateless)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1