use of io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration in project hopsworks by logicalclocks.
the class GitExecutionController method updateGitExecutionState.
public GitOpExecution updateGitExecutionState(Project project, Users hopsworksUser, GitCommandExecutionStateUpdateDTO stateDTO, Integer repositoryId, Integer executionId) throws IllegalArgumentException, GitOpException {
GitOpExecutionState newState = stateDTO.getExecutionState();
if (newState == null) {
throw new IllegalArgumentException("Invalid git execution state. Execution state cannot be null.");
}
LOGGER.log(Level.INFO, "Updating execution, Id = " + executionId + " to " + newState.getExecutionState());
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
GitOpExecution exec = getExecutionInRepository(repository, executionId);
exec.setCommandResultMessage(stateDTO.getMessage());
if (newState.isFinalState()) {
if (newState == GitOpExecutionState.SUCCESS) {
// Every successful operation should update the repository current commit and branch
repository.setCurrentBranch(stateDTO.getBranch());
repository.setCurrentCommit(stateDTO.getCommitHash());
GitCommandConfiguration executedCommandConfig = exec.getGitCommandConfiguration();
if (executedCommandConfig.getCommandType() == GitCommandType.DELETE_BRANCH) {
// if we deleted a branch then we should also delete all the commits for this branch
gitCommitsFacade.deleteAllInBranchAndRepository(executedCommandConfig.getBranchName(), repository);
}
if (executedCommandConfig.getCommandType() == GitCommandType.ADD_REMOTE || executedCommandConfig.getCommandType() == GitCommandType.DELETE_REMOTE) {
// Update the remotes which are in the execution final message
String remotesJson = exec.getCommandResultMessage();
if (!Strings.isNullOrEmpty(remotesJson)) {
gitRepositoryRemotesFacade.updateRepositoryRemotes(gitCommandOperationUtil.convertToRemote(repository, remotesJson), repository);
}
}
}
gitRepositoryFacade.updateRepositoryCid(repository, null);
gitCommandOperationUtil.cleanUp(project, hopsworksUser, exec.getConfigSecret());
}
return gitOpExecutionFacade.updateState(exec, newState, stateDTO.getMessage());
}
use of io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration 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);
}
use of io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration 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);
}
use of io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration 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);
}
Aggregations