hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1305195 - in /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src: main/java/org/apache/hadoop/hdfs/tools/ test/java/org/apache/hadoop/hdfs/tools/
Date Mon, 26 Mar 2012 01:54:15 GMT
Author: todd
Date: Mon Mar 26 01:54:14 2012
New Revision: 1305195

URL: http://svn.apache.org/viewvc?rev=1305195&view=rev
Log:
HADOOP-8193. Refactor FailoverController/HAAdmin code to add an abstract class for "target"
services. Contributed by Todd Lipcon.

Added:
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java
Modified:
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java?rev=1305195&r1=1305194&r2=1305195&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java
Mon Mar 26 01:54:14 2012
@@ -25,8 +25,8 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.ha.HAAdmin;
+import org.apache.hadoop.ha.HAServiceTarget;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
-import org.apache.hadoop.hdfs.DFSUtil;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.util.ToolRunner;
 
@@ -65,15 +65,9 @@ public class DFSHAAdmin extends HAAdmin 
    * Try to map the given namenode ID to its service address.
    */
   @Override
-  protected String getServiceAddr(String nnId) {
+  protected HAServiceTarget resolveTarget(String nnId) {
     HdfsConfiguration conf = (HdfsConfiguration)getConf();
-    String serviceAddr = 
-      DFSUtil.getNamenodeServiceAddr(conf, nameserviceId, nnId);
-    if (serviceAddr == null) {
-      throw new IllegalArgumentException(
-          "Unable to determine service address for namenode '" + nnId + "'");
-    }
-    return serviceAddr;
+    return new NNHAServiceTarget(conf, nameserviceId, nnId);
   }
 
   @Override

Added: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java?rev=1305195&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java
(added)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/NNHAServiceTarget.java
Mon Mar 26 01:54:14 2012
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.tools;
+
+import java.net.InetSocketAddress;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.ha.BadFencingConfigurationException;
+import org.apache.hadoop.ha.HAServiceTarget;
+import org.apache.hadoop.ha.NodeFencer;
+import org.apache.hadoop.hdfs.DFSUtil;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.net.NetUtils;
+
+/**
+ * One of the NN NameNodes acting as the target of an administrative command
+ * (e.g. failover).
+ */
+@InterfaceAudience.Private
+public class NNHAServiceTarget extends HAServiceTarget {
+
+  private final InetSocketAddress addr;
+  private NodeFencer fencer;
+  private BadFencingConfigurationException fenceConfigError;
+
+  public NNHAServiceTarget(HdfsConfiguration conf,
+      String nsId, String nnId) {
+    String serviceAddr = 
+      DFSUtil.getNamenodeServiceAddr(conf, nsId, nnId);
+    if (serviceAddr == null) {
+      throw new IllegalArgumentException(
+          "Unable to determine service address for namenode '" + nnId + "'");
+    }
+    this.addr = NetUtils.createSocketAddr(serviceAddr,
+        NameNode.DEFAULT_PORT);
+    try {
+      this.fencer = NodeFencer.create(conf);
+    } catch (BadFencingConfigurationException e) {
+      this.fenceConfigError = e;
+    }
+  }
+
+  /**
+   * @return the NN's IPC address.
+   */
+  @Override
+  public InetSocketAddress getAddress() {
+    return addr;
+  }
+
+  @Override
+  public void checkFencingConfigured() throws BadFencingConfigurationException {
+    if (fenceConfigError != null) {
+      throw fenceConfigError;
+    }
+  }
+  
+  @Override
+  public NodeFencer getFencer() {
+    return fencer;
+  }
+  
+  @Override
+  public String toString() {
+    return "NameNode at " + addr;
+  }
+
+}

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java?rev=1305195&r1=1305194&r2=1305195&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java
Mon Mar 26 01:54:14 2012
@@ -26,12 +26,14 @@ import java.io.PrintStream;
 
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.Log;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.DFSUtil;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.ha.HAServiceProtocol;
 import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
 import org.apache.hadoop.ha.HAServiceStatus;
+import org.apache.hadoop.ha.HAServiceTarget;
 import org.apache.hadoop.ha.HealthCheckFailedException;
 import org.apache.hadoop.ha.NodeFencer;
 
@@ -79,10 +81,19 @@ public class TestDFSHAAdmin {
   public void setup() throws IOException {
     mockProtocol = Mockito.mock(HAServiceProtocol.class);
     tool = new DFSHAAdmin() {
+
       @Override
-      protected HAServiceProtocol getProtocol(String serviceId) throws IOException {
-        getServiceAddr(serviceId);
-        return mockProtocol;
+      protected HAServiceTarget resolveTarget(String nnId) {
+        HAServiceTarget target = super.resolveTarget(nnId);
+        HAServiceTarget spy = Mockito.spy(target);
+        // OVerride the target to return our mock protocol
+        try {
+          Mockito.doReturn(mockProtocol).when(spy).getProxy(
+              Mockito.<Configuration>any(), Mockito.anyInt()); 
+        } catch (IOException e) {
+          throw new AssertionError(e); // mock setup doesn't really throw
+        }
+        return spy;
       }
     };
     tool.setConf(getHAConf());

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java?rev=1305195&r1=1305194&r2=1305195&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java
Mon Mar 26 01:54:14 2012
@@ -25,12 +25,15 @@ import java.io.PrintStream;
 
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.Log4JLogger;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.MiniDFSNNTopology;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
+import org.apache.hadoop.ha.HAAdmin;
 import org.apache.hadoop.ha.NodeFencer;
+import org.apache.log4j.Level;
 
 import org.junit.After;
 import org.junit.Before;
@@ -43,6 +46,10 @@ import com.google.common.base.Joiner;
  * Tests for HAAdmin command with {@link MiniDFSCluster} set up in HA mode.
  */
 public class TestDFSHAAdminMiniCluster {
+  static {
+    ((Log4JLogger)LogFactory.getLog(HAAdmin.class)).getLogger().setLevel(
+        Level.ALL);
+  }
   private static final Log LOG = LogFactory.getLog(TestDFSHAAdminMiniCluster.class);
   
   private MiniDFSCluster cluster;



Mime
View raw message