Skip to content

Commit

Permalink
[grid] Provide sensible default values for the event bus config
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Feb 1, 2019
1 parent 200d01b commit e90e832
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.commands;

import com.google.common.collect.ImmutableMap;

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

class DefaultHubConfig extends MapConfig {

DefaultHubConfig() {
super(ImmutableMap.of(
"events", ImmutableMap.of(
"address", "tcp://*:4443",
"bind", true)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.commands;

import com.google.common.collect.ImmutableMap;

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

class DefaultStandaloneConfig extends MapConfig {

DefaultStandaloneConfig() {
super(ImmutableMap.of(
"events", ImmutableMap.of(
"address", "inproc://standalone",
"bind", true)));
}

}
7 changes: 6 additions & 1 deletion java/server/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openqa.selenium.grid.server.BaseServerFlags;
import org.openqa.selenium.grid.server.BaseServerOptions;
import org.openqa.selenium.grid.server.EventBusConfig;
import org.openqa.selenium.grid.server.EventBusFlags;
import org.openqa.selenium.grid.server.HelpFlags;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.server.Server;
Expand Down Expand Up @@ -65,11 +66,13 @@ public String getDescription() {
public Executable configure(String... args) {
HelpFlags help = new HelpFlags();
BaseServerFlags baseFlags = new BaseServerFlags(4444);
EventBusFlags eventBusFlags = new EventBusFlags();
NodeFlags nodeFlags = new NodeFlags();

JCommander commander = JCommander.newBuilder()
.programName("standalone")
.addObject(baseFlags)
.addObject(eventBusFlags)
.addObject(help)
.addObject(nodeFlags)
.build();
Expand All @@ -91,7 +94,9 @@ public Executable configure(String... args) {
new EnvConfig(),
new ConcatenatingConfig("selenium", '.', System.getProperties()),
new AnnotatedConfig(help),
new AnnotatedConfig(baseFlags));
new AnnotatedConfig(eventBusFlags),
new AnnotatedConfig(baseFlags),
new DefaultHubConfig());

LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getDescription() {
public Executable configure(String... args) {
HelpFlags help = new HelpFlags();
BaseServerFlags baseFlags = new BaseServerFlags(4444);
EventBusFlags eventFlags = new EventBusFlags(4443);
EventBusFlags eventFlags = new EventBusFlags();
NodeFlags nodeFlags = new NodeFlags();

JCommander commander = JCommander.newBuilder()
Expand Down Expand Up @@ -102,7 +102,8 @@ public Executable configure(String... args) {
new ConcatenatingConfig("selenium", '.', System.getProperties()),
new AnnotatedConfig(help),
new AnnotatedConfig(baseFlags),
new AnnotatedConfig(eventFlags));
new AnnotatedConfig(eventFlags),
new DefaultStandaloneConfig());

LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.httpd;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.MapConfig;

import java.util.Map;

class DefaultDistributorConfig extends MapConfig {

DefaultDistributorConfig() {
super(ImmutableMap.of(
"events", ImmutableMap.of(
"address", "tcp://*:4443",
"bind", true)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openqa.selenium.grid.server.BaseServerFlags;
import org.openqa.selenium.grid.server.BaseServerOptions;
import org.openqa.selenium.grid.server.EventBusConfig;
import org.openqa.selenium.grid.server.EventBusFlags;
import org.openqa.selenium.grid.server.HelpFlags;
import org.openqa.selenium.grid.server.Server;
import org.openqa.selenium.grid.server.W3CCommandHandler;
Expand Down Expand Up @@ -63,6 +64,7 @@ public Executable configure(String... args) {

HelpFlags help = new HelpFlags();
BaseServerFlags serverFlags = new BaseServerFlags(5553);
EventBusFlags eventBusFlags = new EventBusFlags();

JCommander commander = JCommander.newBuilder()
.programName(getName())
Expand All @@ -87,7 +89,9 @@ public Executable configure(String... args) {
new EnvConfig(),
new ConcatenatingConfig("distributor", '.', System.getProperties()),
new AnnotatedConfig(help),
new AnnotatedConfig(serverFlags));
new AnnotatedConfig(eventBusFlags),
new AnnotatedConfig(serverFlags),
new DefaultDistributorConfig());

LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.node.httpd;

import com.google.common.collect.ImmutableMap;

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

class DefaultNodeConfig extends MapConfig {

DefaultNodeConfig() {
super(ImmutableMap.of(
"events", ImmutableMap.of(
"address", "tcp://*:4443")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.openqa.selenium.grid.server.BaseServerFlags;
import org.openqa.selenium.grid.server.BaseServerOptions;
import org.openqa.selenium.grid.server.EventBusConfig;
import org.openqa.selenium.grid.server.EventBusFlags;
import org.openqa.selenium.grid.server.HelpFlags;
import org.openqa.selenium.grid.server.Server;
import org.openqa.selenium.grid.server.W3CCommandHandler;
Expand Down Expand Up @@ -76,12 +77,14 @@ public Executable configure(String... args) {

HelpFlags help = new HelpFlags();
BaseServerFlags serverFlags = new BaseServerFlags(5555);
EventBusFlags eventBusFlags = new EventBusFlags();
NodeFlags nodeFlags = new NodeFlags();

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

Expand All @@ -103,7 +106,9 @@ public Executable configure(String... args) {
new ConcatenatingConfig("node", '.', System.getProperties()),
new AnnotatedConfig(help),
new AnnotatedConfig(serverFlags),
new AnnotatedConfig(nodeFlags));
new AnnotatedConfig(eventBusFlags),
new AnnotatedConfig(nodeFlags),
new DefaultNodeConfig());

LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import org.zeromq.ZContext;

import java.util.Objects;
import java.util.logging.Logger;

public class EventBusConfig {

public static final Logger LOG = Logger.getLogger(EventBus.class.getName());
private final Config config;
private EventBus bus;

Expand All @@ -37,13 +39,18 @@ public EventBus getEventBus() {
String connection = config.get("events", "address")
.orElseThrow(() -> new IllegalArgumentException(
"Unable to determine event bus connection string"));
Boolean bind = config.getBool("events", "bind").orElse(false);
boolean bind = config.getBool("events", "bind").orElse(false);

if (bus == null) {
synchronized (this) {
if (bus == null) {
LOG.fine("Creating new event bus");
ZContext context = new ZContext();
bus = ZeroMqEventBus.create(context, connection, bind);
LOG.info(String.format(
"Started event bus. %s to %s",
(bind ? "Bound" : "Connected"),
connection));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public class EventBusFlags {
private String connectionString;

@Parameter(
names = {"--bus-server"},
names = {"--bind-bus"},
description = "Whether the connection string should be bound or connected")
@ConfigValue(section = "events", name = "bind")
// We use the Boolean here so we can differentiate between there being no option, and a default
// false value.
private boolean bind;

public EventBusFlags(int defaultPort) {
this.connectionString = "tcp://*:" + defaultPort;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.sessionmap.httpd;

import com.google.common.collect.ImmutableMap;

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

class DefaultSessionMapConfig extends MapConfig {

public DefaultSessionMapConfig() {
super(ImmutableMap.of(
"events", ImmutableMap.of(
"address", "tcp://*:4443")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openqa.selenium.grid.server.BaseServerFlags;
import org.openqa.selenium.grid.server.BaseServerOptions;
import org.openqa.selenium.grid.server.EventBusConfig;
import org.openqa.selenium.grid.server.EventBusFlags;
import org.openqa.selenium.grid.server.HelpFlags;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.server.Server;
Expand Down Expand Up @@ -62,11 +63,13 @@ public Executable configure(String... args) {

HelpFlags help = new HelpFlags();
BaseServerFlags serverFlags = new BaseServerFlags(5556);
EventBusFlags eventBusFlags = new EventBusFlags();

JCommander commander = JCommander.newBuilder()
.programName(getName())
.addObject(help)
.addObject(serverFlags)
.addObject(eventBusFlags)
.build();

return () -> {
Expand All @@ -86,7 +89,9 @@ public Executable configure(String... args) {
new EnvConfig(),
new ConcatenatingConfig("sessions", '.', System.getProperties()),
new AnnotatedConfig(help),
new AnnotatedConfig(serverFlags));
new AnnotatedConfig(serverFlags),
new AnnotatedConfig(eventBusFlags),
new DefaultSessionMapConfig());

LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();
Expand Down

0 comments on commit e90e832

Please sign in to comment.