Search in sources :

Example 11 with GitRepository

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();
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitRepositoryRemoteDTO(io.hops.hopsworks.api.git.remote.GitRepositoryRemoteDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 12 with GitRepository

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();
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) BranchDTO(io.hops.hopsworks.api.git.branch.BranchDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 13 with GitRepository

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();
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitRepositoryDTO(io.hops.hopsworks.api.git.repository.GitRepositoryDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 14 with GitRepository

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();
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitRepositoryRemoteDTO(io.hops.hopsworks.api.git.remote.GitRepositoryRemoteDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 15 with GitRepository

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());
}
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

GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)20 GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)7 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)6 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)5 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)5 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)5 ApiOperation (io.swagger.annotations.ApiOperation)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 GitOpException (io.hops.hopsworks.exceptions.GitOpException)3 TransactionAttribute (javax.ejb.TransactionAttribute)3 GitRepositoryRemoteDTO (io.hops.hopsworks.api.git.remote.GitRepositoryRemoteDTO)2 GitCommitDTO (io.hops.hopsworks.common.git.GitCommitDTO)2 GitCommit (io.hops.hopsworks.persistence.entity.git.GitCommit)2 GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)2 BranchDTO (io.hops.hopsworks.api.git.branch.BranchDTO)1 GitRepositoryDTO (io.hops.hopsworks.api.git.repository.GitRepositoryDTO)1 AbstractFacade (io.hops.hopsworks.common.dao.AbstractFacade)1 GitCommitsFacade (io.hops.hopsworks.common.dao.git.GitCommitsFacade)1