|
@@ -28,10 +28,8 @@ import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.FileUtil;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
-import org.apache.hadoop.mapred.TaskController;
|
|
|
-import org.apache.hadoop.mapred.TaskLog;
|
|
|
+import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.mapred.TaskTracker;
|
|
|
-import org.apache.hadoop.mapreduce.JobID;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -97,51 +95,6 @@ public class Localizer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set permission on the given file path using the specified permissions
|
|
|
- * information. We use java api to set permission instead of spawning chmod
|
|
|
- * processes. This saves a lot of time. Using this, one can set all possible
|
|
|
- * combinations of permissions for the owner of the file. But permissions
|
|
|
- * for the group and all others can only be set together, i.e. permissions
|
|
|
- * for group cannot be set different from those for others and vice versa.
|
|
|
- *
|
|
|
- * This method should satisfy the needs of most of the applications. For
|
|
|
- * those it doesn't, {@link FileUtil#chmod} can be used.
|
|
|
- *
|
|
|
- * @param f file path
|
|
|
- * @param pInfo permissions information
|
|
|
- * @return true if success, false otherwise
|
|
|
- */
|
|
|
- public static boolean setPermissions(File f, PermissionsInfo pInfo) {
|
|
|
- if (pInfo == null) {
|
|
|
- LOG.debug(" PermissionsInfo is null, returning.");
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- LOG.debug("Setting permission for " + f.getAbsolutePath());
|
|
|
-
|
|
|
- boolean ret = true;
|
|
|
-
|
|
|
- // Clear all the flags
|
|
|
- ret = f.setReadable(false, false) && ret;
|
|
|
- ret = f.setWritable(false, false) && ret;
|
|
|
- ret = f.setExecutable(false, false) && ret;
|
|
|
-
|
|
|
- ret = f.setReadable(pInfo.readPermissions, pInfo.readPermsOwnerOnly);
|
|
|
- LOG.debug("Readable status for " + f + " set to " + ret);
|
|
|
- ret =
|
|
|
- f.setWritable(pInfo.writePermissions, pInfo.writePermsOwnerOnly)
|
|
|
- && ret;
|
|
|
- LOG.debug("Writable status for " + f + " set to " + ret);
|
|
|
- ret =
|
|
|
- f.setExecutable(pInfo.executablePermissions,
|
|
|
- pInfo.executePermsOwnerOnly)
|
|
|
- && ret;
|
|
|
-
|
|
|
- LOG.debug("Executable status for " + f + " set to " + ret);
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Permissions rwxr_xr_x
|
|
|
*/
|
|
@@ -210,9 +163,8 @@ public class Localizer {
|
|
|
if (fs.exists(userDir) || fs.mkdirs(userDir)) {
|
|
|
|
|
|
// Set permissions on the user-directory
|
|
|
- PermissionsHandler.setPermissions(
|
|
|
- new File(userDir.toUri().getPath()),
|
|
|
- PermissionsHandler.sevenZeroZero);
|
|
|
+ FsPermission userOnly = new FsPermission((short) 0700);
|
|
|
+ FileUtil.setPermission(new File(userDir.toUri().getPath()), userOnly);
|
|
|
userDirStatus = true;
|
|
|
|
|
|
// Set up the jobcache directory
|
|
@@ -220,8 +172,7 @@ public class Localizer {
|
|
|
new File(localDir, TaskTracker.getJobCacheSubdir(user));
|
|
|
if (jobCacheDir.exists() || jobCacheDir.mkdirs()) {
|
|
|
// Set permissions on the jobcache-directory
|
|
|
- PermissionsHandler.setPermissions(jobCacheDir,
|
|
|
- PermissionsHandler.sevenZeroZero);
|
|
|
+ FileUtil.setPermission(jobCacheDir, userOnly);
|
|
|
jobCacheDirStatus = true;
|
|
|
} else {
|
|
|
LOG.warn("Unable to create job cache directory : "
|
|
@@ -233,8 +184,7 @@ public class Localizer {
|
|
|
new File(localDir, TaskTracker.getPrivateDistributedCacheDir(user));
|
|
|
if (distributedCacheDir.exists() || distributedCacheDir.mkdirs()) {
|
|
|
// Set permissions on the distcache-directory
|
|
|
- PermissionsHandler.setPermissions(distributedCacheDir,
|
|
|
- PermissionsHandler.sevenZeroZero);
|
|
|
+ FileUtil.setPermission(distributedCacheDir, userOnly);
|
|
|
distributedCacheDirStatus = true;
|
|
|
} else {
|
|
|
LOG.warn("Unable to create distributed-cache directory : "
|
|
@@ -265,52 +215,6 @@ public class Localizer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Prepare the job directories for a given job. To be called by the job
|
|
|
- * localization code, only if the job is not already localized.
|
|
|
- *
|
|
|
- * <br>
|
|
|
- * Here, we set 700 permissions on the job directories created on all disks.
|
|
|
- * This we do so as to avoid any misuse by other users till the time
|
|
|
- * {@link TaskController#initializeJob} is run at a
|
|
|
- * later time to set proper private permissions on the job directories. <br>
|
|
|
- *
|
|
|
- * @param user
|
|
|
- * @param jobId
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public void initializeJobDirs(String user, JobID jobId)
|
|
|
- throws IOException {
|
|
|
- boolean initJobDirStatus = false;
|
|
|
- String jobDirPath = TaskTracker.getLocalJobDir(user, jobId.toString());
|
|
|
- for (String localDir : localDirs) {
|
|
|
- Path jobDir = new Path(localDir, jobDirPath);
|
|
|
- if (fs.exists(jobDir)) {
|
|
|
- // this will happen on a partial execution of localizeJob. Sometimes
|
|
|
- // copying job.xml to the local disk succeeds but copying job.jar might
|
|
|
- // throw out an exception. We should clean up and then try again.
|
|
|
- fs.delete(jobDir, true);
|
|
|
- }
|
|
|
-
|
|
|
- boolean jobDirStatus = fs.mkdirs(jobDir);
|
|
|
- if (!jobDirStatus) {
|
|
|
- LOG.warn("Not able to create job directory " + jobDir.toString());
|
|
|
- }
|
|
|
-
|
|
|
- initJobDirStatus = initJobDirStatus || jobDirStatus;
|
|
|
-
|
|
|
- // job-dir has to be private to the TT
|
|
|
- Localizer.PermissionsHandler.setPermissions(new File(jobDir.toUri()
|
|
|
- .getPath()), Localizer.PermissionsHandler.sevenZeroZero);
|
|
|
- }
|
|
|
-
|
|
|
- if (!initJobDirStatus) {
|
|
|
- throw new IOException("Not able to initialize job directories "
|
|
|
- + "in any of the configured local directories for job "
|
|
|
- + jobId.toString());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Create taskDirs on all the disks. Otherwise, in some cases, like when
|
|
|
* LinuxTaskController is in use, child might wish to balance load across
|
|
@@ -347,22 +251,4 @@ public class Localizer {
|
|
|
+ attemptId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Create job log directory and set appropriate permissions for the directory.
|
|
|
- *
|
|
|
- * @param jobId
|
|
|
- */
|
|
|
- public void initializeJobLogDir(JobID jobId) {
|
|
|
- File jobUserLogDir = TaskLog.getJobDir(jobId);
|
|
|
- if (!jobUserLogDir.exists()) {
|
|
|
- boolean ret = jobUserLogDir.mkdirs();
|
|
|
- if (!ret) {
|
|
|
- LOG.warn("Could not create job user log directory: " + jobUserLogDir);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- Localizer.PermissionsHandler.setPermissions(jobUserLogDir,
|
|
|
- Localizer.PermissionsHandler.sevenZeroZero);
|
|
|
- }
|
|
|
}
|