Skip to content

Commit 16b3eb9

Browse files
committed
[grid] Adding stereotypes to the Node schema
1 parent df105ba commit 16b3eb9

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

java/server/src/org/openqa/selenium/grid/graphql/Grid.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,23 @@ public List<Node> getNodes() {
6666
ImmutableList.Builder<Node> toReturn = ImmutableList.builder();
6767

6868
for (NodeStatus status : distributorStatus.get().getNodes()) {
69-
Map<Capabilities, Integer> capabilities = new HashMap<>();
69+
Map<Capabilities, Integer> stereotypes = new HashMap<>();
7070
Map<org.openqa.selenium.grid.data.Session, Slot> sessions = new HashMap<>();
7171

7272
for (Slot slot : status.getSlots()) {
7373
slot.getSession().ifPresent(session -> sessions.put(session, slot));
7474

75-
int count = capabilities.getOrDefault(slot.getStereotype(), 0);
75+
int count = stereotypes.getOrDefault(slot.getStereotype(), 0);
7676
count++;
77-
capabilities.put(slot.getStereotype(), count);
77+
stereotypes.put(slot.getStereotype(), count);
7878
}
7979

8080
toReturn.add(new Node(
8181
status.getId(),
8282
status.getUri(),
8383
status.getAvailability(),
8484
status.getMaxSessionCount(),
85-
capabilities,
85+
stereotypes,
8686
sessions,
8787
status.getVersion()));
8888
}

java/server/src/org/openqa/selenium/grid/graphql/Node.java

+23-19
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Node {
3939
private final URI uri;
4040
private final Availability status;
4141
private final int maxSession;
42-
private final Map<Capabilities, Integer> capabilities;
42+
private final Map<Capabilities, Integer> stereotypes;
4343
private final Map<Session, Slot> activeSessions;
4444
private final String version;
4545

@@ -48,22 +48,26 @@ public Node(NodeId id,
4848
URI uri,
4949
Availability status,
5050
int maxSession,
51-
Map<Capabilities, Integer> capabilities,
51+
Map<Capabilities, Integer> stereotypes,
5252
Map<Session, Slot> activeSessions,
5353
String version) {
5454
this.id = Require.nonNull("Node id", id);
5555
this.uri = Require.nonNull("Node uri", uri);
5656
this.status = status;
5757
this.maxSession = maxSession;
58-
this.capabilities = Require.nonNull("Node capabilities", capabilities);
58+
this.stereotypes = Require.nonNull("Node stereotypes", stereotypes);
5959
this.activeSessions = Require.nonNull("Active sessions", activeSessions);
6060
this.version = Require.nonNull("Grid Node version", version);
6161
}
6262

6363
public List<org.openqa.selenium.grid.graphql.Session> getSessions() {
6464
return activeSessions.entrySet().stream()
65-
.map(this::createGraphqlSession)
66-
.collect(ImmutableList.toImmutableList());
65+
.map(this::createGraphqlSession)
66+
.collect(ImmutableList.toImmutableList());
67+
}
68+
69+
public int getSessionCount() {
70+
return activeSessions.size();
6771
}
6872

6973
public NodeId getId() {
@@ -80,15 +84,15 @@ public int getMaxSession() {
8084

8185
public List<String> getActiveSessionIds() {
8286
return activeSessions.keySet().stream().map(session -> session.getId().toString())
83-
.collect(ImmutableList.toImmutableList());
87+
.collect(ImmutableList.toImmutableList());
8488
}
8589

86-
public String getCapabilities() {
87-
List<Map<String, Object> > toReturn = new ArrayList<>();
90+
public String getStereotypes() {
91+
List<Map<String, Object>> toReturn = new ArrayList<>();
8892

89-
for (Map.Entry<Capabilities, Integer> entry : capabilities.entrySet()) {
90-
Map<String, Object> details = new HashMap<>();
91-
details.put("browserName", entry.getKey().getBrowserName());
93+
for (Map.Entry<Capabilities, Integer> entry : stereotypes.entrySet()) {
94+
Map<String, Object> details = new HashMap<>();
95+
details.put("stereotype", entry.getKey());
9296
details.put("slots", entry.getValue());
9397
toReturn.add(details);
9498
}
@@ -105,18 +109,18 @@ public String getVersion() {
105109
}
106110

107111
private org.openqa.selenium.grid.graphql.Session createGraphqlSession(
108-
Map.Entry<Session, Slot> entry) {
112+
Map.Entry<Session, Slot> entry) {
109113
Session session = entry.getKey();
110114
Slot slot = entry.getValue();
111115

112116
return new org.openqa.selenium.grid.graphql.Session(
113-
session.getId().toString(),
114-
session.getCapabilities(),
115-
session.getStartTime(),
116-
session.getUri(),
117-
id.toString(),
118-
uri,
119-
slot
117+
session.getId().toString(),
118+
session.getCapabilities(),
119+
session.getStartTime(),
120+
session.getUri(),
121+
id.toString(),
122+
uri,
123+
slot
120124
);
121125
}
122126
}

java/server/src/org/openqa/selenium/grid/graphql/selenium-grid-schema.graphqls

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type Node {
3333
status: Status!
3434
maxSession: Int!
3535
sessions: [Session]!
36-
capabilities: String!
36+
sessionCount: Int!
37+
stereotypes: String!
3738
version: String!
3839
}
3940

@@ -51,4 +52,4 @@ type Grid {
5152
version: String!
5253
sessionQueueSize: Int!
5354
sessionQueueRequests: [String]!
54-
}
55+
}

0 commit comments

Comments
 (0)