Skip to content

Commit f83eafa

Browse files
author
Suresh Srinivas
committed
YARN-506. Move to common utils FileUtil#setReadable/Writable/Executable and FileUtil#canRead/Write/Execute. Contributed by Ivan Mitic.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1477408 13f79535-47bb-0310-9956-ffa450edef68
1 parent ff36a3a commit f83eafa

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Trunk - Unreleased
4141
classpath with new process's environment variables and localized resources
4242
(Chris Nauroth via bikas)
4343

44-
BREAKDOWN OF HADOOP-8562 SUBTASKS
44+
BREAKDOWN OF HADOOP-8562 SUBTASKS AND RELATED JIRAS
4545

4646
YARN-158. Yarn creating package-info.java must not depend on sh.
4747
(Chris Nauroth via suresh)
@@ -70,6 +70,10 @@ Trunk - Unreleased
7070

7171
YARN-359. Fixing commands for container signalling in Windows. (Chris Nauroth
7272
via vinodkv)
73+
74+
YARN-506. Move to common utils FileUtil#setReadable/Writable/Executable and
75+
FileUtil#canRead/Write/Execute. (Ivan Mitic via suresh)
76+
7377

7478
Release 2.0.5-beta - UNRELEASED
7579

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/NodeHealthScriptRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
3030
import org.apache.hadoop.conf.Configuration;
31+
import org.apache.hadoop.fs.FileUtil;
3132
import org.apache.hadoop.util.Shell.ExitCodeException;
3233
import org.apache.hadoop.util.Shell.ShellCommandExecutor;
3334
import org.apache.hadoop.util.StringUtils;
@@ -321,7 +322,7 @@ public static boolean shouldRun(Configuration conf) {
321322
return false;
322323
}
323324
File f = new File(nodeHealthScript);
324-
return f.exists() && f.canExecute();
325+
return f.exists() && FileUtil.canExecute(f);
325326
}
326327

327328
private synchronized void setHealthStatus(boolean isHealthy, String output) {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/CgroupsLCEResourcesHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.commons.logging.Log;
3636
import org.apache.commons.logging.LogFactory;
3737
import org.apache.hadoop.conf.Configuration;
38+
import org.apache.hadoop.fs.FileUtil;
3839
import org.apache.hadoop.yarn.api.records.ContainerId;
3940
import org.apache.hadoop.yarn.api.records.Resource;
4041
import org.apache.hadoop.yarn.conf.YarnConfiguration;
@@ -307,7 +308,7 @@ private void initializeControllerPaths() throws IOException {
307308
if (controllerPath != null) {
308309
File f = new File(controllerPath + "/" + this.cgroupPrefix);
309310

310-
if (f.canWrite()) {
311+
if (FileUtil.canWrite(f)) {
311312
controllerPaths.put(CONTROLLER_CPU, controllerPath);
312313
} else {
313314
throw new IOException("Not able to enforce cpu weights; cannot write "

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.conf.Configuration;
3737
import org.apache.hadoop.fs.FileContext;
3838
import org.apache.hadoop.fs.FileStatus;
39+
import org.apache.hadoop.fs.FileUtil;
3940
import org.apache.hadoop.fs.Path;
4041
import org.apache.hadoop.fs.permission.FsPermission;
4142
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -104,9 +105,7 @@ public void setup() throws Exception {
104105
FileContext files = FileContext.getLocalFSFileContext();
105106
Path workSpacePath = new Path(workSpace.getAbsolutePath());
106107
files.mkdir(workSpacePath, null, true);
107-
workSpace.setReadable(true, false);
108-
workSpace.setExecutable(true, false);
109-
workSpace.setWritable(true, false);
108+
FileUtil.chmod(workSpace.getAbsolutePath(), "777");
110109
File localDir = new File(workSpace.getAbsoluteFile(), "localDir");
111110
files.mkdir(new Path(localDir.getAbsolutePath()),
112111
new FsPermission("777"), false);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.logging.Log;
3838
import org.apache.commons.logging.LogFactory;
3939
import org.apache.hadoop.conf.Configuration;
40+
import org.apache.hadoop.fs.FileUtil;
4041
import org.apache.hadoop.fs.Path;
4142
import org.apache.hadoop.util.StringUtils;
4243
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -78,8 +79,8 @@ private List<String> readMockParams() throws IOException {
7879
@Before
7980
public void setup() {
8081
File f = new File("./src/test/resources/mock-container-executor");
81-
if(!f.canExecute()) {
82-
f.setExecutable(true);
82+
if(!FileUtil.canExecute(f)) {
83+
FileUtil.setExecutable(f, true);
8384
}
8485
String executorPath = f.getAbsolutePath();
8586
Configuration conf = new Configuration();
@@ -140,8 +141,8 @@ public void testContainerLaunchWithPriority() throws IOException {
140141

141142
// set the scheduler priority to make sure still works with nice -n prio
142143
File f = new File("./src/test/resources/mock-container-executor");
143-
if (!f.canExecute()) {
144-
f.setExecutable(true);
144+
if (!FileUtil.canExecute(f)) {
145+
FileUtil.setExecutable(f, true);
145146
}
146147
String executorPath = f.getAbsolutePath();
147148
Configuration conf = new Configuration();
@@ -204,8 +205,8 @@ public void testContainerLaunchError() throws IOException {
204205

205206
// reinitialize executer
206207
File f = new File("./src/test/resources/mock-container-executer-with-error");
207-
if (!f.canExecute()) {
208-
f.setExecutable(true);
208+
if (!FileUtil.canExecute(f)) {
209+
FileUtil.setExecutable(f, true);
209210
}
210211
String executorPath = f.getAbsolutePath();
211212
Configuration conf = new Configuration();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeHealthService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.commons.logging.LogFactory;
2929
import org.apache.hadoop.conf.Configuration;
3030
import org.apache.hadoop.fs.FileContext;
31+
import org.apache.hadoop.fs.FileUtil;
3132
import org.apache.hadoop.fs.Path;
3233
import org.apache.hadoop.yarn.api.records.NodeHealthStatus;
3334
import org.apache.hadoop.yarn.conf.YarnConfiguration;
@@ -81,7 +82,7 @@ private void writeNodeHealthScriptFile(String scriptStr, boolean setExecutable)
8182
pw.println(scriptStr);
8283
pw.flush();
8384
pw.close();
84-
nodeHealthscriptFile.setExecutable(setExecutable);
85+
FileUtil.setExecutable(nodeHealthscriptFile, setExecutable);
8586
}
8687

8788
@Test

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535
import java.util.Map;
3636

37+
import org.apache.hadoop.fs.FileUtil;
3738
import org.apache.hadoop.fs.Path;
3839
import org.apache.hadoop.fs.UnsupportedFileSystemException;
3940
import org.apache.hadoop.util.Shell;
@@ -99,7 +100,7 @@ public void testSpecialCharSymlinks() throws IOException {
99100
String timeoutCommand = Shell.WINDOWS ? "@echo \"hello\"" :
100101
"echo \"hello\"";
101102
PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
102-
shellFile.setExecutable(true);
103+
FileUtil.setExecutable(shellFile, true);
103104
writer.println(timeoutCommand);
104105
writer.close();
105106

@@ -123,7 +124,7 @@ public void testSpecialCharSymlinks() throws IOException {
123124
ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
124125
fos.flush();
125126
fos.close();
126-
tempFile.setExecutable(true);
127+
FileUtil.setExecutable(tempFile, true);
127128

128129
Shell.ShellCommandExecutor shexc
129130
= new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir);
@@ -367,7 +368,7 @@ public void testDelayedKill() throws Exception {
367368
writer.println("while true; do\nsleep 1s;\ndone");
368369
}
369370
writer.close();
370-
scriptFile.setExecutable(true);
371+
FileUtil.setExecutable(scriptFile, true);
371372

372373
ContainerLaunchContext containerLaunchContext =
373374
recordFactory.newRecordInstance(ContainerLaunchContext.class);

0 commit comments

Comments
 (0)