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