use of org.jboss.pnc.bpm.model.RepositoryCreationProcess in project pnc by project-ncl.
the class SCMRepositoryProviderImpl method repositoryCreationCompleted.
@Override
public void repositoryCreationCompleted(RepositoryCreationResult result) {
if (result.getStatus().isSuccess()) {
Consumer<RepositoryCreated> onRepositoryCreated = event -> {
log.debug("Repository created: {}", event);
if (result.getJobType().equals(JobNotificationType.BUILD_CONFIG_CREATION)) {
buildConfigurationProvider.createBuildConfigurationWithRepository(result.getTaskId().toString(), event.getRepositoryId(), result.getBuildConfiguration());
}
notifySCMRepositoryCreated(event);
};
onRepoCloneSuccess(result.getInternalScmUrl(), result.getTaskId(), onRepositoryCreated, result.getJobType(), result.getExternalUrl(), result.isPreBuildSyncEnabled());
} else {
String eventType;
if (!result.isRepoCreatedSuccessfully()) {
eventType = BpmEventType.RC_REPO_CREATION_ERROR.toString();
} else {
eventType = BpmEventType.RC_REPO_CLONE_ERROR.toString();
}
org.jboss.pnc.bpm.model.RepositoryConfiguration repositoryConfiguration = org.jboss.pnc.bpm.model.RepositoryConfiguration.builder().externalUrl(result.getExternalUrl()).preBuildSyncEnabled(result.isPreBuildSyncEnabled()).build();
RepositoryCreationProcess repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).build();
notifier.sendMessage(new RepositoryCreationFailure(result.getJobType(), eventType, repositoryCreationProcess, result.getTaskId().toString()));
}
}
use of org.jboss.pnc.bpm.model.RepositoryCreationProcess 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