Search in sources :

Example 11 with ProjectException

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

the class DefaultJobConfigurationResource method getByType.

@ApiOperation(value = "Get the default job configuration by JobType", response = DefaultJobConfigurationDTO.class)
@GET
@Path("{type}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getByType(@PathParam("type") JobType jobType, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.JOBCONFIG);
    DefaultJobConfiguration defaultJobConfiguration = projectController.getProjectDefaultJobConfiguration(project, jobType);
    if (defaultJobConfiguration == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_DEFAULT_JOB_CONFIG_NOT_FOUND, Level.FINEST);
    } else {
        DefaultJobConfigurationDTO defaultJobConfigurationDTO = this.defaultJobConfigurationBuilder.build(uriInfo, resourceRequest, defaultJobConfiguration, jobType);
        return Response.ok(defaultJobConfigurationDTO).build();
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) DefaultJobConfiguration(io.hops.hopsworks.persistence.entity.project.jobs.DefaultJobConfiguration) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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)

Example 12 with ProjectException

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

the class DefaultJobConfigurationResource method get.

@ApiOperation(value = "Get all the default job configurations", response = DefaultJobConfigurationDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@BeanParam Pagination pagination, @BeanParam DefaultJobConfigurationBeanParam defaultJobConfigurationBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.JOBCONFIG);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(defaultJobConfigurationBeanParam.getSortBySet());
    resourceRequest.setFilter(defaultJobConfigurationBeanParam.getFilter());
    DefaultJobConfigurationDTO defaultJobConfigurationDTO = this.defaultJobConfigurationBuilder.build(uriInfo, resourceRequest, this.project);
    if (defaultJobConfigurationDTO == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_DEFAULT_JOB_CONFIG_NOT_FOUND, Level.FINEST);
    }
    return Response.ok(defaultJobConfigurationDTO).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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)

Example 13 with ProjectException

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

the class PathValidator method buildProjectDsRelativePath.

private void buildProjectDsRelativePath(Project project, String[] pathComponents, DsPath dsPath) throws ProjectException, DatasetException {
    // Start by 1 as the first component is ""
    Project destProject = projectFacade.findByName(pathComponents[2]);
    if (project == null || destProject == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE);
    }
    Dataset ds = datasetController.getByProjectAndDsName(project, Utils.getProjectPath(pathComponents[2]), pathComponents[3]);
    if (ds == null) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
    }
    dsPath.setDs(ds);
    String dsRelativePathStr = buildRelativePath(pathComponents, 4, pathComponents.length);
    if (!dsRelativePathStr.isEmpty()) {
        dsPath.setDsRelativePath(new Path(dsRelativePathStr));
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Path(org.apache.hadoop.fs.Path) Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Example 14 with ProjectException

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

the class ProjectService method example.

@POST
@Path("starterProject/{type}")
@Produces(MediaType.APPLICATION_JSON)
public Response example(@PathParam("type") String type, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, GenericException, KafkaException, ProjectException, UserException, ServiceException, HopsSecurityException, FeaturestoreException, JobException, IOException, ElasticException, SchemaException, ProvenanceException {
    TourProjectType demoType;
    try {
        demoType = TourProjectType.fromString(type);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Type must be one of: " + Arrays.toString(TourProjectType.values()));
    }
    ProjectDTO projectDTO = new ProjectDTO();
    Project project = null;
    projectDTO.setDescription("A demo project for getting started with " + demoType.getDescription());
    Users user = jWTHelper.getUserPrincipal(sc);
    String username = user.getUsername();
    List<String> projectServices = new ArrayList<>();
    // save the project
    String readMeMessage = null;
    switch(demoType) {
        case KAFKA:
            // It's a Kafka guide
            projectDTO.setProjectName("demo_" + TourProjectType.KAFKA.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.KAFKA);
            readMeMessage = "jar file to demonstrate Kafka streaming";
            break;
        case SPARK:
            // It's a Spark guide
            projectDTO.setProjectName("demo_" + TourProjectType.SPARK.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.SPARK);
            readMeMessage = "jar file to demonstrate the creation of a spark batch job";
            break;
        case FS:
            // It's a Featurestore guide
            projectDTO.setProjectName("demo_" + TourProjectType.FS.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.FS);
            readMeMessage = "Dataset containing a jar file and data that can be used to run a sample spark-job for " + "inserting data in the feature store.";
            break;
        case ML:
            // It's a TensorFlow guide
            projectDTO.setProjectName("demo_" + TourProjectType.ML.getTourName() + "_" + username);
            populateActiveServices(projectServices, TourProjectType.ML);
            readMeMessage = "Jupyter notebooks and training data for demonstrating how to run Deep Learning";
            break;
        default:
            throw new IllegalArgumentException("Type must be one of: " + Arrays.toString(TourProjectType.values()));
    }
    projectDTO.setServices(projectServices);
    DistributedFileSystemOps dfso = null;
    DistributedFileSystemOps udfso = null;
    try {
        project = projectController.createProject(projectDTO, user, req.getSession().getId());
        dfso = dfs.getDfsOps();
        username = hdfsUsersBean.getHdfsUserName(project, user);
        udfso = dfs.getDfsOps(username);
        ProvTypeDTO projectMetaStatus = fsProvenanceController.getProjectProvType(user, project);
        String tourFilesDataset = projectController.addTourFilesToProject(user.getEmail(), project, dfso, dfso, demoType, projectMetaStatus);
        // TestJob dataset
        datasetController.generateReadme(udfso, tourFilesDataset, readMeMessage, project.getName());
    } catch (Exception ex) {
        projectController.cleanup(project, req.getSession().getId());
        throw ex;
    } finally {
        if (dfso != null) {
            dfso.close();
        }
        if (udfso != null) {
            dfs.closeDfsClient(udfso);
        }
    }
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(project).build();
}
Also used : TourProjectType(io.hops.hopsworks.common.project.TourProjectType) ProjectDTO(io.hops.hopsworks.common.project.ProjectDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) ArrayList(java.util.ArrayList) Users(io.hops.hopsworks.persistence.entity.user.Users) ProvTypeDTO(io.hops.hopsworks.common.provenance.core.dto.ProvTypeDTO) DatasetException(io.hops.hopsworks.exceptions.DatasetException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) ElasticException(io.hops.hopsworks.exceptions.ElasticException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) UserException(io.hops.hopsworks.exceptions.UserException) ExecutionException(java.util.concurrent.ExecutionException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) JobException(io.hops.hopsworks.exceptions.JobException) GenericException(io.hops.hopsworks.exceptions.GenericException) KafkaException(io.hops.hopsworks.exceptions.KafkaException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) SchemaException(io.hops.hopsworks.exceptions.SchemaException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 15 with ProjectException

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

the class ProjectService method getPia.

@GET
@Path("{projectId}/pia")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
public Response getPia(@PathParam("projectId") Integer projectId, @Context SecurityContext sc) throws ProjectException {
    Project project = projectController.findProjectById(projectId);
    if (project == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + projectId);
    }
    Pia pia = piaFacade.findByProject(projectId);
    GenericEntity<Pia> genericPia = new GenericEntity<Pia>(pia) {
    };
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(genericPia).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) GenericEntity(javax.ws.rs.core.GenericEntity) Pia(io.hops.hopsworks.persistence.entity.project.pia.Pia) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

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