1717
1818package org .openqa .selenium .grid .router .httpd ;
1919
20- import static java .net .HttpURLConnection .HTTP_NO_CONTENT ;
21- import static org .openqa .selenium .grid .config .StandardGridRoles .DISTRIBUTOR_ROLE ;
22- import static org .openqa .selenium .grid .config .StandardGridRoles .HTTPD_ROLE ;
23- import static org .openqa .selenium .grid .config .StandardGridRoles .ROUTER_ROLE ;
24- import static org .openqa .selenium .grid .config .StandardGridRoles .SESSION_MAP_ROLE ;
25- import static org .openqa .selenium .grid .config .StandardGridRoles .SESSION_QUEUE_ROLE ;
26- import static org .openqa .selenium .net .Urls .fromUri ;
27- import static org .openqa .selenium .remote .http .Route .combine ;
28- import static org .openqa .selenium .remote .http .Route .get ;
29-
3020import com .google .auto .service .AutoService ;
3121import com .google .common .collect .ImmutableMap ;
3222import com .google .common .collect .ImmutableSet ;
5949import org .openqa .selenium .grid .web .GridUiRoute ;
6050import org .openqa .selenium .internal .Require ;
6151import org .openqa .selenium .remote .http .ClientConfig ;
52+ import org .openqa .selenium .remote .http .Contents ;
6253import org .openqa .selenium .remote .http .HttpClient ;
54+ import org .openqa .selenium .remote .http .HttpHandler ;
6355import org .openqa .selenium .remote .http .HttpResponse ;
6456import org .openqa .selenium .remote .http .Routable ;
6557import org .openqa .selenium .remote .http .Route ;
7163import java .util .Set ;
7264import java .util .logging .Logger ;
7365
66+ import static java .net .HttpURLConnection .HTTP_OK ;
67+ import static java .net .HttpURLConnection .HTTP_UNAVAILABLE ;
68+ import static org .openqa .selenium .grid .config .StandardGridRoles .DISTRIBUTOR_ROLE ;
69+ import static org .openqa .selenium .grid .config .StandardGridRoles .HTTPD_ROLE ;
70+ import static org .openqa .selenium .grid .config .StandardGridRoles .ROUTER_ROLE ;
71+ import static org .openqa .selenium .grid .config .StandardGridRoles .SESSION_MAP_ROLE ;
72+ import static org .openqa .selenium .grid .config .StandardGridRoles .SESSION_QUEUE_ROLE ;
73+ import static org .openqa .selenium .net .Urls .fromUri ;
74+ import static org .openqa .selenium .remote .http .Route .combine ;
75+ import static org .openqa .selenium .remote .http .Route .get ;
76+
7477@ AutoService (CliCommand .class )
7578public class RouterServer extends TemplateGridServerCommand {
7679
@@ -154,8 +157,8 @@ protected Handlers createHandlers(Config config) {
154157 getServerVersion ());
155158
156159 Routable ui = new GridUiRoute ();
157- Routable routerWithSpecChecks = new Router (tracer , clientFactory , sessions , queue , distributor )
158- .with (networkOptions .getSpecComplianceChecks ());
160+ Router router = new Router (tracer , clientFactory , sessions , queue , distributor );
161+ Routable routerWithSpecChecks = router .with (networkOptions .getSpecComplianceChecks ());
159162
160163 Routable route = Route .combine (
161164 ui ,
@@ -170,10 +173,17 @@ protected Handlers createHandlers(Config config) {
170173 route = route .with (new BasicAuthenticationFilter (uap .username (), uap .password ()));
171174 }
172175
176+ HttpHandler readinessCheck = req -> {
177+ boolean ready = router .isReady ();
178+ return new HttpResponse ()
179+ .setStatus (ready ? HTTP_OK : HTTP_UNAVAILABLE )
180+ .setContent (Contents .utf8String ("Router is " + ready ));
181+ };
182+
173183 // Since k8s doesn't make it easy to do an authenticated liveness probe, allow unauthenticated access to it.
174184 Routable routeWithLiveness = Route .combine (
175185 route ,
176- get ("/readyz" ).to (() -> req -> new HttpResponse (). setStatus ( HTTP_NO_CONTENT ) ));
186+ get ("/readyz" ).to (() -> readinessCheck ));
177187
178188 return new Handlers (routeWithLiveness , new ProxyWebsocketsIntoGrid (clientFactory , sessions ));
179189 }
0 commit comments