public class HALoadBalancerServlet
extends org.eclipse.jetty.proxy.ProxyServlet
When successfully deployed, requests having prefix corresponding to the URL pattern for the load balancer (typically, "/bigdata/LBS/*") are automatically redirected to a joined service in the met quorum based on the configured load balancer policy.
The use of the load balancer is entirely optional. If the load balancer is not properly configured, then it will simply rewrite itself out of any request and the request will be handled by the host to which it was directed (no proxying).
Note: If the security rules permit, then clients MAY make requests directly against a specific service.
The load balancer policies are "HA aware." They will always redirect update requests to the quorum leader. Read requests will be directed to one of the services that is joined with the met quorum.
Modifier and Type | Class and Description |
---|---|
static interface |
HALoadBalancerServlet.InitParams |
Constructor and Description |
---|
HALoadBalancerServlet() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
protected URI |
doRewriteURI(javax.servlet.http.HttpServletRequest request)
Hook allows the servlet to rewrite the request.
|
void |
forwardToLocalService(boolean isLeaderRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Strip off the
/LBS prefix from the requestURI and forward
the request to the servlet at the resulting requestURI. |
static String |
getConfigParam(javax.servlet.ServletConfig servletConfig,
Class<?> owningClass,
String name,
String def)
Return the configured value of the named parameter.
|
IHALoadBalancerPolicy |
getLBSPolicy()
Return the current
IHALoadBalancerPolicy . |
void |
init() |
static <T> T |
newInstance(javax.servlet.ServletConfig servletConfig,
Class<?> owningClass,
Class<? extends T> iface,
String name,
String def)
Create an instance of some type based on the servlet init parameters.
|
protected void |
onProxyResponseFailure(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.eclipse.jetty.client.api.Response proxyResponse,
Throwable failure) |
protected void |
onProxyRewriteFailed(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Note: This offers an opportunity to handle a failure where we were unable
to rewrite the request to some service, e.g., because the quorum is not
met.
|
protected String |
rewriteTarget(javax.servlet.http.HttpServletRequest request)
Wrapper invokes
doRewriteURI(HttpServletRequest) and handles
any thrown exceptions. |
protected void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
void |
setLBSPolicy(IHALoadBalancerPolicy newValue)
Change the
IHALoadBalancerPolicy associated with this instance of
this servlet. |
static void |
setLBSPolicy(javax.servlet.ServletContext servletContext,
IHALoadBalancerPolicy newValue)
Set the current
IHALoadBalancerPolicy for all
HALoadBalancerServlet instances for the caller specified
ServletContext . |
void |
setRewriter(IHARequestURIRewriter newValue)
Change the
IHARequestURIRewriter associated with this instance of
this servlet. |
String |
toString() |
static String |
toString(javax.servlet.ServletContext servletContext)
Return the
IHALoadBalancerPolicy s that are in force for the
active HALoadBalancerServlet instances. |
newProxyResponseListener, onContinue, onResponseContent, proxyRequestContent
addProxyHeaders, addViaHeader, addXForwardedHeaders, copyRequestHeaders, createHttpClient, createLogger, expects100Continue, filterServerResponseHeader, findConnectionHeaders, getBlackListHosts, getHostHeader, getHttpClient, getRequestId, getTimeout, getViaHost, getWhiteListHosts, hasContent, newHttpClient, onClientRequestFailure, onProxyResponseSuccess, onServerResponseHeaders, sendProxyRequest, sendProxyResponseError, setTimeout, validateDestination
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public void setLBSPolicy(IHALoadBalancerPolicy newValue)
IHALoadBalancerPolicy
associated with this instance of
this servlet. The new policy will be installed iff it can be initialized
successfully. The old policy will be destroyed iff the new policy is
successfully installed.newValue
- The new value (required).public IHALoadBalancerPolicy getLBSPolicy()
IHALoadBalancerPolicy
.public void setRewriter(IHARequestURIRewriter newValue)
IHARequestURIRewriter
associated with this instance of
this servlet. The new policy will be installed iff it can be initialized
successfully. The old policy will be destroyed iff the new policy is
successfully installed.newValue
- The new value (required).public void init() throws javax.servlet.ServletException
Extended to setup the as-configured IHALoadBalancerPolicy
.
Note: If the deployment is does not support HA replication (e.g., either not HA or HA with replicationFactor:=1), then we still want to be able to forward to the local service.
init
in class org.eclipse.jetty.proxy.AbstractProxyServlet
javax.servlet.ServletException
public static void setLBSPolicy(javax.servlet.ServletContext servletContext, IHALoadBalancerPolicy newValue)
IHALoadBalancerPolicy
for all
HALoadBalancerServlet
instances for the caller specified
ServletContext
.servletContext
- The ServletContext
.newValue
- The new IHALoadBalancerPolicy
.IllegalArgumentException
- if the new policy is null
.public static String toString(javax.servlet.ServletContext servletContext)
IHALoadBalancerPolicy
s that are in force for the
active HALoadBalancerServlet
instances.servletContext
- The ServletContext
.IHALoadBalancerPolicy
[] -or- null
if
there are no HALoadBalancerServlet
s.public void destroy()
Extended to destroy the as-configured IHALoadBalancerPolicy
.
destroy
in interface javax.servlet.Servlet
destroy
in class org.eclipse.jetty.proxy.AbstractProxyServlet
public static String getConfigParam(javax.servlet.ServletConfig servletConfig, Class<?> owningClass, String name, String def)
null
). If no value is found for that
variable, it checks the ServletContext
for name (if the
owningClass:=HALoadBalancerServlet) and otherwise for
owningClass.name. If no value is found again, it returns the
default value specified by the caller. This makes it possible to
configure the behavior of the HALoadBalancerServlet
using
environment variables.servletConfig
- The ServletConfig
.owningClass
- The class that declares the init-param (required). This serves
as a namespace when searching the environment variables. This
is also used to impose a namespace when searching
web.xml
when
owningClass!=HALoadBalancerServlet
.name
- The name of the servlet init-param
.def
- The default value for the servlet init-param
.public static <T> T newInstance(javax.servlet.ServletConfig servletConfig, Class<?> owningClass, Class<? extends T> iface, String name, String def) throws javax.servlet.ServletException
Note: The configuration parameter MAY also be specified as
com.bigdata.rdf.sail.webapp.HALoadBalancerServlet.name
.
servletConfig
- The ServletConfig
.owningClass
- The class that declares the init-param. This serves as
a namespace when searching the environment variables.iface
- The interface that the type must implement.name
- The name of the servlet init parameter.def
- The default value for the servlet init parameter.javax.servlet.ServletException
- if anything goes wrong.protected void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
service
in class org.eclipse.jetty.proxy.ProxyServlet
javax.servlet.ServletException
IOException
public void forwardToLocalService(boolean isLeaderRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
/LBS
prefix from the requestURI and forward
the request to the servlet at the resulting requestURI. This forwarding
effectively disables the LBS but still allows requests which target the
LBS to succeed against the webapp on the same host.
Note: If the deployment is does not support HA replication (e.g., either not HA or HA with replicationFactor:=1), then we still want to be able to forward to the local service.
request
- The request.response
- The response.IOException
javax.servlet.ServletException
protected final String rewriteTarget(javax.servlet.http.HttpServletRequest request)
doRewriteURI(HttpServletRequest)
and handles
any thrown exceptions.rewriteTarget
in class org.eclipse.jetty.proxy.AbstractProxyServlet
doRewriteURI(HttpServletRequest)
protected URI doRewriteURI(javax.servlet.http.HttpServletRequest request)
request
- The request.URI
if the request should be proxied to
another service -or- null
if the request should be
locally forwarded.protected void onProxyRewriteFailed(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
onProxyRewriteFailed
in class org.eclipse.jetty.proxy.AbstractProxyServlet
protected void onProxyResponseFailure(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.eclipse.jetty.client.api.Response proxyResponse, Throwable failure)
Overridden to provide more information about the error. The
implementation is derived from the jetty 9.1.4 implementation of the
method in the base ProxyServlet
class, but logs @ ERROR so we can
see more about the underlying problem.
onProxyResponseFailure
in class org.eclipse.jetty.proxy.AbstractProxyServlet
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.