Search in sources :

Example 1 with GitPaths

use of io.hops.hopsworks.common.dao.git.GitPaths in project hopsworks by logicalclocks.

the class GitExecutionController method createExecution.

/**
 * initializes the execution of all git commands
 *
 * @param gitCommandConfiguration
 * @param project
 * @param hopsworksUser
 * @param repository
 * @return
 * @throws HopsSecurityException
 * @throws GitOpException
 */
public GitOpExecution createExecution(GitCommandConfiguration gitCommandConfiguration, Project project, Users hopsworksUser, GitRepository repository) throws HopsSecurityException, GitOpException {
    String hdfsUsername = hdfsUsersController.getHdfsUserName(project, hopsworksUser);
    BasicAuthSecrets authSecrets = gitCommandOperationUtil.getAuthenticationSecrets(hopsworksUser, repository.getGitProvider());
    commandConfigurationValidator.validateProviderConfiguration(authSecrets, gitCommandConfiguration);
    String configSecret = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt()));
    lockRepository(repository.getId());
    GitOpExecution gitOpExecution = null;
    DistributedFileSystemOps udfso = null;
    try {
        udfso = dfsService.getDfsOps(hdfsUsername);
        GitPaths gitPaths = prepareCommandExecution(project, hopsworksUser, udfso, configSecret);
        gitOpExecution = gitOpExecutionFacade.create(gitCommandConfiguration, hopsworksUser, repository, configSecret);
        argumentsWriter.createArgumentFile(gitOpExecution, gitPaths, authSecrets);
        gitCommandExecutor.execute(gitOpExecution, gitPaths);
        return gitOpExecution;
    } catch (Exception ex) {
        gitRepositoryFacade.updateRepositoryCid(repository, null);
        gitCommandOperationUtil.cleanUp(project, hopsworksUser, configSecret);
        if (ex instanceof IOException) {
            throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CERT_MATERIALIZATION_ERROR, Level.SEVERE, ex.getMessage(), null, ex);
        }
        throw new GitOpException(RESTCodes.GitOpErrorCode.GIT_OPERATION_ERROR, Level.SEVERE, ex.getMessage());
    } finally {
        if (udfso != null) {
            dfsService.closeDfsClient(udfso);
        }
    }
}
Also used : GitPaths(io.hops.hopsworks.common.dao.git.GitPaths) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) GitOpException(io.hops.hopsworks.exceptions.GitOpException) IOException(java.io.IOException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) GitOpException(io.hops.hopsworks.exceptions.GitOpException) IOException(java.io.IOException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException)

Example 2 with GitPaths

use of io.hops.hopsworks.common.dao.git.GitPaths in project hopsworks by logicalclocks.

the class GitExecutionController method prepareCommandExecution.

/**
 * Generate the git paths, materialize user certificates, and jwt
 *
 * @param project
 * @param hopsworksUser
 * @param dfso
 * @throws GitOpException
 * @throws IOException
 */
public GitPaths prepareCommandExecution(Project project, Users hopsworksUser, DistributedFileSystemOps dfso, String configSecret) throws GitOpException, IOException {
    GitPaths gitPaths = new GitPaths(settings.getStagingDir() + settings.PRIVATE_DIRS, configSecret);
    gitCommandOperationUtil.generatePaths(gitPaths);
    HopsUtils.materializeCertificatesForUserCustomDir(project.getName(), hopsworksUser.getUsername(), settings.getHdfsTmpCertDir(), dfso, certificateMaterializer, settings, gitPaths.getCertificatesDirPath());
    gitJWTManager.materializeJWT(hopsworksUser, gitPaths.getTokenPath());
    return gitPaths;
}
Also used : GitPaths(io.hops.hopsworks.common.dao.git.GitPaths)

Aggregations

GitPaths (io.hops.hopsworks.common.dao.git.GitPaths)2 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 GitOpException (io.hops.hopsworks.exceptions.GitOpException)1 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)1 GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)1 IOException (java.io.IOException)1