use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class DefaultBuildCoordinator method cancelSet.
@Override
public boolean cancelSet(int buildSetTaskId) {
BuildConfigSetRecord record = datastoreAdapter.getBuildCongigSetRecordById(buildSetTaskId);
if (record == null) {
log.error("Could not find buildConfigSetRecord with id : {}", buildSetTaskId);
return false;
}
log.debug("Cancelling Build Configuration Set: {}", buildSetTaskId);
getSubmittedBuildTasks().stream().filter(Objects::nonNull).filter(t -> t.getBuildSetTask() != null && t.getBuildSetTask().getId().equals(buildSetTaskId)).forEach(buildTask -> {
try {
MDCUtils.addBuildContext(getMDCMeta(buildTask));
log.debug("Received cancel request for buildTaskId: {}.", buildTask.getId());
cancel(buildTask.getId());
} catch (CoreException e) {
log.error("Unable to cancel the build [" + buildTask.getId() + "].", e);
} finally {
MDCUtils.removeBuildContext();
}
});
record.setStatus(BuildStatus.CANCELLED);
record.setEndTime(Date.from(Instant.now()));
try {
datastoreAdapter.saveBuildConfigSetRecord(record);
} catch (DatastoreException e) {
log.error("Failed to update BuildConfigSetRecord (id: {} ) with status CANCELLED", record.getId(), e);
}
return true;
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class RepositoryCreationTask method getProcessParameters.
@Override
protected Serializable getProcessParameters() throws CoreException {
try {
HashMap<String, Object> params = new HashMap<>();
params.put("pncBaseUrl", globalConfig.getPncUrl());
params.put("repourBaseUrl", globalConfig.getExternalRepourUrl());
params.put("jobType", jobType.toString());
if (isJsonEncodedProcessParameters()) {
params.put("taskData", MAPPER.writeValueAsString(repositoryCreationProcessRest));
} else {
params.put("taskData", repositoryCreationProcessRest);
}
return params;
} catch (JsonProcessingException e) {
throw new CoreException("Could not get the parameters.", e);
}
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class BpmManager method startTask.
public boolean startTask(BpmTask task) throws CoreException {
try {
task.setTaskId(getNextTaskId());
task.setGlobalConfig(globalConfig);
task.setBpmConfig(bpmConfig);
if (!task.getConnector().isPresent()) {
defineConnector(task);
}
String processId = task.getProcessId();
Long processInstanceId = task.getConnector().get().startProcess(processId, task.getExtendedProcessParameters(), task.getAccessToken());
task.setProcessInstanceId(processInstanceId);
task.setProcessName(processId);
tasks.put(task.getTaskId(), task);
log.debug("Created new process linked to task: {}", task);
return true;
} catch (Exception e) {
throw new CoreException("Could not start BPM task '" + task + "'.", e);
}
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class BpmTask method getExtendedProcessParameters.
/**
* Extend process parameters from the task with additional useful information, such as pncBaseUrl and taskId, needed
* for notifications. Before use, taskId MUST be assigned.
*
* @throws CoreException
*/
public Map<String, Object> getExtendedProcessParameters() throws CoreException {
Serializable processParameters = getProcessParameters();
requireNonNull(processParameters);
Map<String, Object> actualParameters = new HashMap<>();
if (isJsonEncodedProcessParameters()) {
try {
actualParameters.put("processParameters", MAPPER.writeValueAsString(processParameters));
} catch (JsonProcessingException e) {
throw new CoreException("Could not serialize process processParameters '" + processParameters + "'.", e);
}
} else {
actualParameters.put("processParameters", processParameters);
}
// global not process related parameters
actualParameters.put("taskId", taskId);
actualParameters.put("usersAuthToken", accessToken);
MDCUtils.getUserId().ifPresent(v -> {
log.debug("Setting process parameter userId: {}", v);
actualParameters.put("userId", v);
});
MDCUtils.getRequestContext().ifPresent(v -> {
log.debug("Setting process parameter logRequestContext: {}", v);
actualParameters.put("logRequestContext", v);
});
MDCUtils.getProcessContext().ifPresent(v -> {
log.debug("Setting process parameter logProcessContext: {}", v);
actualParameters.put("logProcessContext", v);
});
return actualParameters;
}
use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.
the class BuildExecutorTriggerer method executeBuild.
public BuildExecutionSession executeBuild(BuildExecutionConfiguration buildExecutionConfig, String callbackUrl, String accessToken) throws CoreException, ExecutorException {
Consumer<BuildExecutionStatusChangedEvent> onExecutionStatusChange = (statusChangedEvent) -> {
log.debug("Received BuildExecutionStatusChangedEvent: " + statusChangedEvent);
if (statusChangedEvent.isFinal() && callbackUrl != null && !callbackUrl.isEmpty()) {
statusChangedEvent.getBuildResult().ifPresent((buildResult) -> bpmNotifier.sendBuildExecutionCompleted(callbackUrl, buildResult, accessToken));
}
};
BuildExecutionSession buildExecutionSession = buildExecutor.startBuilding(buildExecutionConfig, onExecutionStatusChange, accessToken);
return buildExecutionSession;
}
Aggregations