/** * Removes the user project__username from the group projectName. This means the user is no longer * a data_owner in this project. (will be a data_scientist with r, x privileges on datasets inside * the project) * * <p> * * @param user * @param project */ public void modifyProjectMembership(Users user, Project project) { if (user == null || project == null || project.getProjectTeamCollection() == null) { throw new IllegalArgumentException("One or more arguments are null."); } String userName = getHdfsUserName(project, user); byte[] userId = UsersGroups.getUserID(userName); byte[] groupId = UsersGroups.getGroupID(project.getName()); HdfsGroups hdfsGroup = hdfsGroupsFacade.findHdfsGroup(groupId); HdfsUsers hdfsUser = hdfsUsersFacade.findHdfsUser(userId); if (hdfsUser == null || hdfsGroup == null) { throw new IllegalArgumentException("Hdfs user not found or not in project group."); } hdfsUser.getHdfsGroupsCollection().remove(hdfsGroup); hdfsUsersFacade.merge(hdfsUser); }
/** * Adds a new member to the project. This will create a new user in HDFS with the name <code> * projectName</code>__<code>username</code> and adds it to the group <code>projectName</code>. * throws IllegalArgumentException if the project group is not found. * * <p> * * @param project * @param member * @throws java.io.IOException */ public void addNewProjectMember(Project project, ProjectTeam member) throws IOException { byte[] groupId = UsersGroups.getGroupID(project.getName()); HdfsGroups hdfsGroup = hdfsGroupsFacade.findHdfsGroup(groupId); if (hdfsGroup == null) { throw new IllegalArgumentException("No group found for project in HDFS."); } String hdfsUsername; HdfsUsers memberHdfsUser; byte[] memberUserId; Users newMember = userFacade.findByEmail(member.getProjectTeamPK().getTeamMember()); hdfsUsername = getHdfsUserName(project, newMember); memberUserId = UsersGroups.getUserID(hdfsUsername); memberHdfsUser = hdfsUsersFacade.findHdfsUser(memberUserId); if (memberHdfsUser == null) { memberHdfsUser = new HdfsUsers(memberUserId, hdfsUsername); hdfsUsersFacade.persist(memberHdfsUser); } if (memberHdfsUser.getHdfsGroupsCollection() == null) { memberHdfsUser.setHdfsGroupsCollection(new ArrayList<HdfsGroups>()); } // add only data_owners to project group if (member.getTeamRole().equals(AllowedRoles.DATA_OWNER)) { if (!memberHdfsUser.getHdfsGroupsCollection().contains(hdfsGroup)) { memberHdfsUser.getHdfsGroupsCollection().add(hdfsGroup); } } byte[] dsGroupId; String dsGroups; HdfsGroups hdfsDsGroup; // add the member to all dataset groups in the project. List<Dataset> dsInProject = datasetFacade.findByProject(project); for (Dataset ds : dsInProject) { dsGroups = getHdfsGroupName(ds); dsGroupId = UsersGroups.getGroupID(dsGroups); hdfsDsGroup = hdfsGroupsFacade.findHdfsGroup(dsGroupId); if (hdfsDsGroup != null) { if (!memberHdfsUser.getHdfsGroupsCollection().contains(hdfsDsGroup)) { memberHdfsUser.getHdfsGroupsCollection().add(hdfsDsGroup); } } } hdfsUsersFacade.merge(memberHdfsUser); }