Skip to content

Commit 670205c

Browse files
jojochuangaajisaka
authored andcommitted
HADOOP-17653. Do not use guava's Files.createTempDir(). (#2945)
Reviewed-by: Steve Loughran <stevel@apache.org> Signed-off-by: Akira Ajisaka <aajisaka@apache.org> (cherry picked from commit f1e1809)
1 parent 9aa6106 commit 670205c

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreFileImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,18 @@ protected String getRootDir() {
8888
if (this.rootDirectory == null) {
8989
String dir = getConf().get(FEDERATION_STORE_FILE_DIRECTORY);
9090
if (dir == null) {
91-
File tempDir = Files.createTempDir();
91+
File tempDirBase =
92+
new File(System.getProperty("java.io.tmpdir"));
93+
File tempDir = null;
94+
try {
95+
tempDir = java.nio.file.Files.createTempDirectory(
96+
tempDirBase.toPath(), System.currentTimeMillis() + "-").toFile();
97+
} catch (IOException e) {
98+
// fallback to the base upon exception.
99+
LOG.debug("Unable to create a temporary directory. Fall back to " +
100+
" the default system temp directory {}", tempDirBase, e);
101+
tempDir = tempDirBase;
102+
}
92103
dir = tempDir.getAbsolutePath();
93104
LOG.warn("The root directory is not available, using {}", dir);
94105
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestInMemoryLevelDBAliasMapClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.apache.hadoop.hdfs.server.common.blockaliasmap.impl;
1818

19-
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
20-
import org.apache.hadoop.thirdparty.com.google.common.io.Files;
2119
import org.apache.commons.io.FileUtils;
2220
import org.apache.hadoop.conf.Configuration;
2321
import org.apache.hadoop.fs.Path;
@@ -28,7 +26,9 @@
2826
import org.apache.hadoop.hdfs.server.aliasmap.InMemoryLevelDBAliasMapServer;
2927
import org.apache.hadoop.hdfs.server.common.blockaliasmap.BlockAliasMap;
3028
import org.apache.hadoop.hdfs.server.common.FileRegion;
29+
import org.apache.hadoop.test.GenericTestUtils;
3130
import org.apache.hadoop.test.LambdaTestUtils;
31+
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
3232
import org.junit.After;
3333
import org.junit.Before;
3434
import org.junit.Rule;
@@ -44,6 +44,7 @@
4444

4545
import java.io.File;
4646
import java.io.IOException;
47+
import java.nio.file.Files;
4748
import java.util.List;
4849
import java.util.Optional;
4950
import java.util.Random;
@@ -74,7 +75,9 @@ public void setUp() throws IOException {
7475

7576
conf.set(DFSConfigKeys.DFS_PROVIDED_ALIASMAP_INMEMORY_RPC_ADDRESS,
7677
"localhost:" + port);
77-
tempDir = Files.createTempDir();
78+
File testDir = GenericTestUtils.getTestDir();
79+
tempDir = Files
80+
.createTempDirectory(testDir.toPath(), "test").toFile();
7881
File levelDBDir = new File(tempDir, BPID);
7982
levelDBDir.mkdirs();
8083
conf.set(DFSConfigKeys.DFS_PROVIDED_ALIASMAP_INMEMORY_LEVELDB_DIR,

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/TestLevelDbMockAliasMapClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.hadoop.hdfs.server.common.blockaliasmap.impl;
1818

19-
import org.apache.hadoop.thirdparty.com.google.common.io.Files;
2019
import org.apache.commons.io.FileUtils;
2120
import org.apache.hadoop.conf.Configuration;
2221
import org.apache.hadoop.fs.Path;
@@ -26,12 +25,14 @@
2625
import org.apache.hadoop.hdfs.server.aliasmap.InMemoryAliasMap;
2726
import org.apache.hadoop.hdfs.server.aliasmap.InMemoryLevelDBAliasMapServer;
2827
import org.apache.hadoop.hdfs.server.common.FileRegion;
28+
import org.apache.hadoop.test.GenericTestUtils;
2929
import org.iq80.leveldb.DBException;
3030
import org.junit.After;
3131
import org.junit.Before;
3232
import org.junit.Test;
3333
import java.io.File;
3434
import java.io.IOException;
35+
import java.nio.file.Files;
3536

3637
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
3738
import static org.mockito.Mockito.doThrow;
@@ -60,7 +61,9 @@ public void setUp() throws IOException {
6061

6162
conf.set(DFSConfigKeys.DFS_PROVIDED_ALIASMAP_INMEMORY_RPC_ADDRESS,
6263
"localhost:" + port);
63-
tempDir = Files.createTempDir();
64+
File testDir = GenericTestUtils.getTestDir();
65+
tempDir = Files
66+
.createTempDirectory(testDir.toPath(), "test").toFile();
6467
conf.set(DFSConfigKeys.DFS_PROVIDED_ALIASMAP_INMEMORY_LEVELDB_DIR,
6568
tempDir.getAbsolutePath());
6669
levelDBAliasMapServer.setConf(conf);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.curator.framework.CuratorFramework;
2828
import org.apache.curator.framework.CuratorFrameworkFactory;
2929
import org.apache.curator.retry.RetryNTimes;
30-
import org.apache.curator.shaded.com.google.common.io.Files;
3130
import org.apache.hadoop.classification.InterfaceAudience;
3231
import org.apache.hadoop.classification.InterfaceStability;
3332
import org.apache.hadoop.conf.Configuration;
@@ -117,6 +116,7 @@
117116
import java.net.URISyntaxException;
118117
import java.nio.ByteBuffer;
119118
import java.nio.charset.StandardCharsets;
119+
import java.nio.file.Files;
120120
import java.text.MessageFormat;
121121
import java.util.*;
122122
import java.util.concurrent.ConcurrentHashMap;
@@ -1140,7 +1140,10 @@ private void addYarnSysFs(Path path,
11401140
return;
11411141
}
11421142
String buffer = ServiceApiUtil.jsonSerDeser.toJson(app);
1143-
File tmpDir = Files.createTempDir();
1143+
File testDir =
1144+
new File(System.getProperty("java.io.tmpdir"));
1145+
File tmpDir = Files.createTempDirectory(
1146+
testDir.toPath(), System.currentTimeMillis() + "-").toFile();
11441147
if (tmpDir.exists()) {
11451148
String serviceJsonPath = tmpDir.getAbsolutePath() + "/app.json";
11461149
File localFile = new File(serviceJsonPath);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-csi/src/test/java/org/apache/hadoop/yarn/csi/client/TestCsiClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import csi.v0.Csi;
2222
import org.apache.commons.io.FileUtils;
23-
import org.apache.hadoop.thirdparty.com.google.common.io.Files;
23+
import org.apache.hadoop.test.GenericTestUtils;
2424
import org.junit.AfterClass;
2525
import org.junit.Assert;
2626
import org.junit.Assume;
@@ -30,6 +30,7 @@
3030

3131
import java.io.File;
3232
import java.io.IOException;
33+
import java.nio.file.Files;
3334

3435
/**
3536
* Test class for CSI client.
@@ -42,7 +43,9 @@ public class TestCsiClient {
4243

4344
@BeforeClass
4445
public static void setUp() throws IOException {
45-
testRoot = Files.createTempDir();
46+
File testDir = GenericTestUtils.getTestDir();
47+
testRoot = Files
48+
.createTempDirectory(testDir.toPath(), "test").toFile();
4649
File socketPath = new File(testRoot, "csi.sock");
4750
FileUtils.forceMkdirParent(socketPath);
4851
domainSocket = "unix://" + socketPath.getAbsolutePath();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/com/nec/TestNECVEPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
import org.apache.commons.compress.utils.Sets;
4848
import org.apache.commons.io.FileUtils;
49-
import org.apache.curator.shaded.com.google.common.collect.Lists;
49+
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
5050
import org.apache.hadoop.util.Shell.CommandExecutor;
5151
import org.apache.hadoop.yarn.server.nodemanager.api.deviceplugin.Device;
5252
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.ResourceHandlerException;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/TestIntelFpgaOpenclPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25-
import org.apache.curator.shaded.com.google.common.collect.Lists;
25+
import org.apache.hadoop.thirdparty.com.google.common.collect.Lists;
2626
import org.apache.hadoop.fs.Path;
2727
import org.junit.Before;
2828
import org.junit.Test;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/TestDominantResourceFairnessPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.Map;
3030
import java.util.TreeSet;
3131

32-
import org.apache.curator.shaded.com.google.common.base.Joiner;
32+
import org.apache.hadoop.thirdparty.com.google.common.base.Joiner;
3333
import org.apache.hadoop.conf.Configuration;
3434
import org.apache.hadoop.yarn.api.records.Resource;
3535
import org.apache.hadoop.yarn.api.records.ResourceInformation;

0 commit comments

Comments
 (0)