Search in sources :

Example 1 with RemoteProxy

use of org.openqa.grid.internal.RemoteProxy in project selenium_java by sergueik.

the class MyConsoleServlet method getResponse.

private JSONObject getResponse() throws IOException, JSONException {
    JSONObject requestJSON = new JSONObject();
    ProxySet proxies = this.getRegistry().getAllProxies();
    Iterator<RemoteProxy> iterator = proxies.iterator();
    JSONArray busyProxies = new JSONArray();
    JSONArray freeProxies = new JSONArray();
    while (iterator.hasNext()) {
        RemoteProxy eachProxy = iterator.next();
        if (eachProxy.isBusy()) {
            busyProxies.put(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON());
        } else {
            freeProxies.put(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON());
        }
    }
    requestJSON.put("BusyProxies", busyProxies);
    requestJSON.put("FreeProxies", freeProxies);
    return requestJSON;
}
Also used : RemoteProxy(org.openqa.grid.internal.RemoteProxy) JSONObject(org.json.JSONObject) ProxySet(org.openqa.grid.internal.ProxySet) JSONArray(org.json.JSONArray)

Example 2 with RemoteProxy

use of org.openqa.grid.internal.RemoteProxy in project zalenium by zalando.

the class ZaleniumRegistry method removeIfPresent.

/**
 * @see GridRegistry#removeIfPresent(RemoteProxy)
 */
public void removeIfPresent(RemoteProxy proxy) {
    // those test sessions, we need to operate on that original object.
    if (proxies.contains(proxy)) {
        LOG.warn(String.format("Cleaning up stale test sessions on the unregistered node %s", proxy));
        final RemoteProxy p = proxies.remove(proxy);
        p.getTestSlots().forEach(testSlot -> forceRelease(testSlot, SessionTerminationReason.PROXY_REREGISTRATION));
        p.teardown();
    }
}
Also used : DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) RemoteProxy(org.openqa.grid.internal.RemoteProxy)

Example 3 with RemoteProxy

use of org.openqa.grid.internal.RemoteProxy in project zalenium by zalando.

the class LivePreviewServlet method process.

@SuppressWarnings("WeakerAccess")
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String refresh = "1200";
    String testBuild = "";
    try {
        refresh = Optional.ofNullable(request.getParameter("refresh")).orElse(refresh);
        testBuild = Optional.ofNullable(request.getParameter("build")).orElse(testBuild);
    } catch (Exception e) {
        LOGGER.debug(e.toString(), e);
    }
    List<String> nodes = new ArrayList<>();
    for (RemoteProxy proxy : getRegistry().getAllProxies()) {
        if (proxy instanceof DockerSeleniumRemoteProxy) {
            DockerSeleniumRemoteProxy dockerSeleniumRemoteProxy = (DockerSeleniumRemoteProxy) proxy;
            HtmlRenderer renderer = new LiveNodeHtmlRenderer(dockerSeleniumRemoteProxy);
            // Render the nodes that are part of an specified test build
            if (testBuild.isEmpty() || testBuild.equalsIgnoreCase(dockerSeleniumRemoteProxy.getTestBuild())) {
                nodes.add(renderer.renderSummary());
            }
        }
    }
    int size = nodes.size();
    int rightColumnSize = size / 2;
    int leftColumnSize = size - rightColumnSize;
    StringBuilder leftColumnNodes = new StringBuilder();
    for (int i = 0; i < leftColumnSize; i++) {
        leftColumnNodes.append(nodes.get(i));
    }
    StringBuilder rightColumnNodes = new StringBuilder();
    for (int i = leftColumnSize; i < nodes.size(); i++) {
        rightColumnNodes.append(nodes.get(i));
    }
    Map<String, String> livePreviewValues = new HashMap<>();
    livePreviewValues.put("{{refreshInterval}}", refresh);
    livePreviewValues.put("{{leftColumnNodes}}", leftColumnNodes.toString());
    livePreviewValues.put("{{rightColumnNodes}}", rightColumnNodes.toString());
    String templateFile = "html_templates/live_preview_servlet.html";
    TemplateRenderer templateRenderer = new TemplateRenderer(templateFile);
    String renderTemplate = templateRenderer.renderTemplate(livePreviewValues);
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.setStatus(200);
    try (InputStream in = new ByteArrayInputStream(renderTemplate.getBytes("UTF-8"))) {
        ByteStreams.copy(in, response.getOutputStream());
    } finally {
        response.getOutputStream().close();
    }
}
Also used : DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) RemoteProxy(org.openqa.grid.internal.RemoteProxy) DockerSeleniumRemoteProxy(de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) LiveNodeHtmlRenderer(de.zalando.ep.zalenium.servlet.renderer.LiveNodeHtmlRenderer) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) TemplateRenderer(de.zalando.ep.zalenium.servlet.renderer.TemplateRenderer) LiveNodeHtmlRenderer(de.zalando.ep.zalenium.servlet.renderer.LiveNodeHtmlRenderer) HtmlRenderer(org.openqa.grid.internal.utils.HtmlRenderer)

Example 4 with RemoteProxy

use of org.openqa.grid.internal.RemoteProxy in project zalenium by zalando.

the class ZaleniumConsoleServlet method process.

protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Refreshing every 20 minutes by default
    int refresh = 1200;
    if (request.getParameter("refresh") != null) {
        refresh = Integer.parseInt(request.getParameter("refresh"));
    }
    List<String> nodes = new ArrayList<>();
    for (RemoteProxy proxy : getRegistry().getAllProxies()) {
        nodes.add(proxy.getHtmlRender().renderSummary());
    }
    int size = nodes.size();
    int rightColumnSize = size / 2;
    int leftColumnSize = size - rightColumnSize;
    StringBuilder leftColumnNodes = new StringBuilder();
    for (int i = 0; i < leftColumnSize; i++) {
        leftColumnNodes.append(nodes.get(i));
    }
    StringBuilder rightColumnNodes = new StringBuilder();
    for (int i = leftColumnSize; i < nodes.size(); i++) {
        rightColumnNodes.append(nodes.get(i));
    }
    String hubConfigLinkVisible = "";
    String hubConfigVisible = "hidden";
    if (request.getParameter("config") != null) {
        hubConfigLinkVisible = "hidden";
        hubConfigVisible = "";
    }
    Map<String, String> consoleValues = new HashMap<>();
    consoleValues.put("{{refreshInterval}}", String.valueOf(refresh));
    consoleValues.put("{{coreVersion}}", coreVersion);
    consoleValues.put("{{leftColumnNodes}}", leftColumnNodes.toString());
    consoleValues.put("{{rightColumnNodes}}", rightColumnNodes.toString());
    consoleValues.put("{{unprocessedRequests}}", getUnprocessedRequests());
    consoleValues.put("{{requestQueue}}", getRequestQueue());
    consoleValues.put("{{hubConfigLinkVisible}}", hubConfigLinkVisible);
    consoleValues.put("{{hubConfigVisible}}", hubConfigVisible);
    consoleValues.put("{{hubConfig}}", getConfigInfo(request.getParameter("configDebug") != null));
    String renderTemplate = templateRenderer.renderTemplate(consoleValues);
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.setStatus(200);
    try (InputStream in = new ByteArrayInputStream(renderTemplate.getBytes("UTF-8"))) {
        ByteStreams.copy(in, response.getOutputStream());
    } finally {
        response.getOutputStream().close();
    }
}
Also used : RemoteProxy(org.openqa.grid.internal.RemoteProxy) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Example 5 with RemoteProxy

use of org.openqa.grid.internal.RemoteProxy in project carina by qaprosoft.

the class ProxyInfo method process.

protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
    List<RegistrationRequest> proxies = new ArrayList<>();
    Iterator<RemoteProxy> itr = this.getRegistry().getAllProxies().iterator();
    while (itr.hasNext()) {
        RemoteProxy proxy = itr.next();
        proxies.add(proxy.getOriginalRegistrationRequest());
    }
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    try {
        mapper.writeValue(response.getWriter(), proxies);
        response.setStatus(HttpStatus.SC_OK);
    } catch (Exception e) {
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    } finally {
        response.getWriter().close();
    }
}
Also used : RemoteProxy(org.openqa.grid.internal.RemoteProxy) ArrayList(java.util.ArrayList) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

RemoteProxy (org.openqa.grid.internal.RemoteProxy)5 ArrayList (java.util.ArrayList)3 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 LiveNodeHtmlRenderer (de.zalando.ep.zalenium.servlet.renderer.LiveNodeHtmlRenderer)1 TemplateRenderer (de.zalando.ep.zalenium.servlet.renderer.TemplateRenderer)1 ServletException (javax.servlet.ServletException)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)1 ProxySet (org.openqa.grid.internal.ProxySet)1 HtmlRenderer (org.openqa.grid.internal.utils.HtmlRenderer)1