Repository: knox
Updated Branches:
  refs/heads/master faad66d12 -> 7590d4fa7


KNOX-1108 - NiFiHaDispatch not failing over (Jeff Storck via lmccay)

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

Branch: refs/heads/master
Commit: 7590d4fa76b113dad9c4bec08655d5d0ec4201f7
Parents: faad66d
Author: Larry McCay <lmc...@hortonworks.com>
Authored: Fri Feb 9 11:05:50 2018 -0500
Committer: Larry McCay <lmc...@hortonworks.com>
Committed: Fri Feb 9 11:06:08 2018 -0500

----------------------------------------------------------------------
 .../knox/gateway/ha/dispatch/DefaultHaDispatch.java     |  4 ++--
 .../apache/knox/gateway/dispatch/NiFiHaDispatch.java    | 12 +++++++++---
 2 files changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/7590d4fa/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
----------------------------------------------------------------------
diff --git 
a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
 
b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
index 0afb539..1704f9a 100644
--- 
a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
+++ 
b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
@@ -43,7 +43,7 @@ public class DefaultHaDispatch extends DefaultDispatch {
 
   protected static final String FAILOVER_COUNTER_ATTRIBUTE = 
"dispatch.ha.failover.counter";
 
-  private static final HaDispatchMessages LOG = 
MessagesFactory.get(HaDispatchMessages.class);
+  protected static final HaDispatchMessages LOG = 
MessagesFactory.get(HaDispatchMessages.class);
 
   private int maxFailoverAttempts = 
HaServiceConfigConstants.DEFAULT_MAX_FAILOVER_ATTEMPTS;
 
@@ -96,7 +96,7 @@ public class DefaultHaDispatch extends DefaultDispatch {
   }
 
 
-  private void failoverRequest(HttpUriRequest outboundRequest, 
HttpServletRequest inboundRequest, HttpServletResponse outboundResponse, 
HttpResponse inboundResponse, Exception exception) throws IOException {
+  protected void failoverRequest(HttpUriRequest outboundRequest, 
HttpServletRequest inboundRequest, HttpServletResponse outboundResponse, 
HttpResponse inboundResponse, Exception exception) throws IOException {
     LOG.failingOverRequest(outboundRequest.getURI().toString());
     AtomicInteger counter = (AtomicInteger) 
inboundRequest.getAttribute(FAILOVER_COUNTER_ATTRIBUTE);
     if ( counter == null ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/7590d4fa/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
----------------------------------------------------------------------
diff --git 
a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
 
b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
index 5e1e3a0..724eb42 100644
--- 
a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
+++ 
b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
@@ -40,9 +40,15 @@ public class NiFiHaDispatch extends DefaultHaDispatch {
 
   @Override
   protected void executeRequest(HttpUriRequest outboundRequest, 
HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws 
IOException {
-    outboundRequest = NiFiRequestUtil.modifyOutboundRequest(outboundRequest, 
inboundRequest);
-    HttpResponse inboundResponse = executeOutboundRequest(outboundRequest);
-    writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, 
inboundResponse);
+    HttpResponse inboundResponse = null;
+    try {
+      outboundRequest = NiFiRequestUtil.modifyOutboundRequest(outboundRequest, 
inboundRequest);
+      inboundResponse = executeOutboundRequest(outboundRequest);
+      writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, 
inboundResponse);
+    } catch (IOException e) {
+      LOG.errorConnectingToServer(outboundRequest.getURI().toString(), e);
+      failoverRequest(outboundRequest, inboundRequest, outboundResponse, 
inboundResponse, e);
+    }
   }
 
   /**

Reply via email to