[grid] Add `/status` end point to DistributorServer
package org.openqa.selenium.grid.distributor.httpd;
import com.google.auto.service.AutoService;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.openqa.selenium.BuildInfo;
import org.openqa.selenium.cli.CliCommand;
import org.openqa.selenium.grid.sessionmap.SessionMap;
import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;
import org.openqa.selenium.netty.server.NettyServer;
+import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpClient;
+import org.openqa.selenium.remote.http.HttpResponse;
+import org.openqa.selenium.remote.http.Route;
import org.openqa.selenium.remote.tracing.Tracer;
import java.util.Collections;
import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_MAP_ROLE;
+import static org.openqa.selenium.remote.http.HttpMethod.GET;
@AutoService(CliCommand.class)
public class DistributorServer extends TemplateGridCommand {
@@ -103,7 +108,16 @@ protected void execute(Config config) {
sessions,
serverOptions.getRegistrationSecret());
- Server<?> server = new NettyServer(serverOptions, distributor);
+ Route handler = Route.combine(
+ distributor,
+ Route.matching(req -> GET.equals(req.getMethod()) && "/status".equals(req.getUri()))
+ .to(() -> req -> new HttpResponse()
+ .setContent(Contents.asJson(
+ ImmutableMap.of("value", ImmutableMap.of(
+ "ready", true,
+ "message", "Distributor is ready"))))));
+
+ Server<?> server = new NettyServer(serverOptions, handler);
server.start();
BuildInfo info = new BuildInfo();
