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