Search in sources :

Example 1 with RepositoryRefreshListener

use of com.walmartlabs.concord.server.repository.listeners.RepositoryRefreshListener in project concord by walmartlabs.

the class RepositoryRefresher method refresh.

public void refresh(String orgName, String projectName, String repositoryName, boolean sync) {
    UUID orgId = orgManager.assertAccess(orgName, true).getId();
    ProjectEntry projectEntry = assertProject(orgId, projectName, ResourceAccessLevel.READER, true);
    UUID projectId = projectEntry.getId();
    RepositoryEntry repositoryEntry = assertRepository(projectEntry, repositoryName);
    if (!sync) {
        Map<String, Object> event = new HashMap<>();
        event.put("event", "repositoryRefresh");
        event.put("org", orgName);
        event.put("project", projectName);
        event.put("repository", repositoryName);
        externalEventResource.event("concord", event);
        return;
    }
    try (TemporaryPath tmpRepoPath = IOUtils.tempDir("refreshRepo_")) {
        repositoryManager.withLock(repositoryEntry.getUrl(), () -> {
            Repository repo = repositoryManager.fetch(projectId, repositoryEntry);
            repo.export(tmpRepoPath.path());
            return null;
        });
        tx(tx -> {
            for (RepositoryRefreshListener l : listeners) {
                l.onRefresh(tx, repositoryEntry, tmpRepoPath.path());
            }
        });
    } catch (Exception e) {
        String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
        throw new ConcordApplicationException("Error while refreshing repository: \n" + errorMessage, e);
    }
}
Also used : RepositoryUtils.assertRepository(com.walmartlabs.concord.server.org.project.RepositoryUtils.assertRepository) Repository(com.walmartlabs.concord.repository.Repository) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) RepositoryRefreshListener(com.walmartlabs.concord.server.repository.listeners.RepositoryRefreshListener) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException)

Aggregations

TemporaryPath (com.walmartlabs.concord.common.TemporaryPath)1 Repository (com.walmartlabs.concord.repository.Repository)1 RepositoryUtils.assertRepository (com.walmartlabs.concord.server.org.project.RepositoryUtils.assertRepository)1 RepositoryRefreshListener (com.walmartlabs.concord.server.repository.listeners.RepositoryRefreshListener)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)1