Skip to content

Commit 9e9caf4

Browse files
committed
[grid] Add redis grid model flags
1 parent b64deb3 commit 9e9caf4

File tree

9 files changed

+276
-82
lines changed

9 files changed

+276
-82
lines changed

java/server/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public class DistributorOptions {
3333

3434
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 300;
35-
static final String DISTRIBUTOR_SECTION = "distributor";
35+
public static final String DISTRIBUTOR_SECTION = "distributor";
3636
static final String DEFAULT_DISTRIBUTOR_IMPLEMENTATION =
3737
"org.openqa.selenium.grid.distributor.local.LocalDistributor";
3838
static final String DEFAULT_SLOT_MATCHER = "org.openqa.selenium.grid.data.DefaultSlotMatcher";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//java:defs.bzl", "java_library")
3+
4+
java_library(
5+
name = "gridmodel",
6+
srcs = glob(["*.java"]),
7+
visibility = [
8+
"//java/server/src/org/openqa/selenium/grid/commands:__pkg__",
9+
"//java/server/src/org/openqa/selenium/grid/distributor:__pkg__",
10+
"//java/server/src/org/openqa/selenium/grid/distributor:__subpackages__",
11+
]
12+
)

java/server/src/org/openqa/selenium/grid/distributor/gridmodel/local/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ java_library(
1717
"//java/server/src/org/openqa/selenium/grid/data",
1818
"//java/server/src/org/openqa/selenium/grid/distributor",
1919
"//java/server/src/org/openqa/selenium/grid/node",
20+
"//java/server/src/org/openqa/selenium/grid/server",
2021
"//java/server/src/org/openqa/selenium/grid/node/remote",
2122
artifact("com.google.guava:guava"),
2223
],

java/server/src/org/openqa/selenium/grid/distributor/gridmodel/local/LocalGridModel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.collect.ImmutableSet;
2121
import org.openqa.selenium.events.EventBus;
22+
import org.openqa.selenium.grid.config.Config;
2223
import org.openqa.selenium.grid.data.Availability;
2324
import org.openqa.selenium.grid.data.NodeDrainStarted;
2425
import org.openqa.selenium.grid.data.NodeId;
@@ -28,6 +29,7 @@
2829
import org.openqa.selenium.grid.data.Slot;
2930
import org.openqa.selenium.grid.data.SlotId;
3031
import org.openqa.selenium.grid.distributor.GridModel;
32+
import org.openqa.selenium.grid.server.EventBusOptions;
3133
import org.openqa.selenium.internal.Require;
3234
import org.openqa.selenium.remote.SessionId;
3335

@@ -64,6 +66,12 @@ public LocalGridModel(EventBus events) {
6466
this.events.addListener(SessionClosedEvent.listener(this::release));
6567
}
6668

69+
public static GridModel create(Config config) {
70+
EventBus bus = new EventBusOptions(config).getEventBus();
71+
72+
return new LocalGridModel(bus);
73+
}
74+
6775
@Override
6876
public void add(NodeStatus node) {
6977
Require.nonNull("Node", node);
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
load("@rules_jvm_external//:defs.bzl", "artifact")
2-
load("//java:defs.bzl", "java_library")
2+
load("//java:version.bzl", "SE_VERSION")
3+
load("//java:defs.bzl", "java_export")
34

4-
java_library(
5-
name = "redis",
5+
java_export(
6+
name = "grid-model-redis",
67
srcs = glob(["*.java"]),
7-
visibility = [
8-
"//java/server/src/org/openqa/selenium/grid/distributor:__pkg__",
9-
"//java/server/test/org/openqa/selenium/grid:__subpackages__",
8+
maven_coordinates = "org.seleniumhq.selenium:selenium-grid-model-redis:%s" % SE_VERSION,
9+
pom_template = "//java/client/src/org/openqa/selenium:template-pom",
10+
visibility = [
11+
"//visibility:public",
12+
],
13+
exports = [
14+
"//java/server/src/org/openqa/selenium/grid",
1015
],
1116
deps = [
12-
"//java/client/src/org/openqa/selenium/remote",
13-
"//java/server/src/org/openqa/selenium/grid/data",
14-
"//java/server/src/org/openqa/selenium/grid/distributor",
15-
"//java/server/src/org/openqa/selenium/redis",
16-
"//java/server/src/org/openqa/selenium/grid/node",
17-
"//java/server/src/org/openqa/selenium/grid/node/remote",
17+
"//java:auto-service",
18+
"//java/client/src/org/openqa/selenium/remote",
19+
"//java/server/src/org/openqa/selenium/events",
20+
"//java/server/src/org/openqa/selenium/grid",
21+
"//java/server/src/org/openqa/selenium/grid/config",
22+
"//java/server/src/org/openqa/selenium/grid/data",
23+
"//java/server/src/org/openqa/selenium/grid/distributor",
24+
"//java/server/src/org/openqa/selenium/grid/distributor/config",
25+
"//java/server/src/org/openqa/selenium/redis",
26+
"//java/server/src/org/openqa/selenium/grid/node",
27+
"//java/server/src/org/openqa/selenium/grid/node/remote",
28+
"//java/server/src/org/openqa/selenium/grid/server",
29+
artifact("com.beust:jcommander"),
30+
artifact("com.google.guava:guava"),
1831
],
1932
)

java/server/src/org/openqa/selenium/grid/distributor/gridmodel/redis/RedisBackedGridModel.java

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.openqa.selenium.grid.distributor.gridmodel.redis;
2+
3+
import org.openqa.selenium.events.EventBus;
4+
import org.openqa.selenium.grid.config.Config;
5+
import org.openqa.selenium.grid.data.Availability;
6+
import org.openqa.selenium.grid.data.NodeDrainStarted;
7+
import org.openqa.selenium.grid.data.NodeId;
8+
import org.openqa.selenium.grid.data.NodeStatus;
9+
import org.openqa.selenium.grid.data.Session;
10+
import org.openqa.selenium.grid.data.SessionClosedEvent;
11+
import org.openqa.selenium.grid.data.SlotId;
12+
import org.openqa.selenium.grid.distributor.GridModel;
13+
import org.openqa.selenium.grid.server.EventBusOptions;
14+
import org.openqa.selenium.internal.Require;
15+
import org.openqa.selenium.remote.SessionId;
16+
17+
import java.net.URI;
18+
import java.util.Set;
19+
import java.util.logging.Logger;
20+
21+
import static org.openqa.selenium.grid.data.Availability.DRAINING;
22+
23+
public class RedisGridModel implements GridModel {
24+
25+
private static final Logger LOG = Logger.getLogger(RedisGridModel.class.getName());
26+
private final EventBus events;
27+
private final URI redisServerUri;
28+
29+
public RedisGridModel(EventBus events, URI redisServerUri) {
30+
this.events = Require.nonNull("Event bus", events);
31+
this.redisServerUri = Require.nonNull("Redis Server URI", redisServerUri);
32+
33+
this.events.addListener(NodeDrainStarted.listener(nodeId -> setAvailability(nodeId, DRAINING)));
34+
this.events.addListener(SessionClosedEvent.listener(this::release));
35+
}
36+
37+
public static GridModel create(Config config) {
38+
EventBus bus = new EventBusOptions(config).getEventBus();
39+
RedisGridModelOptions options = new RedisGridModelOptions(config);
40+
41+
return new RedisGridModel(bus, options.getRedisServerUri());
42+
}
43+
44+
@Override
45+
public void add(NodeStatus node) {
46+
47+
}
48+
49+
@Override
50+
public void refresh(NodeStatus status) {
51+
52+
}
53+
54+
@Override
55+
public void touch(NodeId id) {
56+
57+
}
58+
59+
@Override
60+
public void remove(NodeId id) {
61+
62+
}
63+
64+
@Override
65+
public void purgeDeadNodes() {
66+
67+
}
68+
69+
@Override
70+
public Availability setAvailability(NodeId id, Availability availability) {
71+
return null;
72+
}
73+
74+
@Override
75+
public boolean reserve(SlotId slotId) {
76+
return false;
77+
}
78+
79+
@Override
80+
public Set<NodeStatus> getSnapshot() {
81+
return null;
82+
}
83+
84+
@Override
85+
public Set<NodeStatus> nodes(Availability availability) {
86+
return null;
87+
}
88+
89+
@Override
90+
public void release(SessionId id) {
91+
92+
}
93+
94+
@Override
95+
public void setSession(SlotId slotId, Session session) {
96+
97+
}
98+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.grid.distributor.gridmodel.redis;
19+
20+
import com.beust.jcommander.Parameter;
21+
import com.google.auto.service.AutoService;
22+
import org.openqa.selenium.grid.config.ConfigValue;
23+
import org.openqa.selenium.grid.config.HasRoles;
24+
import org.openqa.selenium.grid.config.Role;
25+
26+
import java.util.Collections;
27+
import java.util.Set;
28+
29+
import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;
30+
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DISTRIBUTOR_SECTION;
31+
32+
@SuppressWarnings("FieldMayBeFinal")
33+
@AutoService(HasRoles.class)
34+
public class RedisGridModelFlags implements HasRoles {
35+
36+
@Parameter(
37+
names = "--redis-server",
38+
description = "Address of the redis server")
39+
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "redis-server", example = "\"localhost::6378\"")
40+
private String redisServer;
41+
42+
@Parameter(
43+
names = "--redis-host",
44+
description = "Host on which the redis server is running.")
45+
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "redis-host", example = "\"localhost\"")
46+
private String redisServerHost;
47+
48+
@Parameter(
49+
names = "--redis-port",
50+
description = "Port on which the redis server is running.")
51+
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "redis-port", example = "6379")
52+
private Integer redisServerPort;
53+
54+
55+
@Override
56+
public Set<Role> getRoles() {
57+
return Collections.singleton(DISTRIBUTOR_ROLE);
58+
}
59+
}

0 commit comments

Comments
 (0)