Search in sources :

Example 81 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class ModelsResource method getTag.

@ApiOperation(value = "Get tag attached to a model", response = TagsDTO.class)
@GET
@Path("/{id}/tags/{name}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTag(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException, ProvenanceException, ModelRegistryException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
    Map<String, String> result = new HashMap<>();
    result.put(name, tagController.get(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), name));
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), result);
    return Response.status(Response.Status.OK).entity(dto).build();
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) HashMap(java.util.HashMap) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) 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 82 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class GitCommitsBuilder method build.

public GitCommitDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, GitRepository repository, String branchName) throws GitOpException {
    GitCommitDTO dto = new GitCommitDTO();
    dto.setHref(uri(uriInfo, project, repository.getId(), branchName));
    dto.setExpand(expand(resourceRequest));
    if (dto.isExpand()) {
        Integer limit = resourceRequest.getLimit() == null ? DEFAULT_BRANCH_COMMITS_LIMIT : resourceRequest.getLimit();
        Integer offset = resourceRequest.getOffset() == null ? 0 : resourceRequest.getOffset();
        AbstractFacade.CollectionInfo<GitCommit> branchCommits = gitCommitsFacade.getBranchCommits(repository, branchName, limit, offset);
        List<GitCommitDTO> commitDTOs = branchCommits.getItems().stream().map(gitCommit -> new GitCommitDTO(gitCommit.getName(), gitCommit.getEmail(), gitCommit.getMessage(), gitCommit.getHash(), gitCommit.getDate())).collect(Collectors.toList());
        dto.setItems(commitDTOs);
        dto.setCount(branchCommits.getCount());
    }
    return dto;
}
Also used : Stateless(javax.ejb.Stateless) GitCommitsFacade(io.hops.hopsworks.common.dao.git.GitCommitsFacade) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) GitOpException(io.hops.hopsworks.exceptions.GitOpException) GitCommit(io.hops.hopsworks.persistence.entity.git.GitCommit) Collectors(java.util.stream.Collectors) Project(io.hops.hopsworks.persistence.entity.project.Project) GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) List(java.util.List) TransactionAttributeType(javax.ejb.TransactionAttributeType) TransactionAttribute(javax.ejb.TransactionAttribute) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriInfo(javax.ws.rs.core.UriInfo) URI(java.net.URI) GitController(io.hops.hopsworks.common.git.GitController) GitCommitDTO(io.hops.hopsworks.common.git.GitCommitDTO) EJB(javax.ejb.EJB) GitCommit(io.hops.hopsworks.persistence.entity.git.GitCommit) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) GitCommitDTO(io.hops.hopsworks.common.git.GitCommitDTO)

Example 83 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest 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 84 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest 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 85 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class GitResource method branch.

@ApiOperation(value = "Executes a git branch --option command action: add, checkout, delete", response = GitOpExecutionDTO.class)
@POST
@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 branch(@PathParam("repositoryId") Integer repositoryId, @QueryParam("action") GitBranchAction action, @QueryParam("branchName") String branchName, @QueryParam("commit") String commit, @Context HttpServletRequest req, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam ExecutionBeanParam executionBeanParam) throws IllegalArgumentException, GitOpException, HopsSecurityException {
    if (action == null) {
        throw new IllegalArgumentException(RESTCodes.GitOpErrorCode.INVALID_BRANCH_ACTION.getMessage());
    }
    Users hopsworksUser = jWTHelper.getUserPrincipal(sc);
    GitOpExecution execution = gitController.executeBranchAction(action, project, hopsworksUser, repositoryId, branchName, commit);
    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)

Aggregations

ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)171 ApiOperation (io.swagger.annotations.ApiOperation)163 Produces (javax.ws.rs.Produces)157 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)151 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)127 GET (javax.ws.rs.GET)107 Path (javax.ws.rs.Path)99 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)94 Users (io.hops.hopsworks.persistence.entity.user.Users)75 Consumes (javax.ws.rs.Consumes)37 POST (javax.ws.rs.POST)30 PUT (javax.ws.rs.PUT)27 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)20 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)17 AlertException (io.hops.hopsworks.exceptions.AlertException)14 Project (io.hops.hopsworks.persistence.entity.project.Project)14 UriBuilder (javax.ws.rs.core.UriBuilder)12 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)11 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)11 HashMap (java.util.HashMap)9