Search in sources :

Example 6 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class ExperimentsResource method getModelsProjectAndCheckAccess.

private Project getModelsProjectAndCheckAccess(ExperimentDTO experimentDTO) throws ProjectException, DatasetException, GenericException {
    Project modelProject;
    if (experimentDTO.getModelProjectName() == null) {
        modelProject = project;
    } else {
        modelProject = projectFacade.findByName(experimentDTO.getModelProjectName());
        if (modelProject == null) {
            throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.INFO, "model project not found for experiment");
        }
    }
    Dataset modelDataset = datasetCtrl.getByName(modelProject, Settings.HOPS_MODELS_DATASET);
    if (!accessCtrl.hasAccess(project, modelDataset)) {
        throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.INFO);
    }
    return modelProject;
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) GenericException(io.hops.hopsworks.exceptions.GenericException)

Example 7 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class ExperimentsResource method post.

@ApiOperation(value = "Create or update an experiment", response = ExperimentDTO.class)
@PUT
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response post(@PathParam("id") String id, ExperimentDTO experimentDTO, @QueryParam("type") ExperimentOperationType type, @Context HttpServletRequest req, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ProvenanceException, PythonException, MetadataException, ProjectException, GenericException, ExperimentsException {
    if (experimentDTO == null) {
        throw new IllegalArgumentException("No Experiment configuration was provided");
    }
    Users user = jwtHelper.getUserPrincipal(sc);
    Project experimentProject = project;
    switch(type) {
        case INIT:
            {
                String experimentPath = Utils.getProjectPath(project.getName()) + Settings.HOPS_EXPERIMENTS_DATASET + "/" + id + "/" + Settings.ENVIRONMENT_FILE;
                experimentDTO.setEnvironment(environmentController.exportEnv(experimentProject, user, experimentPath));
                try {
                    String program = experimentsController.versionProgram(experimentProject, user, experimentDTO.getJobName(), experimentDTO.getKernelId(), id);
                    experimentDTO.setProgram(program);
                } catch (Exception e) {
                    LOGGER.log(Level.SEVERE, "Could not version notebook " + e.getMessage());
                }
            }
            break;
        case MODEL_UPDATE:
            {
                Project modelProject = getModelsProjectAndCheckAccess(experimentDTO);
                experimentsController.attachModel(user, experimentProject, id, modelProject, experimentDTO.getModel());
            }
            break;
        case FULL_UPDATE:
            {
            // no need to update the summary in any way
            }
            break;
        default:
            {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "unhandled experiment summary operation type:" + type);
            }
    }
    experimentsController.attachExperiment(user, experimentProject, id, experimentDTO);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder().path(id);
    switch(type) {
        case INIT:
            return Response.created(builder.build()).entity(experimentDTO).build();
        case MODEL_UPDATE:
        case FULL_UPDATE:
            return Response.ok(builder.build()).entity(experimentDTO).build();
        default:
            {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "unhandled experiment summary operation type:" + type);
            }
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) UriBuilder(javax.ws.rs.core.UriBuilder) GenericException(io.hops.hopsworks.exceptions.GenericException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) GenericException(io.hops.hopsworks.exceptions.GenericException) PythonException(io.hops.hopsworks.exceptions.PythonException) MetadataException(io.hops.hopsworks.exceptions.MetadataException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 8 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class ProjectMembersService method updateRoleByEmail.

@POST
@Path("/{email}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response updateRoleByEmail(@PathParam("email") String email, @FormParam("role") String role, @Context SecurityContext sc) throws ProjectException, UserException, FeaturestoreException, IOException {
    Project project = projectController.findProjectById(this.projectId);
    RESTApiJsonResponse json = new RESTApiJsonResponse();
    Users user = jWTHelper.getUserPrincipal(sc);
    if (email == null) {
        throw new IllegalArgumentException("Email was not provided.");
    }
    if (role == null || !ProjectRoleTypes.isAllowedRole(role)) {
        throw new IllegalArgumentException("Role was not provided.");
    }
    if (project.getOwner().getEmail().equals(email)) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_OWNER_ROLE_NOT_ALLOWED, Level.FINE);
    }
    projectController.updateMemberRole(project, user, email, ProjectRoleTypes.fromString(role).getRole());
    json.setSuccessMessage(ResponseMessages.MEMBER_ROLE_UPDATED);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(json).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) RESTApiJsonResponse(io.hops.hopsworks.api.util.RESTApiJsonResponse) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 9 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class ProjectService method getDatasetInfo.

@GET
@Path("{projectId}/getInodeInfo/{inodeId}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.ANYONE })
public Response getDatasetInfo(@PathParam("projectId") Integer projectId, @PathParam("inodeId") Long inodeId, @Context SecurityContext sc) throws ProjectException, DatasetException {
    Inode inode = inodes.findById(inodeId);
    if (inode == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.INODE_NOT_FOUND, Level.FINE, "inodeId: " + inodeId);
    }
    Project project = projectFacade.find(projectId);
    if (project == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + projectId);
    }
    DataSetDTO dataset = new DataSetDTO(inode.getInodePK().getName(), inodeId, project);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(dataset).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) DataSetDTO(io.hops.hopsworks.common.dao.dataset.DataSetDTO) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 10 with ProjectException

use of io.hops.hopsworks.exceptions.ProjectException in project hopsworks by logicalclocks.

the class ProjectAlertsResource method createOrUpdate.

@PUT
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an alert.", response = ProjectAlertsDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response createOrUpdate(@PathParam("id") Integer id, ProjectAlertsDTO projectAlertsDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException {
    ProjectServiceAlert projectServiceAlert = projectServiceAlertsFacade.findByProjectAndId(getProject(), id);
    if (projectServiceAlert == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.ALERT_NOT_FOUND, Level.FINE, "Alert not found. Id=" + id.toString());
    }
    if (projectAlertsDTO == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.ALERT_ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Project project = getProject();
    if (projectAlertsDTO.getStatus() != null) {
        if (!projectAlertsDTO.getStatus().equals(projectServiceAlert.getStatus()) && projectServiceAlertsFacade.findByProjectAndStatus(project, projectAlertsDTO.getStatus()) != null) {
            throw new ProjectException(RESTCodes.ProjectErrorCode.ALERT_ALREADY_EXISTS, Level.FINE, "Alert with projectId=" + project.getId() + " status=" + projectAlertsDTO.getStatus() + " already exists.");
        }
        projectServiceAlert.setStatus(projectAlertsDTO.getStatus());
    }
    if (projectAlertsDTO.getSeverity() != null) {
        projectServiceAlert.setSeverity(projectAlertsDTO.getSeverity());
    }
    if (!projectServiceAlert.getReceiver().getName().equals(projectAlertsDTO.getReceiver())) {
        deleteRoute(projectServiceAlert);
        projectServiceAlert.setReceiver(getReceiver(projectAlertsDTO.getReceiver()));
        projectServiceAlert.setAlertType(alertController.getAlertType(projectServiceAlert.getReceiver()));
        createRoute(projectServiceAlert);
    }
    projectServiceAlert = projectServiceAlertsFacade.update(projectServiceAlert);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ALERTS);
    ProjectAlertsDTO dto = projectAlertsBuilder.build(uriInfo, resourceRequest, projectServiceAlert);
    return Response.ok().entity(dto).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Aggregations

ProjectException (io.hops.hopsworks.exceptions.ProjectException)62 Project (io.hops.hopsworks.persistence.entity.project.Project)43 IOException (java.io.IOException)19 Produces (javax.ws.rs.Produces)19 Users (io.hops.hopsworks.persistence.entity.user.Users)17 Path (javax.ws.rs.Path)17 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)12 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 GenericException (io.hops.hopsworks.exceptions.GenericException)12 ServiceException (io.hops.hopsworks.exceptions.ServiceException)11 JupyterProject (io.hops.hopsworks.persistence.entity.jupyter.JupyterProject)11 KafkaException (io.hops.hopsworks.exceptions.KafkaException)10 UserException (io.hops.hopsworks.exceptions.UserException)10 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)10 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)9 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)7 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)7 POST (javax.ws.rs.POST)7