Skip to content

Commit 8e5b132

Browse files
committed
[grid] The model is now a set of node statuses for hosts that are available
1 parent 0e1d94b commit 8e5b132

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

java/server/src/org/openqa/selenium/grid/distributor/Distributor.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.openqa.selenium.grid.data.NodeStatus;
2929
import org.openqa.selenium.grid.data.Session;
3030
import org.openqa.selenium.grid.data.SlotId;
31-
import org.openqa.selenium.grid.distributor.model.Host;
3231
import org.openqa.selenium.grid.distributor.selector.SlotSelector;
3332
import org.openqa.selenium.grid.node.Node;
3433
import org.openqa.selenium.grid.security.RequiresSecretFilter;
@@ -69,8 +68,6 @@
6968
import java.util.function.Supplier;
7069
import java.util.stream.Collectors;
7170

72-
import static com.google.common.collect.ImmutableSet.toImmutableSet;
73-
import static org.openqa.selenium.grid.data.Availability.UP;
7471
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
7572
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES_EVENT;
7673
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
@@ -198,16 +195,10 @@ public CreateSessionResponse newSession(HttpRequest request)
198195
Lock writeLock = this.lock.writeLock();
199196
writeLock.lock();
200197
try {
201-
Set<Host> model = getModel();
202-
203-
// Remove nodes that can't possibly help us
204-
ImmutableSet<NodeStatus> availableHosts = model.stream()
205-
.filter(host -> UP.equals(host.getHostStatus()))
206-
.map(Host::asNodeStatus)
207-
.collect(toImmutableSet());
198+
Set<NodeStatus> model = ImmutableSet.copyOf(getAvailableNodes());
208199

209200
// Find a host that supports the capabilities present in the new session
210-
Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getCapabilities(), availableHosts);
201+
Set<SlotId> slotIds = slotSelector.selectSlot(firstRequest.getCapabilities(), model);
211202
if (!slotIds.isEmpty()) {
212203
selected = Optional.of(reserve(slotIds.iterator().next(), firstRequest));
213204
} else {
@@ -283,7 +274,7 @@ public CreateSessionResponse newSession(HttpRequest request)
283274

284275
public abstract DistributorStatus getStatus();
285276

286-
protected abstract Set<Host> getModel();
277+
protected abstract Set<NodeStatus> getAvailableNodes();
287278

288279
protected abstract Supplier<CreateSessionResponse> reserve(SlotId slot, CreateSessionRequest request);
289280

java/server/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
import static com.google.common.collect.ImmutableSet.toImmutableSet;
7272
import static org.openqa.selenium.grid.data.Availability.DRAINING;
73+
import static org.openqa.selenium.grid.data.Availability.UP;
7374
import static org.openqa.selenium.grid.data.NodeDrainComplete.NODE_DRAIN_COMPLETE;
7475
import static org.openqa.selenium.grid.data.NodeStatusEvent.NODE_STATUS;
7576

@@ -269,11 +270,14 @@ public void refresh() {
269270
}
270271

271272
@Override
272-
protected Set<Host> getModel() {
273+
protected Set<NodeStatus> getAvailableNodes() {
273274
Lock readLock = this.lock.readLock();
274275
readLock.lock();
275276
try {
276-
return ImmutableSet.copyOf(hosts);
277+
return hosts.stream()
278+
.filter(host -> UP.equals(host.getHostStatus()))
279+
.map(Host::asNodeStatus)
280+
.collect(toImmutableSet());
277281
} finally {
278282
readLock.unlock();
279283
}

java/server/src/org/openqa/selenium/grid/distributor/remote/RemoteDistributor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import org.openqa.selenium.grid.data.CreateSessionResponse;
2323
import org.openqa.selenium.grid.data.DistributorStatus;
2424
import org.openqa.selenium.grid.data.NodeId;
25+
import org.openqa.selenium.grid.data.NodeStatus;
2526
import org.openqa.selenium.grid.data.SlotId;
2627
import org.openqa.selenium.grid.distributor.Distributor;
27-
import org.openqa.selenium.grid.distributor.model.Host;
2828
import org.openqa.selenium.grid.node.Node;
2929
import org.openqa.selenium.grid.security.Secret;
3030
import org.openqa.selenium.grid.sessionmap.NullSessionMap;
@@ -132,7 +132,7 @@ public DistributorStatus getStatus() {
132132
}
133133

134134
@Override
135-
protected Set<Host> getModel() {
135+
protected Set<NodeStatus> getAvailableNodes() {
136136
throw new UnsupportedOperationException("getModel is not required for remote sessions");
137137
}
138138

java/server/test/org/openqa/selenium/grid/distributor/DistributorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void testDrainedNodeShutsDownOnceEmpty() throws URISyntaxException, Inter
264264

265265
assertThat(latch.getCount()).isEqualTo(0);
266266

267-
assertThat(distributor.getModel().size()).isEqualTo(0);
267+
assertThat(distributor.getAvailableNodes().size()).isEqualTo(0);
268268

269269
try (NewSessionPayload payload = NewSessionPayload.create(caps)) {
270270
assertThatExceptionOfType(SessionNotCreatedException.class)
@@ -302,7 +302,7 @@ public void drainedNodeDoesNotShutDownIfNotEmpty() throws URISyntaxException, In
302302

303303
assertThat(latch.getCount()).isEqualTo(1);
304304

305-
assertThat(distributor.getModel().size()).isEqualTo(1);
305+
assertThat(distributor.getAvailableNodes().size()).isEqualTo(1);
306306
}
307307

308308
@Test
@@ -333,15 +333,15 @@ public void drainedNodeShutsDownAfterSessionsFinish() throws URISyntaxException,
333333

334334
distributor.drain(node.getId());
335335

336-
assertThat(distributor.getModel().size()).isEqualTo(1);
336+
assertThat(distributor.getAvailableNodes().size()).isEqualTo(1);
337337

338338
node.stop(firstResponse.getSession().getId());
339339
node.stop(secondResponse.getSession().getId());
340340

341341
latch.await(5, SECONDS);
342342

343343
assertThat(latch.getCount()).isEqualTo(0);
344-
assertThat(distributor.getModel().size()).isEqualTo(0);
344+
assertThat(distributor.getAvailableNodes().size()).isEqualTo(0);
345345
}
346346

347347
@Test

0 commit comments

Comments
 (0)