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;
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations