hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1304204 - in /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src: main/java/org/apache/hadoop/ha/ main/java/org/apache/hadoop/ha/protocolPB/ main/proto/ test/java/org/apache/hadoop/ha/
Date Fri, 23 Mar 2012 06:29:49 GMT
Author: todd
Date: Fri Mar 23 06:29:48 2012
New Revision: 1304204

URL: http://svn.apache.org/viewvc?rev=1304204&view=rev
Log:
HDFS-3071. haadmin failover command does not provide enough detail when target NN is not ready
to be active. Contributed by Todd Lipcon.

Added:
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceStatus.java
Modified:
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolClientSideTranslatorPB.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolServerSideTranslatorPB.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/proto/HAServiceProtocol.proto
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestFailoverController.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHealthMonitor.java

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java
Fri Mar 23 06:29:48 2012
@@ -60,20 +60,32 @@ public class FailoverController {
                                         InetSocketAddress toSvcAddr,
                                         boolean forceActive)
       throws FailoverFailedException {
-    HAServiceState toSvcState;
+    HAServiceStatus toSvcStatus;
 
     try {
-      toSvcState = toSvc.getServiceState();
+      toSvcStatus = toSvc.getServiceStatus();
     } catch (IOException e) {
       String msg = "Unable to get service state for " + toSvcAddr;
       LOG.error(msg, e);
       throw new FailoverFailedException(msg, e);
     }
 
-    if (!toSvcState.equals(HAServiceState.STANDBY)) {
+    if (!toSvcStatus.getState().equals(HAServiceState.STANDBY)) {
       throw new FailoverFailedException(
           "Can't failover to an active service");
     }
+    
+    if (!toSvcStatus.isReadyToBecomeActive()) {
+      String notReadyReason = toSvcStatus.getNotReadyReason();
+      if (!forceActive) {
+        throw new FailoverFailedException(
+            toSvcAddr + " is not ready to become active: " +
+            notReadyReason);
+      } else {
+        LOG.warn("Service is not ready to become active, but forcing: " +
+            notReadyReason);
+      }
+    }
 
     try {
       HAServiceProtocolHelper.monitorHealth(toSvc);
@@ -84,18 +96,6 @@ public class FailoverController {
       throw new FailoverFailedException(
           "Got an IO exception", e);
     }
-
-    try {
-      if (!toSvc.readyToBecomeActive()) {
-        if (!forceActive) {
-          throw new FailoverFailedException(
-              toSvcAddr + " is not ready to become active");
-        }
-      }
-    } catch (IOException e) {
-      throw new FailoverFailedException(
-          "Got an IO exception", e);
-    }
   }
 
   /**

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
Fri Mar 23 06:29:48 2012
@@ -32,7 +32,6 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.ha.protocolPB.HAServiceProtocolClientSideTranslatorPB;
-import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
@@ -221,7 +220,7 @@ public abstract class HAAdmin extends Co
     }
 
     HAServiceProtocol proto = getProtocol(argv[1]);
-    out.println(proto.getServiceState());
+    out.println(proto.getServiceStatus().getState());
     return 0;
   }
 

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
Fri Mar 23 06:29:48 2012
@@ -115,27 +115,15 @@ public interface HAServiceProtocol {
                                            IOException;
 
   /**
-   * Return the current state of the service.
+   * Return the current status of the service. The status indicates
+   * the current <em>state</em> (e.g ACTIVE/STANDBY) as well as
+   * some additional information. {@see HAServiceStatus}
    * 
    * @throws AccessControlException
    *           if access is denied.
    * @throws IOException
    *           if other errors happen
    */
-  public HAServiceState getServiceState() throws AccessControlException,
-                                                 IOException;
-
-  /**
-   * Return true if the service is capable and ready to transition
-   * from the standby state to the active state.
-   * 
-   * @return true if the service is ready to become active, false otherwise.
-   * @throws AccessControlException
-   *           if access is denied.
-   * @throws IOException
-   *           if other errors happen
-   */
-  public boolean readyToBecomeActive() throws ServiceFailedException,
-                                              AccessControlException,
-                                              IOException;
+  public HAServiceStatus getServiceStatus() throws AccessControlException,
+                                                   IOException;
 }

Added: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceStatus.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceStatus.java?rev=1304204&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceStatus.java
(added)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceStatus.java
Fri Mar 23 06:29:48 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.ha;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
+
+@InterfaceAudience.Private
+public class HAServiceStatus {
+  private HAServiceState state;
+  private boolean readyToBecomeActive;
+  private String notReadyReason;
+  
+  public HAServiceStatus(HAServiceState state) {
+    this.state = state;
+  }
+
+  public HAServiceState getState() {
+    return state;
+  }
+
+  public HAServiceStatus setReadyToBecomeActive() {
+    this.readyToBecomeActive = true;
+    this.notReadyReason = null;
+    return this;
+  }
+  
+  public HAServiceStatus setNotReadyToBecomeActive(String reason) {
+    this.readyToBecomeActive = false;
+    this.notReadyReason = reason;
+    return this;
+  }
+
+  public boolean isReadyToBecomeActive() {
+    return readyToBecomeActive;
+  }
+
+  public String getNotReadyReason() {
+    return notReadyReason;
+  }
+}

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthMonitor.java
Fri Mar 23 06:29:48 2012
@@ -77,7 +77,8 @@ class HealthMonitor {
   private List<Callback> callbacks = Collections.synchronizedList(
       new LinkedList<Callback>());
 
-  private HAServiceState lastServiceState = HAServiceState.INITIALIZING;
+  private HAServiceStatus lastServiceState = new HAServiceStatus(
+      HAServiceState.INITIALIZING);
   
   enum State {
     /**
@@ -188,10 +189,10 @@ class HealthMonitor {
 
   private void doHealthChecks() throws InterruptedException {
     while (shouldRun) {
-      HAServiceState state = null;
+      HAServiceStatus status = null;
       boolean healthy = false;
       try {
-        state = proxy.getServiceState();
+        status = proxy.getServiceStatus();
         proxy.monitorHealth();
         healthy = true;
       } catch (HealthCheckFailedException e) {
@@ -207,8 +208,8 @@ class HealthMonitor {
         return;
       }
       
-      if (state != null) {
-        setLastServiceState(state);
+      if (status != null) {
+        setLastServiceStatus(status);
       }
       if (healthy) {
         enterState(State.SERVICE_HEALTHY);
@@ -218,8 +219,8 @@ class HealthMonitor {
     }
   }
   
-  private synchronized void setLastServiceState(HAServiceState serviceState) {
-    this.lastServiceState = serviceState;
+  private synchronized void setLastServiceStatus(HAServiceStatus status) {
+    this.lastServiceState = status;
   }
 
   private synchronized void enterState(State newState) {
@@ -238,7 +239,7 @@ class HealthMonitor {
     return state;
   }
   
-  synchronized HAServiceState getLastServiceState() {
+  synchronized HAServiceStatus getLastServiceStatus() {
     return lastServiceState;
   }
   

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolClientSideTranslatorPB.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolClientSideTranslatorPB.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolClientSideTranslatorPB.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolClientSideTranslatorPB.java
Fri Mar 23 06:29:48 2012
@@ -27,10 +27,11 @@ import org.apache.hadoop.classification.
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.ha.HAServiceProtocol;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStateRequestProto;
+import org.apache.hadoop.ha.HAServiceStatus;
+import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStatusRequestProto;
+import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStatusResponseProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.HAServiceStateProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.MonitorHealthRequestProto;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.ReadyToBecomeActiveRequestProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.TransitionToActiveRequestProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.TransitionToStandbyRequestProto;
 import org.apache.hadoop.ipc.ProtobufHelper;
@@ -60,10 +61,8 @@ public class HAServiceProtocolClientSide
       TransitionToActiveRequestProto.newBuilder().build();
   private final static TransitionToStandbyRequestProto TRANSITION_TO_STANDBY_REQ = 
       TransitionToStandbyRequestProto.newBuilder().build();
-  private final static GetServiceStateRequestProto GET_SERVICE_STATE_REQ = 
-      GetServiceStateRequestProto.newBuilder().build();
-  private final static ReadyToBecomeActiveRequestProto ACTIVE_READY_REQ = 
-      ReadyToBecomeActiveRequestProto.newBuilder().build();
+  private final static GetServiceStatusRequestProto GET_SERVICE_STATUS_REQ = 
+      GetServiceStatusRequestProto.newBuilder().build();
   
   private final HAServiceProtocolPB rpcProxy;
 
@@ -113,14 +112,26 @@ public class HAServiceProtocolClientSide
   }
 
   @Override
-  public HAServiceState getServiceState() throws IOException {
-    HAServiceStateProto state;
+  public HAServiceStatus getServiceStatus() throws IOException {
+    GetServiceStatusResponseProto status;
     try {
-      state = rpcProxy.getServiceState(NULL_CONTROLLER,
-          GET_SERVICE_STATE_REQ).getState();
+      status = rpcProxy.getServiceStatus(NULL_CONTROLLER,
+          GET_SERVICE_STATUS_REQ);
     } catch (ServiceException e) {
       throw ProtobufHelper.getRemoteException(e);
     }
+    
+    HAServiceStatus ret = new HAServiceStatus(
+        convert(status.getState()));
+    if (status.getReadyToBecomeActive()) {
+      ret.setReadyToBecomeActive();
+    } else {
+      ret.setNotReadyToBecomeActive(status.getNotReadyReason());
+    }
+    return ret;
+  }
+  
+  private HAServiceState convert(HAServiceStateProto state) {
     switch(state) {
     case ACTIVE:
       return HAServiceState.ACTIVE;
@@ -138,16 +149,6 @@ public class HAServiceProtocolClientSide
   }
 
   @Override
-  public boolean readyToBecomeActive() throws IOException {
-    try {
-      return rpcProxy.readyToBecomeActive(NULL_CONTROLLER, ACTIVE_READY_REQ)
-          .getReadyToBecomeActive();
-    } catch (ServiceException e) {
-      throw ProtobufHelper.getRemoteException(e);
-    }
-  }
-
-  @Override
   public Object getUnderlyingProxyObject() {
     return rpcProxy;
   }

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolServerSideTranslatorPB.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolServerSideTranslatorPB.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolServerSideTranslatorPB.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/protocolPB/HAServiceProtocolServerSideTranslatorPB.java
Fri Mar 23 06:29:48 2012
@@ -22,14 +22,12 @@ import java.io.IOException;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.ha.HAServiceProtocol;
-import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStateRequestProto;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStateResponseProto;
+import org.apache.hadoop.ha.HAServiceStatus;
+import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStatusRequestProto;
+import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.GetServiceStatusResponseProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.HAServiceStateProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.MonitorHealthRequestProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.MonitorHealthResponseProto;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.ReadyToBecomeActiveRequestProto;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.ReadyToBecomeActiveResponseProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.TransitionToActiveRequestProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.TransitionToActiveResponseProto;
 import org.apache.hadoop.ha.proto.HAServiceProtocolProtos.TransitionToStandbyRequestProto;
@@ -99,29 +97,37 @@ public class HAServiceProtocolServerSide
   }
 
   @Override
-  public GetServiceStateResponseProto getServiceState(RpcController controller,
-      GetServiceStateRequestProto request) throws ServiceException {
-    HAServiceState s;
+  public GetServiceStatusResponseProto getServiceStatus(RpcController controller,
+      GetServiceStatusRequestProto request) throws ServiceException {
+    HAServiceStatus s;
     try {
-      s = server.getServiceState();
+      s = server.getServiceStatus();
     } catch(IOException e) {
       throw new ServiceException(e);
     }
     
-    HAServiceStateProto ret;
-    switch (s) {
+    HAServiceStateProto retState;
+    switch (s.getState()) {
     case ACTIVE:
-      ret = HAServiceStateProto.ACTIVE;
+      retState = HAServiceStateProto.ACTIVE;
       break;
     case STANDBY:
-      ret = HAServiceStateProto.STANDBY;
+      retState = HAServiceStateProto.STANDBY;
       break;
     case INITIALIZING:
     default:
-      ret = HAServiceStateProto.INITIALIZING;
+      retState = HAServiceStateProto.INITIALIZING;
       break;
     }
-    return GetServiceStateResponseProto.newBuilder().setState(ret).build();
+    
+    GetServiceStatusResponseProto.Builder ret =
+      GetServiceStatusResponseProto.newBuilder()
+        .setState(retState)
+        .setReadyToBecomeActive(s.isReadyToBecomeActive());
+    if (!s.isReadyToBecomeActive()) {
+      ret.setNotReadyReason(s.getNotReadyReason());
+    }
+    return ret.build();
   }
 
   @Override
@@ -143,16 +149,4 @@ public class HAServiceProtocolServerSide
         RPC.getProtocolVersion(HAServiceProtocolPB.class),
         HAServiceProtocolPB.class);
   }
-
-  @Override
-  public ReadyToBecomeActiveResponseProto readyToBecomeActive(
-      RpcController controller, ReadyToBecomeActiveRequestProto request)
-      throws ServiceException {
-    try {
-      return ReadyToBecomeActiveResponseProto.newBuilder()
-          .setReadyToBecomeActive(server.readyToBecomeActive()).build();
-    } catch (IOException e) {
-      throw new ServiceException(e);
-    }
-  }
 }

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/proto/HAServiceProtocol.proto
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/proto/HAServiceProtocol.proto?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/proto/HAServiceProtocol.proto
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/proto/HAServiceProtocol.proto
Fri Mar 23 06:29:48 2012
@@ -66,27 +66,20 @@ message TransitionToStandbyResponseProto
 /**
  * void request
  */
-message GetServiceStateRequestProto { 
+message GetServiceStatusRequestProto { 
 }
 
 /**
  * Returns the state of the service
  */
-message GetServiceStateResponseProto { 
+message GetServiceStatusResponseProto { 
   required HAServiceStateProto state = 1;
-}
 
-/**
- * void request
- */
-message ReadyToBecomeActiveRequestProto { 
-}
-
-/**
- * Returns true if service is ready to become active
- */
-message ReadyToBecomeActiveResponseProto { 
-  required bool readyToBecomeActive = 1;
+  // If state is STANDBY, indicate whether it is
+  // ready to become active.
+  optional bool readyToBecomeActive = 2;
+  // If not ready to become active, a textual explanation of why not
+  optional string notReadyReason = 3;
 }
 
 /**
@@ -115,14 +108,8 @@ service HAServiceProtocolService {
       returns(TransitionToStandbyResponseProto);
 
   /**
-   * Get the current state of the service.
-   */
-  rpc getServiceState(GetServiceStateRequestProto)
-      returns(GetServiceStateResponseProto);
-
-  /**
-   * Check if the service is ready to become active
+   * Get the current status of the service.
    */
-  rpc readyToBecomeActive(ReadyToBecomeActiveRequestProto)
-      returns(ReadyToBecomeActiveResponseProto);
+  rpc getServiceStatus(GetServiceStatusRequestProto)
+      returns(GetServiceStatusResponseProto);
 }

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestFailoverController.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestFailoverController.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestFailoverController.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestFailoverController.java
Fri Mar 23 06:29:48 2012
@@ -30,8 +30,6 @@ import org.apache.hadoop.ha.protocolPB.H
 import org.apache.hadoop.ha.TestNodeFencer.AlwaysSucceedFencer;
 import org.apache.hadoop.ha.TestNodeFencer.AlwaysFailFencer;
 import static org.apache.hadoop.ha.TestNodeFencer.setupFencer;
-import org.apache.hadoop.ipc.ProtocolSignature;
-import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.AccessControlException;
 
@@ -66,13 +64,16 @@ public class TestFailoverController {
     }
 
     @Override
-    public HAServiceState getServiceState() throws IOException {
-      return state;
+    public HAServiceStatus getServiceStatus() throws IOException {
+      HAServiceStatus ret = new HAServiceStatus(state);
+      if (state == HAServiceState.STANDBY) {
+        ret.setReadyToBecomeActive();
+      }
+      return ret;
     }
-
-    @Override
-    public boolean readyToBecomeActive() throws ServiceFailedException, IOException {
-      return true;
+    
+    private HAServiceState getServiceState() {
+      return state;
     }
   }
   
@@ -127,13 +128,13 @@ public class TestFailoverController {
   public void testFailoverWithoutPermission() throws Exception {
     DummyService svc1 = new DummyService(HAServiceState.ACTIVE) {
       @Override
-      public HAServiceState getServiceState() throws IOException {
+      public HAServiceStatus getServiceStatus() throws IOException {
         throw new AccessControlException("Access denied");
       }
     };
     DummyService svc2 = new DummyService(HAServiceState.STANDBY) {
       @Override
-      public HAServiceState getServiceState() throws IOException {
+      public HAServiceStatus getServiceStatus() throws IOException {
         throw new AccessControlException("Access denied");
       }
     };
@@ -153,8 +154,10 @@ public class TestFailoverController {
     DummyService svc1 = new DummyService(HAServiceState.ACTIVE);
     DummyService svc2 = new DummyService(HAServiceState.STANDBY) {
       @Override
-      public boolean readyToBecomeActive() throws ServiceFailedException, IOException {
-        return false;
+      public HAServiceStatus getServiceStatus() throws IOException {
+        HAServiceStatus ret = new HAServiceStatus(HAServiceState.STANDBY);
+        ret.setNotReadyToBecomeActive("injected not ready");
+        return ret;
       }
     };
     NodeFencer fencer = setupFencer(AlwaysSucceedFencer.class.getName());
@@ -164,6 +167,9 @@ public class TestFailoverController {
       fail("Can't failover to a service that's not ready");
     } catch (FailoverFailedException ffe) {
       // Expected
+      if (!ffe.getMessage().contains("injected not ready")) {
+        throw ffe;
+      }
     }
 
     assertEquals(HAServiceState.ACTIVE, svc1.getServiceState());

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
Fri Mar 23 06:29:48 2012
@@ -30,7 +30,6 @@ import org.apache.hadoop.conf.Configurat
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-import static org.mockito.Mockito.when;
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Joiner;
@@ -46,7 +45,6 @@ public class TestHAAdmin {
   @Before
   public void setup() throws IOException {
     mockProtocol = Mockito.mock(HAServiceProtocol.class);
-    when(mockProtocol.readyToBecomeActive()).thenReturn(true);
     tool = new HAAdmin() {
       @Override
       protected HAServiceProtocol getProtocol(String target) throws IOException {

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHealthMonitor.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHealthMonitor.java?rev=1304204&r1=1304203&r2=1304204&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHealthMonitor.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHealthMonitor.java
Fri Mar 23 06:29:48 2012
@@ -64,8 +64,8 @@ public class TestHealthMonitor {
     conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
     conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
     mockProxy = Mockito.mock(HAServiceProtocol.class);
-    Mockito.doReturn(HAServiceState.ACTIVE)
-      .when(mockProxy).getServiceState();
+    Mockito.doReturn(new HAServiceStatus(HAServiceState.ACTIVE))
+      .when(mockProxy).getServiceStatus();
     
     hm = new HealthMonitor(conf, BOGUS_ADDR) {
       @Override



Mime
View raw message