|
| 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.sessionqueue; |
| 19 | + |
| 20 | +import com.google.common.collect.ImmutableMap; |
| 21 | +import org.openqa.selenium.internal.Require; |
| 22 | +import org.openqa.selenium.remote.http.HttpHandler; |
| 23 | +import org.openqa.selenium.remote.http.HttpRequest; |
| 24 | +import org.openqa.selenium.remote.http.HttpResponse; |
| 25 | +import org.openqa.selenium.remote.tracing.Span; |
| 26 | +import org.openqa.selenium.remote.tracing.Tracer; |
| 27 | + |
| 28 | +import static org.openqa.selenium.remote.http.Contents.asJson; |
| 29 | +import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf; |
| 30 | +import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST; |
| 31 | +import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE; |
| 32 | + |
| 33 | +class GetNewSessionQueueSize implements HttpHandler { |
| 34 | + |
| 35 | + private final Tracer tracer; |
| 36 | + private final NewSessionQueuer newSessionQueuer; |
| 37 | + |
| 38 | + GetNewSessionQueueSize(Tracer tracer, NewSessionQueuer newSessionQueuer) { |
| 39 | + this.tracer = Require.nonNull("Tracer", tracer); |
| 40 | + this.newSessionQueuer = Require.nonNull("New Session Queuer", newSessionQueuer); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public HttpResponse execute(HttpRequest req) { |
| 45 | + try (Span span = newSpanAsChildOf(tracer, req, "sessionqueue.size")) { |
| 46 | + HTTP_REQUEST.accept(span, req); |
| 47 | + |
| 48 | + int value = newSessionQueuer.getQueueSize(); |
| 49 | + |
| 50 | + span.setAttribute("request.retry", value); |
| 51 | + |
| 52 | + HttpResponse response = new HttpResponse() |
| 53 | + .setContent(asJson(ImmutableMap.of("value", value))); |
| 54 | + |
| 55 | + HTTP_RESPONSE.accept(span, response); |
| 56 | + |
| 57 | + return response; |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
0 commit comments