use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.
the class SCMRepositoryProviderImpl method startRCreationTask.
/**
* @param externalURL
* @param preBuildSyncEnabled
* @param jobType
* @param consumer
* @param buildConfiguration required when repository is created as part of BC creation process
* @return
*/
private Integer startRCreationTask(String externalURL, String revision, boolean preBuildSyncEnabled, JobNotificationType jobType, Consumer<RepositoryCreated> consumer, Optional<BuildConfiguration> buildConfiguration) {
String userToken = userService.currentUserToken();
org.jboss.pnc.bpm.model.RepositoryConfiguration repositoryConfiguration = org.jboss.pnc.bpm.model.RepositoryConfiguration.builder().externalUrl(externalURL).preBuildSyncEnabled(preBuildSyncEnabled).build();
RepositoryCreationTask task;
if (bpmConfig.isNewBpmForced() || userService.hasLoggedInUserRole(WORK_WITH_TECH_PREVIEW)) {
RepositoryCreationProcess.RepositoryCreationProcessBuilder repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision);
buildConfiguration.ifPresent(bc -> repositoryCreationProcess.buildConfiguration(bc));
task = new RepositoryCreationTask(repositoryCreationProcess.build(), userToken);
task.setTaskId(bpmManager.getNextTaskId());
task.setGlobalConfig(globalConfig);
task.setJsonEncodedProcessParameters(false);
task.setJobType(jobType);
RestConnector restConnector = new RestConnector(bpmConfig);
try {
Map<String, Object> processParameters = task.getExtendedProcessParameters();
restConnector.startProcess(bpmConfig.getNewBcCreationProcessId(), processParameters, userToken);
} catch (CoreException e) {
throw new RuntimeException("Could not get process parameters: " + task, e);
} catch (ProcessManagerException e) {
throw new RuntimeException("Could not start BPM task using REST connector: " + task, e);
}
} else {
// deprecated
RepositoryCreationProcess repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision).build();
task = new RepositoryCreationTask(repositoryCreationProcess, userToken);
task.setJobType(jobType);
Consumer<RepositoryCloneSuccess> successListener = event -> onRepoCloneSuccess(event.getData().getInternalUrl(), task.getTaskId(), consumer, jobType, externalURL, preBuildSyncEnabled);
task.addListener(BpmEventType.RC_REPO_CLONE_SUCCESS, MDCWrappers.wrap(successListener));
addErrorListeners(jobType, task);
try {
bpmManager.startTask(task);
} catch (CoreException e) {
throw new RuntimeException("Could not start BPM task: " + task, e);
}
}
return task.getTaskId();
}
Aggregations