Search in sources :

Example 1 with SCMRepositoryCreationSuccess

use of org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess 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);
        }
    });
}
Also used : ClientException(org.jboss.pnc.client.ClientException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) SCMRepositoryCreationSuccess(org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess) RepositoryCreationFailure(org.jboss.pnc.dto.notification.RepositoryCreationFailure)

Example 2 with SCMRepositoryCreationSuccess

use of org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess in project pnc by project-ncl.

the class SCMRepositoryProviderImpl method notifySCMRepositoryCreated.

private void notifySCMRepositoryCreated(RepositoryCreated event) {
    final SCMRepository repository = getSpecific(Integer.toString(event.getRepositoryId()));
    final String taskId = event.getTaskId() == null ? null : event.getTaskId().toString();
    if (taskId != null)
        notifier.sendMessage(new SCMRepositoryCreationSuccess(repository, taskId));
}
Also used : SCMRepository(org.jboss.pnc.dto.SCMRepository) SCMRepositoryCreationSuccess(org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess)

Aggregations

SCMRepositoryCreationSuccess (org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess)2 ClientException (org.jboss.pnc.client.ClientException)1 SCMRepository (org.jboss.pnc.dto.SCMRepository)1 RepositoryCreationFailure (org.jboss.pnc.dto.notification.RepositoryCreationFailure)1 RepositoryCreationResponse (org.jboss.pnc.dto.response.RepositoryCreationResponse)1