Exemplo n.º 1
0
 /**
  * Adds a user to project group if the member have a Data owner role in the project.
  *
  * <p>throws IllegalArgumentException if the project group is not found.
  *
  * <p>
  *
  * @param project
  * @param member
  */
 public void addUserToProjectGroup(Project project, ProjectTeam member) {
   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);
     }
   }
 }
Exemplo n.º 2
0
 /**
  * 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);
 }