hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asur...@apache.org
Subject [42/50] [abbrv] hadoop git commit: HADOOP-14638. Replace commons-logging APIs with slf4j in StreamPumper.
Date Wed, 12 Jul 2017 04:53:58 GMT
HADOOP-14638. Replace commons-logging APIs with slf4j in StreamPumper.

This closes #247

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/fce79510
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/fce79510
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/fce79510

Branch: refs/heads/YARN-5972
Commit: fce795101461cbce37334b0799b2238825f5a5aa
Parents: f1efa14
Author: wenxinhe <wenxin.he@gmail.com>
Authored: Mon Jul 10 11:37:48 2017 +0800
Committer: Akira Ajisaka <aajisaka@apache.org>
Committed: Tue Jul 11 13:30:13 2017 +0900

----------------------------------------------------------------------
 .../org/apache/hadoop/ha/PowerShellFencer.java  |  7 +--
 .../apache/hadoop/ha/ShellCommandFencer.java    |  7 ++-
 .../org/apache/hadoop/ha/SshFenceByTcpPort.java |  7 +--
 .../java/org/apache/hadoop/ha/StreamPumper.java |  8 +--
 .../hadoop/ha/TestShellCommandFencer.java       | 55 ++++++++++++++++++--
 5 files changed, 65 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/fce79510/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/PowerShellFencer.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/PowerShellFencer.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/PowerShellFencer.java
index 761b40a..6de618c 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/PowerShellFencer.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/PowerShellFencer.java
@@ -25,10 +25,10 @@ import java.io.OutputStreamWriter;
 import java.net.InetSocketAddress;
 import java.nio.charset.StandardCharsets;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Fencer method that uses PowerShell to remotely connect to a machine and kill
@@ -41,7 +41,8 @@ import org.apache.hadoop.util.StringUtils;
  */
 public class PowerShellFencer extends Configured implements FenceMethod {
 
-  private static final Log LOG = LogFactory.getLog(PowerShellFencer.class);
+  private static final Logger LOG = LoggerFactory.getLogger(PowerShellFencer
+      .class);
 
 
   @Override

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fce79510/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
index 15edee9..7e4a88f 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java
@@ -21,12 +21,12 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configured;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.hadoop.util.Shell;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Fencing method that runs a shell command. It should be specified
@@ -61,8 +61,7 @@ public class ShellCommandFencer
   private static final String TARGET_PREFIX = "target_";
 
   @VisibleForTesting
-  static Log LOG = LogFactory.getLog(
-      ShellCommandFencer.class);
+  static Logger LOG = LoggerFactory.getLogger(ShellCommandFencer.class);
 
   @Override
   public void checkArgs(String args) throws BadFencingConfigurationException {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fce79510/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java
index 5815564..64cd5a8 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java
@@ -32,6 +32,8 @@ import com.jcraft.jsch.ChannelExec;
 import com.jcraft.jsch.JSch;
 import com.jcraft.jsch.JSchException;
 import com.jcraft.jsch.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This fencing implementation sshes to the target node and uses 
@@ -58,9 +60,8 @@ import com.jcraft.jsch.Session;
 public class SshFenceByTcpPort extends Configured
   implements FenceMethod {
 
-  static final Log LOG = LogFactory.getLog(
-      SshFenceByTcpPort.class);
-  
+  static final Logger LOG = LoggerFactory.getLogger(SshFenceByTcpPort.class);
+
   static final String CONF_CONNECT_TIMEOUT_KEY =
     "dfs.ha.fencing.ssh.connect-timeout";
   private static final int CONF_CONNECT_TIMEOUT_DEFAULT =

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fce79510/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/StreamPumper.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/StreamPumper.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/StreamPumper.java
index 8018f43..12a24fd 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/StreamPumper.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/StreamPumper.java
@@ -17,14 +17,14 @@
  */
 package org.apache.hadoop.ha;
 
+import org.slf4j.Logger;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 
-import org.apache.commons.logging.Log;
-
 /**
  * Class responsible for pumping the streams of the subprocess
  * out to log4j. stderr is pumped to WARN level and stdout is
@@ -35,7 +35,7 @@ class StreamPumper {
     STDOUT, STDERR;
   }
 
-  private final Log log;
+  private final Logger log;
   
   final Thread thread;
   final String logPrefix;
@@ -43,7 +43,7 @@ class StreamPumper {
   private final InputStream stream;
   private boolean started = false;
   
-  StreamPumper(final Log log, final String logPrefix,
+  StreamPumper(final Logger log, final String logPrefix,
       final InputStream stream, final StreamType type) {
     this.log = log;
     this.logPrefix = logPrefix;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fce79510/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
index 6750b3b..3a2cf05 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestShellCommandFencer.java
@@ -19,30 +19,43 @@ package org.apache.hadoop.ha;
 
 import static org.junit.Assert.*;
 
+import java.lang.reflect.Method;
 import java.net.InetSocketAddress;
+import java.util.List;
 
+import com.google.common.collect.Lists;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
 import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.util.StringUtils;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.slf4j.Logger;
 
-import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.mock;
 
 public class TestShellCommandFencer {
   private ShellCommandFencer fencer = createFencer();
   private static final HAServiceTarget TEST_TARGET =
       new DummyHAService(HAServiceState.ACTIVE,
           new InetSocketAddress("dummyhost", 1234));
-  
+  private static final Logger LOG = ShellCommandFencer.LOG;
+
   @BeforeClass
-  public static void setupLogSpy() {
-    ShellCommandFencer.LOG = spy(ShellCommandFencer.LOG);
+  public static void setupLogMock() {
+    ShellCommandFencer.LOG = mock(Logger.class, new LogAnswer());
   }
-  
+
+  @AfterClass
+  public static void tearDownLogMock() throws Exception {
+    ShellCommandFencer.LOG = LOG;
+  }
+
   @Before
   public void resetLogSpy() {
     Mockito.reset(ShellCommandFencer.LOG);
@@ -173,4 +186,36 @@ public class TestShellCommandFencer {
     assertEquals("a...gh", ShellCommandFencer.abbreviate("abcdefgh", 6));
     assertEquals("ab...gh", ShellCommandFencer.abbreviate("abcdefgh", 7));
   }
+
+  /**
+   * An answer simply delegate some basic log methods to real LOG.
+   */
+  private static class LogAnswer implements Answer {
+
+    private static final List<String> DELEGATE_METHODS = Lists.asList("error",
+        new String[]{"warn", "info", "debug", "trace"});
+
+    @Override
+    public Object answer(InvocationOnMock invocation) {
+
+      String methodName = invocation.getMethod().getName();
+
+      if (!DELEGATE_METHODS.contains(methodName)) {
+        return null;
+      }
+
+      try {
+        String msg = invocation.getArguments()[0].toString();
+        Method delegateMethod = LOG.getClass().getMethod(methodName,
+            msg.getClass());
+        delegateMethod.invoke(LOG, msg);
+      } catch (Throwable e) {
+        throw new IllegalStateException(
+            "Unsupported delegate method: " + methodName);
+      }
+
+      return null;
+    }
+  }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message