List of usage examples for org.apache.hadoop.fs FileStatus getOwner
public String getOwner()
From source file:org.apache.tajo.master.QueryMaster.java
License:Apache License
/** * It initializes the final output and staging directory and sets * them to variables./* www . ja v a2 s . c o m*/ */ private void initStagingDir() throws IOException { QueryConf conf = getContext().getConf(); String realUser; String currentUser; UserGroupInformation ugi; ugi = UserGroupInformation.getLoginUser(); realUser = ugi.getShortUserName(); currentUser = UserGroupInformation.getCurrentUser().getShortUserName(); String givenOutputTableName = conf.getOutputTable(); Path stagingDir; // If final output directory is not given by an user, // we use the query id as a output directory. if (givenOutputTableName.equals("")) { this.isCreateTableStmt = false; FileSystem defaultFS = FileSystem.get(conf); Path homeDirectory = defaultFS.getHomeDirectory(); if (!defaultFS.exists(homeDirectory)) { defaultFS.mkdirs(homeDirectory, new FsPermission(USER_DIR_PERMISSION)); } Path userQueryDir = new Path(homeDirectory, TajoConstants.USER_QUERYDIR_PREFIX); if (defaultFS.exists(userQueryDir)) { FileStatus fsStatus = defaultFS.getFileStatus(userQueryDir); String owner = fsStatus.getOwner(); if (!(owner.equals(currentUser) || owner.equals(realUser))) { throw new IOException("The ownership on the user's query " + "directory " + userQueryDir + " is not as expected. " + "It is owned by " + owner + ". The directory must " + "be owned by the submitter " + currentUser + " or " + "by " + realUser); } if (!fsStatus.getPermission().equals(USER_DIR_PERMISSION)) { LOG.info("Permissions on staging directory " + userQueryDir + " are " + "incorrect: " + fsStatus.getPermission() + ". Fixing permissions " + "to correct value " + USER_DIR_PERMISSION); defaultFS.setPermission(userQueryDir, new FsPermission(USER_DIR_PERMISSION)); } } else { defaultFS.mkdirs(userQueryDir, new FsPermission(USER_DIR_PERMISSION)); } stagingDir = StorageUtil.concatPath(userQueryDir, queryId.toString()); if (defaultFS.exists(stagingDir)) { throw new IOException("The staging directory " + stagingDir + "already exists. The directory must be unique to each query"); } else { defaultFS.mkdirs(stagingDir, new FsPermission(USER_DIR_PERMISSION)); } // Set the query id to the output table name conf.setOutputTable(queryId.toString()); } else { this.isCreateTableStmt = true; Path warehouseDir = new Path(conf.getVar(TajoConf.ConfVars.ROOT_DIR), TajoConstants.WAREHOUSE_DIR); stagingDir = new Path(warehouseDir, conf.getOutputTable()); FileSystem fs = warehouseDir.getFileSystem(conf); if (fs.exists(stagingDir)) { throw new IOException("The staging directory " + stagingDir + " already exists. The directory must be unique to each query"); } else { // TODO - should have appropriate permission fs.mkdirs(stagingDir, new FsPermission(USER_DIR_PERMISSION)); } } conf.setOutputPath(stagingDir); outputPath = stagingDir; LOG.info("Initialized Query Staging Dir: " + outputPath); }
From source file:org.apache.tajo.master.rule.FileSystemRule.java
License:Apache License
private void canAccessToPath(FileStatus fsStatus, FsAction action) throws Exception { FsPermission permission = fsStatus.getPermission(); UserGroupInformation userGroupInformation = UserGroupInformation.getCurrentUser(); String userName = userGroupInformation.getShortUserName(); List<String> groupList = Arrays.asList(userGroupInformation.getGroupNames()); if (userName.equals(fsStatus.getOwner())) { if (permission.getUserAction().implies(action)) { return; }//from ww w . j a va2 s .c o m } else if (groupList.contains(fsStatus.getGroup())) { if (permission.getGroupAction().implies(action)) { return; } } else { if (permission.getOtherAction().implies(action)) { return; } } throw new AccessControlException( String.format("Permission denied: user=%s, path=\"%s\":%s:%s:%s%s", userName, fsStatus.getPath(), fsStatus.getOwner(), fsStatus.getGroup(), fsStatus.isDirectory() ? "d" : "-", permission)); }
From source file:org.apache.tajo.storage.FileTablespace.java
License:Apache License
public URI prepareStagingSpace(TajoConf conf, String queryId, OverridableConf context, TableMeta meta) throws IOException { String realUser;/*from ww w . j a v a2 s. c o m*/ String currentUser; UserGroupInformation ugi; ugi = UserGroupInformation.getLoginUser(); realUser = ugi.getShortUserName(); currentUser = UserGroupInformation.getCurrentUser().getShortUserName(); Path stagingDir = new Path(getStagingUri(context, queryId, meta)); //////////////////////////////////////////// // Create Output Directory //////////////////////////////////////////// if (fs.exists(stagingDir)) { throw new IOException("The staging directory '" + stagingDir + "' already exists"); } fs.mkdirs(stagingDir, new FsPermission(STAGING_DIR_PERMISSION)); FileStatus fsStatus = fs.getFileStatus(stagingDir); String owner = fsStatus.getOwner(); if (!owner.isEmpty() && !(owner.equals(currentUser) || owner.equals(realUser))) { throw new IOException("The ownership on the user's query " + "directory " + stagingDir + " is not as expected. " + "It is owned by " + owner + ". The directory must " + "be owned by the submitter " + currentUser + " or " + "by " + realUser); } if (!fsStatus.getPermission().equals(STAGING_DIR_PERMISSION)) { LOG.info("Permissions on staging directory " + stagingDir + " are " + "incorrect: " + fsStatus.getPermission() + ". Fixing permissions " + "to correct value " + STAGING_DIR_PERMISSION); fs.setPermission(stagingDir, new FsPermission(STAGING_DIR_PERMISSION)); } Path stagingResultDir = new Path(stagingDir, TajoConstants.RESULT_DIR_NAME); fs.mkdirs(stagingResultDir); return stagingDir.toUri(); }
From source file:org.apache.tez.client.TezClientUtils.java
License:Apache License
/** * Verify or create the Staging area directory on the configured Filesystem * @param stagingArea Staging area directory path * @return the FileSytem for the staging area directory * @throws IOException//from w ww .j a v a2s.c o m */ public static FileSystem ensureStagingDirExists(Configuration conf, Path stagingArea) throws IOException { FileSystem fs = stagingArea.getFileSystem(conf); String realUser; String currentUser; UserGroupInformation ugi = UserGroupInformation.getLoginUser(); realUser = ugi.getShortUserName(); currentUser = UserGroupInformation.getCurrentUser().getShortUserName(); if (fs.exists(stagingArea)) { FileStatus fsStatus = fs.getFileStatus(stagingArea); String owner = fsStatus.getOwner(); if (!(owner.equals(currentUser) || owner.equals(realUser))) { throw new IOException("The ownership on the staging directory " + stagingArea + " is not as expected. " + "It is owned by " + owner + ". The directory must " + "be owned by the submitter " + currentUser + " or " + "by " + realUser); } if (!fsStatus.getPermission().equals(TezCommonUtils.TEZ_AM_DIR_PERMISSION)) { LOG.info("Permissions on staging directory " + stagingArea + " are " + "incorrect: " + fsStatus.getPermission() + ". Fixing permissions " + "to correct value " + TezCommonUtils.TEZ_AM_DIR_PERMISSION); fs.setPermission(stagingArea, TezCommonUtils.TEZ_AM_DIR_PERMISSION); } } else { TezCommonUtils.mkDirForAM(fs, stagingArea); } return fs; }
From source file:org.apache.tinkerpop.gremlin.hadoop.structure.io.FileSystemStorage.java
License:Apache License
private static String fileStatusString(final FileStatus status) { StringBuilder s = new StringBuilder(); s.append(status.getPermission()).append(" "); s.append(status.getOwner()).append(SPACE); s.append(status.getGroup()).append(SPACE); s.append(status.getLen()).append(SPACE); if (status.isDirectory()) s.append(D_SPACE);//from ww w. java 2 s.co m s.append(status.getPath().getName()); return s.toString(); }
From source file:org.araqne.storage.hdfs.HDFSFilePath.java
License:Apache License
@Override public boolean canRead() throws SecurityException { String username = System.getProperty("user.name"); FileStatus fs; try {/*from w ww. ja v a 2s.c om*/ fs = root.getFileSystem().getFileStatus(path); } catch (IOException e) { throw new IllegalStateException("Unexpected IOException", e); } FsPermission permission = fs.getPermission(); // TODO handle user group FsAction action = (username.equals(fs.getOwner())) ? permission.getUserAction() : permission.getOtherAction(); return action.and(FsAction.READ).equals(FsAction.READ); }
From source file:org.araqne.storage.hdfs.HDFSFilePath.java
License:Apache License
@Override public boolean canWrite() throws SecurityException { String username = System.getProperty("user.name"); FileStatus fs; try {/*from w ww .ja v a2 s .com*/ fs = root.getFileSystem().getFileStatus(path); } catch (IOException e) { throw new IllegalStateException("Unexpected IOException", e); } FsPermission permission = fs.getPermission(); // TODO handle user group FsAction action = (username.equals(fs.getOwner())) ? permission.getUserAction() : permission.getOtherAction(); return action.and(FsAction.WRITE).equals(FsAction.WRITE); }
From source file:org.elasticsearch.hadoop.mr.NTFSLocalFileSystem.java
License:Apache License
@Override public FileStatus getFileStatus(Path f) throws IOException { // it's the RawFS in place which messes things up as it dynamically returns the permissions... // workaround by doing a copy FileStatus fs = super.getFileStatus(f); // work-around for Hive 0.14 if (SCRATCH_DIR.equals(f.toString())) { System.out.println("Faking scratch dir permissions on Windows..."); return new FileStatus(fs.getLen(), fs.isDir(), fs.getReplication(), fs.getBlockSize(), fs.getModificationTime(), fs.getAccessTime(), SCRATCH_DIR_PERMS, fs.getOwner(), fs.getGroup(), fs.getPath());/*from w ww. j av a 2 s. c o m*/ // this doesn't work since the RawFS impl has its own algo that does the lookup dynamically //fs.getPermission().fromShort((short) 777); } return fs; }
From source file:org.exem.flamingo.agent.nn.hdfs.HdfsFileInfo.java
License:Apache License
public HdfsFileInfo(FileStatus fileStatus, ContentSummary contentSummary) { this.fullyQualifiedPath = fileStatus.getPath().toUri().getPath(); this.filename = isEmpty(getFilename(fullyQualifiedPath)) ? getDirectoryName(fullyQualifiedPath) : getFilename(fullyQualifiedPath); this.length = fileStatus.isFile() ? fileStatus.getLen() : contentSummary.getLength(); this.path = getPath(fullyQualifiedPath); this.directory = fileStatus.isDirectory(); this.file = !fileStatus.isDirectory(); this.owner = fileStatus.getOwner(); this.group = fileStatus.getGroup(); this.blockSize = fileStatus.getBlockSize(); this.replication = fileStatus.getReplication(); this.modificationTime = fileStatus.getModificationTime(); if (contentSummary != null) { this.spaceConsumed = contentSummary.getSpaceConsumed(); this.spaceQuota = contentSummary.getSpaceQuota(); this.quota = contentSummary.getQuota(); this.directoryCount = contentSummary.getDirectoryCount(); this.fileCount = contentSummary.getFileCount(); }/*w w w . j a v a 2 s .c om*/ this.accessTime = fileStatus.getAccessTime(); this.permission = fileStatus.getPermission().toString(); }
From source file:org.exem.flamingo.agent.nn.hdfs.HdfsFileOnlyInfo.java
License:Apache License
public HdfsFileOnlyInfo(FileStatus fileStatus, ContentSummary contentSummary) { String qualifiedPath = fileStatus.getPath().toUri().getPath(); this.filename = isEmpty(getFilename(qualifiedPath)) ? getDirectoryName(qualifiedPath) : getFilename(qualifiedPath); this.length = fileStatus.getLen(); this.path = getPath(qualifiedPath); this.directory = fileStatus.isDirectory(); this.modificationTime = fileStatus.getModificationTime(); this.file = !fileStatus.isDirectory(); this.replication = fileStatus.getReplication(); this.owner = fileStatus.getOwner(); this.group = fileStatus.getGroup(); this.permission = fileStatus.getPermission().toString(); if (contentSummary != null) { this.spaceConsumed = contentSummary.getSpaceConsumed(); this.spaceQuota = contentSummary.getSpaceQuota(); }//ww w . j a v a2 s .c o m }