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