Search in sources :

Example 16 with GitRepository

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

the class GitController method fileCheckout.

public GitOpExecution fileCheckout(Project project, Users hopsworksUser, Integer repositoryId, List<String> filePaths) throws GitOpException, HopsSecurityException {
    if (filePaths.isEmpty()) {
        throw new IllegalArgumentException("File paths are empty.");
    }
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    String repositoryFullPath = inodeController.getPath(repository.getInode());
    GitCommandConfiguration fileCheckoutConfiguration = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.FILE_CHECKOUT).setPath(repositoryFullPath).setFiles(filePaths).build();
    return executionController.createExecution(fileCheckoutConfiguration, project, hopsworksUser, repository);
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)

Example 17 with GitRepository

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

the class GitController method addOrDeleteRemote.

public GitOpExecution addOrDeleteRemote(GitRemotesAction action, Project project, Users hopsworksUser, Integer repositoryId, String remoteName, String remoteUrl) throws GitOpException, IllegalArgumentException, HopsSecurityException {
    if (Strings.isNullOrEmpty(remoteName)) {
        throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTE_NAME.getMessage());
    }
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    String repositoryFullPath = inodeController.getPath(repository.getInode());
    GitCommandConfigurationBuilder builder = new GitCommandConfigurationBuilder().setPath(repositoryFullPath).setRemoteName(remoteName);
    switch(action) {
        case ADD:
            if (Strings.isNullOrEmpty(remoteUrl)) {
                throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTE_URL_PROVIDED.getMessage());
            }
            builder.setCommandType(GitCommandType.ADD_REMOTE);
            builder.setRemoteUrl(remoteUrl);
            return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
        case DELETE:
            builder.setCommandType(GitCommandType.DELETE_REMOTE);
            return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
        default:
            throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTES_ACTION.getMessage());
    }
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository)

Example 18 with GitRepository

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

the class GitController method pull.

public GitOpExecution pull(PullCommandConfiguration configDTO, Project project, Users hopsworksUser, Integer repositoryId) throws GitOpException, HopsSecurityException, IllegalArgumentException {
    commandConfigurationValidator.verifyRemoteNameAndBranch(configDTO.getRemoteName(), configDTO.getBranchName());
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    String repositoryFullPath = inodeController.getPath(repository.getInode());
    GitCommandConfiguration pullCommandConfiguration = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.PULL).setRemoteName(configDTO.getRemoteName()).setForce(configDTO.isForce()).setBranchName(configDTO.getBranchName()).setPath(repositoryFullPath).build();
    return executionController.createExecution(pullCommandConfiguration, project, hopsworksUser, repository);
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)

Example 19 with GitRepository

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

the class GitController method executeBranchAction.

public GitOpExecution executeBranchAction(GitBranchAction action, Project project, Users hopsworksUser, Integer repositoryId, String branchName, String commit) throws GitOpException, HopsSecurityException, IllegalArgumentException {
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    String repositoryFullPath = inodeController.getPath(repository.getInode());
    GitCommandConfigurationBuilder builder = new GitCommandConfigurationBuilder();
    builder.setBranchName(branchName);
    builder.setPath(repositoryFullPath);
    switch(action) {
        case CREATE:
        case CREATE_CHECKOUT:
            if (Strings.isNullOrEmpty(branchName)) {
                throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_NAME, Level.WARNING, "Branch name is empty" + ".");
            }
            builder.setCommandType(GitCommandType.CREATE_BRANCH);
            builder.setCheckout(action == GitBranchAction.CREATE_CHECKOUT);
            return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
        case DELETE:
            if (Strings.isNullOrEmpty(branchName)) {
                throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_NAME, Level.WARNING, "Branch name is empty" + ".");
            }
            builder.setCommandType(GitCommandType.DELETE_BRANCH);
            builder.setDeleteOnRemote(false);
            return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
        case CHECKOUT:
        case CHECKOUT_FORCE:
            if (Strings.isNullOrEmpty(branchName) && Strings.isNullOrEmpty(commit)) {
                throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_AND_COMMIT_CHECKOUT_COMBINATION, Level.WARNING, "Please provide either branch or commit to checkout.");
            } else if (!Strings.isNullOrEmpty(branchName) && !Strings.isNullOrEmpty(commit)) {
                throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_AND_COMMIT_CHECKOUT_COMBINATION, Level.WARNING, "Checkout requires a commit or branch but not both.");
            }
            builder.setCommandType(GitCommandType.CHECKOUT);
            builder.setCommit(commit);
            builder.setForce(action == GitBranchAction.CHECKOUT_FORCE);
            return executionController.createExecution(builder.build(), project, hopsworksUser, repository);
        default:
            throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_ACTION.getMessage());
    }
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitOpException(io.hops.hopsworks.exceptions.GitOpException)

Example 20 with GitRepository

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

the class GitController method status.

public GitOpExecution status(Project project, Users hopsworksUser, Integer repositoryId) throws GitOpException, HopsSecurityException {
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    String repositoryFullPath = inodeController.getPath(repository.getInode());
    GitCommandConfiguration statusCommandConfig = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.STATUS).setPath(repositoryFullPath).build();
    return executionController.createExecution(statusCommandConfig, project, hopsworksUser, repository);
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)

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