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