Class UsersLoadBalancer


  • public class UsersLoadBalancer
    extends Object
    This load balancer allows to assign a user to a specific node with help of a special cookie jetbrains.buildServer.xmlrpc.XmlRpcConstants#NODE_ID_COOKIE. This cookie should also be supported on the HTTP proxy side.
    Since:
    2022.10
    • Constructor Detail

      • UsersLoadBalancer

        public UsersLoadBalancer​(@NotNull
                                 TeamCityNodes teamCityNodes)
    • Method Detail

      • assignUnauthenticatedRequestToNode

        public String assignUnauthenticatedRequestToNode​(@NotNull
                                                         javax.servlet.http.HttpServletRequest request,
                                                         @NotNull
                                                         javax.servlet.http.HttpServletResponse response)
      • assignAuthenticatedUserToNode

        @Nullable
        public String assignAuthenticatedUserToNode​(@NotNull
                                                    SUser user,
                                                    @NotNull
                                                    javax.servlet.http.HttpServletRequest request,
                                                    @Nullable
                                                    javax.servlet.http.HttpServletResponse response)
        Tries to assign further requests from a user to some other node, by setting a cookie. Result of the assignment attempt should be handled separately. For regular authentication through login pages, the redirect to the corresponding node is made by the page itself. No additional actions should be performed For passthrough (as in jetbrains.buildServer.controllers.interceptors.AuthorizationInterceptorImpl) the explicit redirect to the node must be made (see ProxyLoginSupport#sendRedirect)
        Parameters:
        user - user
        request - request
        response - response
        Returns:
        id of the node if assignment was made to some other node (as it require further processing), null if no node assignment was made
        See Also:
        WebLoginModelImpl.doLogin(boolean, HttpServletRequest, HttpServletResponse, Supplier), AuthorizationInterceptorImpl.preHandle(HttpServletRequest, HttpServletResponse, Object)
      • isEnabled

        public static boolean isEnabled​(@NotNull
                                        javax.servlet.http.HttpServletRequest request)
      • sendRedirect

        public static void sendRedirect​(@NotNull
                                        javax.servlet.http.HttpServletRequest request,
                                        @NotNull
                                        javax.servlet.http.HttpServletResponse response,
                                        @NotNull
                                        String nodeId)
                                 throws IOException
        Sends redirect to the same URL the initial request came from. Adds PARAM_REDIRECTED to the query string to prevent infinite redirects
        Parameters:
        request - initial request
        response - response
        Throws:
        IOException - if something goes wrong
      • shouldRedirect

        public static boolean shouldRedirect​(@NotNull
                                             javax.servlet.http.HttpServletRequest request,
                                             @NotNull
                                             String nodeId)
        Checks whether redirect to the initial request's URL is required
        See Also:
        UsersLoadBalancer#sendRedirect(HttpServletRequest, HttpServletResponse), NODE_ID_PARAM