Search in sources :

Example 96 with Project

use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.

the class TestPitJoinController method setup.

@Before
public void setup() {
    fs = new Featurestore();
    fs.setHiveDbId(1l);
    fs.setProject(new Project("test_proj"));
    cachedFeaturegroup = new CachedFeaturegroup();
    cachedFeaturegroup.setTimeTravelFormat(TimeTravelFormat.NONE);
    fgLeft = new Featuregroup(1);
    fgLeft.setEventTime("ts");
    fgLeft.setName("fg0");
    fgLeft.setVersion(1);
    fgLeft.setCachedFeaturegroup(cachedFeaturegroup);
    fgLeft.setFeaturestore(fs);
    fgRight = new Featuregroup(2);
    fgRight.setEventTime("ts");
    fgRight.setName("fg1");
    fgRight.setVersion(1);
    fgRight.setCachedFeaturegroup(cachedFeaturegroup);
    fgRight.setFeaturestore(fs);
    fgRight1 = new Featuregroup(3);
    fgRight1.setEventTime("ts");
    fgRight1.setName("fg2");
    fgRight1.setVersion(1);
    fgRight1.setCachedFeaturegroup(cachedFeaturegroup);
    fgRight1.setFeaturestore(fs);
    FeaturegroupController featuregroupController = Mockito.mock(FeaturegroupController.class);
    FeaturegroupFacade featuregroupFacade = Mockito.mock(FeaturegroupFacade.class);
    FeaturestoreFacade featurestoreFacade = Mockito.mock(FeaturestoreFacade.class);
    OnlineFeaturestoreController onlineFeaturestoreController = Mockito.mock(OnlineFeaturestoreController.class);
    CachedFeaturegroupController cachedFeaturegroupController = Mockito.mock(CachedFeaturegroupController.class);
    FilterController filterController = new FilterController(new ConstructorController());
    JoinController joinController = new JoinController(new ConstructorController());
    ConstructorController constructorController = new ConstructorController(featuregroupController, featurestoreFacade, featuregroupFacade, onlineFeaturestoreController, cachedFeaturegroupController, filterController, joinController);
    pitJoinController = new PitJoinController(constructorController, filterController, joinController);
}
Also used : FeaturegroupFacade(io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupFacade) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) CachedFeaturegroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeaturegroup) CachedFeaturegroupController(io.hops.hopsworks.common.featurestore.featuregroup.cached.CachedFeaturegroupController) FeaturestoreFacade(io.hops.hopsworks.common.featurestore.FeaturestoreFacade) ConstructorController(io.hops.hopsworks.common.featurestore.query.ConstructorController) Project(io.hops.hopsworks.persistence.entity.project.Project) PitJoinController(io.hops.hopsworks.common.featurestore.query.pit.PitJoinController) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) FilterController(io.hops.hopsworks.common.featurestore.query.filter.FilterController) JoinController(io.hops.hopsworks.common.featurestore.query.join.JoinController) PitJoinController(io.hops.hopsworks.common.featurestore.query.pit.PitJoinController) OnlineFeaturestoreController(io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController) CachedFeaturegroupController(io.hops.hopsworks.common.featurestore.featuregroup.cached.CachedFeaturegroupController) FeaturegroupController(io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController) CachedFeaturegroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeaturegroup) Before(org.junit.Before)

Example 97 with Project

use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.

the class TestFilterController method setup.

@Before
public void setup() {
    constructorController = new ConstructorController();
    filterController = new FilterController(constructorController);
    Featurestore fs = new Featurestore();
    fs.setHiveDbId(1l);
    fs.setProject(new Project("test_proj"));
    CachedFeaturegroup cachedFeaturegroup = new CachedFeaturegroup();
    cachedFeaturegroup.setTimeTravelFormat(TimeTravelFormat.NONE);
    fg1 = new Featuregroup(1);
    fg1.setName("fg1");
    fg1.setVersion(1);
    fg1.setCachedFeaturegroup(cachedFeaturegroup);
    fg1.setFeaturestore(fs);
    fg2 = new Featuregroup(2);
    fg2.setName("fg2");
    fg2.setVersion(1);
    fg2.setCachedFeaturegroup(cachedFeaturegroup);
    fg2.setFeaturestore(fs);
    fg3 = new Featuregroup(3);
    fg3.setName("fg3");
    fg3.setVersion(1);
    fg3.setCachedFeaturegroup(cachedFeaturegroup);
    fg3.setFeaturestore(fs);
    fgLookup = new HashMap<>();
    fgLookup.put(fg1.getId(), fg1);
    fgLookup.put(fg2.getId(), fg2);
    fgLookup.put(fg3.getId(), fg3);
    fg1Features = new ArrayList<>();
    fg1Features.add(new Feature("fg1_pk", "fg1", "string", true, null, "prefix2_", fg1));
    fg1Features.add(new Feature("fg1_ft", "fg1", "integer", false, null, "prefix2_", fg1));
    fg1Features.add(new Feature("join", "fg1", "string", true, null, "prefix2_", fg1));
    fg2Features = new ArrayList<>();
    fg2Features.add(new Feature("fg2_pk", "fg2", "string", true, null, "prefix2_"));
    fg2Features.add(new Feature("fg2_ft", "fg2", "double", false, "10.0", "prefix2_"));
    fg3Features.add(new Feature("join", "fg2", "string", true, null, "prefix2_"));
    fg3Features = new ArrayList<>();
    fg3Features.add(new Feature("fg3_pk", "fg3", "string", true, null, "prefix3_"));
    fg3Features.add(new Feature("fg3_ft", "fg3", "string", false, "default", "prefix3_"));
    fg3Features.add(new Feature("join", "fg3", "string", true, null, "prefix3_"));
    joinFeatures = new ArrayList<>();
    joinFeatures.add(fg1Features.get(2));
    leftOn = new ArrayList<>();
    leftOn.add(fg1Features.get(0));
    leftOn.add(fg1Features.get(2));
    rightOn = new ArrayList<>();
    rightOn.add(fg3Features.get(0));
    rightOn.add(fg3Features.get(2));
    availableFeatureLookup = new HashMap<>();
    availableFeatureLookup.put(fg1.getId(), fg1Features);
    availableFeatureLookup.put(fg2.getId(), fg2Features);
    availableFeatureLookup.put(fg3.getId(), fg3Features);
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) CachedFeaturegroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeaturegroup) ConstructorController(io.hops.hopsworks.common.featurestore.query.ConstructorController) Feature(io.hops.hopsworks.common.featurestore.query.Feature) CachedFeaturegroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeaturegroup) Before(org.junit.Before)

Example 98 with Project

use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.

the class ProjectMembersService method removeMembersByID.

@DELETE
@Path("/{email}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response removeMembersByID(@PathParam("email") String email, @Context SecurityContext sc) throws ProjectException, ServiceException, HopsSecurityException, UserException, GenericException, IOException, JobException, TensorBoardException, FeaturestoreException {
    Project project = projectController.findProjectById(this.projectId);
    RESTApiJsonResponse json = new RESTApiJsonResponse();
    Users reqUser = jWTHelper.getUserPrincipal(sc);
    if (email == null) {
        throw new IllegalArgumentException("Email was not provided");
    }
    // Not able to remove members that do not exist
    String userProjectRole = projectTeamFacade.findCurrentRole(project, email);
    if (userProjectRole == null || userProjectRole.isEmpty()) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.TEAM_MEMBER_NOT_FOUND, Level.FINE);
    }
    // Data scientists can only remove themselves
    String reqUserProjectRole = projectTeamFacade.findCurrentRole(project, reqUser.getEmail());
    if (reqUserProjectRole.equals(AllowedProjectRoles.DATA_SCIENTIST) && !reqUser.getEmail().equals(email)) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.MEMBER_REMOVAL_NOT_ALLOWED, Level.FINE);
    }
    projectController.removeMemberFromTeam(project, reqUser, email);
    json.setSuccessMessage(ResponseMessages.MEMBER_REMOVED_FROM_TEAM);
    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) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 99 with Project

use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.

the class ProjectMembersService method addMembers.

@POST
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response addMembers(MembersDTO members, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException, FeaturestoreException {
    Project project = projectController.findProjectById(this.projectId);
    RESTApiJsonResponse json = new RESTApiJsonResponse();
    List<String> failedMembers = null;
    Users user = jWTHelper.getUserPrincipal(sc);
    if (members.getProjectTeam() == null || members.getProjectTeam().isEmpty()) {
        throw new IllegalArgumentException("Member was not provided in MembersDTO");
    }
    if (project != null) {
        // add new members of the project
        failedMembers = projectController.addMembers(project, user, members.getProjectTeam());
    }
    if (members.getProjectTeam().size() > 1) {
        json.setSuccessMessage(ResponseMessages.PROJECT_MEMBERS_ADDED);
    } else {
        json.setSuccessMessage(ResponseMessages.PROJECT_MEMBER_ADDED);
    }
    if (failedMembers != null && !failedMembers.isEmpty()) {
        String msg;
        if (members.getProjectTeam().size() == 1) {
            msg = "Failed to add a member. Member " + failedMembers.get(0) + " was not added.";
        } else if (members.getProjectTeam().size() == failedMembers.size()) {
            msg = "Failed to add all members. Members " + failedMembers + " were not added.";
        } else if (failedMembers.size() == 1) {
            msg = "Failed to add a member. Member " + failedMembers.get(0) + " was not added.";
        } else {
            msg = "Failed to add some members. Members " + failedMembers + " were not added.";
        }
        throw new ProjectException(RESTCodes.ProjectErrorCode.FAILED_TO_ADD_MEMBER, Level.FINE, msg);
    }
    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) 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 100 with Project

use of io.hops.hopsworks.persistence.entity.project.Project in project hopsworks by logicalclocks.

the class ProjectService method getReadmeByInodeId.

@GET
@Path("/readme/byInodeId/{inodeId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getReadmeByInodeId(@PathParam("inodeId") Long inodeId, @Context SecurityContext sc) throws DatasetException {
    if (inodeId == null) {
        throw new IllegalArgumentException("No inodeId provided.");
    }
    Inode inode = inodes.findById(inodeId);
    Inode parent = inodes.findParent(inode);
    Project proj = projectFacade.findByName(parent.getInodePK().getName());
    Dataset ds = datasetFacade.findByProjectAndInode(proj, inode);
    if (ds != null && !ds.isSearchable()) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.README_NOT_ACCESSIBLE, Level.FINE);
    }
    DistributedFileSystemOps dfso = dfs.getDfsOps();
    FilePreviewDTO filePreviewDTO;
    String path = inodeController.getPath(inode);
    try {
        filePreviewDTO = datasetController.getReadme(path + "/README.md", dfso);
    } catch (IOException ex) {
        filePreviewDTO = new FilePreviewDTO();
        filePreviewDTO.setContent("No README file found for this dataset.");
        return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(filePreviewDTO).build();
    }
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(filePreviewDTO).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) FilePreviewDTO(io.hops.hopsworks.common.dataset.FilePreviewDTO) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) IOException(java.io.IOException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Project (io.hops.hopsworks.persistence.entity.project.Project)149 Users (io.hops.hopsworks.persistence.entity.user.Users)56 ProjectException (io.hops.hopsworks.exceptions.ProjectException)47 Produces (javax.ws.rs.Produces)39 Path (javax.ws.rs.Path)35 ArrayList (java.util.ArrayList)28 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)26 IOException (java.io.IOException)25 DatasetException (io.hops.hopsworks.exceptions.DatasetException)24 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)24 ApiOperation (io.swagger.annotations.ApiOperation)21 GET (javax.ws.rs.GET)20 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)19 TransactionAttribute (javax.ejb.TransactionAttribute)19 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)17 Featurestore (io.hops.hopsworks.persistence.entity.featurestore.Featurestore)16 List (java.util.List)16 EJB (javax.ejb.EJB)16 TransactionAttributeType (javax.ejb.TransactionAttributeType)16 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)14