Search in sources :

Example 6 with GitRepository

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

the class GitRepositoryFacade method create.

public GitRepository create(Inode inode, Project project, GitProvider gitProvider, Users user) {
    GitRepository gitRepository = new GitRepository(inode, project, gitProvider, user);
    em.persist(gitRepository);
    em.flush();
    return gitRepository;
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository)

Example 7 with GitRepository

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

the class GitTimeoutCommandsMonitor method rotate.

@Schedule(persistent = false, minute = "*/1", hour = "*")
public void rotate(Timer timer) {
    LOGGER.log(Level.INFO, "Running GitTimeoutCommandsMonitor");
    Collection<GitRepository> repositories = gitRepositoryFacade.findAllWithOngoingOperations();
    for (GitRepository repository : repositories) {
        Optional<GitOpExecution> optional = gitOpExecutionFacade.findRunningInRepository(repository);
        if (optional.isPresent()) {
            GitOpExecution execution = optional.get();
            Long timeElapsed = System.currentTimeMillis() - execution.getExecutionStart();
            if (timeElapsed > (settings.getGitJwtExpMs() + BONUS_TIME)) {
                // kill this container
                LOGGER.log(Level.INFO, "Killing git execution with Id + [" + execution.getId() + "] with state " + execution.getState().toString());
                gitOpExecutionFacade.updateState(execution, GitOpExecutionState.TIMEDOUT, "Timeout");
                gitCommandOperationUtil.shutdownCommandService(repository, execution);
            }
        } else {
            // A repository with a pid but no execution object
            try {
                long executionStart = Long.parseLong(repository.getCid());
                Long timeElapsed = System.currentTimeMillis() - executionStart;
                if (timeElapsed > WAIT_TIME_BEFORE_EXECUTION_OBJECT_CREATION) {
                    LOGGER.log(Level.INFO, "Failed to create execution in repository with Id + [" + repository.getId() + "] ");
                    gitRepositoryFacade.updateRepositoryCid(repository, null);
                }
            } catch (NumberFormatException e) {
                // It is probably the container id
                gitRepositoryFacade.updateRepositoryCid(repository, null);
            }
        }
    }
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Schedule(javax.ejb.Schedule)

Example 8 with GitRepository

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

the class GitExecutionController method lockRepository.

private synchronized void lockRepository(Integer repositoryId) throws GitOpException {
    Optional<GitRepository> optional = gitRepositoryFacade.findById(repositoryId);
    if (!optional.isPresent()) {
        throw new GitOpException(RESTCodes.GitOpErrorCode.REPOSITORY_NOT_FOUND, Level.SEVERE, "Git " + "repository with id [" + optional + "] was not found.");
    } else {
        GitRepository repository = optional.get();
        if (repository.getCid() != null) {
            throw new GitOpException(RESTCodes.GitOpErrorCode.GIT_OPERATION_ERROR, Level.WARNING, "There is another ongoing operation in the repository.");
        }
        // lock repository
        repository.setCid(String.valueOf(System.currentTimeMillis()));
        gitRepositoryFacade.updateRepository(repository);
    }
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitOpException(io.hops.hopsworks.exceptions.GitOpException)

Example 9 with GitRepository

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

the class GitResource method getBranchCommits.

@ApiOperation(value = "Gets the branch commits. Similar to git log --oneline", response = GitCommitDTO.class)
@GET
@Path("/repository/{repositoryId}/branch/{branchName}/commit")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getBranchCommits(@Context UriInfo uriInfo, @Context SecurityContext sc, @BeanParam Pagination pagination, @PathParam("repositoryId") Integer repositoryId, @PathParam("branchName") String branchName) throws GitOpException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.COMMIT);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    GitCommitDTO commits = gitCommitsBuilder.build(uriInfo, resourceRequest, project, repository, branchName);
    return Response.ok().entity(commits).build();
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) GitCommitDTO(io.hops.hopsworks.common.git.GitCommitDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 10 with GitRepository

use of io.hops.hopsworks.persistence.entity.git.GitRepository 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

GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)20 GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)7 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)6 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)5 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)5 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)5 ApiOperation (io.swagger.annotations.ApiOperation)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 GitOpException (io.hops.hopsworks.exceptions.GitOpException)3 TransactionAttribute (javax.ejb.TransactionAttribute)3 GitRepositoryRemoteDTO (io.hops.hopsworks.api.git.remote.GitRepositoryRemoteDTO)2 GitCommitDTO (io.hops.hopsworks.common.git.GitCommitDTO)2 GitCommit (io.hops.hopsworks.persistence.entity.git.GitCommit)2 GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)2 BranchDTO (io.hops.hopsworks.api.git.branch.BranchDTO)1 GitRepositoryDTO (io.hops.hopsworks.api.git.repository.GitRepositoryDTO)1 AbstractFacade (io.hops.hopsworks.common.dao.AbstractFacade)1 GitCommitsFacade (io.hops.hopsworks.common.dao.git.GitCommitsFacade)1