From 5e013d50d1a98d37accf8c6b07b14254ad4f3639 Mon Sep 17 00:00:00 2001 From: fang zhenyi Date: Thu, 15 Mar 2018 16:11:53 +0900 Subject: [PATCH] HADOOP-15305. Replace FileUtils.writeStringToFile(File, String) with (File, String, Charset) to fix deprecation warnings. Signed-off-by: Akira Ajisaka --- .../server/TestHttpFSServerWebServer.java | 4 ++-- .../datamodel/DiskBalancerCluster.java | 3 ++- .../azure/TestShellDecryptionKeyProvider.java | 4 +++- .../PublishedConfigurationOutputter.java | 3 ++- .../yarn/util/DockerClientConfigHandler.java | 3 ++- .../yarn/util/TestProcfsBasedProcessTree.java | 4 +++- .../TestCGroupsResourceCalculator.java | 21 ++++++++++--------- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServerWebServer.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServerWebServer.java index a05876620e..5250543b71 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServerWebServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServerWebServer.java @@ -22,7 +22,7 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import org.apache.commons.io.FileUtils; @@ -61,7 +61,7 @@ public static void beforeClass() throws Exception { System.setProperty("httpfs.log.dir", logsDir.getAbsolutePath()); System.setProperty("httpfs.config.dir", confDir.getAbsolutePath()); FileUtils.writeStringToFile(new File(confDir, "httpfs-signature.secret"), - "foo", Charset.forName("UTF-8")); + "foo", StandardCharsets.UTF_8); } @Before diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/datamodel/DiskBalancerCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/datamodel/DiskBalancerCluster.java index 2f54141cda..8de19aa28a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/datamodel/DiskBalancerCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/datamodel/DiskBalancerCluster.java @@ -34,6 +34,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -284,7 +285,7 @@ public void setOutput(String output) { public void createSnapshot(String snapShotName) throws IOException { String json = this.toJson(); File outFile = new File(getOutput() + "/" + snapShotName); - FileUtils.writeStringToFile(outFile, json); + FileUtils.writeStringToFile(outFile, json, StandardCharsets.UTF_8); } /** diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestShellDecryptionKeyProvider.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestShellDecryptionKeyProvider.java index 0334c39a5c..f863e66e45 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestShellDecryptionKeyProvider.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestShellDecryptionKeyProvider.java @@ -21,6 +21,7 @@ import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows; import java.io.File; +import java.nio.charset.StandardCharsets; import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; @@ -65,7 +66,8 @@ public void testValidScript() throws Exception { // Create a simple script which echoes the given key plus the given // expected result (so that we validate both script input and output) File scriptFile = new File(TEST_ROOT_DIR, "testScript.cmd"); - FileUtils.writeStringToFile(scriptFile, "@echo %1 " + expectedResult); + FileUtils.writeStringToFile(scriptFile, "@echo %1 " + expectedResult, + StandardCharsets.UTF_8); ShellDecryptionKeyProvider provider = new ShellDecryptionKeyProvider(); Configuration conf = new Configuration(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/PublishedConfigurationOutputter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/PublishedConfigurationOutputter.java index 88ecf2c7f0..8bdc102892 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/PublishedConfigurationOutputter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/PublishedConfigurationOutputter.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.Properties; /** @@ -61,7 +62,7 @@ public void save(File dest) throws IOException { } */ public void save(File dest) throws IOException { - FileUtils.writeStringToFile(dest, asString(), Charsets.UTF_8); + FileUtils.writeStringToFile(dest, asString(), StandardCharsets.UTF_8); } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/DockerClientConfigHandler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/DockerClientConfigHandler.java index 98bdbddbd5..13c576b22b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/DockerClientConfigHandler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/DockerClientConfigHandler.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Iterator; /** @@ -178,6 +179,6 @@ public static void writeDockerCredentialsToPath(File outConfigFile, rootNode.put(CONFIG_AUTHS_KEY, registryUrlNode); String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode); - FileUtils.writeStringToFile(outConfigFile, json, Charset.defaultCharset()); + FileUtils.writeStringToFile(outConfigFile, json, StandardCharsets.UTF_8); } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestProcfsBasedProcessTree.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestProcfsBasedProcessTree.java index 215e5b089d..7349d22a1e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestProcfsBasedProcessTree.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestProcfsBasedProcessTree.java @@ -30,6 +30,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Random; import java.util.Vector; @@ -154,7 +155,8 @@ public void testProcessTree() throws Exception { + " $(($1-1))\n" + "else\n" + " echo $$ > " + lowestDescendant + "\n" + "(sleep 300&\n" + "echo $! > " + lostDescendant + ")\n" - + " while true\n do\n" + " sleep 5\n" + " done\n" + "fi"); + + " while true\n do\n" + " sleep 5\n" + " done\n" + "fi", + StandardCharsets.UTF_8); Thread t = new RogueTaskThread(); t.start(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsResourceCalculator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsResourceCalculator.java index a2ad11fc88..0158bc2503 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsResourceCalculator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsResourceCalculator.java @@ -26,6 +26,7 @@ import org.junit.Test; import java.io.File; +import java.nio.charset.StandardCharsets; import static org.mockito.Mockito.*; @@ -62,7 +63,7 @@ public void testNoMemoryCGgroupMount() throws Exception { new File(procfs, CGroupsResourceCalculator.CGROUP), "7:devices:/yarn/container_1\n" + "6:cpuacct,cpu:/yarn/container_1\n" + - "5:pids:/yarn/container_1\n"); + "5:pids:/yarn/container_1\n", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( "1234", basePath, @@ -84,7 +85,7 @@ public void testCGgroupNotFound() throws Exception { "7:devices:/yarn/container_1\n" + "6:cpuacct,cpu:/yarn/container_1\n" + "5:pids:/yarn/container_1\n" + - "4:memory:/yarn/container_1\n"); + "4:memory:/yarn/container_1\n", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( @@ -118,12 +119,12 @@ public void testCPUParsing() throws Exception { "7:devices:/yarn/container_1\n" + "6:cpuacct,cpu:/yarn/container_1\n" + "5:pids:/yarn/container_1\n" + - "4:memory:/yarn/container_1\n"); + "4:memory:/yarn/container_1\n", StandardCharsets.UTF_8); FileUtils.writeStringToFile( new File(cgcpuacctContainerDir, CGroupsResourceCalculator.CPU_STAT), "Can you handle this?\n" + "user 5415\n" + - "system 3632"); + "system 3632", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( "1234", basePath, @@ -159,10 +160,10 @@ public void testMemoryParsing() throws Exception { FileUtils.writeStringToFile( new File(procfs, CGroupsResourceCalculator.CGROUP), "6:cpuacct,cpu:/yarn/container_1\n" + - "4:memory:/yarn/container_1\n"); + "4:memory:/yarn/container_1\n", StandardCharsets.UTF_8); FileUtils.writeStringToFile( new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEM_STAT), - "418496512\n"); + "418496512\n", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( @@ -182,7 +183,7 @@ public void testMemoryParsing() throws Exception { // Test the case where memsw is available FileUtils.writeStringToFile( new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEMSW_STAT), - "418496513\n"); + "418496513\n", StandardCharsets.UTF_8); calculator.updateProcessTree(); Assert.assertEquals("Incorrect swap usage", 418496513, @@ -206,7 +207,7 @@ public void testCPUParsingRoot() throws Exception { FileUtils.writeStringToFile( new File(cgcpuacctRootDir, CGroupsResourceCalculator.CPU_STAT), "user 5415\n" + - "system 3632"); + "system 3632", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( null, basePath, @@ -241,7 +242,7 @@ public void testMemoryParsingRoot() throws Exception { try { FileUtils.writeStringToFile( new File(cgMemoryRootDir, CGroupsResourceCalculator.MEM_STAT), - "418496512\n"); + "418496512\n", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( @@ -262,7 +263,7 @@ public void testMemoryParsingRoot() throws Exception { // Test the case where memsw is available FileUtils.writeStringToFile( new File(cgMemoryRootDir, CGroupsResourceCalculator.MEMSW_STAT), - "418496513\n"); + "418496513\n", StandardCharsets.UTF_8); calculator.updateProcessTree(); Assert.assertEquals("Incorrect swap usage", 418496513,