Search in sources :

Example 1 with GitRepositoryRemote

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

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

the class GitRepositoryRemoteBuilder method build.

public GitRepositoryRemoteDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, GitRepository repository, String remoteName) throws GitOpException {
    Optional<GitRepositoryRemote> optional = gitRepositoryRemotesFacade.findByNameAndRepository(repository, remoteName);
    GitRepositoryRemote remote = optional.orElseThrow(() -> new GitOpException(RESTCodes.GitOpErrorCode.REMOTE_NOT_FOUND, Level.FINE, "Remote with name [" + remoteName + "] not found"));
    return build(uriInfo, resourceRequest, project, repository, remote);
}
Also used : GitRepositoryRemote(io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote) GitOpException(io.hops.hopsworks.exceptions.GitOpException)

Example 3 with GitRepositoryRemote

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

the class GitCommandOperationUtil method convertToRemote.

/**
 * Converts [{"remoteName":"gibson","url":"https://github.com/logicalclocks/hops-hadoop-chef.git"},
 * {"remoteName":"origin","url":"https://github.com/logicalclocks/hops-hadoop-chef.git"}] to List<GitRepositoryRemote>
 */
public List<GitRepositoryRemote> convertToRemote(GitRepository repository, String remotesJson) {
    List<GitRepositoryRemote> remotes = new ArrayList<>();
    try {
        JSONArray array = new JSONArray(remotesJson);
        for (int i = 0; i < array.length(); i++) {
            JSONObject object = array.getJSONObject(i);
            remotes.add(new GitRepositoryRemote(repository, object.getString("name"), object.getString("url")));
        }
    } catch (JSONException e) {
        LOGGER.log(Level.SEVERE, "Could not convert json string ", e);
    }
    return remotes;
}
Also used : JSONObject(org.json.JSONObject) GitRepositoryRemote(io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

GitRepositoryRemote (io.hops.hopsworks.persistence.entity.git.GitRepositoryRemote)3 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 GitOpException (io.hops.hopsworks.exceptions.GitOpException)1 GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)1 GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)1 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)1 ArrayList (java.util.ArrayList)1 Path (org.apache.hadoop.fs.Path)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1