Search in sources :

Example 61 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class LibraryResource method install.

@ApiOperation(value = "Install a python library in the environment")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{library}")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.PYTHON }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response install(LibrarySpecification librarySpecification, @PathParam("library") String library, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws ServiceException, GenericException, PythonException, DatasetException {
    Users user = jwtHelper.getUserPrincipal(req);
    environmentController.checkCondaEnabled(project, pythonVersion, true);
    PackageSource packageSource = librarySpecification.getPackageSource();
    if (packageSource == null) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE);
    }
    switch(packageSource) {
        case PIP:
            validateLibrary(librarySpecification, library);
            librarySpecification.setChannelUrl("pypi");
            break;
        case CONDA:
            validateLibrary(librarySpecification, library);
            break;
        case EGG:
        case WHEEL:
        case REQUIREMENTS_TXT:
        case ENVIRONMENT_YAML:
            validateBundledDependency(user, librarySpecification);
            break;
        case GIT:
            validateGitURL(librarySpecification.getDependencyUrl());
            break;
        default:
            throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE);
    }
    environmentController.checkCondaEnvExists(project, user);
    PythonDep dep = libraryController.installLibrary(project, user, CondaInstallType.valueOf(packageSource.name().toUpperCase()), librarySpecification.getChannelUrl(), library, librarySpecification.getVersion(), librarySpecification.getDependencyUrl(), librarySpecification.getGitBackend(), librarySpecification.getGitApiKey());
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.LIBRARIES);
    LibraryDTO libraryDTO = librariesBuilder.build(uriInfo, resourceRequest, dep, project);
    return Response.created(libraryDTO.getHref()).entity(libraryDTO).build();
}
Also used : PackageSource(io.hops.hopsworks.common.python.library.PackageSource) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep) PythonException(io.hops.hopsworks.exceptions.PythonException) 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) Consumes(javax.ws.rs.Consumes) 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 62 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class LibraryResource method uninstall.

@ApiOperation(value = "Uninstall a python library from the environment")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("{library}")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.PYTHON }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response uninstall(@Context SecurityContext sc, @PathParam("library") String library) throws ServiceException, GenericException, PythonException {
    validatePattern(library);
    Users user = jwtHelper.getUserPrincipal(sc);
    environmentController.checkCondaEnabled(project, pythonVersion, true);
    if (settings.getImmutablePythonLibraryNames().contains(library)) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_DEP_REMOVE_FORBIDDEN, Level.INFO, "library: " + library);
    }
    environmentController.checkCondaEnvExists(project, user);
    commandsController.deleteCommands(project, library);
    libraryController.uninstallLibrary(project, user, library);
    return Response.noContent().build();
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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 63 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class InferenceResource method infer.

@POST
@Path("/models/{modelName: [a-zA-Z0-9]+}{version:(/versions/[0-9]+)?}{verb:((" + InferenceVerb.ANNOTATION + "))?}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Make inference")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB, Audience.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response infer(@ApiParam(value = "Name of the model to query", required = true) @PathParam("modelName") String modelName, @ApiParam(value = "Version of the model to query") @PathParam("version") String modelVersion, @ApiParam(value = "Type of query") @PathParam("verb") InferenceVerb verb, @Context SecurityContext sc, @Context HttpHeaders httpHeaders, String inferenceRequestJson) throws InferenceException, ApiKeyException {
    Integer version = null;
    if (!Strings.isNullOrEmpty(modelVersion)) {
        version = Integer.valueOf(modelVersion.split("/")[2]);
    }
    Users user = jWTHelper.getUserPrincipal(sc);
    String authHeader = httpHeaders.getRequestHeader(HttpHeaders.AUTHORIZATION).get(0);
    String inferenceResult = inferenceController.infer(project, sc.getUserPrincipal().getName(), modelName, version, verb, inferenceRequestJson, authHeader);
    return Response.ok().entity(inferenceResult).build();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) 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 64 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class MessageService method moveToTrash.

@PUT
@Path("moveToTrash/{msgId}")
@Produces(MediaType.APPLICATION_JSON)
public Response moveToTrash(@PathParam("msgId") Integer msgId, @Context SecurityContext sc) throws RequestException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Message msg = msgFacade.find(msgId);
    if (msg == null) {
        throw new RequestException(RESTCodes.RequestErrorCode.MESSAGE_NOT_FOUND, Level.FINE);
    }
    // Delete Dataset request from the database
    if (!Strings.isNullOrEmpty(msg.getSubject())) {
        DatasetRequest dsReq = dsReqFacade.findByMessageId(msg);
        if (dsReq != null) {
            dsReqFacade.remove(dsReq);
        }
    }
    // check if the user is the owner of the message
    checkMsgUser(msg, user);
    msg.setDeleted(true);
    msgFacade.update(msg);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).build();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) DatasetRequest(io.hops.hopsworks.persistence.entity.dataset.DatasetRequest) Users(io.hops.hopsworks.persistence.entity.user.Users) RequestException(io.hops.hopsworks.exceptions.RequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 65 with Users

use of io.hops.hopsworks.persistence.entity.user.Users in project hopsworks by logicalclocks.

the class MessageService method restoreFromTrash.

@PUT
@Path("restoreFromTrash/{msgId}")
@Produces(MediaType.APPLICATION_JSON)
public Response restoreFromTrash(@PathParam("msgId") Integer msgId, @Context SecurityContext sc) throws RequestException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Message msg = msgFacade.find(msgId);
    if (msg == null) {
        throw new RequestException(RESTCodes.RequestErrorCode.MESSAGE_NOT_FOUND, Level.FINE);
    }
    // check if the user is the owner of the message
    checkMsgUser(msg, user);
    msg.setDeleted(false);
    msgFacade.update(msg);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).build();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) Users(io.hops.hopsworks.persistence.entity.user.Users) RequestException(io.hops.hopsworks.exceptions.RequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

Users (io.hops.hopsworks.persistence.entity.user.Users)325 Produces (javax.ws.rs.Produces)195 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)169 Path (javax.ws.rs.Path)167 ApiOperation (io.swagger.annotations.ApiOperation)158 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)150 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)116 GET (javax.ws.rs.GET)86 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)78 POST (javax.ws.rs.POST)65 Consumes (javax.ws.rs.Consumes)52 Project (io.hops.hopsworks.persistence.entity.project.Project)48 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)44 DELETE (javax.ws.rs.DELETE)34 UserException (io.hops.hopsworks.exceptions.UserException)33 PUT (javax.ws.rs.PUT)33 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)26 GenericEntity (javax.ws.rs.core.GenericEntity)24 RESTApiJsonResponse (io.hops.hopsworks.api.util.RESTApiJsonResponse)21 IOException (java.io.IOException)21