34
34
import org .openqa .selenium .grid .security .RequiresSecretFilter ;
35
35
import org .openqa .selenium .grid .security .Secret ;
36
36
import org .openqa .selenium .grid .sessionmap .SessionMap ;
37
+ import org .openqa .selenium .grid .sessionqueue .SessionRequest ;
37
38
import org .openqa .selenium .internal .Either ;
38
39
import org .openqa .selenium .internal .Require ;
39
40
import org .openqa .selenium .json .Json ;
40
- import org .openqa .selenium .remote .NewSessionPayload ;
41
41
import org .openqa .selenium .remote .SessionId ;
42
42
import org .openqa .selenium .remote .http .HttpClient ;
43
43
import org .openqa .selenium .remote .http .HttpRequest ;
53
53
import org .openqa .selenium .remote .tracing .Tracer ;
54
54
import org .openqa .selenium .status .HasReadyState ;
55
55
56
- import java .io .IOException ;
57
- import java .io .Reader ;
58
56
import java .io .UncheckedIOException ;
59
57
import java .util .HashMap ;
60
58
import java .util .Iterator ;
61
59
import java .util .Map ;
62
- import java .util .Objects ;
63
60
import java .util .Set ;
64
61
import java .util .UUID ;
65
62
import java .util .concurrent .locks .Lock ;
73
70
import static org .openqa .selenium .remote .RemoteTags .CAPABILITIES_EVENT ;
74
71
import static org .openqa .selenium .remote .RemoteTags .SESSION_ID ;
75
72
import static org .openqa .selenium .remote .RemoteTags .SESSION_ID_EVENT ;
76
- import static org .openqa .selenium .remote .http .Contents .reader ;
77
73
import static org .openqa .selenium .remote .http .Route .delete ;
78
74
import static org .openqa .selenium .remote .http .Route .get ;
79
75
import static org .openqa .selenium .remote .http .Route .post ;
80
- import static org .openqa .selenium .remote .tracing .HttpTracing .newSpanAsChildOf ;
81
76
import static org .openqa .selenium .remote .tracing .Tags .EXCEPTION ;
82
77
83
78
/**
@@ -160,24 +155,21 @@ protected Distributor(
160
155
.with (new SpanDecorator (tracer , req -> "distributor.status" )));
161
156
}
162
157
163
- public Either <SessionNotCreatedException , CreateSessionResponse > newSession (HttpRequest request )
158
+ public Either <SessionNotCreatedException , CreateSessionResponse > newSession (SessionRequest request )
164
159
throws SessionNotCreatedException {
160
+ Require .nonNull ("Requests to process" , request );
165
161
166
- Span span = newSpanAsChildOf ( tracer , request , "distributor.create_session_response" );
162
+ Span span = tracer . getCurrentContext (). createSpan ( "distributor.create_session_response" );
167
163
Map <String , EventAttributeValue > attributeMap = new HashMap <>();
168
- try (
169
- Reader reader = reader (request );
170
- NewSessionPayload payload = NewSessionPayload .create (reader )) {
171
- Objects .requireNonNull (payload , "Requests to process must be set." );
172
-
164
+ try {
173
165
attributeMap .put (AttributeKey .LOGGER_CLASS .getKey (),
174
166
EventAttribute .setValue (getClass ().getName ()));
175
167
176
- Iterator <Capabilities > iterator = payload . stream ().iterator ();
177
- attributeMap .put ("request.payload" , EventAttribute .setValue (payload .toString ()));
168
+ Iterator <Capabilities > iterator = request . getDesiredCapabilities ().iterator ();
169
+ attributeMap .put ("request.payload" , EventAttribute .setValue (request . getDesiredCapabilities () .toString ()));
178
170
String sessionReceivedMessage = "Session request received by the distributor" ;
179
171
span .addEvent (sessionReceivedMessage , attributeMap );
180
- LOG .info (String .format ("%s: \n %s" , sessionReceivedMessage , payload ));
172
+ LOG .info (String .format ("%s: \n %s" , sessionReceivedMessage , request . getDesiredCapabilities () ));
181
173
182
174
if (!iterator .hasNext ()) {
183
175
SessionNotCreatedException exception =
@@ -192,7 +184,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Http
192
184
193
185
Either <SessionNotCreatedException , CreateSessionResponse > selected ;
194
186
CreateSessionRequest firstRequest = new CreateSessionRequest (
195
- payload .getDownstreamDialects (),
187
+ request .getDownstreamDialects (),
196
188
iterator .next (),
197
189
ImmutableMap .of ("span" , span ));
198
190
@@ -208,7 +200,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Http
208
200
if (!hostsWithCaps ) {
209
201
String errorMessage = String .format (
210
202
"No Node supports the required capabilities: %s" ,
211
- payload .stream ().map (Capabilities ::toString )
203
+ request . getDesiredCapabilities () .stream ().map (Capabilities ::toString )
212
204
.collect (Collectors .joining (", " )));
213
205
SessionNotCreatedException exception = new SessionNotCreatedException (errorMessage );
214
206
span .setAttribute (AttributeKey .ERROR .getKey (), true );
@@ -229,7 +221,7 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Http
229
221
String errorMessage =
230
222
String .format (
231
223
"Unable to find provider for session: %s" ,
232
- payload .stream ().map (Capabilities ::toString )
224
+ request . getDesiredCapabilities () .stream ().map (Capabilities ::toString )
233
225
.collect (Collectors .joining (", " )));
234
226
SessionNotCreatedException exception = new RetrySessionRequestException (errorMessage );
235
227
selected = Either .left (exception );
@@ -270,14 +262,13 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Http
270
262
span .addEvent (AttributeKey .EXCEPTION_EVENT .getKey (), attributeMap );
271
263
272
264
return Either .left (e );
273
- } catch (IOException e ) {
265
+ } catch (UncheckedIOException e ) {
274
266
span .setAttribute (AttributeKey .ERROR .getKey (), true );
275
267
span .setStatus (Status .UNKNOWN );
276
268
277
269
EXCEPTION .accept (attributeMap , e );
278
270
attributeMap .put (AttributeKey .EXCEPTION_MESSAGE .getKey (),
279
- EventAttribute .setValue ("Unknown error in LocalDistributor while creating session: " +
280
- e .getMessage ()));
271
+ EventAttribute .setValue ("Unknown error in LocalDistributor while creating session: " + e .getMessage ()));
281
272
span .addEvent (AttributeKey .EXCEPTION_EVENT .getKey (), attributeMap );
282
273
283
274
return Either .left (new SessionNotCreatedException (e .getMessage (), e ));
@@ -296,8 +287,9 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Http
296
287
297
288
protected abstract Set <NodeStatus > getAvailableNodes ();
298
289
299
- protected abstract Either <SessionNotCreatedException , CreateSessionResponse > reserve (SlotId slot ,
300
- CreateSessionRequest request );
290
+ protected abstract Either <SessionNotCreatedException , CreateSessionResponse > reserve (
291
+ SlotId slot ,
292
+ CreateSessionRequest request );
301
293
302
294
@ Override
303
295
public boolean test (HttpRequest httpRequest ) {
0 commit comments