knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject [12/14] knox git commit: Added HA support and URL-level dispatch for webhdfs KNOX-483
Date Tue, 27 Jan 2015 16:26:38 GMT
Added HA support and URL-level dispatch for webhdfs KNOX-483


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

Branch: refs/heads/KNOX-481
Commit: 38406df02c87986350b8fb54b2937351b4eaa0c0
Parents: feae9e9
Author: Sumit Gupta <sumit@apache.org>
Authored: Tue Jan 20 11:16:00 2015 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Tue Jan 27 11:25:21 2015 -0500

----------------------------------------------------------------------
 .../ServiceDefinitionDeploymentContributor.java | 51 +++++++++++++++-----
 .../service/definition/CustomDispatch.java      | 11 +++++
 .../gateway/service/definition/UrlBinding.java  | 11 +++++
 .../services/webhdfs/2.4.0/service.xml          |  2 +
 ...NameNodeHaDispatchDeploymentContributor.java |  6 +--
 .../hdfs/dispatch/WebHdfsHaDispatchFilter.java  | 36 ++++++++++++++
 .../dispatch/WebHdfsHaHttpClientDispatch.java   | 48 ++++++++++--------
 .../WebHdfsHaHttpClientDispatchTest.java        |  8 ++-
 .../deploy/DeploymentFactoryFuncTest.java       |  6 +--
 9 files changed, 135 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
index 79cc4a5..755fc67 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.gateway.service.definition.CustomDispatch;
 import org.apache.hadoop.gateway.service.definition.RewriteFilter;
 import org.apache.hadoop.gateway.service.definition.ServiceDefinition;
 import org.apache.hadoop.gateway.service.definition.UrlBinding;
+import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
 
 import java.net.URISyntaxException;
@@ -86,7 +87,7 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
         }
       }
       try {
-        contributeResource(context, service, binding.getPattern(), filterParams);
+        contributeResource(context, service, binding, filterParams);
       } catch ( URISyntaxException e ) {
         e.printStackTrace();
       }
@@ -94,11 +95,11 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
 
   }
 
-  private void contributeResource(DeploymentContext context, Service service, String pattern,
Map<String, String> filterParams) throws URISyntaxException {
+  private void contributeResource(DeploymentContext context, Service service, UrlBinding
binding, Map<String, String> filterParams) throws URISyntaxException {
     List<FilterParamDescriptor> params = new ArrayList<FilterParamDescriptor>();
     ResourceDescriptor resource = context.getGatewayDescriptor().addResource();
     resource.role(service.getRole());
-    resource.pattern(pattern);
+    resource.pattern(binding.getPattern());
     addWebAppSecFilters(context, service, resource);
     addAuthenticationFilter(context, service, resource);
     addIdentityAssertionFilter(context, service, resource);
@@ -109,20 +110,46 @@ public class ServiceDefinitionDeploymentContributor extends ServiceDeploymentCon
       }
     }
     addRewriteFilter(context, service, resource, params);
-    CustomDispatch customDispatch = serviceDefinition.getDispatch();
-    if (customDispatch != null) {
-      String contributorName = customDispatch.getContributorName();
-      if (contributorName != null) {
-        addDispatchFilter(context, service, resource, DISPATCH_ROLE, contributorName);
+    addDispatchFilter(context, service, resource, binding);
+  }
+
+  private void addDispatchFilter(DeploymentContext context, Service service, ResourceDescriptor
resource, UrlBinding binding) {
+    CustomDispatch customDispatch = binding.getDispatch();
+    if ( customDispatch == null ) {
+      customDispatch = serviceDefinition.getDispatch();
+    }
+    if ( customDispatch != null ) {
+      boolean isHaEnabled = isHaEnabled(context);
+      if ( isHaEnabled && (customDispatch.getHaContributorName() != null) ) {
+        addDispatchFilter(context, service, resource, DISPATCH_ROLE, customDispatch.getHaContributorName());
       } else {
-        String className = customDispatch.getClassName();
-        if (className != null) {
-          FilterDescriptor filter = resource.addFilter().name( getName() ).role( DISPATCH_ROLE
).impl( GatewayDispatchFilter.class );
-          filter.param().name(DISPATCH_IMPL_PARAM).value(className);
+        String contributorName = customDispatch.getContributorName();
+        if ( contributorName != null ) {
+          addDispatchFilter(context, service, resource, DISPATCH_ROLE, contributorName);
+        } else {
+          String className = customDispatch.getClassName();
+          if ( className != null ) {
+            FilterDescriptor filter = resource.addFilter().name(getName()).role(DISPATCH_ROLE).impl(GatewayDispatchFilter.class);
+            filter.param().name(DISPATCH_IMPL_PARAM).value(className);
+          }
         }
       }
     } else {
       addDispatchFilter(context, service, resource, DISPATCH_ROLE, "http-client");
     }
   }
+
+  private boolean isHaEnabled(DeploymentContext context) {
+    Provider provider = getProviderByRole(context, "ha");
+    if ( provider != null && provider.isEnabled() ) {
+      Map<String, String> params = provider.getParams();
+      if ( params != null ) {
+        if ( params.containsKey(getRole()) ) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
index af4f83c..230bdb7 100644
--- a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/CustomDispatch.java
@@ -25,6 +25,8 @@ public class CustomDispatch {
 
   private String contributorName;
 
+  private String haContributorName;
+
   private String className;
 
   @XmlAttribute(name = "contributor-name")
@@ -36,6 +38,15 @@ public class CustomDispatch {
     this.contributorName = contributorName;
   }
 
+  @XmlAttribute(name = "ha-contributor-name")
+  public String getHaContributorName() {
+    return haContributorName;
+  }
+
+  public void setHaContributorName(String haContributorName) {
+    this.haContributorName = haContributorName;
+  }
+
   @XmlAttribute(name = "classname")
   public String getClassName() {
     return className;

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
index 3630ebf..c64658c 100644
--- a/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
+++ b/gateway-service-definitions/src/main/java/org/apache/hadoop/gateway/service/definition/UrlBinding.java
@@ -29,6 +29,8 @@ public class UrlBinding {
 
   private List<RewriteFilter> rewriteFilters;
 
+  private CustomDispatch dispatch;
+
   @XmlAttribute
   public String getPattern() {
     return pattern;
@@ -46,4 +48,13 @@ public class UrlBinding {
   public void setRewriteFilters(List<RewriteFilter> rewriteFilters) {
     this.rewriteFilters = rewriteFilters;
   }
+
+  @XmlElement(name = "dispatch")
+  public CustomDispatch getDispatch() {
+    return dispatch;
+  }
+
+  public void setDispatch(CustomDispatch dispatch) {
+    this.dispatch = dispatch;
+  }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
b/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
index 1aeaf70..a89f51d 100644
--- a/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
+++ b/gateway-service-definitions/src/main/resources/services/webhdfs/2.4.0/service.xml
@@ -33,6 +33,8 @@
         </url>
         <url pattern="/webhdfs/data/v1/**?**">
             <rewrite-filter ref="WEBHDFS/webhdfs/inbound/datanode" apply-to="request.url"/>
+            <dispatch contributor-name="http-client" />
         </url>
     </urls>
+    <dispatch contributor-name="hdfs" ha-contributor-name="ha-hdfs"/>
 </service>

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java
b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java
index c88bd14..d43cf1b 100644
--- a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java
+++ b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/NameNodeHaDispatchDeploymentContributor.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.gateway.descriptor.FilterDescriptor;
 import org.apache.hadoop.gateway.descriptor.FilterParamDescriptor;
 import org.apache.hadoop.gateway.descriptor.ResourceDescriptor;
 import org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter;
+import org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaDispatchFilter;
 import org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaHttpClientDispatch;
 import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
@@ -54,13 +55,12 @@ public class NameNodeHaDispatchDeploymentContributor extends ProviderDeploymentC
       if (params == null) {
          params = new ArrayList<FilterParamDescriptor>();
       }
-      params.add(resource.createFilterParam().name(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE).value(resource.role()));
+//      params.add(resource.createFilterParam().name(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE).value(resource.role()));
       Map<String, String> providerParams = provider.getParams();
       for (Map.Entry<String, String> entry : providerParams.entrySet()) {
          params.add(resource.createFilterParam().name(entry.getKey().toLowerCase()).value(entry.getValue()));
       }
-      FilterDescriptor filter = resource.addFilter().name(getName()).role(getRole()).impl(GatewayDispatchFilter.class).params(params);
+      FilterDescriptor filter = resource.addFilter().name(getName()).role(getRole()).impl(WebHdfsHaDispatchFilter.class).params(params);
       filter.param().name(DISPATCH_IMPL_PARAM).value(WebHdfsHaHttpClientDispatch.class.getName());
-
    }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java
----------------------------------------------------------------------
diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java
b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java
new file mode 100644
index 0000000..be0fe18
--- /dev/null
+++ b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaDispatchFilter.java
@@ -0,0 +1,36 @@
+/**
+ * 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.gateway.hdfs.dispatch;
+
+import org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter;
+import org.apache.hadoop.gateway.ha.provider.HaProvider;
+import org.apache.hadoop.gateway.ha.provider.HaServletContextListener;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+
+public class WebHdfsHaDispatchFilter extends GatewayDispatchFilter {
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+    super.init(filterConfig);
+    HaProvider haProvider = HaServletContextListener.getHaProvider(filterConfig.getServletContext());
+    ((WebHdfsHaHttpClientDispatch)getDispatch()).setHaProvider(haProvider);
+    getDispatch().init();
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java
b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java
index 800b9ff..c5ed82c 100644
--- a/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java
+++ b/gateway-service-webhdfs/src/main/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatch.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
 import org.apache.hadoop.gateway.ha.provider.HaProvider;
 import org.apache.hadoop.gateway.ha.provider.HaServiceConfig;
 import org.apache.hadoop.gateway.ha.provider.HaServletContextListener;
+import org.apache.hadoop.gateway.ha.provider.impl.HaServiceConfigConstants;
 import org.apache.hadoop.gateway.hdfs.i18n.WebHdfsMessages;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.http.HttpResponse;
@@ -43,19 +44,17 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch {
 
    private static final String RETRY_COUNTER_ATTRIBUTE = "dispatch.ha.retry.counter";
 
-   public static final String RESOURCE_ROLE_ATTRIBUTE = "resource.role";
+   public static final String RESOURCE_ROLE = "WEBHDFS";
 
    private static final WebHdfsMessages LOG = MessagesFactory.get(WebHdfsMessages.class);
 
-   private int maxFailoverAttempts;
+   private int maxFailoverAttempts = HaServiceConfigConstants.DEFAULT_MAX_FAILOVER_ATTEMPTS;
 
-   private int failoverSleep;
+   private int failoverSleep = HaServiceConfigConstants.DEFAULT_FAILOVER_SLEEP;
 
-   private int maxRetryAttempts;
+   private int maxRetryAttempts = HaServiceConfigConstants.DEFAULT_MAX_RETRY_ATTEMPTS;
 
-   private int retrySleep;
-
-   private String resourceRole;
+   private int retrySleep = HaServiceConfigConstants.DEFAULT_RETRY_SLEEP;
 
    private HaProvider haProvider;
 
@@ -69,17 +68,24 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch {
    @Override
    public void init() {
      super.init();
-//      resourceRole = filterConfig.getInitParameter(RESOURCE_ROLE_ATTRIBUTE);
-//      LOG.initializingForResourceRole(resourceRole);
-//      haProvider = HaServletContextListener.getHaProvider(filterConfig.getServletContext());
-//      HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(resourceRole);
-//      maxFailoverAttempts = serviceConfig.getMaxFailoverAttempts();
-//      failoverSleep = serviceConfig.getFailoverSleep();
-//      maxRetryAttempts = serviceConfig.getMaxRetryAttempts();
-//      retrySleep = serviceConfig.getRetrySleep();
+     if (haProvider != null) {
+       HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(RESOURCE_ROLE);
+       maxFailoverAttempts = serviceConfig.getMaxFailoverAttempts();
+       failoverSleep = serviceConfig.getFailoverSleep();
+       maxRetryAttempts = serviceConfig.getMaxRetryAttempts();
+       retrySleep = serviceConfig.getRetrySleep();
+     }
    }
 
-   @Override
+  public HaProvider getHaProvider() {
+    return haProvider;
+  }
+
+  public void setHaProvider(HaProvider haProvider) {
+    this.haProvider = haProvider;
+  }
+
+  @Override
    protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest,
HttpServletResponse outboundResponse) throws IOException {
       HttpResponse inboundResponse = null;
       try {
@@ -126,7 +132,7 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch {
       }
       inboundRequest.setAttribute(FAILOVER_COUNTER_ATTRIBUTE, counter);
       if (counter.incrementAndGet() <= maxFailoverAttempts) {
-         haProvider.markFailedURL(resourceRole, outboundRequest.getURI().toString());
+         haProvider.markFailedURL(RESOURCE_ROLE, outboundRequest.getURI().toString());
          //null out target url so that rewriters run again
          inboundRequest.setAttribute(AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME,
null);
          URI uri = getDispatchUrl(inboundRequest);
@@ -135,12 +141,12 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch {
             try {
                Thread.sleep(failoverSleep);
             } catch (InterruptedException e) {
-               LOG.failoverSleepFailed(resourceRole, e);
+               LOG.failoverSleepFailed(RESOURCE_ROLE, e);
             }
          }
          executeRequest(outboundRequest, inboundRequest, outboundResponse);
       } else {
-         LOG.maxFailoverAttemptsReached(maxFailoverAttempts, resourceRole);
+         LOG.maxFailoverAttemptsReached(maxFailoverAttempts, RESOURCE_ROLE);
          if (inboundResponse != null) {
             writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse);
          } else {
@@ -161,12 +167,12 @@ public class WebHdfsHaHttpClientDispatch extends HdfsDispatch {
             try {
                Thread.sleep(retrySleep);
             } catch (InterruptedException e) {
-               LOG.retrySleepFailed(resourceRole, e);
+               LOG.retrySleepFailed(RESOURCE_ROLE, e);
             }
          }
          executeRequest(outboundRequest, inboundRequest, outboundResponse);
       } else {
-         LOG.maxRetryAttemptsReached(maxRetryAttempts, resourceRole, outboundRequest.getURI().toString());
+         LOG.maxRetryAttemptsReached(maxRetryAttempts, RESOURCE_ROLE, outboundRequest.getURI().toString());
          if (inboundResponse != null) {
             writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse);
          } else {

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java
b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java
index b3d99c6..757288f 100644
--- a/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java
+++ b/gateway-service-webhdfs/src/test/java/org/apache/hadoop/gateway/hdfs/dispatch/WebHdfsHaHttpClientDispatchTest.java
@@ -70,7 +70,6 @@ public class WebHdfsHaHttpClientDispatchTest {
      EasyMock.expect(context.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(haProvider).anyTimes();
      FilterConfig config = EasyMock.createNiceMock( FilterConfig.class );
      EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes();
-     EasyMock.expect(config.getInitParameter( WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE
)).andReturn("test-role").anyTimes();
      EasyMock.expect(config.getInitParameter(EasyMock.anyObject(String.class))).andReturn(null).anyTimes();
      InstrumentedWebHdfsHaHttpClientDispatch dispatch = new InstrumentedWebHdfsHaHttpClientDispatch();
      EasyMock.replay(context,config);
@@ -95,7 +94,6 @@ public class WebHdfsHaHttpClientDispatchTest {
       FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
       ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
 
-      EasyMock.expect(filterConfig.getInitParameter(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE)).andReturn(serviceName).anyTimes();
       EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
       EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(provider).anyTimes();
 
@@ -127,6 +125,7 @@ public class WebHdfsHaHttpClientDispatchTest {
       Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
       WebHdfsHaHttpClientDispatch dispatch = new WebHdfsHaHttpClientDispatch();
       dispatch.setHttpClient(new DefaultHttpClient());
+      dispatch.setHaProvider(provider);
       dispatch.init();
       long startTime = System.currentTimeMillis();
       try {
@@ -135,9 +134,8 @@ public class WebHdfsHaHttpClientDispatchTest {
         //this is expected after the failover limit is reached
       }
       long elapsedTime = System.currentTimeMillis() - startTime;
-     //TODO: [sumit] fix HA after wiring up config for the HA dispatch
-//      Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName));
+      Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName));
       //test to make sure the sleep took place
-//      Assert.assertTrue(elapsedTime > 1000);
+      Assert.assertTrue(elapsedTime > 1000);
    }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/38406df0/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
index 8f8f236..31a370a 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
@@ -69,7 +69,7 @@ public class DeploymentFactoryFuncTest {
 
 //    ((GatewayTestConfig) config).setDeploymentDir( "clusters" );
 
-    addStacksDir(config, gatewayDir);
+    addStacksDir(config, targetDir);
     DefaultGatewayServices srvcs = new DefaultGatewayServices();
     Map<String,String> options = new HashMap<String,String>();
     options.put("persist-master", "false");
@@ -123,7 +123,7 @@ public class DeploymentFactoryFuncTest {
     ((GatewayTestConfig) config).setGatewayHomeDir( gatewayDir.getAbsolutePath() );
     File deployDir = new File( config.getGatewayDeploymentDir() );
     deployDir.mkdirs();
-    addStacksDir(config, gatewayDir);
+    addStacksDir(config, targetDir);
 
     DefaultGatewayServices srvcs = new DefaultGatewayServices();
     Map<String,String> options = new HashMap<String,String>();
@@ -178,7 +178,7 @@ public class DeploymentFactoryFuncTest {
     ((GatewayTestConfig) config).setGatewayHomeDir( gatewayDir.getAbsolutePath() );
     File deployDir = new File( config.getGatewayDeploymentDir() );
     deployDir.mkdirs();
-    addStacksDir(config, gatewayDir);
+    addStacksDir(config, targetDir);
 
     DefaultGatewayServices srvcs = new DefaultGatewayServices();
     Map<String,String> options = new HashMap<String,String>();


Mime
View raw message