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