use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitController method updateBranchCommits.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateBranchCommits(Project project, BranchCommits commits, Integer repositoryId, String branchName) throws GitOpException {
if (Strings.isNullOrEmpty(branchName)) {
throw new IllegalArgumentException("Branch name cannot be null");
}
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
// delete all
gitCommitsFacade.deleteAllInBranchAndRepository(branchName, repository);
// create new entries
for (GitCommit commit : commits.getCommits()) {
commit.setBranch(branchName);
commit.setRepository(repository);
gitCommitsFacade.create(commit);
}
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository 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);
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository 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);
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository 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);
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class AsynchronousGitCommandExecutor method execute.
@Asynchronous
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void execute(GitOpExecution gitOpExecution, GitPaths gitPaths) {
int maxTries = 5;
String pid = "";
String gitCommand = gitOpExecution.getGitCommandConfiguration().getCommandType().getGitCommand();
String prog = settings.getSudoersDir() + "/git.sh";
String commandArgumentsFile = gitPaths.getConfDirPath() + File.separator + GitContainerLaunchScriptArgumentsTemplate.FILE_NAME;
while (maxTries > 0 && Strings.isNullOrEmpty(pid)) {
try {
ProcessDescriptor processDescriptor = new ProcessDescriptor.Builder().addCommand("/usr/bin/sudo").addCommand(prog).addCommand("start").addCommand(commandArgumentsFile).redirectErrorStream(true).setCurrentWorkingDirectory(new File(gitPaths.getGitPath())).setWaitTimeout(60L, TimeUnit.SECONDS).build();
String pidFile = gitPaths.getRunDirPath() + "/git.pid";
ProcessResult processResult = osProcessExecutor.execute(processDescriptor);
if (processResult.getExitCode() != 0) {
String errorMsg = "Could not start git service to execute command " + gitCommand + " . " + "Exit code: " + processResult.getExitCode() + " Error: stdout: " + processResult.getStdout() + " stderr: " + processResult.getStderr();
LOGGER.log(Level.SEVERE, errorMsg);
throw new IOException(errorMsg);
} else {
pid = com.google.common.io.Files.readFirstLine(new File(pidFile), Charset.defaultCharset());
// Get the updated repository
Optional<GitRepository> optional = gitRepositoryFacade.findById(gitOpExecution.getRepository().getId());
gitRepositoryFacade.updateRepositoryCid(optional.get(), pid);
// gitOpExecutionFacade.updateState(gitOpExecution, GitOpExecutionState.SUBMITTED);
}
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Problem executing shell script to start git command service", ex);
maxTries--;
}
}
if (Strings.isNullOrEmpty(pid)) {
updateExecutionStateToFail(gitOpExecution);
}
}
Aggregations