use of org.jboss.pnc.dto.notification.RepositoryCreationFailure in project pnc by project-ncl.
the class AdvancedSCMRepositoryClient method createNewAndWait.
/**
* If the scm repository is already created and present in the Orch database, a RemoteResourceException is thrown.
* It's recommended that you check the presence of the repository before creating it.
*
* @param request scm to create
* @return CompletableFuture of the result, whether it was successful or not
* @throws RemoteResourceException Most likely thrown if repository already exists
* @throws ClientException if the response from the server is strange: both task id and scm repository is null
*/
public CompletableFuture<SCMCreationResult> createNewAndWait(CreateAndSyncSCMRequest request) throws RemoteResourceException, ClientException {
RepositoryCreationResponse response = super.createNew(request);
if (response.getTaskId() == null) {
if (response.getRepository() != null) {
// if repository is internal, it'll get created immediately. Just wrap the results into the
// CompletableFuture
SCMRepositoryCreationSuccess dto = new SCMRepositoryCreationSuccess(response.getRepository(), null);
return CompletableFuture.completedFuture(new SCMCreationResult(true, dto, null));
} else {
throw new ClientException("Something went wrong on creation of repository. task id and repository are both null");
}
}
webSocketClient.connect("ws://" + configuration.getHost() + BASE_PATH + "/notifications").join();
// if bpm task called, listen to either creation or failure events
return CompletableFuture.anyOf(waitForScmCreationFailure(webSocketClient, response.getTaskId().toString()), waitForScmCreationSuccess(webSocketClient, response.getTaskId().toString())).thenApply(a -> {
if (a instanceof SCMRepositoryCreationSuccess) {
return new SCMCreationResult(true, (SCMRepositoryCreationSuccess) a, null);
} else if (a instanceof RepositoryCreationFailure) {
return new SCMCreationResult(false, null, (RepositoryCreationFailure) a);
} else {
return new SCMCreationResult(false, null, null);
}
});
}
use of org.jboss.pnc.dto.notification.RepositoryCreationFailure in project pnc by project-ncl.
the class SCMRepositoryProviderImpl method onRepoCloneSuccess.
private void onRepoCloneSuccess(String internalScmUrl, Integer taskId, Consumer<RepositoryCreated> consumer, JobNotificationType jobType, String externalURL, boolean preBuildSyncEnabled) {
RepositoryConfiguration existing = repository.queryByPredicates(withExactInternalScmRepoUrl(internalScmUrl));
if (existing != null) {
RepositoryCreationFailure error = new RepositoryCreationFailure(jobType, RC_REPO_CREATION_CONFLICT, existing, taskId.toString());
notifier.sendMessage(error);
} else {
SCMRepository scmRepo = createSCMRepositoryFromValues(externalURL, internalScmUrl, preBuildSyncEnabled);
RepositoryCreated notification = new RepositoryCreated(taskId, Integer.parseInt(scmRepo.getId()));
consumer.accept(notification);
}
}
use of org.jboss.pnc.dto.notification.RepositoryCreationFailure 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()));
}
}
Aggregations