Java Code Examples for org.apache.hadoop.fs.permission.PermissionStatus#createImmutable()

The following examples show how to use org.apache.hadoop.fs.permission.PermissionStatus#createImmutable() . 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: TestINodeFile.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * For a given path, build a tree of INodes and return the leaf node.
 */
private INode createTreeOfInodes(String path) throws QuotaExceededException {
  byte[][] components = INode.getPathComponents(path);
  FsPermission perm = FsPermission.createImmutable((short)0755);
  PermissionStatus permstatus = PermissionStatus.createImmutable("", "", perm);
  
  long id = 0;
  INodeDirectory prev = new INodeDirectory(++id, new byte[0], permstatus, 0);
  INodeDirectory dir = null;
  for (byte[] component : components) {
    if (component.length == 0) {
      continue;
    }
    System.out.println("Adding component " + DFSUtil.bytes2String(component));
    dir = new INodeDirectory(++id, component, permstatus, 0);
    prev.addChild(dir, false, Snapshot.CURRENT_STATE_ID);
    prev = dir;
  }
  return dir; // Last Inode in the chain
}
 
Example 2
Source File: FSImageTestUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Create an aborted in-progress log in the given directory, containing
 * only a specified number of "mkdirs" operations.
 */
public static void createAbortedLogWithMkdirs(File editsLogDir, int numDirs,
    long firstTxId, long newInodeId) throws IOException {
  FSEditLog editLog = FSImageTestUtil.createStandaloneEditLog(editsLogDir);
  editLog.setNextTxId(firstTxId);
  editLog.openForWrite();
  
  PermissionStatus perms = PermissionStatus.createImmutable("fakeuser", "fakegroup",
      FsPermission.createImmutable((short)0755));
  for (int i = 1; i <= numDirs; i++) {
    String dirName = "dir" + i;
    INodeDirectory dir = new INodeDirectory(newInodeId + i - 1,
        DFSUtil.string2Bytes(dirName), perms, 0L);
    editLog.logMkDir("/" + dirName, dir);
  }
  editLog.logSync();
  editLog.abortCurrentLogSegment();
}
 
Example 3
Source File: TestINodeFile.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * For a given path, build a tree of INodes and return the leaf node.
 */
private INode createTreeOfInodes(String path) throws QuotaExceededException {
  byte[][] components = INode.getPathComponents(path);
  FsPermission perm = FsPermission.createImmutable((short)0755);
  PermissionStatus permstatus = PermissionStatus.createImmutable("", "", perm);
  
  long id = 0;
  INodeDirectory prev = new INodeDirectory(++id, new byte[0], permstatus, 0);
  INodeDirectory dir = null;
  for (byte[] component : components) {
    if (component.length == 0) {
      continue;
    }
    System.out.println("Adding component " + DFSUtil.bytes2String(component));
    dir = new INodeDirectory(++id, component, permstatus, 0);
    prev.addChild(dir, false, Snapshot.CURRENT_STATE_ID);
    prev = dir;
  }
  return dir; // Last Inode in the chain
}
 
Example 4
Source File: FSImageTestUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Create an aborted in-progress log in the given directory, containing
 * only a specified number of "mkdirs" operations.
 */
public static void createAbortedLogWithMkdirs(File editsLogDir, int numDirs,
    long firstTxId, long newInodeId) throws IOException {
  FSEditLog editLog = FSImageTestUtil.createStandaloneEditLog(editsLogDir);
  editLog.setNextTxId(firstTxId);
  editLog.openForWrite();
  
  PermissionStatus perms = PermissionStatus.createImmutable("fakeuser", "fakegroup",
      FsPermission.createImmutable((short)0755));
  for (int i = 1; i <= numDirs; i++) {
    String dirName = "dir" + i;
    INodeDirectory dir = new INodeDirectory(newInodeId + i - 1,
        DFSUtil.string2Bytes(dirName), perms, 0L);
    editLog.logMkDir("/" + dirName, dir);
  }
  editLog.logSync();
  editLog.abortCurrentLogSegment();
}
 
Example 5
Source File: TestFSPermissionChecker.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static INodeDirectory createINodeDirectory(INodeDirectory parent,
    String name, String owner, String group, short perm) throws IOException {
  PermissionStatus permStatus = PermissionStatus.createImmutable(owner, group,
    FsPermission.createImmutable(perm));
  INodeDirectory inodeDirectory = new INodeDirectory(
    INodeId.GRANDFATHER_INODE_ID, name.getBytes("UTF-8"), permStatus, 0L);
  parent.addChild(inodeDirectory);
  return inodeDirectory;
}
 
Example 6
Source File: TestFSPermissionChecker.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static INodeFile createINodeFile(INodeDirectory parent, String name,
    String owner, String group, short perm) throws IOException {
  PermissionStatus permStatus = PermissionStatus.createImmutable(owner, group,
    FsPermission.createImmutable(perm));
  INodeFile inodeFile = new INodeFile(INodeId.GRANDFATHER_INODE_ID,
    name.getBytes("UTF-8"), permStatus, 0L, 0L, null, REPLICATION,
    PREFERRED_BLOCK_SIZE, (byte)0);
  parent.addChild(inodeFile);
  return inodeFile;
}
 
Example 7
Source File: TestNestedSnapshots.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link Snapshot#ID_COMPARATOR}.
 */
@Test (timeout=300000)
public void testIdCmp() {
  final PermissionStatus perm = PermissionStatus.createImmutable(
      "user", "group", FsPermission.createImmutable((short)0));
  final INodeDirectory snapshottable = new INodeDirectory(0,
      DFSUtil.string2Bytes("foo"), perm, 0L);
  snapshottable.addSnapshottableFeature();
  final Snapshot[] snapshots = {
    new Snapshot(1, "s1", snapshottable),
    new Snapshot(1, "s1", snapshottable),
    new Snapshot(2, "s2", snapshottable),
    new Snapshot(2, "s2", snapshottable),
  };

  Assert.assertEquals(0, Snapshot.ID_COMPARATOR.compare(null, null));
  for(Snapshot s : snapshots) {
    Assert.assertTrue(Snapshot.ID_COMPARATOR.compare(null, s) > 0);
    Assert.assertTrue(Snapshot.ID_COMPARATOR.compare(s, null) < 0);
    
    for(Snapshot t : snapshots) {
      final int expected = s.getRoot().getLocalName().compareTo(
          t.getRoot().getLocalName());
      final int computed = Snapshot.ID_COMPARATOR.compare(s, t);
      Assert.assertEquals(expected > 0, computed > 0);
      Assert.assertEquals(expected == 0, computed == 0);
      Assert.assertEquals(expected < 0, computed < 0);
    }
  }
}
 
Example 8
Source File: TestFSPermissionChecker.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static INodeDirectory createINodeDirectory(INodeDirectory parent,
    String name, String owner, String group, short perm) throws IOException {
  PermissionStatus permStatus = PermissionStatus.createImmutable(owner, group,
    FsPermission.createImmutable(perm));
  INodeDirectory inodeDirectory = new INodeDirectory(
    INodeId.GRANDFATHER_INODE_ID, name.getBytes("UTF-8"), permStatus, 0L);
  parent.addChild(inodeDirectory);
  return inodeDirectory;
}
 
Example 9
Source File: TestFSPermissionChecker.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static INodeFile createINodeFile(INodeDirectory parent, String name,
    String owner, String group, short perm) throws IOException {
  PermissionStatus permStatus = PermissionStatus.createImmutable(owner, group,
    FsPermission.createImmutable(perm));
  INodeFile inodeFile = new INodeFile(INodeId.GRANDFATHER_INODE_ID,
    name.getBytes("UTF-8"), permStatus, 0L, 0L, null, REPLICATION,
    PREFERRED_BLOCK_SIZE, (byte)0);
  parent.addChild(inodeFile);
  return inodeFile;
}
 
Example 10
Source File: TestNestedSnapshots.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link Snapshot#ID_COMPARATOR}.
 */
@Test (timeout=300000)
public void testIdCmp() {
  final PermissionStatus perm = PermissionStatus.createImmutable(
      "user", "group", FsPermission.createImmutable((short)0));
  final INodeDirectory snapshottable = new INodeDirectory(0,
      DFSUtil.string2Bytes("foo"), perm, 0L);
  snapshottable.addSnapshottableFeature();
  final Snapshot[] snapshots = {
    new Snapshot(1, "s1", snapshottable),
    new Snapshot(1, "s1", snapshottable),
    new Snapshot(2, "s2", snapshottable),
    new Snapshot(2, "s2", snapshottable),
  };

  Assert.assertEquals(0, Snapshot.ID_COMPARATOR.compare(null, null));
  for(Snapshot s : snapshots) {
    Assert.assertTrue(Snapshot.ID_COMPARATOR.compare(null, s) > 0);
    Assert.assertTrue(Snapshot.ID_COMPARATOR.compare(s, null) < 0);
    
    for(Snapshot t : snapshots) {
      final int expected = s.getRoot().getLocalName().compareTo(
          t.getRoot().getLocalName());
      final int computed = Snapshot.ID_COMPARATOR.compare(s, t);
      Assert.assertEquals(expected > 0, computed > 0);
      Assert.assertEquals(expected == 0, computed == 0);
      Assert.assertEquals(expected < 0, computed < 0);
    }
  }
}