@@ -42,6 +42,18 @@ public SessionData(Distributor distributor) {
42
42
distributorStatus = Suppliers .memoize (distributor ::getStatus );
43
43
}
44
44
45
+ private static class SessionInSlot {
46
+ private final org .openqa .selenium .grid .data .Session session ;
47
+ private final NodeStatus node ;
48
+ private final Slot slot ;
49
+
50
+ SessionInSlot (org .openqa .selenium .grid .data .Session session , NodeStatus node , Slot slot ) {
51
+ this .session = session ;
52
+ this .node = node ;
53
+ this .slot = slot ;
54
+ }
55
+ }
56
+
45
57
@ Override
46
58
public Object get (DataFetchingEnvironment environment ) {
47
59
String sessionId = environment .getArgument ("id" );
@@ -52,38 +64,35 @@ public Object get(DataFetchingEnvironment environment) {
52
64
53
65
Set <NodeStatus > nodeStatuses = distributorStatus .get ().getNodes ();
54
66
55
- Optional <org .openqa .selenium .grid .data .Session > currentSession = Optional .empty ();
56
- NodeStatus currentSessionNode = null ;
57
- Slot currentSessionSlot = null ;
67
+ SessionInSlot currentSession = findSession (sessionId , nodeStatuses );
68
+
69
+ if (currentSession != null ) {
70
+ org .openqa .selenium .grid .data .Session session = currentSession .session ;
71
+
72
+ return new org .openqa .selenium .grid .graphql .Session (
73
+ session .getId ().toString (),
74
+ session .getCapabilities (),
75
+ session .getStartTime (),
76
+ session .getUri (),
77
+ currentSession .node .getId ().toString (),
78
+ currentSession .node .getUri (),
79
+ currentSession .slot );
80
+ } else {
81
+ throw new SessionNotFoundException ("No ongoing session found with the requested session id." ,
82
+ sessionId );
83
+ }
84
+ }
58
85
86
+ private SessionInSlot findSession (String sessionId , Set <NodeStatus > nodeStatuses ) {
59
87
for (NodeStatus status : nodeStatuses ) {
60
88
for (Slot slot : status .getSlots ()) {
61
89
Optional <org .openqa .selenium .grid .data .Session > session = slot .getSession ();
62
90
63
- if (session .isPresent ()
64
- && sessionId .equals (session .get ().getId ().toString ())) {
65
- currentSession = Optional .of (session .get ());
66
- currentSessionNode = status ;
67
- currentSessionSlot = slot ;
68
- break ;
91
+ if (session .isPresent () && sessionId .equals (session .get ().getId ().toString ())) {
92
+ return new SessionInSlot (session .get (), status , slot );
69
93
}
70
94
}
71
95
}
72
-
73
- if (currentSession .isPresent ()) {
74
- org .openqa .selenium .grid .data .Session session = currentSession .get ();
75
-
76
- return new org .openqa .selenium .grid .graphql .Session (
77
- session .getId ().toString (),
78
- session .getCapabilities (),
79
- session .getStartTime (),
80
- session .getUri (),
81
- currentSessionNode .getId ().toString (),
82
- currentSessionNode .getUri (),
83
- currentSessionSlot );
84
- } else {
85
- throw new SessionNotFoundException ("No ongoing session found with the requested session id." ,
86
- sessionId );
87
- }
96
+ return null ;
88
97
}
89
98
}
0 commit comments