Skip to content

Commit

Permalink
[grid]: Migrate distributor flags to distributor.config
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Feb 20, 2019
1 parent 73b27b8 commit 6e34961
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 18 deletions.
17 changes: 17 additions & 0 deletions java/server/src/org/openqa/selenium/grid/distributor/config/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
java_library(
name = "config",
srcs = glob(["*.java"]),
exported_deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
],
deps = [
"//java/server/src/org/openqa/selenium/grid/distributor/remote:remote",
"//third_party/java/beust:jcommander",
],
visibility = [
"//java/server/src/org/openqa/selenium/grid/...",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.grid.distributor.config;


import com.beust.jcommander.Parameter;

import org.openqa.selenium.grid.config.ConfigValue;

import java.net.URI;

public class DistributorFlags {

@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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.grid.distributor;
package org.openqa.selenium.grid.distributor.config;

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

import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.tracing.DistributedTracer;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Optional;

public class DistributorOptions {
Expand Down Expand Up @@ -68,4 +75,12 @@ public URI getDistributorUri() {
port.get());
}
}

public Distributor getDistributor(DistributedTracer tracer, HttpClient.Factory clientFactory) {
URL distributorUrl = fromUri(getDistributorUri());
return new RemoteDistributor(
tracer,
clientFactory,
distributorUrl);
}
}
3 changes: 1 addition & 2 deletions java/server/src/org/openqa/selenium/grid/router/httpd/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ java_library(
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/cli:cli",
"//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/distributor/config:config",
"//java/server/src/org/openqa/selenium/grid/node/local:local",
"//java/server/src/org/openqa/selenium/grid/router:router",
"//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.router.httpd;

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

import com.google.auto.service.AutoService;

import com.beust.jcommander.JCommander;
Expand All @@ -31,10 +29,9 @@
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.distributor.config.DistributorFlags;
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.node.local.NodeFlags;
import org.openqa.selenium.grid.router.Router;
import org.openqa.selenium.grid.server.BaseServer;
import org.openqa.selenium.grid.server.BaseServerFlags;
Expand All @@ -50,8 +47,6 @@
import org.openqa.selenium.remote.tracing.DistributedTracer;
import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;

import java.net.URL;

@AutoService(CliCommand.class)
public class RouterServer implements CliCommand {

Expand All @@ -71,14 +66,14 @@ public Executable configure(String... args) {
HelpFlags help = new HelpFlags();
BaseServerFlags serverFlags = new BaseServerFlags(4444);
SessionMapFlags sessionMapFlags = new SessionMapFlags();
NodeFlags nodeFlags = new NodeFlags();
DistributorFlags distributorFlags = new DistributorFlags();

JCommander commander = JCommander.newBuilder()
.programName(getName())
.addObject(help)
.addObject(serverFlags)
.addObject(sessionMapFlags)
.addObject(nodeFlags)
.addObject(distributorFlags)
.build();

return () -> {
Expand All @@ -100,7 +95,7 @@ public Executable configure(String... args) {
new AnnotatedConfig(help),
new AnnotatedConfig(serverFlags),
new AnnotatedConfig(sessionMapFlags),
new AnnotatedConfig(nodeFlags));
new AnnotatedConfig(distributorFlags));

LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();
Expand All @@ -115,11 +110,7 @@ public Executable configure(String... args) {
BaseServerOptions serverOptions = new BaseServerOptions(config);

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

Router router = new Router(tracer, clientFactory, sessions, distributor);

Expand Down

0 comments on commit 6e34961

Please sign in to comment.