org.apache.hadoop.fs.permission.PermissionStatus Java Examples

The following examples show how to use org.apache.hadoop.fs.permission.PermissionStatus. 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: NativeAzureFileSystem.java    From hadoop with Apache License 2.0 7 votes vote down vote up
@Override
public void setPermission(Path p, FsPermission permission) throws IOException {
  Path absolutePath = makeAbsolute(p);
  String key = pathToKey(absolutePath);
  FileMetadata metadata = store.retrieveMetadata(key);
  if (metadata == null) {
    throw new FileNotFoundException("File doesn't exist: " + p);
  }
  permission = applyUMask(permission,
      metadata.isDir() ? UMaskApplyMode.ChangeExistingDirectory
          : UMaskApplyMode.ChangeExistingFile);
  if (metadata.getBlobMaterialization() == BlobMaterialization.Implicit) {
    // It's an implicit folder, need to materialize it.
    store.storeEmptyFolder(key, createPermissionStatus(permission));
  } else if (!metadata.getPermissionStatus().getPermission().
      equals(permission)) {
    store.changePermissionStatus(key, new PermissionStatus(
        metadata.getPermissionStatus().getUserName(),
        metadata.getPermissionStatus().getGroupName(),
        permission));
  }
}
 
Example #2
Source File: NativeAzureFileSystem.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void setOwner(Path p, String username, String groupname)
    throws IOException {
  Path absolutePath = makeAbsolute(p);
  String key = pathToKey(absolutePath);
  FileMetadata metadata = store.retrieveMetadata(key);
  if (metadata == null) {
    throw new FileNotFoundException("File doesn't exist: " + p);
  }
  PermissionStatus newPermissionStatus = new PermissionStatus(
      username == null ?
          metadata.getPermissionStatus().getUserName() : username,
      groupname == null ?
          metadata.getPermissionStatus().getGroupName() : groupname,
      metadata.getPermissionStatus().getPermission());
  if (metadata.getBlobMaterialization() == BlobMaterialization.Implicit) {
    // It's an implicit folder, need to materialize it.
    store.storeEmptyFolder(key, newPermissionStatus);
  } else {
    store.changePermissionStatus(key, newPermissionStatus);
  }
}
 
Example #3
Source File: FSImageLoader.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
 
Example #4
Source File: TestGetBlockLocations.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static FSNamesystem setupFileSystem() throws IOException {
  Configuration conf = new Configuration();
  conf.setLong(DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, 1L);
  FSEditLog editlog = mock(FSEditLog.class);
  FSImage image = mock(FSImage.class);
  when(image.getEditLog()).thenReturn(editlog);
  final FSNamesystem fsn = new FSNamesystem(conf, image, true);

  final FSDirectory fsd = fsn.getFSDirectory();
  INodesInPath iip = fsd.getINodesInPath("/", true);
  PermissionStatus perm = new PermissionStatus(
      "hdfs", "supergroup",
      FsPermission.createImmutable((short) 0x1ff));
  final INodeFile file = new INodeFile(
      MOCK_INODE_ID, FILE_NAME.getBytes(Charsets.UTF_8),
      perm, 1, 1, new BlockInfoContiguous[] {}, (short) 1,
      DFS_BLOCK_SIZE_DEFAULT);
  fsn.getFSDirectory().addINode(iip, file);
  return fsn;
}
 
Example #5
Source File: TestDefaultBlockPlacementPolicy.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  StaticMapping.resetMap();
  Configuration conf = new HdfsConfiguration();
  final String[] racks = { "/RACK0", "/RACK0", "/RACK2", "/RACK3", "/RACK2" };
  final String[] hosts = { "/host0", "/host1", "/host2", "/host3", "/host4" };

  conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, DEFAULT_BLOCK_SIZE);
  conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY, DEFAULT_BLOCK_SIZE / 2);
  cluster = new MiniDFSCluster.Builder(conf).numDataNodes(5).racks(racks)
      .hosts(hosts).build();
  cluster.waitActive();
  nameNodeRpc = cluster.getNameNodeRpc();
  namesystem = cluster.getNamesystem();
  perm = new PermissionStatus("TestDefaultBlockPlacementPolicy", null,
      FsPermission.getDefault());
}
 
Example #6
Source File: NameNode.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void create(String src, 
                   FsPermission masked,
                           String clientName, 
                           boolean overwrite,
                           short replication,
                           long blockSize
                           ) throws IOException {
  String clientMachine = getClientMachine();
  if (stateChangeLog.isDebugEnabled()) {
    stateChangeLog.debug("*DIR* NameNode.create: file "
                       +src+" for "+clientName+" at "+clientMachine);
  }
  if (!checkPathLength(src)) {
    throw new IOException("create: Pathname too long.  Limit " 
                          + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
  }
  namesystem.startFile(src,
      new PermissionStatus(UserGroupInformation.getCurrentUGI().getUserName(),
          null, masked),
      clientName, clientMachine, overwrite, replication, blockSize);
  myMetrics.numFilesCreated.inc();
  myMetrics.numCreateFileOps.inc();
}
 
Example #7
Source File: FSEditLog.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/** 
 * Add create directory record to edit log
 */
public void logMkDir(String path, INode newNode) {
  PermissionStatus permissions = newNode.getPermissionStatus();
  MkdirOp op = MkdirOp.getInstance(cache.get())
    .setInodeId(newNode.getId())
    .setPath(path)
    .setTimestamp(newNode.getModificationTime())
    .setPermissionStatus(permissions);

  AclFeature f = newNode.getAclFeature();
  if (f != null) {
    op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode));
  }

  XAttrFeature x = newNode.getXAttrFeature();
  if (x != null) {
    op.setXAttrs(x.getXAttrs());
  }
  logEdit(op);
}
 
Example #8
Source File: TestDefaultBlockPlacementPolicy.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  StaticMapping.resetMap();
  Configuration conf = new HdfsConfiguration();
  final String[] racks = { "/RACK0", "/RACK0", "/RACK2", "/RACK3", "/RACK2" };
  final String[] hosts = { "/host0", "/host1", "/host2", "/host3", "/host4" };

  conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, DEFAULT_BLOCK_SIZE);
  conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY, DEFAULT_BLOCK_SIZE / 2);
  cluster = new MiniDFSCluster.Builder(conf).numDataNodes(5).racks(racks)
      .hosts(hosts).build();
  cluster.waitActive();
  nameNodeRpc = cluster.getNameNodeRpc();
  namesystem = cluster.getNamesystem();
  perm = new PermissionStatus("TestDefaultBlockPlacementPolicy", null,
      FsPermission.getDefault());
}
 
Example #9
Source File: TestGetBlockLocations.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static FSNamesystem setupFileSystem() throws IOException {
  Configuration conf = new Configuration();
  conf.setLong(DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, 1L);
  FSEditLog editlog = mock(FSEditLog.class);
  FSImage image = mock(FSImage.class);
  when(image.getEditLog()).thenReturn(editlog);
  final FSNamesystem fsn = new FSNamesystem(conf, image, true);

  final FSDirectory fsd = fsn.getFSDirectory();
  INodesInPath iip = fsd.getINodesInPath("/", true);
  PermissionStatus perm = new PermissionStatus(
      "hdfs", "supergroup",
      FsPermission.createImmutable((short) 0x1ff));
  final INodeFile file = new INodeFile(
      MOCK_INODE_ID, FILE_NAME.getBytes(Charsets.UTF_8),
      perm, 1, 1, new BlockInfoContiguous[] {}, (short) 1,
      DFS_BLOCK_SIZE_DEFAULT);
  fsn.getFSDirectory().addINode(iip, file);
  return fsn;
}
 
Example #10
Source File: INodeFileUnderConstruction.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public INodeFileUnderConstruction(byte[] name,
                           short blockReplication,
                           long modificationTime,
                           long preferredBlockSize,
                           BlockInfo[] blocks,
                           PermissionStatus perm,
                           String clientName,
                           String clientMachine,
                           DatanodeDescriptor clientNode) {
  super(perm, blocks, blockReplication, modificationTime, modificationTime,
        preferredBlockSize);
  setLocalName(name);
  this.clientName = clientName;
  this.clientMachine = clientMachine;
  this.clientNode = clientNode;
}
 
Example #11
Source File: FSImageLoader.java    From big-c with Apache License 2.0 6 votes vote down vote up
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
 
Example #12
Source File: FSImageFormat.java    From big-c with Apache License 2.0 6 votes vote down vote up
/** Load {@link INodeFileAttributes}. */
public INodeFileAttributes loadINodeFileAttributes(DataInput in)
    throws IOException {
  final int layoutVersion = getLayoutVersion();
  
  if (!NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.OPTIMIZE_SNAPSHOT_INODES, layoutVersion)) {
    return loadINodeWithLocalName(true, in, false).asFile();
  }
  
  final byte[] name = FSImageSerialization.readLocalName(in);
  final PermissionStatus permissions = PermissionStatus.read(in);
  final long modificationTime = in.readLong();
  final long accessTime = in.readLong();
  
  final short replication = namesystem.getBlockManager().adjustReplication(
      in.readShort());
  final long preferredBlockSize = in.readLong();

  return new INodeFileAttributes.SnapshotCopy(name, permissions, null, modificationTime,
      accessTime, replication, preferredBlockSize, (byte) 0, null);
}
 
Example #13
Source File: FSImageFormat.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/** Load {@link INodeFileAttributes}. */
public INodeFileAttributes loadINodeFileAttributes(DataInput in)
    throws IOException {
  final int layoutVersion = getLayoutVersion();
  
  if (!NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.OPTIMIZE_SNAPSHOT_INODES, layoutVersion)) {
    return loadINodeWithLocalName(true, in, false).asFile();
  }
  
  final byte[] name = FSImageSerialization.readLocalName(in);
  final PermissionStatus permissions = PermissionStatus.read(in);
  final long modificationTime = in.readLong();
  final long accessTime = in.readLong();
  
  final short replication = namesystem.getBlockManager().adjustReplication(
      in.readShort());
  final long preferredBlockSize = in.readLong();

  return new INodeFileAttributes.SnapshotCopy(name, permissions, null, modificationTime,
      accessTime, replication, preferredBlockSize, (byte) 0, null);
}
 
Example #14
Source File: FSEditLog.java    From big-c with Apache License 2.0 6 votes vote down vote up
/** 
 * Add create directory record to edit log
 */
public void logMkDir(String path, INode newNode) {
  PermissionStatus permissions = newNode.getPermissionStatus();
  MkdirOp op = MkdirOp.getInstance(cache.get())
    .setInodeId(newNode.getId())
    .setPath(path)
    .setTimestamp(newNode.getModificationTime())
    .setPermissionStatus(permissions);

  AclFeature f = newNode.getAclFeature();
  if (f != null) {
    op.setAclEntries(AclStorage.readINodeLogicalAcl(newNode));
  }

  XAttrFeature x = newNode.getXAttrFeature();
  if (x != null) {
    op.setXAttrs(x.getXAttrs());
  }
  logEdit(op);
}
 
Example #15
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 #16
Source File: TestFSPermissionChecker.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
  Configuration conf = new Configuration();
  FSNamesystem fsn = mock(FSNamesystem.class);
  doAnswer(new Answer() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      Object[] args = invocation.getArguments();
      FsPermission perm = (FsPermission) args[0];
      return new PermissionStatus(SUPERUSER, SUPERGROUP, perm);
    }
  }).when(fsn).createFsOwnerPermissions(any(FsPermission.class));
  dir = new FSDirectory(fsn, conf);
  inodeRoot = dir.getRoot();
}
 
Example #17
Source File: FSImageSerialization.java    From RDFS with Apache License 2.0 5 votes vote down vote up
static INodeFileUnderConstruction readINodeUnderConstruction(
                          DataInputStream in) throws IOException {
  byte[] name = readBytes(in);
  String path = DFSUtil.bytes2String(name);
  short blockReplication = in.readShort();
  long modificationTime = in.readLong();
  long preferredBlockSize = in.readLong();
  int numBlocks = in.readInt();
  BlockInfo[] blocks = new BlockInfo[numBlocks];
  Block blk = new Block();
  for (int i = 0; i < numBlocks; i++) {
    blk.readFields(in);
    blocks[i] = new BlockInfo(blk, blockReplication);
  }
  PermissionStatus perm = PermissionStatus.read(in);
  String clientName = readString(in);
  String clientMachine = readString(in);

  // These locations are not used at all
  int numLocs = in.readInt();
  DatanodeDescriptor[] locations = new DatanodeDescriptor[numLocs];
  for (int i = 0; i < numLocs; i++) {
    locations[i] = new DatanodeDescriptor();
    locations[i].readFields(in);
  }

  return new INodeFileUnderConstruction(name, 
                                        blockReplication, 
                                        modificationTime,
                                        preferredBlockSize,
                                        blocks,
                                        perm,
                                        clientName,
                                        clientMachine,
                                        null);
}
 
Example #18
Source File: AzureNativeFileSystemStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public static PermissionStatus fromJSONString(String jsonString) {
  // The JSON class can only find out about an object's class (and call me)
  // if we store the class name in the JSON string. Since I don't want to
  // do that (it's an implementation detail), I just deserialize as a
  // the default Map (JSON's default behavior) and parse that.
  return fromJSONMap((Map) PERMISSION_JSON_SERIALIZER.fromJSON(jsonString));
}
 
Example #19
Source File: AzureNativeFileSystemStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static void storePermissionStatus(CloudBlobWrapper blob,
    PermissionStatus permissionStatus) {
  storeMetadataAttribute(blob, PERMISSION_METADATA_KEY,
      PERMISSION_JSON_SERIALIZER.toJSON(permissionStatus));
  // Remove the old metadata key if present
  removeMetadataAttribute(blob, OLD_PERMISSION_METADATA_KEY);
}
 
Example #20
Source File: FSImage.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private static void saveINode2Image(ByteBuffer name,
                                    INode node,
                                    DataOutputStream out) throws IOException {
  int nameLen = name.position();
  out.writeShort(nameLen);
  out.write(name.array(), name.arrayOffset(), nameLen);
  if (!node.isDirectory()) {  // write file inode
    INodeFile fileINode = (INodeFile)node;
    out.writeShort(fileINode.getReplication());
    out.writeLong(fileINode.getModificationTime());
    out.writeLong(fileINode.getAccessTime());
    out.writeLong(fileINode.getPreferredBlockSize());
    Block[] blocks = fileINode.getBlocks();
    out.writeInt(blocks.length);
    for (Block blk : blocks)
      blk.write(out);
    FILE_PERM.fromShort(fileINode.getFsPermissionShort());
    PermissionStatus.write(out, fileINode.getUserName(),
                           fileINode.getGroupName(),
                           FILE_PERM);
  } else {   // write directory inode
    out.writeShort(0);  // replication
    out.writeLong(node.getModificationTime());
    out.writeLong(0);   // access time
    out.writeLong(0);   // preferred block size
    out.writeInt(-1);    // # of blocks
    out.writeLong(node.getNsQuota());
    out.writeLong(node.getDsQuota());
    FILE_PERM.fromShort(node.getFsPermissionShort());
    PermissionStatus.write(out, node.getUserName(),
                           node.getGroupName(),
                           FILE_PERM);
  }
}
 
Example #21
Source File: FSEditLogOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static PermissionStatus permissionStatusFromXml(Stanza st)
    throws InvalidXmlException {
  Stanza status = st.getChildren("PERMISSION_STATUS").get(0);
  String username = status.getValue("USERNAME");
  String groupname = status.getValue("GROUPNAME");
  FsPermission mode = fsPermissionFromXml(status);
  return new PermissionStatus(username, groupname, mode);
}
 
Example #22
Source File: NameNodeRpcServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override // ClientProtocol
public HdfsFileStatus create(String src, FsPermission masked,
    String clientName, EnumSetWritable<CreateFlag> flag,
    boolean createParent, short replication, long blockSize, 
    CryptoProtocolVersion[] supportedVersions)
    throws IOException {
  checkNNStartup();
  String clientMachine = getClientMachine();
  if (stateChangeLog.isDebugEnabled()) {
    stateChangeLog.debug("*DIR* NameNode.create: file "
        +src+" for "+clientName+" at "+clientMachine);
  }
  if (!checkPathLength(src)) {
    throw new IOException("create: Pathname too long.  Limit "
        + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
  }

  CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion(retryCache, null);
  if (cacheEntry != null && cacheEntry.isSuccess()) {
    return (HdfsFileStatus) cacheEntry.getPayload();
  }

  HdfsFileStatus status = null;
  try {
    PermissionStatus perm = new PermissionStatus(getRemoteUser()
        .getShortUserName(), null, masked);
    status = namesystem.startFile(src, perm, clientName, clientMachine,
        flag.get(), createParent, replication, blockSize, supportedVersions,
        cacheEntry != null);
  } finally {
    RetryCache.setState(cacheEntry, status != null, status);
  }

  metrics.incrFilesCreated();
  metrics.incrCreateFileOps();
  return status;
}
 
Example #23
Source File: AzureNativeFileSystemStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void toJSON(Object obj, JSON.Output out) {
  PermissionStatus permissionStatus = (PermissionStatus) obj;
  // Don't store group as null, just store it as empty string
  // (which is FileStatus behavior).
  String group = permissionStatus.getGroupName() == null ? ""
      : permissionStatus.getGroupName();
  out.add(OWNER_TAG, permissionStatus.getUserName());
  out.add(GROUP_TAG, group);
  out.add(PERMISSIONS_TAG, permissionStatus.getPermission().toString());
}
 
Example #24
Source File: TestDistCh.java    From RDFS with Apache License 2.0 5 votes vote down vote up
static void checkFileStatus(PermissionStatus expected, FileStatus actual) {
  assertEquals(expected.getUserName(), actual.getOwner());
  assertEquals(expected.getGroupName(), actual.getGroup());
  FsPermission perm = expected.getPermission(); 
  if (!actual.isDir()) {
    perm = perm.applyUMask(UMASK);
  }
  assertEquals(perm, actual.getPermission());
}
 
Example #25
Source File: NameNodeAdapter.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static FSEditLogOp createMkdirOp(String path) {
  MkdirOp op = MkdirOp.getInstance(new FSEditLogOp.OpInstanceCache())
    .setPath(path)
    .setTimestamp(0)
    .setPermissionStatus(new PermissionStatus(
            "testuser", "testgroup", FsPermission.getDefault()));
  return op;
}
 
Example #26
Source File: FSEditLogOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
void readFields(DataInputStream in, int logVersion)
    throws IOException {
  if (!NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
    this.length = in.readInt();
    if (this.length != 4) {
      throw new IOException("Incorrect data format. "
          + "symlink operation.");
    }
  }
  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.ADD_INODE_ID, logVersion)) {
    this.inodeId = FSImageSerialization.readLong(in);
  } else {
    // This id should be updated when the editLogOp is applied
    this.inodeId = INodeId.GRANDFATHER_INODE_ID;
  }
  this.path = FSImageSerialization.readString(in);
  this.value = FSImageSerialization.readString(in);

  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
    this.mtime = FSImageSerialization.readLong(in);
    this.atime = FSImageSerialization.readLong(in);
  } else {
    this.mtime = readLong(in);
    this.atime = readLong(in);
  }
  this.permissionStatus = PermissionStatus.read(in);
  
  // read RPC ids if necessary
  readRpcIds(in, logVersion);
}
 
Example #27
Source File: FSImageLoader.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Return the JSON formatted ACL status of the specified file.
 * @param path a path specifies a file
 * @return JSON formatted AclStatus
 * @throws IOException if failed to serialize fileStatus to JSON.
 */
String getAclStatus(String path) throws IOException {
  PermissionStatus p = getPermissionStatus(path);
  List<AclEntry> aclEntryList = getAclEntryList(path);
  FsPermission permission = p.getPermission();
  AclStatus.Builder builder = new AclStatus.Builder();
  builder.owner(p.getUserName()).group(p.getGroupName())
      .addEntries(aclEntryList).setPermission(permission)
      .stickyBit(permission.getStickyBit());
  AclStatus aclStatus = builder.build();
  return JsonUtil.toJsonString(aclStatus);
}
 
Example #28
Source File: INodeAttributes.java    From hadoop with Apache License 2.0 5 votes vote down vote up
SnapshotCopy(byte[] name, PermissionStatus permissions,
    AclFeature aclFeature, long modificationTime, long accessTime, 
    XAttrFeature xAttrFeature) {
  this.name = name;
  this.permission = PermissionStatusFormat.toLong(permissions);
  if (aclFeature != null) {
    aclFeature = AclStorage.addAclFeature(aclFeature);
  }
  this.aclFeature = aclFeature;
  this.modificationTime = modificationTime;
  this.accessTime = accessTime;
  this.xAttrFeature = xAttrFeature;
}
 
Example #29
Source File: FSImage.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
static INodeFileUnderConstruction readINodeUnderConstruction(
                          DataInputStream in) throws IOException {
  byte[] name = readBytes(in);
  short blockReplication = in.readShort();
  long modificationTime = in.readLong();
  long preferredBlockSize = in.readLong();
  int numBlocks = in.readInt();
  BlockInfo[] blocks = new BlockInfo[numBlocks];
  Block blk = new Block();
  for (int i = 0; i < numBlocks; i++) {
    blk.readFields(in);
    blocks[i] = new BlockInfo(blk, blockReplication);
  }
  PermissionStatus perm = PermissionStatus.read(in);
  String clientName = readString(in);
  String clientMachine = readString(in);

  // These locations are not used at all
  int numLocs = in.readInt();
  DatanodeDescriptor[] locations = new DatanodeDescriptor[numLocs];
  for (int i = 0; i < numLocs; i++) {
    locations[i] = new DatanodeDescriptor();
    locations[i].readFields(in);
  }

  return new INodeFileUnderConstruction(name, 
                                        blockReplication, 
                                        modificationTime,
                                        preferredBlockSize,
                                        blocks,
                                        perm,
                                        clientName,
                                        clientMachine,
                                        null);
}
 
Example #30
Source File: AzureNativeFileSystemStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JSON serializer that can serialize a PermissionStatus object into
 * the JSON string we want in the blob metadata.
 * 
 * @return The JSON serializer.
 */
private static JSON createPermissionJsonSerializer() {
  JSON serializer = new JSON();
  serializer.addConvertor(PermissionStatus.class,
      new PermissionStatusJsonSerializer());
  return serializer;
}