|
24 | 24 | import org.openqa.selenium.grid.config.Config;
|
25 | 25 | import org.openqa.selenium.grid.config.ConfigException;
|
26 | 26 | import org.openqa.selenium.grid.data.NodeRemovedEvent;
|
| 27 | +import org.openqa.selenium.grid.data.NodeRestartedEvent; |
27 | 28 | import org.openqa.selenium.grid.data.Session;
|
28 | 29 | import org.openqa.selenium.grid.data.SessionClosedEvent;
|
29 | 30 | import org.openqa.selenium.grid.log.LoggingOptions;
|
@@ -89,6 +90,8 @@ public JdbcBackedSessionMap(Tracer tracer, Connection jdbcConnection, EventBus b
|
89 | 90 | .filter(slot -> slot.getSession() != null)
|
90 | 91 | .map(slot -> slot.getSession().getId())
|
91 | 92 | .forEach(this::remove)));
|
| 93 | + |
| 94 | + bus.addListener(NodeRestartedEvent.listener(nodeStatus -> this.removeByUri(nodeStatus.getExternalUri()))); |
92 | 95 | }
|
93 | 96 |
|
94 | 97 | public static SessionMap create(Config config) {
|
@@ -310,6 +313,42 @@ public void remove(SessionId id) {
|
310 | 313 | }
|
311 | 314 | }
|
312 | 315 |
|
| 316 | + public void removeByUri(URI sessionUri) { |
| 317 | + Require.nonNull("Session URI", sessionUri); |
| 318 | + try (Span span = tracer.getCurrentContext().createSpan( |
| 319 | + "DELETE from sessions_map where session_uri = ?")) { |
| 320 | + Map<String, EventAttributeValue> attributeMap = new HashMap<>(); |
| 321 | + |
| 322 | + try (PreparedStatement statement = connection.prepareStatement( |
| 323 | + String.format("delete from %1$s where %2$s = ?", |
| 324 | + TABLE_NAME, |
| 325 | + SESSION_URI_COL))) { |
| 326 | + |
| 327 | + statement.setString(1, sessionUri.toString()); |
| 328 | + String statementStr = statement.toString(); |
| 329 | + span.setAttribute(DATABASE_STATEMENT, statementStr); |
| 330 | + span.setAttribute(DATABASE_OPERATION, "delete"); |
| 331 | + attributeMap.put(DATABASE_STATEMENT, EventAttribute.setValue(statementStr)); |
| 332 | + attributeMap.put(DATABASE_OPERATION, EventAttribute.setValue("delete")); |
| 333 | + |
| 334 | + int rowCount = statement.executeUpdate(); |
| 335 | + attributeMap.put("rows.deleted", EventAttribute.setValue(rowCount)); |
| 336 | + span.addEvent("Deleted session from the database", attributeMap); |
| 337 | + |
| 338 | + } catch (SQLException e) { |
| 339 | + span.setAttribute("error", true); |
| 340 | + span.setStatus(Status.CANCELLED); |
| 341 | + EXCEPTION.accept(attributeMap, e); |
| 342 | + attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(), |
| 343 | + EventAttribute.setValue( |
| 344 | + "Unable to delete session information from the database: " + e |
| 345 | + .getMessage())); |
| 346 | + span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap); |
| 347 | + throw new JdbcException(e.getMessage()); |
| 348 | + } |
| 349 | + } |
| 350 | + } |
| 351 | + |
313 | 352 | @Override
|
314 | 353 | public void close() {
|
315 | 354 | try {
|
|
0 commit comments