knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: KNOX-451: WebHDFS HA failover does not account for URL of unsuccessful request
Date Thu, 23 Oct 2014 01:35:33 GMT
Repository: knox
Updated Branches:
  refs/heads/v0.5.0 4add01305 -> 3265a1c83


KNOX-451: WebHDFS HA failover does not account for URL of unsuccessful request

(cherry picked from commit 0105554ab4f921afe010e3d6a56b82671fb1b63a)


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

Branch: refs/heads/v0.5.0
Commit: 3265a1c834a7a1de9de212ddee8852af7fcefd64
Parents: 4add013
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Wed Oct 22 21:31:07 2014 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Wed Oct 22 21:31:28 2014 -0400

----------------------------------------------------------------------
 .../gateway/ha/provider/impl/URLManager.java    | 26 ++++++++++++++-----
 .../ha/provider/impl/i18n/HaMessages.java       |  5 ++++
 .../ha/provider/impl/URLManagerTest.java        | 27 ++++++++++++++++++++
 3 files changed, 52 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/3265a1c8/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/URLManager.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/URLManager.java
b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/URLManager.java
index 9f7bab8..f14eb25 100644
--- a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/URLManager.java
+++ b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/URLManager.java
@@ -18,12 +18,17 @@
 package org.apache.hadoop.gateway.ha.provider.impl;
 
 import com.google.common.collect.Lists;
+import org.apache.hadoop.gateway.ha.provider.impl.i18n.HaMessages;
+import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 
+import java.net.URI;
 import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 public class URLManager {
 
+   private static final HaMessages LOG = MessagesFactory.get(HaMessages.class);
+
    private ConcurrentLinkedQueue<String> urls = new ConcurrentLinkedQueue<String>();
 
    public URLManager(List<String> urls) {
@@ -45,12 +50,21 @@ public class URLManager {
       }
    }
 
-   public void markFailed(String url) {
-      //TODO: check if the url is the one on top
-//      if (urls.peek().equals(url)) {
+   public synchronized void markFailed(String url) {
+      String top = urls.peek();
+      boolean pushToBottom = false;
+      URI topUri = URI.create(top);
+      URI incomingUri = URI.create(url);
+      String topHostPort = topUri.getHost() + topUri.getPort();
+      String incomingHostPort = incomingUri.getHost() + incomingUri.getPort();
+      if (topHostPort.equals(incomingHostPort)) {
+         pushToBottom = true;
+      }
       //put the failed url at the bottom
-      String failed = urls.poll();
-      urls.offer(failed);
-//      }
+      if (pushToBottom) {
+         String failed = urls.poll();
+         urls.offer(failed);
+         LOG.markedFailedUrl(failed, top);
+      }
    }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/3265a1c8/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/i18n/HaMessages.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/i18n/HaMessages.java
b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/i18n/HaMessages.java
index ade11b4..61a2b96 100644
--- a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/i18n/HaMessages.java
+++ b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/i18n/HaMessages.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.gateway.i18n.messages.Messages;
 
 @Messages(logger = "org.apache.hadoop.gateway")
 public interface HaMessages {
+
    @Message(level = MessageLevel.ERROR, text = "Failed to Write HA Descriptor: {0}")
    void failedToWriteHaDescriptor(Exception e);
 
@@ -34,4 +35,8 @@ public interface HaMessages {
 
    @Message(level = MessageLevel.INFO, text = "No Service by this name was found: {0}")
    void noServiceFound(String serviceName);
+
+   @Message(level = MessageLevel.DEBUG, text = "Moving failed URL to the bottom {0}, new
top is {1}")
+   void markedFailedUrl(String failedUrl, String top);
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/3265a1c8/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/URLManagerTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/URLManagerTest.java
b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/URLManagerTest.java
index cb3f451..1de2a7c 100644
--- a/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/URLManagerTest.java
+++ b/gateway-provider-ha/src/test/java/org/apache/hadoop/gateway/ha/provider/impl/URLManagerTest.java
@@ -41,4 +41,31 @@ public class URLManagerTest {
       manager.markFailed(url2);
       assertEquals(url1, manager.getActiveURL());
    }
+
+   @Test
+   public void testMarkingFailedURL() {
+      ArrayList<String> urls = new ArrayList<String>();
+      String url1 = "http://host1:4555";
+      urls.add(url1);
+      String url2 = "http://host2:1234";
+      urls.add(url2);
+      String url3 = "http://host1:1234";
+      urls.add(url3);
+      String url4 = "http://host2:4555";
+      urls.add(url4);
+      URLManager manager = new URLManager(urls);
+      assertTrue(manager.getURLs().containsAll(urls));
+      assertEquals(url1, manager.getActiveURL());
+      manager.markFailed(url1);
+      assertEquals(url2, manager.getActiveURL());
+      manager.markFailed(url1);
+      assertEquals(url2, manager.getActiveURL());
+      manager.markFailed(url3);
+      assertEquals(url2, manager.getActiveURL());
+      manager.markFailed(url4);
+      assertEquals(url2, manager.getActiveURL());
+      manager.markFailed(url2);
+      assertEquals(url3, manager.getActiveURL());
+   }
+
 }


Mime
View raw message