Search in sources :

Example 1 with GitOpExecutionState

use of io.hops.hopsworks.persistence.entity.git.config.GitOpExecutionState 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());
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitCommandConfiguration(io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration) GitOpExecutionState(io.hops.hopsworks.persistence.entity.git.config.GitOpExecutionState) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution)

Aggregations

GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)1 GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)1 GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)1 GitOpExecutionState (io.hops.hopsworks.persistence.entity.git.config.GitOpExecutionState)1