use of io.hops.hopsworks.persistence.entity.git.GitOpExecution 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.GitOpExecution 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);
}
}
}
Aggregations