From 21a3fc3d2d773d000724dfccf8c7666fbfdefc8a Mon Sep 17 00:00:00 2001 From: belugabehr <12578579+belugabehr@users.noreply.github.com> Date: Mon, 1 Feb 2021 12:40:01 -0500 Subject: [PATCH] HADOOP-17482: Remove Commons Logger from FileSystem Class (#2633) --- .../apache/hadoop/fs/DelegationTokenRenewer.java | 6 ++---- .../main/java/org/apache/hadoop/fs/FileSystem.java | 14 ++------------ .../org/apache/hadoop/fs/RawLocalFileSystem.java | 2 +- .../org/apache/hadoop/fs/viewfs/InodeTree.java | 7 +++---- .../apache/hadoop/fs/viewfs/ViewFileSystem.java | 13 ++++--------- .../org/apache/hadoop/fs/TestFilterFileSystem.java | 4 ++-- .../java/org/apache/hadoop/fs/TestFilterFs.java | 4 ++-- .../org/apache/hadoop/fs/TestFcHdfsSetUMask.java | 13 ------------- .../org/apache/hadoop/hdfs/TestListFilesInDFS.java | 7 ------- .../hadoop/hdfs/TestListFilesInFileContext.java | 6 ------ .../WindowsSecureContainerExecutor.java | 2 +- 11 files changed, 17 insertions(+), 61 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java index 193c52c60d..19c29cfa3d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java @@ -223,7 +223,7 @@ public RenewAction addRenewAction(final T if (action.token != null) { queue.add(action); } else { - fs.LOG.error("does not have a token for renewal"); + FileSystem.LOG.error("does not have a token for renewal"); } return action; } @@ -247,7 +247,6 @@ public void removeRenewAction( } } - @SuppressWarnings("static-access") @Override public void run() { for(;;) { @@ -260,8 +259,7 @@ public void run() { } catch (InterruptedException ie) { return; } catch (Exception ie) { - action.weakFs.get().LOG.warn("Failed to renew token, action=" + action, - ie); + FileSystem.LOG.warn("Failed to renew token, action=" + action, ie); } } } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index 6cb0109da2..c6cf941cee 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -48,8 +48,6 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicLong; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; @@ -183,7 +181,7 @@ public abstract class FileSystem extends Configured * so must be considered something to only be changed with care. */ @InterfaceAudience.Private - public static final Log LOG = LogFactory.getLog(FileSystem.class); + public static final Logger LOG = LoggerFactory.getLogger(FileSystem.class); /** * The SLF4J logger to use in logging within the FileSystem class itself. @@ -3391,15 +3389,7 @@ private static void loadFileSystems() { LOGGER.info("Full exception loading: {}", fs, e); } } catch (ServiceConfigurationError ee) { - LOG.warn("Cannot load filesystem: " + ee); - Throwable cause = ee.getCause(); - // print all the nested exception messages - while (cause != null) { - LOG.warn(cause.toString()); - cause = cause.getCause(); - } - // and at debug: the full stack - LOG.debug("Stack Trace", ee); + LOGGER.warn("Cannot load filesystem", ee); } } FILE_SYSTEMS_LOADED = true; diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java index 2aeb17b90c..44802536e3 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java @@ -318,7 +318,7 @@ private LocalFSFileOutputStream(Path f, boolean append, success = true; } finally { if (!success) { - IOUtils.cleanup(LOG, this.fos); + IOUtils.cleanupWithLogger(LOG, this.fos); } } } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/InodeTree.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/InodeTree.java index fd7b5619b2..79c323aa35 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/InodeTree.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/InodeTree.java @@ -630,10 +630,9 @@ protected InodeTree(final Configuration config, final String viewName, .append(theUri.getScheme()).append("://").append(mountTableName) .append("/").toString()); } - StringBuilder msg = - new StringBuilder("Empty mount table detected for ").append(theUri) - .append(" and considering itself as a linkFallback."); - FileSystem.LOG.info(msg.toString()); + FileSystem.LOG + .info("Empty mount table detected for {} and considering itself " + + "as a linkFallback.", theUri); rootFallbackLink = new INodeLink(mountTableName, ugi, getTargetFileSystem(theUri), theUri); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java index 473b51489a..708d361c28 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java @@ -1289,10 +1289,8 @@ public FSDataOutputStream create(final Path f, .create(fileToCreate, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IOException e) { - StringBuilder msg = - new StringBuilder("Failed to create file:").append(fileToCreate) - .append(" at fallback : ").append(linkedFallbackFs.getUri()); - LOG.error(msg.toString(), e); + LOG.error("Failed to create file: {} at fallback: {}", fileToCreate, + linkedFallbackFs.getUri(), e); throw e; } } @@ -1523,11 +1521,8 @@ public boolean mkdirs(Path dir, FsPermission permission) return linkedFallbackFs.mkdirs(dirToCreate, permission); } catch (IOException e) { if (LOG.isDebugEnabled()) { - StringBuilder msg = - new StringBuilder("Failed to create ").append(dirToCreate) - .append(" at fallback : ") - .append(linkedFallbackFs.getUri()); - LOG.debug(msg.toString(), e); + LOG.debug("Failed to create: {} at fallback: {}", dirToCreate, + linkedFallbackFs.getUri(), e); } throw e; } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java index 6cd450610b..5ed4d9bc9a 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java @@ -28,7 +28,6 @@ import java.util.EnumSet; import java.util.Iterator; -import org.apache.commons.logging.Log; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.Options.CreateOpts; @@ -39,10 +38,11 @@ import org.apache.hadoop.util.Progressable; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; public class TestFilterFileSystem { - private static final Log LOG = FileSystem.LOG; + private static final Logger LOG = FileSystem.LOG; private static final Configuration conf = new Configuration(); @BeforeClass diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java index 5ed743f4c3..396924810d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFs.java @@ -23,14 +23,14 @@ import java.net.URI; import java.util.Iterator; -import org.apache.commons.logging.Log; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.viewfs.ConfigUtil; import org.junit.Test; +import org.slf4j.Logger; public class TestFilterFs { - private static final Log LOG = FileSystem.LOG; + private static final Logger LOG = FileSystem.LOG; public static class DontCheck { public void checkScheme(URI uri, String supportedScheme) { } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsSetUMask.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsSetUMask.java index 09163472ca..eef2235677 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsSetUMask.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsSetUMask.java @@ -29,10 +29,7 @@ import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hadoop.test.GenericTestUtils; -import org.apache.hadoop.util.StringUtils; import static org.apache.hadoop.fs.FileContextTestHelper.*; -import org.apache.log4j.Level; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; @@ -100,16 +97,6 @@ public static void ClusterShutdownAtEnd() throws Exception { cluster.shutdown(); } } - - { - try { - GenericTestUtils.setLogLevel(FileSystem.LOG, Level.DEBUG); - } - catch(Exception e) { - System.out.println("Cannot change log level\n" - + StringUtils.stringifyException(e)); - } - } @Before public void setUp() throws Exception { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInDFS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInDFS.java index 53b21d0b51..7bb624e166 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInDFS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInDFS.java @@ -17,11 +17,8 @@ */ package org.apache.hadoop.hdfs; -import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.TestListFiles; -import org.apache.hadoop.test.GenericTestUtils; -import org.apache.log4j.Level; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -29,10 +26,6 @@ * This class tests the FileStatus API. */ public class TestListFilesInDFS extends TestListFiles { - { - GenericTestUtils.setLogLevel(FileSystem.LOG, Level.ALL); - } - private static MiniDFSCluster cluster; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInFileContext.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInFileContext.java index 1e424177e9..2f73a39f7f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInFileContext.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestListFilesInFileContext.java @@ -29,14 +29,11 @@ import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileContext; -import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.LocatedFileStatus; import org.apache.hadoop.fs.Options; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.permission.FsPermission; -import org.apache.hadoop.test.GenericTestUtils; -import org.apache.log4j.Level; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -46,9 +43,6 @@ * This class tests the FileStatus API. */ public class TestListFilesInFileContext { - { - GenericTestUtils.setLogLevel(FileSystem.LOG, Level.ALL); - } static final long seed = 0xDEADBEEFL; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java index c4d6918cf1..c13efadff1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/WindowsSecureContainerExecutor.java @@ -374,7 +374,7 @@ protected OutputStream createOutputStreamWithMode(Path f, boolean append, return os; } finally { if (!success) { - IOUtils.cleanup(LOG, os); + IOUtils.cleanupWithLogger(LOG, os); } } }