Search in sources :

Example 1 with GitCommit

use of io.hops.hopsworks.persistence.entity.git.GitCommit in project hopsworks by logicalclocks.

the class GitController method updateBranchCommits.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateBranchCommits(Project project, BranchCommits commits, Integer repositoryId, String branchName) throws GitOpException {
    if (Strings.isNullOrEmpty(branchName)) {
        throw new IllegalArgumentException("Branch name cannot be null");
    }
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    // delete all
    gitCommitsFacade.deleteAllInBranchAndRepository(branchName, repository);
    // create new entries
    for (GitCommit commit : commits.getCommits()) {
        commit.setBranch(branchName);
        commit.setRepository(repository);
        gitCommitsFacade.create(commit);
    }
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitCommit(io.hops.hopsworks.persistence.entity.git.GitCommit) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with GitCommit

use of io.hops.hopsworks.persistence.entity.git.GitCommit in project hopsworks by logicalclocks.

the class GitRepositoryBuilder method build.

public GitRepositoryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, GitRepository repository) {
    GitRepositoryDTO repositoryDTO = new GitRepositoryDTO();
    repositoryDTO.setHref(uri(uriInfo, project, repository.getId()));
    repositoryDTO.setExpand(expand(resourceRequest));
    if (repositoryDTO.isExpand()) {
        repositoryDTO.setId(repository.getId());
        repositoryDTO.setName(repository.getInode().getInodePK().getName());
        repositoryDTO.setPath(inodeController.getPath(repository.getInode()));
        repositoryDTO.setProvider(repository.getGitProvider());
        repositoryDTO.setCurrentBranch(repository.getCurrentBranch());
        repositoryDTO.setCreator(usersBuilder.build(uriInfo, resourceRequest.get(ResourceRequest.Name.CREATOR), repository.getCreator()));
        Optional<GitCommit> commitOptional = gitCommitsFacade.findByHashAndRepository(repository);
        if (commitOptional.isPresent()) {
            GitCommit commit = commitOptional.get();
            GitCommitDTO gitCommitDTO = new GitCommitDTO(commit.getName(), commit.getEmail(), commit.getMessage(), commit.getHash(), commit.getDate());
            gitCommitDTO.setExpand(true);
            repositoryDTO.setCurrentCommit(gitCommitDTO);
        }
        // check if repository has an ongoing operation
        if (repository.getCid() != null) {
            Optional<GitOpExecution> optional = gitOpExecutionFacade.findRunningInRepository(repository);
            if (optional.isPresent()) {
                repositoryDTO.setOngoingOperation(gitOpExecutionBuilder.build(uriInfo, null, optional.get()));
            } else {
                LOGGER.log(Level.SEVERE, "There is a repository in locked state but with no execution object");
            }
        }
    }
    return repositoryDTO;
}
Also used : GitCommit(io.hops.hopsworks.persistence.entity.git.GitCommit) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) GitCommitDTO(io.hops.hopsworks.common.git.GitCommitDTO)

Example 3 with GitCommit

use of io.hops.hopsworks.persistence.entity.git.GitCommit in project hopsworks by logicalclocks.

the class GitCommitsBuilder method build.

public GitCommitDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, GitRepository repository, String branchName) throws GitOpException {
    GitCommitDTO dto = new GitCommitDTO();
    dto.setHref(uri(uriInfo, project, repository.getId(), branchName));
    dto.setExpand(expand(resourceRequest));
    if (dto.isExpand()) {
        Integer limit = resourceRequest.getLimit() == null ? DEFAULT_BRANCH_COMMITS_LIMIT : resourceRequest.getLimit();
        Integer offset = resourceRequest.getOffset() == null ? 0 : resourceRequest.getOffset();
        AbstractFacade.CollectionInfo<GitCommit> branchCommits = gitCommitsFacade.getBranchCommits(repository, branchName, limit, offset);
        List<GitCommitDTO> commitDTOs = branchCommits.getItems().stream().map(gitCommit -> new GitCommitDTO(gitCommit.getName(), gitCommit.getEmail(), gitCommit.getMessage(), gitCommit.getHash(), gitCommit.getDate())).collect(Collectors.toList());
        dto.setItems(commitDTOs);
        dto.setCount(branchCommits.getCount());
    }
    return dto;
}
Also used : Stateless(javax.ejb.Stateless) GitCommitsFacade(io.hops.hopsworks.common.dao.git.GitCommitsFacade) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) GitOpException(io.hops.hopsworks.exceptions.GitOpException) GitCommit(io.hops.hopsworks.persistence.entity.git.GitCommit) Collectors(java.util.stream.Collectors) Project(io.hops.hopsworks.persistence.entity.project.Project) GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) List(java.util.List) TransactionAttributeType(javax.ejb.TransactionAttributeType) TransactionAttribute(javax.ejb.TransactionAttribute) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriInfo(javax.ws.rs.core.UriInfo) URI(java.net.URI) GitController(io.hops.hopsworks.common.git.GitController) GitCommitDTO(io.hops.hopsworks.common.git.GitCommitDTO) EJB(javax.ejb.EJB) GitCommit(io.hops.hopsworks.persistence.entity.git.GitCommit) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) GitCommitDTO(io.hops.hopsworks.common.git.GitCommitDTO)

Aggregations

GitCommit (io.hops.hopsworks.persistence.entity.git.GitCommit)3 GitCommitDTO (io.hops.hopsworks.common.git.GitCommitDTO)2 GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)2 TransactionAttribute (javax.ejb.TransactionAttribute)2 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)1 AbstractFacade (io.hops.hopsworks.common.dao.AbstractFacade)1 GitCommitsFacade (io.hops.hopsworks.common.dao.git.GitCommitsFacade)1 GitController (io.hops.hopsworks.common.git.GitController)1 GitOpException (io.hops.hopsworks.exceptions.GitOpException)1 GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 URI (java.net.URI)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 EJB (javax.ejb.EJB)1 Stateless (javax.ejb.Stateless)1 TransactionAttributeType (javax.ejb.TransactionAttributeType)1 UriInfo (javax.ws.rs.core.UriInfo)1