Skip to content

Commit

Permalink
[grid] Nodes now only need to know about the EventBus
Browse files Browse the repository at this point in the history
Whether this makes life easier for folks is an open
question, but it now means that implementors of new
nodes don't need to take a dependency on the
distributor.
  • Loading branch information
shs96c committed Feb 20, 2019
1 parent 967f3a1 commit 73b27b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
2 changes: 0 additions & 2 deletions java/server/src/org/openqa/selenium/grid/node/httpd/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ java_library(
"//java/server/src/org/openqa/selenium/cli:cli",
"//java/server/src/org/openqa/selenium/concurrent:concurrent",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
"//java/server/src/org/openqa/selenium/grid/distributor/remote:remote",
"//java/server/src/org/openqa/selenium/grid/node:node",
"//java/server/src/org/openqa/selenium/grid/node/local:local",
"//java/server/src/org/openqa/selenium/grid/server:server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.openqa.selenium.grid.node.httpd;

import static org.openqa.selenium.net.Urls.fromUri;

import com.google.auto.service.AutoService;

import com.beust.jcommander.JCommander;
Expand All @@ -27,14 +25,13 @@
import org.openqa.selenium.cli.CliCommand;
import org.openqa.selenium.concurrent.Regularly;
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.grid.component.HealthCheck;
import org.openqa.selenium.grid.config.AnnotatedConfig;
import org.openqa.selenium.grid.config.CompoundConfig;
import org.openqa.selenium.grid.config.ConcatenatingConfig;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.EnvConfig;
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.DistributorOptions;
import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;
import org.openqa.selenium.grid.data.NodeStatusEvent;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.node.local.LocalNode;
import org.openqa.selenium.grid.node.local.NodeFlags;
Expand All @@ -51,9 +48,7 @@
import org.openqa.selenium.remote.tracing.DistributedTracer;
import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;

import java.net.URL;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

@AutoService(CliCommand.class)
Expand Down Expand Up @@ -130,31 +125,22 @@ public Executable configure(String... args) {
nodeFlags.configure(config, clientFactory, builder);
LocalNode node = builder.build();

DistributorOptions distributorOptions = new DistributorOptions(config);
URL distributorUrl = fromUri(distributorOptions.getDistributorUri());
Distributor distributor = new RemoteDistributor(
tracer,
clientFactory,
distributorUrl);

Server<?> server = new BaseServer<>(serverOptions);
server.addRoute(Routes.matching(node).using(node).decorateWith(W3CCommandHandler.class));
server.start();

Regularly regularly = new Regularly("Register Node with Distributor");

AtomicBoolean registered = new AtomicBoolean(false);

regularly.submit(
() -> {
boolean previously = registered.get();
registered.set(false);

distributor.add(node);
registered.set(true);
if (!previously) {
LOG.info("Successfully registered with distributor");
HealthCheck.Result check = node.getHealthCheck().check();
if (!check.isAlive()) {
LOG.info("Node is not alive: " + check.getMessage());
// Throw an exception to force another check sooner.
throw new UnsupportedOperationException("Node cannot be registered");
}

bus.fire(new NodeStatusEvent(node.getStatus()));
},
Duration.ofMinutes(5),
Duration.ofSeconds(30));
Expand Down
16 changes: 0 additions & 16 deletions java/server/src/org/openqa/selenium/grid/node/local/NodeFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@

public class NodeFlags {

@Parameter(names = {"--distributor", "-d"}, description = "Address of the distributor.")
@ConfigValue(section = "distributor", name = "host")
private URI distributorServer;

@Parameter(
names = "--distributor-port",
description = "Port on which the distributor is listening.")
@ConfigValue(section = "distributor", name = "port")
private int distributorServerPort;

@Parameter(
names = "--distributor-host",
description = "Port on which the distributor is listening.")
@ConfigValue(section = "distributor", name = "hostname")
private String distributorServerHost;

@Parameter(
names = {"--detect-drivers"},
description = "Autodetect which drivers are available on the current system, and add them to the node.")
Expand Down

0 comments on commit 73b27b8

Please sign in to comment.