Search in sources :

Example 1 with GitCommandConfiguration

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

the class GitController method commit.

public GitOpExecution commit(CommitCommandConfiguration commitConfigurationDTO, Project project, Users hopsworksUser, Integer repositoryId) throws IllegalArgumentException, GitOpException, HopsSecurityException {
    commandConfigurationValidator.verifyCommitOptions(commitConfigurationDTO);
    String userFullName = hopsworksUser.getFname() + " " + hopsworksUser.getLname();
    GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    String repositoryFullPath = inodeController.getPath(repository.getInode());
    GitCommandConfiguration commandConfiguration = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.COMMIT).setMessage(commitConfigurationDTO.getMessage()).setFiles(commitConfigurationDTO.getFiles()).setAll(commitConfigurationDTO.isAll()).setCommitter(new CommitterSignature(userFullName, hopsworksUser.getEmail())).setPath(repositoryFullPath).build();
    return executionController.createExecution(commandConfiguration, project, hopsworksUser, repository);
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration) CommitterSignature(io.hops.hopsworks.persistence.entity.git.CommitterSignature)

Example 2 with GitCommandConfiguration

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

the class GitController method clone.

public GitOpExecution clone(CloneCommandConfiguration cloneConfigurationDTO, Project project, Users hopsworksUser) throws IllegalArgumentException, GitOpException, HopsSecurityException, DatasetException {
    commandConfigurationValidator.verifyCloneOptions(cloneConfigurationDTO);
    // create the repository dir. The go-git does not create a directory, so we need to create it before
    String fullRepoDirPath = cloneConfigurationDTO.getPath() + File.separator + commandConfigurationValidator.getRepositoryName(cloneConfigurationDTO.getUrl());
    DistributedFileSystemOps udfso = dfsService.getDfsOps(hdfsUsersController.getHdfsUserName(project, hopsworksUser));
    try {
        datasetController.createSubDirectory(project, new Path(fullRepoDirPath), udfso);
    } finally {
        // Close the udfso
        dfsService.closeDfsClient(udfso);
    }
    Inode inode = inodeController.getInodeAtPath(fullRepoDirPath);
    GitRepository repository = gitRepositoryFacade.create(inode, project, cloneConfigurationDTO.getProvider(), hopsworksUser);
    // Create the default remote
    gitRepositoryRemotesFacade.save(new GitRepositoryRemote(repository, Constants.REPOSITORY_DEFAULT_REMOTE_NAME, cloneConfigurationDTO.getUrl()));
    GitCommandConfiguration configuration = new GitCommandConfigurationBuilder().setCommandType(GitCommandType.CLONE).setUrl(cloneConfigurationDTO.getUrl()).setProvider(cloneConfigurationDTO.getProvider()).setPath(fullRepoDirPath).setBranchName(cloneConfigurationDTO.getBranch()).build();
    return executionController.createExecution(configuration, project, hopsworksUser, repository);
}
Also used : Path(org.apache.hadoop.fs.Path) GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) GitRepositoryRemote(io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote) GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)

Example 3 with GitCommandConfiguration

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

the class GitController method push.

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

Example 4 with GitCommandConfiguration

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

the class GitCommandConfigurationBuilder method build.

public GitCommandConfiguration build() throws GitOpException {
    GitCommandConfiguration commandConfiguration = new GitCommandConfiguration();
    commandConfiguration.setRemoteName(this.remoteName);
    commandConfiguration.setRemoteUrl(this.remoteUrl);
    commandConfiguration.setBranchName(this.branchName);
    commandConfiguration.setForce(this.force);
    commandConfiguration.setCommit(this.commit);
    commandConfiguration.setUrl(this.url);
    commandConfiguration.setProvider(this.provider);
    commandConfiguration.setMessage(this.message);
    commandConfiguration.setCommitter(this.committer);
    commandConfiguration.setAll(this.all);
    commandConfiguration.setFiles(this.files);
    commandConfiguration.setCheckout(this.checkout);
    commandConfiguration.setDeleteOnRemote(this.deleteOnRemote);
    commandConfiguration.setCommandType(this.commandType);
    commandConfiguration.setPath(this.path);
    if (Strings.isNullOrEmpty(this.path) || this.commandType == null) {
        throw new GitOpException(RESTCodes.GitOpErrorCode.INVALID_GIT_COMMAND_CONFIGURATION, Level.FINE, "Path and " + "command type in command configuration cannot be null");
    }
    return commandConfiguration;
}
Also used : GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration) GitOpException(io.hops.hopsworks.exceptions.GitOpException)

Example 5 with GitCommandConfiguration

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

the class GitCommandConfigurationConverter method convertToEntityAttribute.

@Override
public GitCommandConfiguration convertToEntityAttribute(String jsonConfig) {
    if (Strings.isNullOrEmpty(jsonConfig)) {
        return null;
    }
    try {
        Unmarshaller unmarshaller = commandConfigurationContext.createUnmarshaller();
        StreamSource json = new StreamSource(new StringReader(jsonConfig));
        unmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
        unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
        return unmarshaller.unmarshal(json, GitCommandConfiguration.class).getValue();
    } catch (JAXBException e) {
        throw new IllegalStateException(e);
    }
}
Also used : GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)9 GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)7 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 GitOpException (io.hops.hopsworks.exceptions.GitOpException)1 CommitterSignature (io.hops.hopsworks.persistence.entity.git.CommitterSignature)1 GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)1 GitRepositoryRemote (io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote)1 GitOpExecutionState (io.hops.hopsworks.persistence.entity.git.config.GitOpExecutionState)1 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)1 StringReader (java.io.StringReader)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Path (org.apache.hadoop.fs.Path)1