This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new e8e7cbd KNOX-2061 - ConfigurableHADispatch needs to be wired up
e8e7cbd is described below
commit e8e7cbd03616e1a4ab7aa4c5bcf5632c57ed815d
Author: Kevin Risden <[email protected]>
AuthorDate: Tue Oct 15 12:44:09 2019 -0400
KNOX-2061 - ConfigurableHADispatch needs to be wired up
Signed-off-by: Kevin Risden <[email protected]>
---
.../ServiceDefinitionDeploymentContributor.java | 42 ++++++++++------------
.../main/resources/services/hue/1.0.0/service.xml | 5 +--
.../resources/services/ranger/1.0.0/service.xml | 3 +-
.../resources/services/rangerui/1.0.0/service.xml | 3 +-
4 files changed, 26 insertions(+), 27 deletions(-)
diff --git
a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
index 202fe1d..2e7bb00 100644
---
a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
+++
b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ServiceDefinitionDeploymentContributor.java
@@ -45,7 +45,6 @@ import java.util.Locale;
import java.util.Map;
public class ServiceDefinitionDeploymentContributor extends
ServiceDeploymentContributorBase {
-
private static final String DISPATCH_ROLE = "dispatch";
private static final String DISPATCH_IMPL_PARAM = "dispatch-impl";
@@ -128,7 +127,6 @@ public class ServiceDefinitionDeploymentContributor extends
ServiceDeploymentCon
e.printStackTrace();
}
}
-
}
private void contributeResource(DeploymentContext context, Service service,
Route binding, Map<String, String> filterParams) throws URISyntaxException {
@@ -139,17 +137,17 @@ public class ServiceDefinitionDeploymentContributor
extends ServiceDeploymentCon
//add x-forwarded filter if enabled in config
if (context.getGatewayConfig().isXForwardedEnabled()) {
final FilterDescriptor filter = resource.addFilter()
- .name(XFORWARDED_FILTER_NAME).role(XFORWARDED_FILTER_ROLE)
- .impl(XForwardedHeaderFilter.class);
+
.name(XFORWARDED_FILTER_NAME).role(XFORWARDED_FILTER_ROLE)
+ .impl(XForwardedHeaderFilter.class);
/* check if we need to add service name to the context */
if(service.getParams().containsKey(SERVICE_CONTEXT)) {
filter.param().name(APPEND_SERVICE_NAME_PARAM).value("true");
filter.param().name(SERVICE_CONTEXT).value(service.getParams().get(SERVICE_CONTEXT));
}
else if (context.getGatewayConfig().getXForwardContextAppendServices()
!= null
- && !context.getGatewayConfig().getXForwardContextAppendServices()
- .isEmpty() && context.getGatewayConfig()
- .getXForwardContextAppendServices().contains(service.getRole())) {
+ &&
!context.getGatewayConfig().getXForwardContextAppendServices()
+ .isEmpty() && context.getGatewayConfig()
+
.getXForwardContextAppendServices().contains(service.getRole())) {
filter.param().name(APPEND_SERVICE_NAME_PARAM).value("true");
}
}
@@ -260,14 +258,13 @@ public class ServiceDefinitionDeploymentContributor
extends ServiceDeploymentCon
private void addDefaultHaDispatchFilter(DeploymentContext context, Service
service, ResourceDescriptor resource,
Map<String, String> dispatchParams) {
- FilterDescriptor filter = addDispatchFilterForClass(context, service,
resource, DEFAULT_HA_DISPATCH_CLASS, null, dispatchParams);
- filter.param().name(SERVICE_ROLE_PARAM).value(service.getRole());
+ addDispatchFilterForClass(context, service, resource,
DEFAULT_HA_DISPATCH_CLASS, null, dispatchParams);
}
- private FilterDescriptor addDispatchFilterForClass(DeploymentContext
context, Service service,
- ResourceDescriptor
resource, String dispatchClass,
- String httpClientFactory,
boolean useTwoWaySsl,
- Map<String, String>
dispatchParams) {
+ private void addDispatchFilterForClass(DeploymentContext context, Service
service,
+ ResourceDescriptor resource, String
dispatchClass,
+ String httpClientFactory, boolean
useTwoWaySsl,
+ Map<String, String> dispatchParams) {
FilterDescriptor filter =
resource.addFilter().name(getName()).role(DISPATCH_ROLE).impl(GatewayDispatchFilter.class);
filter.param().name(DISPATCH_IMPL_PARAM).value(dispatchClass);
if (httpClientFactory != null) {
@@ -293,26 +290,25 @@ public class ServiceDefinitionDeploymentContributor
extends ServiceDeploymentCon
//special case for hive
filter.param().name("basicAuthPreemptive").value("true");
}
- return filter;
+
+ // Ensure that serviceRole is set in case of HA
+ filter.param().name(SERVICE_ROLE_PARAM).value(service.getRole());
}
- private FilterDescriptor addDispatchFilterForClass(DeploymentContext
context, Service service,
- ResourceDescriptor
resource, String dispatchClass,
- String httpClientFactory,
Map<String, String> dispatchParams) {
- return addDispatchFilterForClass(context, service, resource,
dispatchClass, httpClientFactory, false, dispatchParams);
+ private void addDispatchFilterForClass(DeploymentContext context, Service
service,
+ ResourceDescriptor resource, String
dispatchClass,
+ String httpClientFactory, Map<String,
String> dispatchParams) {
+ addDispatchFilterForClass(context, service, resource, dispatchClass,
httpClientFactory, false, dispatchParams);
}
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;
- }
+ if (params != null && params.containsKey(getRole())) {
+ return true;
}
}
return false;
}
-
}
diff --git
a/gateway-service-definitions/src/main/resources/services/hue/1.0.0/service.xml
b/gateway-service-definitions/src/main/resources/services/hue/1.0.0/service.xml
index 7694feb..b0285f6 100644
---
a/gateway-service-definitions/src/main/resources/services/hue/1.0.0/service.xml
+++
b/gateway-service-definitions/src/main/resources/services/hue/1.0.0/service.xml
@@ -49,10 +49,11 @@
<rewrite apply="HUE/hue/outbound/huerooturl" to="response.body"/>
</route>
</routes>
- <dispatch classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
ha-classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch">
+ <dispatch classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
+
ha-classname="org.apache.knox.gateway.ha.dispatch.ConfigurableHADispatch">
<param>
<name>responseExcludeHeaders</name>
<value>WWW-AUTHENTICATE</value>
</param>
</dispatch>
-</service>
\ No newline at end of file
+</service>
diff --git
a/gateway-service-definitions/src/main/resources/services/ranger/1.0.0/service.xml
b/gateway-service-definitions/src/main/resources/services/ranger/1.0.0/service.xml
index eddb5b3..9970034 100644
---
a/gateway-service-definitions/src/main/resources/services/ranger/1.0.0/service.xml
+++
b/gateway-service-definitions/src/main/resources/services/ranger/1.0.0/service.xml
@@ -22,7 +22,8 @@
<route path="/ranger/service/assets/**"/>
<route path="/ranger"/>
</routes>
- <dispatch
classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
ha-classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch">
+ <dispatch classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
+
ha-classname="org.apache.knox.gateway.ha.dispatch.ConfigurableHADispatch">
<param>
<name>responseExcludeHeaders</name>
<value>WWW-AUTHENTICATE</value>
diff --git
a/gateway-service-definitions/src/main/resources/services/rangerui/1.0.0/service.xml
b/gateway-service-definitions/src/main/resources/services/rangerui/1.0.0/service.xml
index 28c67b8..0e64b86 100644
---
a/gateway-service-definitions/src/main/resources/services/rangerui/1.0.0/service.xml
+++
b/gateway-service-definitions/src/main/resources/services/rangerui/1.0.0/service.xml
@@ -32,7 +32,8 @@
<rewrite apply="RANGERUI/rangerui/outbound/headers"
to="response.headers"/>
</route>
</routes>
- <dispatch
classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
ha-classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch">
+ <dispatch classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
+
ha-classname="org.apache.knox.gateway.ha.dispatch.ConfigurableHADispatch">
<param>
<name>responseExcludeHeaders</name>
<value>WWW-AUTHENTICATE</value>