Search in sources :

Example 1 with PackageSource

use of io.hops.hopsworks.common.python.library.PackageSource 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 2 with PackageSource

use of io.hops.hopsworks.common.python.library.PackageSource in project hopsworks by logicalclocks.

the class LibraryResource method validateLibrary.

private void validateLibrary(LibrarySpecification librarySpecification, String library) throws PythonException {
    String version = librarySpecification.getVersion();
    PackageSource packageSource = librarySpecification.getPackageSource();
    String channel = librarySpecification.getChannelUrl();
    if (packageSource.equals(PackageSource.CONDA)) {
        if (channel == null) {
            throw new PythonException(RESTCodes.PythonErrorCode.CONDA_INSTALL_REQUIRES_CHANNEL, Level.FINE);
        } else {
            validateChannel(channel);
        }
    }
    validatePattern(library);
    if (!Strings.isNullOrEmpty(version)) {
        validatePattern(version);
    }
}
Also used : PackageSource(io.hops.hopsworks.common.python.library.PackageSource) PythonException(io.hops.hopsworks.exceptions.PythonException)

Example 3 with PackageSource

use of io.hops.hopsworks.common.python.library.PackageSource in project hopsworks by logicalclocks.

the class LibraryResource method validateBundledDependency.

private void validateBundledDependency(Users user, LibrarySpecification librarySpecification) throws DatasetException, PythonException {
    String dependencyUrl = librarySpecification.getDependencyUrl();
    PackageSource packageSource = librarySpecification.getPackageSource();
    datasetController.checkFileExists(new org.apache.hadoop.fs.Path(dependencyUrl), hdfsUsersController.getHdfsUserName(project, user));
    if (packageSource.equals(PackageSource.EGG) && !dependencyUrl.endsWith(".egg")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not an .egg file: " + dependencyUrl);
    } else if (packageSource.equals(PackageSource.WHEEL) && !dependencyUrl.endsWith(".whl")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a .whl file: " + dependencyUrl);
    } else if (packageSource.equals(PackageSource.REQUIREMENTS_TXT) && !dependencyUrl.endsWith("/requirements.txt")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a requirements.txt file: " + dependencyUrl);
    } else if (packageSource.equals(PackageSource.ENVIRONMENT_YAML) && !dependencyUrl.endsWith(".yml")) {
        throw new PythonException(RESTCodes.PythonErrorCode.INSTALL_TYPE_NOT_SUPPORTED, Level.FINE, "The library to install is not a conda environment.yml file: " + dependencyUrl);
    }
}
Also used : PackageSource(io.hops.hopsworks.common.python.library.PackageSource) PythonException(io.hops.hopsworks.exceptions.PythonException)

Example 4 with PackageSource

use of io.hops.hopsworks.common.python.library.PackageSource in project hopsworks by logicalclocks.

the class LibraryResource method search.

@ApiOperation(value = "Search for libraries using conda or pip package managers", response = LibrarySearchDTO.class)
@GET
@Path("{search: conda|pip}")
@Produces(MediaType.APPLICATION_JSON)
@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 search(@PathParam("search") String search, @QueryParam("query") String query, @QueryParam("channel") String channel, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ServiceException, PythonException {
    validatePattern(query);
    environmentController.checkCondaEnabled(project, pythonVersion, true);
    LibrarySearchDTO librarySearchDTO;
    PackageSource packageSource = PackageSource.fromString(search);
    switch(packageSource) {
        case CONDA:
            validateChannel(channel);
            librarySearchDTO = librariesSearchBuilder.buildCondaItems(uriInfo, query, project, channel);
            break;
        case PIP:
            librarySearchDTO = librariesSearchBuilder.buildPipItems(uriInfo, query, project);
            break;
        default:
            throw new PythonException(RESTCodes.PythonErrorCode.PYTHON_SEARCH_TYPE_NOT_SUPPORTED, Level.FINE);
    }
    return Response.ok().entity(librarySearchDTO).build();
}
Also used : LibrarySearchDTO(io.hops.hopsworks.api.python.library.search.LibrarySearchDTO) PackageSource(io.hops.hopsworks.common.python.library.PackageSource) PythonException(io.hops.hopsworks.exceptions.PythonException) 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)

Aggregations

PackageSource (io.hops.hopsworks.common.python.library.PackageSource)4 PythonException (io.hops.hopsworks.exceptions.PythonException)4 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)2 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 LibrarySearchDTO (io.hops.hopsworks.api.python.library.search.LibrarySearchDTO)1 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)1 PythonDep (io.hops.hopsworks.persistence.entity.python.PythonDep)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1