Skip to content

Commit 42ad3c2

Browse files
committed
[grid] Fire an event when starting to drain a node
1 parent d11870f commit 42ad3c2

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.data;
19+
20+
import org.openqa.selenium.events.Event;
21+
import org.openqa.selenium.events.Type;
22+
23+
public class NodeDrainStarted extends Event {
24+
25+
public static final Type NODE_DRAIN_STARTED = new Type("node-drain-started");
26+
27+
public NodeDrainStarted(NodeId id) {
28+
super(NODE_DRAIN_STARTED, id);
29+
}
30+
31+
}

java/server/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openqa.selenium.grid.data.CreateSessionRequest;
3333
import org.openqa.selenium.grid.data.CreateSessionResponse;
3434
import org.openqa.selenium.grid.data.NodeDrainComplete;
35+
import org.openqa.selenium.grid.data.NodeDrainStarted;
3536
import org.openqa.selenium.grid.data.NodeId;
3637
import org.openqa.selenium.grid.data.NodeStatus;
3738
import org.openqa.selenium.grid.data.Session;
@@ -324,8 +325,6 @@ public boolean isSupporting(Capabilities capabilities) {
324325

325326
@Override
326327
public NodeStatus getStatus() {
327-
328-
329328
return new NodeStatus(
330329
getId(),
331330
getUri(),
@@ -344,6 +343,7 @@ public NodeStatus getStatus() {
344343

345344
@Override
346345
public void drain() {
346+
events.fire(new NodeDrainStarted(getId()));
347347
draining = true;
348348
}
349349

java/server/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.openqa.selenium.grid.data.CreateSessionRequest;
3636
import org.openqa.selenium.grid.data.CreateSessionResponse;
3737
import org.openqa.selenium.grid.data.NodeDrainComplete;
38+
import org.openqa.selenium.grid.data.NodeDrainStarted;
3839
import org.openqa.selenium.grid.data.NodeId;
3940
import org.openqa.selenium.grid.data.NodeStatus;
4041
import org.openqa.selenium.grid.data.Session;
@@ -447,11 +448,12 @@ public HealthCheck getHealthCheck() {
447448

448449
@Override
449450
public void drain() {
451+
bus.fire(new NodeDrainStarted(getId()));
450452
draining = true;
451453
int currentSessionCount = getCurrentSessionCount();
452454
if (currentSessionCount == 0) {
453455
LOG.info("Firing node drain complete message");
454-
bus.fire(new NodeDrainComplete(this.getId()));
456+
bus.fire(new NodeDrainComplete(getId()));
455457
} else {
456458
pendingSessions.set(currentSessionCount);
457459
}

0 commit comments

Comments
 (0)