Search in sources :

Example 1 with GitOpExecution

use of io.hops.hopsworks.persistence.entity.git.GitOpExecution in project hopsworks by logicalclocks.

the class GitOpExecutionFacade method create.

public GitOpExecution create(GitCommandConfiguration gitCommandConfiguration, Users user, GitRepository repository, String secret) {
    GitOpExecution gitOpExecution = new GitOpExecution(gitCommandConfiguration, new Date(), user, repository, GitOpExecutionState.INITIALIZING, secret);
    gitOpExecution.setExecutionStart(System.currentTimeMillis());
    em.persist(gitOpExecution);
    em.flush();
    return gitOpExecution;
}
Also used : GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Date(java.util.Date)

Example 2 with GitOpExecution

use of io.hops.hopsworks.persistence.entity.git.GitOpExecution in project hopsworks by logicalclocks.

the class GitTimeoutCommandsMonitor method rotate.

@Schedule(persistent = false, minute = "*/1", hour = "*")
public void rotate(Timer timer) {
    LOGGER.log(Level.INFO, "Running GitTimeoutCommandsMonitor");
    Collection<GitRepository> repositories = gitRepositoryFacade.findAllWithOngoingOperations();
    for (GitRepository repository : repositories) {
        Optional<GitOpExecution> optional = gitOpExecutionFacade.findRunningInRepository(repository);
        if (optional.isPresent()) {
            GitOpExecution execution = optional.get();
            Long timeElapsed = System.currentTimeMillis() - execution.getExecutionStart();
            if (timeElapsed > (settings.getGitJwtExpMs() + BONUS_TIME)) {
                // kill this container
                LOGGER.log(Level.INFO, "Killing git execution with Id + [" + execution.getId() + "] with state " + execution.getState().toString());
                gitOpExecutionFacade.updateState(execution, GitOpExecutionState.TIMEDOUT, "Timeout");
                gitCommandOperationUtil.shutdownCommandService(repository, execution);
            }
        } else {
            // A repository with a pid but no execution object
            try {
                long executionStart = Long.parseLong(repository.getCid());
                Long timeElapsed = System.currentTimeMillis() - executionStart;
                if (timeElapsed > WAIT_TIME_BEFORE_EXECUTION_OBJECT_CREATION) {
                    LOGGER.log(Level.INFO, "Failed to create execution in repository with Id + [" + repository.getId() + "] ");
                    gitRepositoryFacade.updateRepositoryCid(repository, null);
                }
            } catch (NumberFormatException e) {
                // It is probably the container id
                gitRepositoryFacade.updateRepositoryCid(repository, null);
            }
        }
    }
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Schedule(javax.ejb.Schedule)

Example 3 with GitOpExecution

use of io.hops.hopsworks.persistence.entity.git.GitOpExecution in project hopsworks by logicalclocks.

the class GitResource method remotes.

@ApiOperation(value = "Add or delete a git remote", response = GitOpExecutionDTO.class)
@POST
@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 remotes(@PathParam("repositoryId") Integer repositoryId, @QueryParam("action") GitRemotesAction action, @QueryParam("url") String remoteUrl, @QueryParam("name") String remoteName, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam ExecutionBeanParam executionBeanParam) throws GitOpException, HopsSecurityException, IllegalArgumentException {
    if (action == null) {
        throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_REMOTES_ACTION.getMessage());
    }
    Users hopsworksUser = jWTHelper.getUserPrincipal(sc);
    GitOpExecution execution = gitController.addOrDeleteRemote(action, project, hopsworksUser, repositoryId, remoteName, remoteUrl);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXECUTION);
    resourceRequest.setExpansions(executionBeanParam.getExpansions().getResources());
    GitOpExecutionDTO dto = executionBuilder.build(uriInfo, resourceRequest, execution);
    return Response.ok().entity(dto).build();
}
Also used : GitOpExecutionDTO(io.hops.hopsworks.api.git.execution.GitOpExecutionDTO) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) 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 4 with GitOpExecution

use of io.hops.hopsworks.persistence.entity.git.GitOpExecution in project hopsworks by logicalclocks.

the class GitResource method executeRepositoryAction.

@ApiOperation(value = "Perform a git repository action: commit, pull, push, status", response = GitOpExecutionDTO.class)
@POST
@Path("/repository/{repositoryId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(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 executeRepositoryAction(@PathParam("repositoryId") Integer repository, @QueryParam("action") GitRepositoryAction action, RepositoryActionCommandConfiguration configuration, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam ExecutionBeanParam executionBeanParam) throws GitOpException, HopsSecurityException, IllegalArgumentException {
    Users hopsworksUser = jWTHelper.getUserPrincipal(sc);
    GitOpExecution execution = gitController.executeRepositoryAction(configuration, project, hopsworksUser, action, repository);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXECUTION);
    resourceRequest.setExpansions(executionBeanParam.getExpansions().getResources());
    GitOpExecutionDTO dto = executionBuilder.build(uriInfo, resourceRequest, execution);
    return Response.ok().entity(dto).build();
}
Also used : GitOpExecutionDTO(io.hops.hopsworks.api.git.execution.GitOpExecutionDTO) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) 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 5 with GitOpExecution

use of io.hops.hopsworks.persistence.entity.git.GitOpExecution in project hopsworks by logicalclocks.

the class GitResource method clone.

@ApiOperation(value = "Clone a git repository", response = GitOpExecutionDTO.class)
@POST
@Path("/clone")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(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 clone(CloneCommandConfiguration commandDTO, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam ExecutionBeanParam executionBeanParam) throws GitOpException, HopsSecurityException, IllegalArgumentException, UserException, DatasetException {
    Users hopsworksUser = jWTHelper.getUserPrincipal(sc);
    GitOpExecution execution = gitController.clone(commandDTO, project, hopsworksUser);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXECUTION);
    resourceRequest.setExpansions(executionBeanParam.getExpansions().getResources());
    GitOpExecutionDTO dto = executionBuilder.build(uriInfo, resourceRequest, execution);
    return Response.ok().entity(dto).build();
}
Also used : GitOpExecutionDTO(io.hops.hopsworks.api.git.execution.GitOpExecutionDTO) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) 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)

Aggregations

GitOpExecution (io.hops.hopsworks.persistence.entity.git.GitOpExecution)12 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)7 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)7 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)7 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)7 ApiOperation (io.swagger.annotations.ApiOperation)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 Users (io.hops.hopsworks.persistence.entity.user.Users)6 GitOpExecutionDTO (io.hops.hopsworks.api.git.execution.GitOpExecutionDTO)5 POST (javax.ws.rs.POST)5 Consumes (javax.ws.rs.Consumes)4 GitRepository (io.hops.hopsworks.persistence.entity.git.GitRepository)2 GitPaths (io.hops.hopsworks.common.dao.git.GitPaths)1 GitCommitDTO (io.hops.hopsworks.common.git.GitCommitDTO)1 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1 GitOpException (io.hops.hopsworks.exceptions.GitOpException)1 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)1 GitCommit (io.hops.hopsworks.persistence.entity.git.GitCommit)1 GitCommandConfiguration (io.hops.hopsworks.persistence.entity.git.config.GitCommandConfiguration)1