/** * return the platform for the proxy. It should be the same for all slots of the proxy, so checking that. * @param proxy remote proxy * @return Either the platform name, "Unknown", "mixed OS", or "not specified". */ private static String getPlatform(RemoteProxy proxy) { Platform res; if (proxy.getTestSlots().size() == 0) { return "Unknown"; } res = getPlatform(proxy.getTestSlots().get(0)); for (TestSlot slot : proxy.getTestSlots()) { Platform tmp = getPlatform(slot); if (!tmp.is(res)) { return "mixed OS"; } res = tmp; } if (res == null) { return "not specified"; } return res.toString(); }
private String tabConfig() { return proxy.getConfig().toString("<p>%1$s: %2$s</p>"); }
public String renderSummary() { Map<String, String> renderSummaryValues = new HashMap<>(); renderSummaryValues.put("{{proxyName}}", proxy.getClass().getSimpleName()); renderSummaryValues.put("{{proxyVersion}}", getHtmlNodeVersion()); renderSummaryValues.put("{{proxyId}}", proxy.getId()); renderSummaryValues.put("{{proxyPlatform}}", getPlatform(proxy)); renderSummaryValues.put("{{tabBrowsers}}", tabBrowsers()); renderSummaryValues.put("{{tabConfig}}", tabConfig()); return templateRenderer.renderTemplate(renderSummaryValues); }
/** * @see GridRegistry#removeIfPresent(RemoteProxy) */ public void removeIfPresent(RemoteProxy proxy) { // Find the original proxy. While the supplied one is logically equivalent, it may be a fresh object with // an empty TestSlot list, which doesn't figure into the proxy equivalence check. Since we want to free up // those test sessions, we need to operate on that original object. if (proxies.contains(proxy)) { LOG.debug(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(); } }
private TestSession createNewSession(Map<String, Object> desiredCapabilities) { List<RemoteProxy> sorted = getSorted(); LOGGER.debug("Available nodes: " + sorted); // Removing the proxies with Android so they are not taken into account to create a session. List<RemoteProxy> proxiesToConsider; if (Platform.LINUX.equals(getPlatformFromCaps(desiredCapabilities))) { proxiesToConsider = sorted.stream() .filter(remoteProxy -> remoteProxy .getTestSlots().stream() .noneMatch(testSlot -> Platform.ANDROID.equals(getPlatformFromCaps(testSlot.getCapabilities())))) .collect(Collectors.toList()); } else { proxiesToConsider = sorted; } return proxiesToConsider.stream() .map(proxy -> proxy.getNewSession(desiredCapabilities)) .filter(Objects::nonNull) .findFirst().orElse(null); }
localBuilder.append("listening on ").append(proxy.getRemoteHost()); Object instanceId = proxy.getConfig().get(AutomationConstants.INSTANCE_ID); if(instanceId != null) { AutomationDynamicNode node = AutomationContext.getContext().getNode((String)instanceId); if (proxy.getTimeOut() > 0) { int inSec = proxy.getTimeOut() / 1000; localBuilder.append("test session time out after ").append(inSec).append(" sec.<br />"); localBuilder.append("Supports up to <b>").append(proxy.getMaxNumberOfConcurrentTestSessions()) .append("</b> concurrent tests from: <br />"); for (TestSlot slot : proxy.getTestSlots()) { TestSession session = slot.getSession();
/** * Initializes proxy information from the supplied {@link RemoteProxy} object * * @param proxy * the {@link RemoteProxy} * @param queryStatus * whether to query the node status over HTTP via /wd/hub/status */ ProxyInfo(RemoteProxy proxy, boolean queryStatus) { // selenium supported features isBusy = proxy.isBusy(); percentResourceUsage = proxy.getResourceUsageInPercent(); totalUsed = proxy.getTotalUsed(); configuration = proxy.getConfig(); determineStatus(proxy, queryStatus); initUsageBySlot(proxy); // SelionRemoteProxy only initSeLionRemoteProxySpecificValues(proxy); }
private void initSeLionRemoteProxySpecificValues(RemoteProxy proxy) { if (SeLionRemoteProxy.class.getCanonicalName().equals( proxy.getOriginalRegistrationRequest().getConfiguration().proxy)) { SeLionRemoteProxy srp = (SeLionRemoteProxy) proxy; // figure out if the proxy is scheduled to shutdown isShuttingDown = srp.isScheduledForRecycle(); // update the logsLocation if the proxy supports LogServlet if (srp.supportsViewLogs()) { logsLocation = proxy.getRemoteHost().toExternalForm() + "/extra/" + LogServlet.class.getSimpleName(); } totalSessionsStarted = srp.getTotalSessionsStarted(); totalSessionsComplete = srp.getTotalSessionsComplete(); uptimeInMinutes = srp.getUptimeInMinutes(); } }
/** * Returns true if the specified node is empty and has no runs on it, and false otherwise * @param instanceToFind * @return */ public boolean isNodeCurrentlyEmpty(String instanceToFind) { ProxySet proxySet = getProxySet(); for(RemoteProxy proxy : proxySet){ List<TestSlot> slots = proxy.getTestSlots(); Object instanceId = proxy.getConfig().get(AutomationConstants.INSTANCE_ID); // If the instance id's do not match, this means this is not the node we are looking for // and we should continue on to the next one if(!instanceToFind.equals(instanceId)) { continue; } // Now that we found the matching node, iterate over all its test slots to see if any sessions are running for (TestSlot testSlot : slots) { // If we find a running session, this means the node is occupied, so we should return false if(testSlot.getSession() != null) { return false; } } // If we reached this point, this means we found our target node AND it had no sessions, meaning the node was empty return true; } // If we didn't find a matching node, we're going to say the nodes is empty so we can terminate it log.warn("No matching node was found in the proxy set. Instance id: " + instanceToFind); return true; } }
private List<URL> getRegistryURLs(GridRegistry registry) { Iterator<RemoteProxy> remoteProxyIterator = registry.getAllProxies().iterator(); List<URL> urlList = new ArrayList<>(); while (remoteProxyIterator.hasNext()) { RemoteProxy remoteProxy = remoteProxyIterator.next(); urlList.add(remoteProxy.getRemoteHost()); } return urlList; }
private JsonObject getResponse() throws IOException { 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.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } else { freeProxies.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } } requestJSON.add("BusyProxies", busyProxies); requestJSON.add("FreeProxies", freeProxies); return requestJSON; }
public Collection<SeleniumTestSlotGroup> call() { Map<URL, SeleniumTestSlotGroup> groups = new HashMap<URL, SeleniumTestSlotGroup>(); if (HubHolder.getHub() == null) { return Collections.emptyList(); } GridRegistry registry = HubHolder.getHub().getRegistry(); if (registry != null) { for (RemoteProxy proxy : registry.getAllProxies()) { for (TestSlot slot : proxy.getTestSlots()) { URL host = slot.getProxy().getRemoteHost(); SeleniumTestSlotGroup grp = groups.get(host); if (grp == null) { grp = new SeleniumTestSlotGroup(host); groups.put(host, grp); } grp.addTestSlot(new SeleniumTestSlot(slot)); } } } List<SeleniumTestSlotGroup> values = new ArrayList<SeleniumTestSlotGroup>(groups.values()); Collections.sort(values); return values; } });
int runningSessions = 0; int matchingRunningSessions = 0; int maxNodeThreadsAvailable = proxy.getMaxNumberOfConcurrentTestSessions(); Map<String,Object> config = proxy.getConfig(); String instanceId = null; if(config.containsKey(AutomationConstants.INSTANCE_ID)) { log.info("Analyzing node..."); for (TestSlot testSlot : proxy.getTestSlots()) {
@Override public List<MetricFamilySamples> collect() { GaugeMetricFamily testSessionMetric = new GaugeMetricFamily("selenium_test_sessions_running", "The number of Selenium test sessions that are running by proxy type", Collections.singletonList("proxy")); Iterable<RemoteProxy> iterable = () -> proxySet.iterator(); Map<String, Integer> countByProxies = StreamSupport.stream(iterable.spliterator(), false).collect( Collectors.groupingBy(p -> p.getClass().getSimpleName(), Collectors.summingInt(p -> p.getTotalUsed()))); countByProxies.entrySet().stream() .forEach(e -> testSessionMetric.addMetric(Collections.singletonList(e.getKey()), e.getValue())); List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); mfs.add(testSessionMetric); return mfs; }
/** * Initializes proxy information from the supplied {@link RemoteProxy} object * * @param proxy * the {@link RemoteProxy} * @param queryStatus * whether to query the node status over HTTP via /wd/hub/status */ ProxyInfo(RemoteProxy proxy, boolean queryStatus) { // selenium supported features isBusy = proxy.isBusy(); percentResourceUsage = proxy.getResourceUsageInPercent(); totalUsed = proxy.getTotalUsed(); configuration = proxy.getConfig(); determineStatus(proxy, queryStatus); initUsageBySlot(proxy); // SelionRemoteProxy only initSeLionRemoteProxySpecificValues(proxy); }
private void initSeLionRemoteProxySpecificValues(RemoteProxy proxy) { if (SeLionRemoteProxy.class.getCanonicalName().equals( proxy.getOriginalRegistrationRequest().getRemoteProxyClass())) { SeLionRemoteProxy srp = (SeLionRemoteProxy) proxy; // figure out if the proxy is scheduled to shutdown isShuttingDown = srp.isScheduledForRecycle(); // update the logsLocation if the proxy supports LogServlet if (srp.supportsViewLogs()) { logsLocation = proxy.getRemoteHost().toExternalForm() + "/extra/" + LogServlet.class.getSimpleName(); } totalSessionsStarted = srp.getTotalSessionsStarted(); totalSessionsComplete = srp.getTotalSessionsComplete(); uptimeInMinutes = srp.getUptimeInMinutes(); } }
Map<String,RemoteProxy> proxies = new HashMap<>(); for(RemoteProxy proxy : proxySet) { Object instanceId = proxy.getConfig().get(AutomationConstants.INSTANCE_ID); if(node.getInstanceId().equals(instanceId)) { for(TestSlot testSlot : proxy.getTestSlots()) { AutomationRunRequest requestRepresentation = AutomationRunRequest.requestFromCapabilities(testSlot.getCapabilities()); existingSlots.add(requestRepresentation); for(TestSlot testSlot : proxy.getTestSlots()) {
private List<URL> getRegistryURLs(Registry registry) { Iterator<RemoteProxy> remoteProxyIterator = registry.getAllProxies().iterator(); List<URL> urlList = new ArrayList<>(); while (remoteProxyIterator.hasNext()) { RemoteProxy remoteProxy = remoteProxyIterator.next(); urlList.add(remoteProxy.getRemoteHost()); } return urlList; }
private JsonObject getResponse() throws IOException { 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.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } else { freeProxies.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } } requestJSON.add("BusyProxies", busyProxies); requestJSON.add("FreeProxies", freeProxies); return requestJSON; }
private String tabBrowsers() { List<TestSlot> testSlots = proxy.getTestSlots(); StringBuilder slotLines = new StringBuilder(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(testSlots.get(0).getCapabilities()); String version = desiredCapabilities.getVersion(); if (version != null) { version = "v:" + version; } Map<String, String> linesValues = new HashMap<>(); linesValues.put("{{browserVersion}}", version); // the lines of icons representing the possible slots StringBuilder singleSlotsHtml = new StringBuilder(); for (TestSlot testSlot : testSlots) { singleSlotsHtml.append(getSingleSlotHtml(testSlot)); } linesValues.put("{{singleSlots}}", singleSlotsHtml.toString()); slotLines.append(templateRenderer.renderSection("{{tabBrowsers}}", linesValues)); return slotLines.toString(); }