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

The following examples show how to use org.apache.hadoop.fs.permission.FsPermission#getGroupAction() . 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: FsDatasetImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void setPinning(ExtendedBlock block) throws IOException {
  if (!blockPinningEnabled) {
    return;
  }

  File f = getBlockFile(block);
  Path p = new Path(f.getAbsolutePath());
  
  FsPermission oldPermission = localFS.getFileStatus(
      new Path(f.getAbsolutePath())).getPermission();
  //sticky bit is used for pinning purpose
  FsPermission permission = new FsPermission(oldPermission.getUserAction(),
      oldPermission.getGroupAction(), oldPermission.getOtherAction(), true);
  localFS.setPermission(p, permission);
}
 
Example 2
Source File: GetHDFSFileInfo.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected String getPerms(final FsPermission permission) {

        final StringBuilder sb = new StringBuilder();
        for (FsAction action : new FsAction[]{permission.getUserAction(), permission.getGroupAction(), permission.getOtherAction()}) {
            if (action.implies(FsAction.READ)) {
                sb.append("r");
            } else {
                sb.append("-");
            }

            if (action.implies(FsAction.WRITE)) {
                sb.append("w");
            } else {
                sb.append("-");
            }

            if (action.implies(FsAction.EXECUTE)) {
                sb.append("x");
            } else {
                sb.append("-");
            }
        }

        return sb.toString();
    }
 
Example 3
Source File: BlurSerDeTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startCluster() throws IOException {
  System.setProperty("hadoop.log.dir", "./target/tmp_BlurSerDeTest_hadoop_log");
  GCWatcher.init(0.60);
  LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
  File testDirectory = new File(TMPDIR, "blur-SerDe-test").getAbsoluteFile();
  testDirectory.mkdirs();

  Path directory = new Path(testDirectory.getPath());
  FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
  FsAction userAction = dirPermissions.getUserAction();
  FsAction groupAction = dirPermissions.getGroupAction();
  FsAction otherAction = dirPermissions.getOtherAction();

  StringBuilder builder = new StringBuilder();
  builder.append(userAction.ordinal());
  builder.append(groupAction.ordinal());
  builder.append(otherAction.ordinal());
  String dirPermissionNum = builder.toString();
  System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
  testDirectory.delete();
  miniCluster = new MiniCluster();
  miniCluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true, externalProcesses);
  miniCluster.startMrMiniCluster();
}
 
Example 4
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startCluster() throws IOException {
  GCWatcher.init(0.60);
  LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
  File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
  testDirectory.mkdirs();

  Path directory = new Path(testDirectory.getPath());
  FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
  FsAction userAction = dirPermissions.getUserAction();
  FsAction groupAction = dirPermissions.getGroupAction();
  FsAction otherAction = dirPermissions.getOtherAction();

  StringBuilder builder = new StringBuilder();
  builder.append(userAction.ordinal());
  builder.append(groupAction.ordinal());
  builder.append(otherAction.ordinal());
  String dirPermissionNum = builder.toString();
  System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
  testDirectory.delete();
  miniCluster = new MiniCluster();
  miniCluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true);
  connectionStr = miniCluster.getControllerConnectionStr();

}
 
Example 5
Source File: BlurClusterTestBase.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startCluster() throws IOException {
  GCWatcher.init(0.60);
  LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
  File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
  testDirectory.mkdirs();

  Path directory = new Path(testDirectory.getPath());
  FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
  FsAction userAction = dirPermissions.getUserAction();
  FsAction groupAction = dirPermissions.getGroupAction();
  FsAction otherAction = dirPermissions.getOtherAction();

  StringBuilder builder = new StringBuilder();
  builder.append(userAction.ordinal());
  builder.append(groupAction.ordinal());
  builder.append(otherAction.ordinal());
  String dirPermissionNum = builder.toString();
  System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
  testDirectory.delete();
  miniCluster = new MiniCluster();
  miniCluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true, externalProcesses);
}
 
Example 6
Source File: HdfsTraceStorageTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException, InterruptedException {
  rmr(TMPDIR);
  LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
  File testDirectory = new File(TMPDIR, "HdfsTraceStorageTest").getAbsoluteFile();
  testDirectory.mkdirs();

  Path directory = new Path(testDirectory.getPath());
  FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
  FsAction userAction = dirPermissions.getUserAction();
  FsAction groupAction = dirPermissions.getGroupAction();
  FsAction otherAction = dirPermissions.getOtherAction();

  StringBuilder builder = new StringBuilder();
  builder.append(userAction.ordinal());
  builder.append(groupAction.ordinal());
  builder.append(otherAction.ordinal());
  String dirPermissionNum = builder.toString();
  System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);

  configuration = new BlurConfiguration();
  configuration.set(BLUR_HDFS_TRACE_PATH, directory.makeQualified(localFS).toString());
  _storage = new HdfsTraceStorage(configuration);
  _storage.init(new Configuration());
}
 
Example 7
Source File: FsDatasetImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void setPinning(ExtendedBlock block) throws IOException {
  if (!blockPinningEnabled) {
    return;
  }

  File f = getBlockFile(block);
  Path p = new Path(f.getAbsolutePath());
  
  FsPermission oldPermission = localFS.getFileStatus(
      new Path(f.getAbsolutePath())).getPermission();
  //sticky bit is used for pinning purpose
  FsPermission permission = new FsPermission(oldPermission.getUserAction(),
      oldPermission.getGroupAction(), oldPermission.getOtherAction(), true);
  localFS.setPermission(p, permission);
}
 
Example 8
Source File: FileUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException
 */
public static void setPermission(File f, FsPermission permission
                                 ) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }
  
  boolean rv = true;
  
  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
Example 9
Source File: FileUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException exception on setPermission
 */
public static void setPermission(File f, FsPermission permission
) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }

  boolean rv = true;

  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
Example 10
Source File: FSPermissionDTO.java    From hudi with Apache License 2.0 5 votes vote down vote up
public static FSPermissionDTO fromFsPermission(FsPermission permission) {
  if (null == permission) {
    return null;
  }
  FSPermissionDTO dto = new FSPermissionDTO();
  dto.useraction = permission.getUserAction();
  dto.groupaction = permission.getGroupAction();
  dto.otheraction = permission.getOtherAction();
  dto.stickyBit = permission.getStickyBit();
  return dto;
}
 
Example 11
Source File: HadoopPosixFileAttributes.java    From jsr203-hadoop with Apache License 2.0 5 votes vote down vote up
public HadoopPosixFileAttributes(HadoopFileSystem hdfs, Object fileKey,
    FileStatus fileStatus) throws IOException {
  super(fileKey, fileStatus);
  this.owner = hdfs.getUserPrincipalLookupService()
      .lookupPrincipalByGroupName(fileStatus.getOwner());
  this.group = hdfs.getUserPrincipalLookupService()
      .lookupPrincipalByGroupName(fileStatus.getGroup());
  FsPermission fsPermission = getFileStatus().getPermission();
  String perms = fsPermission.getUserAction().SYMBOL
      + fsPermission.getGroupAction().SYMBOL
      + fsPermission.getOtherAction().SYMBOL;
  this.permissions = PosixFilePermissions.fromString(perms);
}
 
Example 12
Source File: RunMiniCluster.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
  // GCWatcher.init(0.60);
  LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
  File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
  testDirectory.mkdirs();

  Path directory = new Path(testDirectory.getPath());
  FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
  FsAction userAction = dirPermissions.getUserAction();
  FsAction groupAction = dirPermissions.getGroupAction();
  FsAction otherAction = dirPermissions.getOtherAction();

  StringBuilder builder = new StringBuilder();
  builder.append(userAction.ordinal());
  builder.append(groupAction.ordinal());
  builder.append(otherAction.ordinal());
  String dirPermissionNum = builder.toString();
  System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
  testDirectory.delete();
  MiniCluster miniCluster = new MiniCluster();
  miniCluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true, false);

  System.out.println("ZK Connection String = [" + miniCluster.getZkConnectionString() + "]");
  System.out.println("Controller Connection String = [" + miniCluster.getControllerConnectionStr() + "]");
  System.out.println("HDFS URI = [" + miniCluster.getFileSystemUri() + "]");

}
 
Example 13
Source File: FSDirMkdirOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static PermissionStatus addImplicitUwx(PermissionStatus parentPerm,
    PermissionStatus perm) {
  FsPermission p = parentPerm.getPermission();
  FsPermission ancestorPerm = new FsPermission(
      p.getUserAction().or(FsAction.WRITE_EXECUTE),
      p.getGroupAction(),
      p.getOtherAction());
  return new PermissionStatus(perm.getUserName(), perm.getGroupName(),
      ancestorPerm);
}
 
Example 14
Source File: FileUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Set permissions to the required value. Uses the java primitives instead
 * of forking if group == other.
 * @param f the file to change
 * @param permission the new permissions
 * @throws IOException
 */
public static void setPermission(File f, FsPermission permission
                                 ) throws IOException {
  FsAction user = permission.getUserAction();
  FsAction group = permission.getGroupAction();
  FsAction other = permission.getOtherAction();

  // use the native/fork if the group/other permissions are different
  // or if the native is available or on Windows
  if (group != other || NativeIO.isAvailable() || Shell.WINDOWS) {
    execSetPermission(f, permission);
    return;
  }
  
  boolean rv = true;
  
  // read perms
  rv = f.setReadable(group.implies(FsAction.READ), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
    rv = f.setReadable(user.implies(FsAction.READ), true);
    checkReturnValue(rv, f, permission);
  }

  // write perms
  rv = f.setWritable(group.implies(FsAction.WRITE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
    rv = f.setWritable(user.implies(FsAction.WRITE), true);
    checkReturnValue(rv, f, permission);
  }

  // exec perms
  rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
  checkReturnValue(rv, f, permission);
  if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
    rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);
    checkReturnValue(rv, f, permission);
  }
}
 
Example 15
Source File: BlurOutputFormatMiniClusterTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupTest() throws Exception {
  GCWatcher.init(0.60);
  JavaHome.checkJavaHome();
  LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
  File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
  testDirectory.mkdirs();

  Path directory = new Path(testDirectory.getPath());
  FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
  FsAction userAction = dirPermissions.getUserAction();
  FsAction groupAction = dirPermissions.getGroupAction();
  FsAction otherAction = dirPermissions.getOtherAction();

  StringBuilder builder = new StringBuilder();
  builder.append(userAction.ordinal());
  builder.append(groupAction.ordinal());
  builder.append(otherAction.ordinal());
  String dirPermissionNum = builder.toString();
  System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
  testDirectory.delete();
  miniCluster = new MiniCluster();
  miniCluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2, 3, true, false);

  TEST_ROOT_DIR = new Path(miniCluster.getFileSystemUri().toString() + "/blur_test");
  System.setProperty("hadoop.log.dir", "./target/BlurOutputFormatTest/hadoop_log");
  try {
    fileSystem = TEST_ROOT_DIR.getFileSystem(conf);
  } catch (IOException io) {
    throw new RuntimeException("problem getting local fs", io);
  }

  FileSystem.setDefaultUri(conf, miniCluster.getFileSystemUri());

  miniCluster.startMrMiniCluster();
  conf = miniCluster.getMRConfiguration();

  BufferStore.initNewBuffer(128, 128 * 128);
}
 
Example 16
Source File: FSDirMkdirOp.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static PermissionStatus addImplicitUwx(PermissionStatus parentPerm,
    PermissionStatus perm) {
  FsPermission p = parentPerm.getPermission();
  FsPermission ancestorPerm = new FsPermission(
      p.getUserAction().or(FsAction.WRITE_EXECUTE),
      p.getGroupAction(),
      p.getOtherAction());
  return new PermissionStatus(perm.getUserName(), perm.getGroupName(),
      ancestorPerm);
}
 
Example 17
Source File: NativeAzureFileSystemBaseTest.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static FsPermission ignoreStickyBit(FsPermission original) {
  return new FsPermission(original.getUserAction(),
      original.getGroupAction(), original.getOtherAction());
}
 
Example 18
Source File: FileAwareInputStreamDataWriter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
static FsPermission addExecutePermissionToOwner(FsPermission fsPermission) {
  FsAction newOwnerAction = fsPermission.getUserAction().or(FsAction.EXECUTE);
  return new FsPermission(newOwnerAction, fsPermission.getGroupAction(), fsPermission.getOtherAction());
}
 
Example 19
Source File: FileContextLocation.java    From twill with Apache License 2.0 4 votes vote down vote up
@Override
public String getPermissions() throws IOException {
  FsPermission permission = fc.getFileStatus(path).getPermission();
  return permission.getUserAction().SYMBOL + permission.getGroupAction().SYMBOL + permission.getOtherAction().SYMBOL;
}
 
Example 20
Source File: NativeAzureFileSystemBaseTest.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private static FsPermission ignoreStickyBit(FsPermission original) {
  return new FsPermission(original.getUserAction(),
      original.getGroupAction(), original.getOtherAction());
}