use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.
the class RestConnector method startProcess.
public Long startProcess(String processId, Object requestObject, String correlationKey, String accessToken) throws ProcessManagerException {
HttpPost request = endpointUrl.startProcessInstance(currentDeploymentId, processId, correlationKey);
log.debug("Starting new process using http endpoint: {}", request.getURI());
Map<String, Object> processParameters = new HashMap<>();
processParameters.put("auth", Collections.singletonMap("token", accessToken));
processParameters.put("mdc", new MDCParameters());
processParameters.put("task", requestObject);
Map<String, Map<String, Object>> body = Collections.singletonMap("initData", processParameters);
HttpEntity requestEntity;
try {
requestEntity = new StringEntity(JsonOutputConverterMapper.apply(body));
} catch (UnsupportedEncodingException e) {
throw new ProcessManagerException("Cannot prepare BPM REST call.", e);
}
request.setEntity(requestEntity);
configureRequest(accessToken, request);
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 201) {
Long processInstanceId = JsonOutputConverterMapper.readValue(response.getEntity().getContent(), Long.class);
log.info("Started new process instance with id: {}", processInstanceId);
return processInstanceId;
} else {
throw new ProcessManagerException("Cannot start new process instance, response status: " + statusCode);
}
} catch (IOException e) {
throw new ProcessManagerException("Cannot start new process instance.", e);
}
}
use of org.jboss.pnc.spi.exception.ProcessManagerException 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.spi.exception.ProcessManagerException in project pnc by project-ncl.
the class ProductMilestoneReleaseManager method storeBuildRecordPush.
private void storeBuildRecordPush(BuildImportResultRest buildRest, ProductMilestoneRelease productMilestoneRelease) {
Base32LongID recordId = BuildMapper.idMapper.toEntity(buildRest.getBuildRecordId());
BuildRecord record = buildRecordRepository.queryById(recordId);
if (record == null) {
log.error("No record found for record id: {}, skipped saving info: {}", recordId, buildRest);
return;
}
BuildPushStatus status;
try {
status = convertStatus(buildRest.getStatus());
} catch (ProcessManagerException e) {
log.error("Cannot convert status.", e);
throw new RuntimeException("Cannot convert status.", e);
}
BuildRecordPushResult buildRecordPush = BuildRecordPushResult.newBuilder().id(Sequence.nextId()).buildRecord(record).status(status).brewBuildId(buildRest.getBrewBuildId()).brewBuildUrl(buildRest.getBrewBuildUrl()).tagPrefix(// TODO tag!
"").productMilestoneRelease(productMilestoneRelease).build();
buildRecordPushResultRepository.save(buildRecordPush);
}
use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.
the class BpmMock method startTask.
@Override
public boolean startTask(BpmTask task) throws CoreException {
Connector connector = Mockito.mock(Connector.class);
try {
Mockito.when(connector.startProcess(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1L);
} catch (ProcessManagerException e) {
log.error("Cannot mock start process.", e);
}
task.setConnector(connector);
boolean started = super.startTask(task);
onTaskStarted.ifPresent(supplier -> supplier.accept(task));
return started;
}
use of org.jboss.pnc.spi.exception.ProcessManagerException 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);
}
}
Aggregations