Search in sources :

Example 11 with PermissionStatus

use of org.apache.hadoop.fs.permission.PermissionStatus in project hadoop by apache.

the class FSDirMkdirOp method addImplicitUwx.

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);
}
Also used : FsPermission(org.apache.hadoop.fs.permission.FsPermission) PermissionStatus(org.apache.hadoop.fs.permission.PermissionStatus)

Example 12 with PermissionStatus

use of org.apache.hadoop.fs.permission.PermissionStatus in project hadoop by apache.

the class FSDirSymlinkOp method addSymlink.

/**
   * Add the given symbolic link to the fs. Record it in the edits log.
   */
private static INodeSymlink addSymlink(FSDirectory fsd, String path, INodesInPath iip, String target, PermissionStatus dirPerms, boolean createParent, boolean logRetryCache) throws IOException {
    final long mtime = now();
    final INodesInPath parent;
    if (createParent) {
        parent = FSDirMkdirOp.createAncestorDirectories(fsd, iip, dirPerms);
        if (parent == null) {
            return null;
        }
    } else {
        parent = iip.getParentINodesInPath();
    }
    final String userName = dirPerms.getUserName();
    long id = fsd.allocateNewInodeId();
    PermissionStatus perm = new PermissionStatus(userName, null, FsPermission.getDefault());
    INodeSymlink newNode = unprotectedAddSymlink(fsd, parent, iip.getLastLocalName(), id, target, mtime, mtime, perm);
    if (newNode == null) {
        NameNode.stateChangeLog.info("addSymlink: failed to add " + path);
        return null;
    }
    fsd.getEditLog().logSymlink(path, target, mtime, mtime, newNode, logRetryCache);
    if (NameNode.stateChangeLog.isDebugEnabled()) {
        NameNode.stateChangeLog.debug("addSymlink: " + path + " is added");
    }
    return newNode;
}
Also used : PermissionStatus(org.apache.hadoop.fs.permission.PermissionStatus)

Example 13 with PermissionStatus

use of org.apache.hadoop.fs.permission.PermissionStatus in project hadoop by apache.

the class TestDefaultBlockPlacementPolicy method setup.

@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());
}
Also used : MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) PermissionStatus(org.apache.hadoop.fs.permission.PermissionStatus) Before(org.junit.Before)

Example 14 with PermissionStatus

use of org.apache.hadoop.fs.permission.PermissionStatus in project hadoop by apache.

the class FSEditLogOp method permissionStatusFromXml.

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);
}
Also used : Stanza(org.apache.hadoop.hdfs.util.XMLUtils.Stanza) FsPermission(org.apache.hadoop.fs.permission.FsPermission) PermissionStatus(org.apache.hadoop.fs.permission.PermissionStatus)

Example 15 with PermissionStatus

use of org.apache.hadoop.fs.permission.PermissionStatus in project hadoop by apache.

the class FSImageSerialization method readINodeUnderConstruction.

// Helper function that reads in an INodeUnderConstruction
// from the input stream
//
static INodeFile readINodeUnderConstruction(DataInput in, FSNamesystem fsNamesys, int imgVersion) throws IOException {
    byte[] name = readBytes(in);
    long inodeId = NameNodeLayoutVersion.supports(LayoutVersion.Feature.ADD_INODE_ID, imgVersion) ? in.readLong() : fsNamesys.dir.allocateNewInodeId();
    short blockReplication = in.readShort();
    long modificationTime = in.readLong();
    long preferredBlockSize = in.readLong();
    int numBlocks = in.readInt();
    final BlockInfoContiguous[] blocksContiguous = new BlockInfoContiguous[numBlocks];
    Block blk = new Block();
    int i = 0;
    for (; i < numBlocks - 1; i++) {
        blk.readFields(in);
        blocksContiguous[i] = new BlockInfoContiguous(blk, blockReplication);
    }
    // last block is UNDER_CONSTRUCTION
    if (numBlocks > 0) {
        blk.readFields(in);
        blocksContiguous[i] = new BlockInfoContiguous(blk, blockReplication);
        blocksContiguous[i].convertToBlockUnderConstruction(BlockUCState.UNDER_CONSTRUCTION, null);
    }
    PermissionStatus perm = PermissionStatus.read(in);
    String clientName = readString(in);
    String clientMachine = readString(in);
    // We previously stored locations for the last block, now we
    // just record that there are none
    int numLocs = in.readInt();
    assert numLocs == 0 : "Unexpected block locations";
    // Images in the pre-protobuf format will not have the lazyPersist flag,
    // so it is safe to pass false always.
    INodeFile file = new INodeFile(inodeId, name, perm, modificationTime, modificationTime, blocksContiguous, blockReplication, preferredBlockSize);
    file.toUnderConstruction(clientName, clientMachine);
    return file;
}
Also used : BlockInfoContiguous(org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous) Block(org.apache.hadoop.hdfs.protocol.Block) PermissionStatus(org.apache.hadoop.fs.permission.PermissionStatus)

Aggregations

PermissionStatus (org.apache.hadoop.fs.permission.PermissionStatus)33 FsPermission (org.apache.hadoop.fs.permission.FsPermission)11 Configuration (org.apache.hadoop.conf.Configuration)9 IOException (java.io.IOException)7 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)6 Test (org.junit.Test)6 Path (org.apache.hadoop.fs.Path)5 Before (org.junit.Before)5 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)4 Block (org.apache.hadoop.hdfs.protocol.Block)3 BlockInfoContiguous (org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous)3 StorageException (com.microsoft.azure.storage.StorageException)2 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)2 BlockInfo (org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2