Class ExternalLoadBalancerInterceptor

  • All Implemented Interfaces:
    org.springframework.web.servlet.AsyncHandlerInterceptor, org.springframework.web.servlet.HandlerInterceptor

    public class ExternalLoadBalancerInterceptor
    extends Object
    implements org.springframework.web.servlet.AsyncHandlerInterceptor
    Interceptor, responsible for managing requests that come from external load balancers When external proxy is used to route requests between agents and multi-node TeamCity setup, the agents use cookies to hint proxy where to route the request. On the server side, we check whether the request landed on a node which is responsible for the build that produced the request or not. If the request has landed on a responsible node, ExternalLoadBalancerInterceptor prolongs the lifetime of the cookie by the value of PROPERTY_MULTI_NODE_COOKIE_LONG_LIFETIME property If (when the responsible node is down) the request has landed on another node for the first time, ExternalLoadBalancerInterceptor sets a new cookie lifetime with value of PROPERTY_MULTI_NODE_COOKIE_SHORT_LIFETIME and refuses to process the request by sending HttpStatus.SC_SERVICE_UNAVAILABLE. When the cookie expires and the request without cookie lands on any node that is capable of taking the responsibility for the build, the build is reassigned to this node, a new cookie with PROPERTY_MULTI_NODE_COOKIE_LONG_LIFETIME is set and the node proceeds with processing the request.
    Author:
    Oleg Rybak (oleg.rybak@jetbrains.com)
    See Also:
    TW-66859 issue in YouTrack
    • Method Detail

      • preHandle

        public boolean preHandle​(@NotNull
                                 javax.servlet.http.HttpServletRequest request,
                                 @NotNull
                                 javax.servlet.http.HttpServletResponse response,
                                 @NotNull
                                 Object handler)
                          throws Exception
        Specified by:
        preHandle in interface org.springframework.web.servlet.HandlerInterceptor
        Throws:
        Exception
      • getShortCookieLifetimeMillis

        public long getShortCookieLifetimeMillis()
      • getLongCookieLifetimeMillis

        public long getLongCookieLifetimeMillis()