Java Code Examples for org.apache.hadoop.fs.permission.FsPermission#toShort()

The following examples show how to use org.apache.hadoop.fs.permission.FsPermission#toShort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobHistoryEventHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void mkdir(FileSystem fs, Path path, FsPermission fsp)
    throws IOException {
  if (!fs.exists(path)) {
    try {
      fs.mkdirs(path, fsp);
      FileStatus fsStatus = fs.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        fs.setPermission(path, fsp);
      }
    } catch (FileAlreadyExistsException e) {
      LOG.info("Directory: [" + path + "] already exists.");
    }
  }
}
 
Example 2
Source File: HistoryFileManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void mkdir(FileContext fc, Path path, FsPermission fsp)
    throws IOException {
  if (!fc.util().exists(path)) {
    try {
      fc.mkdir(path, fsp, true);

      FileStatus fsStatus = fc.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        fc.setPermission(path, fsp);
      }
    } catch (FileAlreadyExistsException e) {
      LOG.info("Directory: [" + path + "] already exists.");
    }
  }
}
 
Example 3
Source File: HistoryFileManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void makeDoneSubdir(Path path) throws IOException {
  try {
    doneDirFc.getFileStatus(path);
    existingDoneSubdirs.add(path);
  } catch (FileNotFoundException fnfE) {
    try {
      FsPermission fsp = new FsPermission(
          JobHistoryUtils.HISTORY_DONE_DIR_PERMISSION);
      doneDirFc.mkdir(path, fsp, true);
      FileStatus fsStatus = doneDirFc.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        doneDirFc.setPermission(path, fsp);
      }
      existingDoneSubdirs.add(path);
    } catch (FileAlreadyExistsException faeE) { // Nothing to do.
    }
  }
}
 
Example 4
Source File: TestDFSPermission.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void createAndCheckPermission(OpType op, Path name, short umask,
    FsPermission permission, boolean delete) throws Exception {
  // create the file/directory
  create(op, name, umask, permission);

  // get the short form of the permission
  short permissionNum = (DEFAULT_PERMISSION.equals(permission)) ? MAX_PERMISSION
      : permission.toShort();

  // get the expected permission
  short expectedPermission = (op == OpType.CREATE) ? (short) (~umask
      & permissionNum) : (short) (~umask & permissionNum);

  // check if permission is correctly set
  checkPermission(name, expectedPermission, delete);
}
 
Example 5
Source File: JobHistoryEventHandler.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void mkdir(FileSystem fs, Path path, FsPermission fsp)
    throws IOException {
  if (!fs.exists(path)) {
    try {
      fs.mkdirs(path, fsp);
      FileStatus fsStatus = fs.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        fs.setPermission(path, fsp);
      }
    } catch (FileAlreadyExistsException e) {
      LOG.info("Directory: [" + path + "] already exists.");
    }
  }
}
 
Example 6
Source File: HistoryFileManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void mkdir(FileContext fc, Path path, FsPermission fsp)
    throws IOException {
  if (!fc.util().exists(path)) {
    try {
      fc.mkdir(path, fsp, true);

      FileStatus fsStatus = fc.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        fc.setPermission(path, fsp);
      }
    } catch (FileAlreadyExistsException e) {
      LOG.info("Directory: [" + path + "] already exists.");
    }
  }
}
 
Example 7
Source File: HistoryFileManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void makeDoneSubdir(Path path) throws IOException {
  try {
    doneDirFc.getFileStatus(path);
    existingDoneSubdirs.add(path);
  } catch (FileNotFoundException fnfE) {
    try {
      FsPermission fsp = new FsPermission(
          JobHistoryUtils.HISTORY_DONE_DIR_PERMISSION);
      doneDirFc.mkdir(path, fsp, true);
      FileStatus fsStatus = doneDirFc.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        doneDirFc.setPermission(path, fsp);
      }
      existingDoneSubdirs.add(path);
    } catch (FileAlreadyExistsException faeE) { // Nothing to do.
    }
  }
}
 
Example 8
Source File: TestDFSPermission.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void createAndCheckPermission(OpType op, Path name, short umask,
    FsPermission permission, boolean delete) throws Exception {
  // create the file/directory
  create(op, name, umask, permission);

  // get the short form of the permission
  short permissionNum = (DEFAULT_PERMISSION.equals(permission)) ? MAX_PERMISSION
      : permission.toShort();

  // get the expected permission
  short expectedPermission = (op == OpType.CREATE) ? (short) (~umask
      & permissionNum) : (short) (~umask & permissionNum);

  // check if permission is correctly set
  checkPermission(name, expectedPermission, delete);
}
 
Example 9
Source File: FsShellPermissions.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
@Override
public void run(FileStatus file, FileSystem srcFs) throws IOException {
  FsPermission perms = file.getPermission();
  int existing = perms.toShort();
  boolean exeOk = file.isDir() || (existing & 0111) != 0;
  int newperms = ( applyChmod(userType, userMode, 
                              (existing>>>6)&7, exeOk) << 6 |
                   applyChmod(groupType, groupMode, 
                              (existing>>>3)&7, exeOk) << 3 |
                   applyChmod(othersType, othersMode, existing&7, exeOk) );

  if (existing != newperms) {
    try {
      srcFs.setPermission(file.getPath(), 
                            new FsPermission((short)newperms));
    } catch (IOException e) {
      System.err.println(getName() + ": changing permissions of '" + 
                         file.getPath() + "':" + e.getMessage());
    }
  }
}
 
Example 10
Source File: HdfsCossEndpoint.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * {@link Acl} to {@link FsPermission}
 * 
 * @param acl
 * @return
 */
final public static FsPermission toFsPermission(ACL acl) {
	int posixPermission = toPosixPermission(acl);
	for (FsPermission fp : ACL_PERMISSSIONS) {
		if (posixPermission == fp.toShort())
			return fp;
	}
	throw new IllegalStateException(format("Unkown acl: %s", acl));
}
 
Example 11
Source File: FsPermissionExtension.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new FsPermissionExtension based on the given FsPermission.
 *
 * @param perm FsPermission containing permission bits
 */
public FsPermissionExtension(FsPermission perm, boolean hasAcl,
    boolean isEncrypted) {
  super(perm.toShort());
  aclBit = hasAcl;
  encryptedBit = isEncrypted;
}
 
Example 12
Source File: FsPermissionExtension.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new FsPermissionExtension based on the given FsPermission.
 *
 * @param perm FsPermission containing permission bits
 */
public FsPermissionExtension(FsPermission perm, boolean hasAcl,
    boolean isEncrypted) {
  super(perm.toShort());
  aclBit = hasAcl;
  encryptedBit = isEncrypted;
}
 
Example 13
Source File: INodeWithAdditionalFields.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
void setPermission(FsPermission permission) {
  final short mode = permission.toShort();
  updatePermissionStatus(PermissionStatusFormat.MODE, mode);
}
 
Example 14
Source File: INodeWithAdditionalFields.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
void setPermission(FsPermission permission) {
  final short mode = permission.toShort();
  updatePermissionStatus(PermissionStatusFormat.MODE, mode);
}
 
Example 15
Source File: PermissionParam.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 * @param value the parameter value.
 */
public PermissionParam(final FsPermission value) {
  super(DOMAIN, value == null? null: value.toShort(), null, null);
}
 
Example 16
Source File: PermissionParam.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 * @param value the parameter value.
 */
public PermissionParam(final FsPermission value) {
  super(DOMAIN, value == null? null: value.toShort(), null, null);
}