use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitResource method getRepositoryRemotes.
@ApiOperation(value = "Get repository configured remotes: git remotes -v", response = GitRepositoryRemoteDTO.class)
@GET
@Path("/repository/{repositoryId}/remote")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getRepositoryRemotes(@Context UriInfo uriInfo, @Context SecurityContext sc, @PathParam("repositoryId") Integer repositoryId) throws GitOpException {
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.REMOTE);
GitRepositoryRemoteDTO dto = gitRepositoryRemoteBuilder.build(uriInfo, resourceRequest, project, repository);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitResource method getRepositoryBranches.
@ApiOperation(value = "Get branches for the given repository", response = BranchDTO.class)
@GET
@Path("/repository/{repositoryId}/branch")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getRepositoryBranches(@Context UriInfo uriInfo, @Context SecurityContext sc, @BeanParam Pagination pagination, @PathParam("repositoryId") Integer repositoryId) throws GitOpException {
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.BRANCH);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
BranchDTO repositoryBranches = branchBuilder.build(uriInfo, resourceRequest, project, repository);
return Response.ok().entity(repositoryBranches).build();
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitResource method gitRepository.
@ApiOperation(value = "Get a repository with a particular Id", response = GitRepositoryDTO.class)
@GET
@Path("/repository/{repositoryId}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response gitRepository(@PathParam("repositoryId") Integer repositoryId, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam RepositoryBeanParam repositoryBeanParam) throws GitOpException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.REPOSITORY);
resourceRequest.setExpansions(repositoryBeanParam.getExpansions().getResources());
GitRepository gitRepository = commandConfigurationValidator.verifyRepository(project, repositoryId);
GitRepositoryDTO dto = gitRepositoryBuilder.build(uriInfo, resourceRequest, project, gitRepository);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository in project hopsworks by logicalclocks.
the class GitResource method getRepositoryRemote.
@ApiOperation(value = "Get repository remote of a particular name", response = GitRepositoryRemoteDTO.class)
@GET
@Path("/repository/{repositoryId}/remote/{remoteName}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getRepositoryRemote(@Context UriInfo uriInfo, @Context SecurityContext sc, @PathParam("repositoryId") Integer repositoryId, @PathParam("remoteName") String remoteName) throws GitOpException {
if (Strings.isNullOrEmpty(remoteName)) {
throw new IllegalArgumentException("Remote name is empty");
}
GitRepository repository = commandConfigurationValidator.verifyRepository(project, repositoryId);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.REMOTE);
GitRepositoryRemoteDTO dto = gitRepositoryRemoteBuilder.build(uriInfo, resourceRequest, project, repository, remoteName);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.git.GitRepository 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());
}
Aggregations