Exemplo n.º 1
0
 /**
  * This will return a group name for the dataset Warning if the dataset is shared this will still
  * give us the group in the owning project.
  *
  * <p>
  *
  * @param dataset
  * @return
  */
 public String getHdfsGroupName(Dataset dataset) {
   if (dataset == null) {
     return null;
   }
   Inode inode = inodes.findById(dataset.getInode().getInodePK().getParentId());
   return inode.getInodePK().getName()
       + USER_NAME_DELIMITER
       + dataset.getInode().getInodePK().getName();
 }
Exemplo n.º 2
0
 public DataSetDTO(Dataset ds, Project project, List<String> sharedWith) {
   this.inodeId = ds.getInode().getId();
   this.name = ds.getInode().getInodePK().getName();
   this.description = ds.getDescription();
   this.projectName = project.getName();
   this.sharedWith = sharedWith;
   this.projectTeam = new ArrayList<>();
   // this have to be done because project team contains too much info.
   for (ProjectTeam member : project.getProjectTeamCollection()) {
     projectTeam.add(
         new UserCardDTO(
             member.getUser().getFname(),
             member.getUser().getLname(),
             member.getUser().getEmail()));
   }
 }
Exemplo n.º 3
0
 /**
  * If the dataset is shared with this project we will get a group name that does not exist.
  *
  * <p>
  *
  * @param project
  * @param ds
  * @return
  */
 public String getHdfsGroupName(Project project, Dataset ds) {
   if (project == null || ds == null) {
     return null;
   }
   return project.getName() + USER_NAME_DELIMITER + ds.getInode().getInodePK().getName();
 }
Exemplo n.º 4
0
  /**
   * Create a new group in HDFS with the name project.name__datasetName if it does not exist, then
   * adds all members of the project to this group. This is done when a new dataset is created in a
   * project. If stickyBit is set true: all members of the project will be given r, w, x privileges.
   * If stickyBit is set false: user will get all privileges, and all other members will have r and
   * x privileges.
   *
   * <p>
   *
   * @param owner
   * @param project
   * @param dataset
   * @param stickyBit
   * @throws java.io.IOException
   */
  public void addDatasetUsersGroups(
      Users owner, Project project, Dataset dataset, boolean stickyBit) throws IOException {
    if (owner == null
        || project == null
        || project.getProjectTeamCollection() == null
        || dataset == null) {
      throw new IllegalArgumentException("One or more arguments are null.");
    }
    String datasetGroup = getHdfsGroupName(project, dataset);
    String dsOwner = getHdfsUserName(project, owner);
    String dsPath =
        File.separator
            + settings.DIR_ROOT
            + File.separator
            + project.getName()
            + File.separator
            + dataset.getInode().getInodePK().getName();
    Path location = new Path(dsPath);
    // FsPermission(FsAction u, FsAction g, FsAction o, boolean sb)
    FsPermission fsPermission =
        new FsPermission(
            FsAction.ALL, FsAction.READ_EXECUTE, FsAction.NONE); // Permission hdfs dfs -chmod 750
    if (stickyBit) {
      fsPermission =
          new FsPermission(
              FsAction.ALL,
              FsAction.ALL,
              FsAction.NONE,
              stickyBit); // Permission hdfs dfs -chmod 1770
    }
    fsOps.setOwner(location, dsOwner, datasetGroup);
    fsOps.setPermission(location, fsPermission);

    String hdfsUsername;
    HdfsUsers hdfsUser;
    byte[] userId;
    byte[] groupId = UsersGroups.getGroupID(datasetGroup);
    HdfsGroups hdfsGroup = hdfsGroupsFacade.findHdfsGroup(groupId);
    if (hdfsGroup == null) {
      throw new IllegalArgumentException("Could not create dataset group in HDFS.");
    }
    if (hdfsGroup.getHdfsUsersCollection() == null) {
      hdfsGroup.setHdfsUsersCollection(new ArrayList<HdfsUsers>());
    }
    // add every member to the new ds group
    for (ProjectTeam member : project.getProjectTeamCollection()) {
      hdfsUsername = getHdfsUserName(project, member.getUser());
      userId = UsersGroups.getUserID(hdfsUsername);
      hdfsUser = hdfsUsersFacade.findHdfsUser(userId);
      // the owner does not need to be added to the group.
      if (hdfsUsername.equals(dsOwner)) {
        continue;
      }
      if (hdfsUser == null) {
        hdfsUser = new HdfsUsers(userId, hdfsUsername);
        hdfsUsersFacade.persist(hdfsUser);
      }
      if (!hdfsGroup.getHdfsUsersCollection().contains(hdfsUser)) {
        hdfsGroup.getHdfsUsersCollection().add(hdfsUser);
      }
    }
    hdfsGroupsFacade.merge(hdfsGroup);
  }