Skip to content

Commit 830327f

Browse files
[sessionmap] Fix JDBC "Driver not found" exception. (#8553)
* [sessionmap] Fix "Driver not found" exception. * [sessionmap] Add JdbcBackedSessionMap doc * [sessionmap] Update sessionmaps.txt with "Create TABLE" for JDBC session map Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk>
1 parent 70a5eb9 commit 830327f

2 files changed

Lines changed: 54 additions & 5 deletions

File tree

java/server/src/org/openqa/selenium/grid/commands/sessionmaps.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,42 @@ After the sessionmap server successfully starts, you should see some log lines a
2525
15:22:55.136 INFO [KqueueProvider.<clinit>] - Starting with kqueue library
2626
15:22:55.328 INFO [SessionMapServer.execute] - Started Selenium session map 4.0.0-alpha-7 (revision a5536dfb7b*): http://192.168.0.5:5556
2727
```
28+
2. JdbcBackedSessionMap
29+
========================
30+
31+
`JdbcBackedSessionMap` uses the JDBC API to talk to the JDBC driver and use related database for sessions map store.
32+
33+
The table name used to store sessions is : sessions_map
34+
It consists of three columns of string datatype : session_ids, session_caps, session_uri
35+
36+
Prerequisites
37+
1. Ensure the appropriate JDBC driver jar is downloaded on the host machine.
38+
2. Ensure the "sessions_map" table with varchar "session_ids", "session_caps" and "session_uri" columns is created in the database.
39+
40+
Example of creating the table:
41+
`CREATE TABLE sessions_map
42+
(
43+
session_ids varchar(1000),
44+
session_caps varchar(1000),
45+
session_uri varchar(1000)
46+
);`
47+
Here the limit for varchar type is given 1000 as an arbitrary number in the example. Ensure the datatype and limit matches the selected database.
48+
Also, the limit for varchar type should be able to accommodate the capabilities json stored in "sessions_caps".
49+
50+
Below are the steps to start a `JdbcBackedSessionMap`.
51+
52+
1. Set an environment variable using `export SESSIONS_IMPLEMENTATION='org.openqa.selenium.grid.sessionmap.jdbc.JdbcBackedSessionMap'`
53+
3. Build the grid deployment jar by running the command
54+
`bazel build grid`
55+
2. Start the JdbcBackedSessionMap using the command
56+
`java -jar <path/to/grid/jar> --ext path/to/selenium/bazel-bin/java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/libjdbc.jar:path/to/jdbc-driver.jar sessions --jdbc-user "<jdbc_user>" --jdbc-password "<jdbc_password>" --jdbc-url "<jdbc_url>"`
57+
58+
After the sessionmap server successfully starts, you should see some log lines as below:
59+
```
60+
15:05:20.345 INFO [LoggingOptions.getTracer] - Using OpenTelemetry for tracing
61+
15:05:20.348 INFO [LoggingOptions.createTracer] - Using OpenTelemetry for tracing
62+
15:05:20.439 INFO [UnboundZmqEventBus.<init>] - Connecting to tcp://*:4442 and tcp://*:4443
63+
15:05:20.489 INFO [UnboundZmqEventBus.<init>] - Sockets created
64+
15:05:20.492 INFO [UnboundZmqEventBus.lambda$new$2] - Bus started
65+
15:05:21.483 INFO [SessionMapServer.execute] - Started Selenium session map 4.0.0-alpha-7 (revision 857fe401ae): http://192.168.29.132:5556
66+
```

java/server/src/org/openqa/selenium/grid/sessionmap/jdbc/JdbcSessionMapOptions.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.sql.Connection;
2424
import java.sql.DriverManager;
2525
import java.sql.SQLException;
26+
import java.util.NoSuchElementException;
2627
import java.util.logging.Logger;
2728

2829
public class JdbcSessionMapOptions {
@@ -39,10 +40,19 @@ public JdbcSessionMapOptions(Config config) {
3940
}
4041

4142
public Connection getJdbcConnection() throws SQLException {
42-
String jdbcUrl = String.valueOf(config.get(SESSIONS_SECTION, "jdbc-url"));
43-
String jdbcUser = String.valueOf(config.get(SESSIONS_SECTION, "jdbc-user"));
44-
String jdbcPassword = String.valueOf(config.get(SESSIONS_SECTION, "jdbc-password"));
45-
46-
return DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
43+
try {
44+
String jdbcUrl = config.get(SESSIONS_SECTION, "jdbc-url").get();
45+
String jdbcUser = config.get(SESSIONS_SECTION, "jdbc-user").get();
46+
String jdbcPassword = config.get(SESSIONS_SECTION, "jdbc-password").get();
47+
48+
if (jdbcUrl.isEmpty()) {
49+
throw new JdbcException(
50+
"Missing JDBC Url value. Add sessions option value --jdbc-url <url-value>");
51+
}
52+
return DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
53+
} catch (NoSuchElementException e) {
54+
throw new JdbcException(
55+
"Missing session options. Check and add all the following options \n --jdbc-url <url> \n --jdbc-user <user> \n --jdbc-password <password>");
56+
}
4757
}
4858
}

0 commit comments

Comments
 (0)