How to use getExternalUri method of org.openqa.selenium.grid.data.NodeStatus class

Best Selenium code snippet using org.openqa.selenium.grid.data.NodeStatus.getExternalUri

Source:LocalDistributor.java Github

copy

Full Screen

...256 RemoteNode remoteNode = new RemoteNode(257 tracer,258 clientFactory,259 status.getNodeId(),260 status.getExternalUri(),261 registrationSecret,262 capabilities);263 add(remoteNode);264 } finally {265 writeLock.unlock();266 }267 }268 @Override269 public LocalDistributor add(Node node) {270 Require.nonNull("Node", node);271 // An exception occurs if Node heartbeat has started but the server is not ready.272 // Unhandled exception blocks the event-bus thread from processing any event henceforth.273 NodeStatus initialNodeStatus;274 try {275 initialNodeStatus = node.getStatus();276 model.add(initialNodeStatus);277 nodes.put(node.getId(), node);278 } catch (Exception e) {279 LOG.log(280 Debug.getDebugLogLevel(),281 String.format("Exception while adding Node %s", node.getUri()),282 e);283 return this;284 }285 // Extract the health check286 Runnable healthCheck = asRunnableHealthCheck(node);287 allChecks.put(node.getId(), healthCheck);288 updateNodeStatus(initialNodeStatus, healthCheck);289 LOG.info(String.format(290 "Added node %s at %s. Health check every %ss",291 node.getId(),292 node.getUri(),293 healthcheckInterval.toMillis() / 1000));294 bus.fire(new NodeAddedEvent(node.getId()));295 return this;296 }297 private void updateNodeStatus(NodeStatus status, Runnable healthCheck) {298 // Setting the Node as available if the initial call to status was successful.299 // Otherwise, retry to have it available as soon as possible.300 if (status.getAvailability() == UP) {301 updateNodeAvailability(status.getExternalUri(), status.getNodeId(), status.getAvailability());302 } else {303 // Running the health check right after the Node registers itself. We retry the304 // execution because the Node might on a complex network topology. For example,305 // Kubernetes pods with IPs that take a while before they are reachable.306 RetryPolicy<Object> initialHealthCheckPolicy = new RetryPolicy<>()307 .withMaxAttempts(-1)308 .withMaxDuration(Duration.ofSeconds(90))309 .withDelay(Duration.ofSeconds(15))310 .abortIf(result -> true);311 LOG.log(getDebugLogLevel(), "Running health check for Node " + status.getExternalUri());312 Executors.newSingleThreadExecutor().submit(313 () -> Failsafe.with(initialHealthCheckPolicy).run(healthCheck::run));314 }315 }316 private Runnable runNodeHealthChecks() {317 return () -> {318 ImmutableMap<NodeId, Runnable> nodeHealthChecks = ImmutableMap.copyOf(allChecks);319 for (Runnable nodeHealthCheck : nodeHealthChecks.values()) {320 GuardedRunnable.guard(nodeHealthCheck).run();321 }322 };323 }324 private Runnable asRunnableHealthCheck(Node node) {325 HealthCheck healthCheck = node.getHealthCheck();...

Full Screen

Full Screen

Source:GridModel.java Github

copy

Full Screen

...79 NodeStatus next = iterator.next();80 // If the ID and the URI are the same, use the same81 // availability as the version we have now: we're just refreshing82 // an existing node.83 if (next.getNodeId().equals(node.getNodeId()) && next.getExternalUri().equals(node.getExternalUri())) {84 iterator.remove();85 LOG.log(Debug.getDebugLogLevel(), "Refreshing node with id %s", node.getNodeId());86 NodeStatus refreshed = rewrite(node, next.getAvailability());87 nodes.add(refreshed);88 nodePurgeTimes.put(refreshed.getNodeId(), Instant.now());89 updateHealthCheckCount(refreshed.getNodeId(), refreshed.getAvailability());90 return;91 }92 // If the URI is the same but NodeId is different, then the Node has restarted93 if(!next.getNodeId().equals(node.getNodeId()) &&94 next.getExternalUri().equals(node.getExternalUri())) {95 LOG.info(String.format("Re-adding node with id %s and URI %s.", node.getNodeId(), node.getExternalUri()));96 events.fire(new NodeRestartedEvent(node));97 iterator.remove();98 break;99 }100 // If the URI has changed, then assume this is a new node and fall101 // out of the loop: we want to add it as `DOWN` until something102 // changes our mind.103 if (next.getNodeId().equals(node.getNodeId())) {104 LOG.info(String.format("Re-adding node with id %s and URI %s.", node.getNodeId(), node.getExternalUri()));105 iterator.remove();106 break;107 }108 }109 // Nodes are initially added in the "down" state until something changes their availability110 LOG.log(111 Debug.getDebugLogLevel(),112 String.format("Adding node with id %s and URI %s", node.getNodeId(), node.getExternalUri()));113 NodeStatus refreshed = rewrite(node, DOWN);114 nodes.add(refreshed);115 nodePurgeTimes.put(refreshed.getNodeId(), Instant.now());116 updateHealthCheckCount(refreshed.getNodeId(), refreshed.getAvailability());117 } finally {118 writeLock.unlock();119 }120 }121 public void refresh(NodeStatus status) {122 Require.nonNull("Node status", status);123 Lock writeLock = lock.writeLock();124 writeLock.lock();125 try {126 Iterator<NodeStatus> iterator = nodes.iterator();127 while (iterator.hasNext()) {128 NodeStatus node = iterator.next();129 if (node.getNodeId().equals(status.getNodeId())) {130 iterator.remove();131 // if the node was marked as "down", keep it down until a healthcheck passes:132 // just because the node can hit the event bus doesn't mean it's reachable133 if (node.getAvailability() == DOWN) {134 nodes.add(rewrite(status, DOWN));135 } else {136 // Otherwise, trust what it tells us.137 nodes.add(status);138 }139 nodePurgeTimes.put(status.getNodeId(), Instant.now());140 return;141 }142 }143 } finally {144 writeLock.unlock();145 }146 }147 public void touch(NodeId id) {148 Require.nonNull("Node ID", id);149 Lock writeLock = lock.writeLock();150 writeLock.lock();151 try {152 NodeStatus node = getNode(id);153 if (node != null) {154 nodePurgeTimes.put(node.getNodeId(), Instant.now());155 }156 } finally {157 writeLock.unlock();158 }159 }160 public void remove(NodeId id) {161 Require.nonNull("Node ID", id);162 Lock writeLock = lock.writeLock();163 writeLock.lock();164 try {165 nodes.removeIf(n -> n.getNodeId().equals(id));166 nodePurgeTimes.remove(id);167 nodeHealthCount.remove(id);168 } finally {169 writeLock.unlock();170 }171 }172 public void purgeDeadNodes() {173 Lock writeLock = lock.writeLock();174 writeLock.lock();175 try {176 Map<NodeStatus, NodeStatus> replacements = new HashMap<>();177 Set<NodeStatus> toRemove = new HashSet<>();178 for (NodeStatus node : nodes) {179 NodeId id = node.getNodeId();180 if (nodeHealthCount.getOrDefault(id, 0) > UNHEALTHY_THRESHOLD) {181 toRemove.add(node);182 break;183 }184 Instant now = Instant.now();185 Instant lastTouched = nodePurgeTimes.getOrDefault(id, Instant.now());186 Instant lostTime = lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER / 2));187 Instant deadTime = lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER));188 if (node.getAvailability() == UP && lostTime.isBefore(now)) {189 LOG.info(String.format("Switching Node %s from UP to DOWN", node.getExternalUri()));190 replacements.put(node, rewrite(node, DOWN));191 }192 if (node.getAvailability() == DOWN && deadTime.isBefore(now)) {193 LOG.info(String.format("Removing Node %s, DOWN for too long", node.getExternalUri()));194 toRemove.add(node);195 }196 }197 replacements.forEach((before, after) -> {198 nodes.remove(before);199 nodes.add(after);200 });201 toRemove.forEach(node -> {202 nodes.remove(node);203 nodePurgeTimes.remove(node.getNodeId());204 nodeHealthCount.remove(node.getNodeId());205 events.fire(new NodeRemovedEvent(node));206 });207 } finally {208 writeLock.unlock();209 }210 }211 public Availability setAvailability(NodeId id, Availability availability) {212 Require.nonNull("Node ID", id);213 Require.nonNull("Availability", availability);214 Lock writeLock = lock.writeLock();215 writeLock.lock();216 try {217 NodeStatus node = getNode(id);218 if (node == null) {219 return DOWN;220 }221 if (availability.equals(node.getAvailability())) {222 if (node.getAvailability() == UP) {223 nodePurgeTimes.put(node.getNodeId(), Instant.now());224 }225 return availability;226 }227 LOG.info(String.format(228 "Switching node %s (uri: %s) from %s to %s",229 id,230 node.getExternalUri(),231 node.getAvailability(),232 availability));233 Availability previous = node.getAvailability();234 NodeStatus refreshed = rewrite(node, availability);235 nodes.remove(node);236 nodes.add(refreshed);237 nodePurgeTimes.put(node.getNodeId(), Instant.now());238 return previous;239 } finally {240 writeLock.unlock();241 }242 }243 public boolean reserve(SlotId slotId) {244 Lock writeLock = lock.writeLock();245 writeLock.lock();246 try {247 NodeStatus node = getNode(slotId.getOwningNodeId());248 if (node == null) {249 LOG.warning(String.format("Asked to reserve slot on node %s, but unable to find node", slotId.getOwningNodeId()));250 return false;251 }252 if (!UP.equals(node.getAvailability())) {253 LOG.warning(String.format(254 "Asked to reserve a slot on node %s, but node is %s",255 slotId.getOwningNodeId(),256 node.getAvailability()));257 return false;258 }259 Optional<Slot> maybeSlot = node.getSlots().stream()260 .filter(slot -> slotId.equals(slot.getId()))261 .findFirst();262 if (!maybeSlot.isPresent()) {263 LOG.warning(String.format(264 "Asked to reserve slot on node %s, but no slot with id %s found",265 node.getNodeId(),266 slotId));267 return false;268 }269 reserve(node, maybeSlot.get());270 return true;271 } finally {272 writeLock.unlock();273 }274 }275 public Set<NodeStatus> getSnapshot() {276 Lock readLock = this.lock.readLock();277 readLock.lock();278 try {279 return ImmutableSet.copyOf(nodes);280 } finally {281 readLock.unlock();282 }283 }284 private NodeStatus getNode(NodeId id) {285 Require.nonNull("Node ID", id);286 Lock readLock = lock.readLock();287 readLock.lock();288 try {289 return nodes.stream()290 .filter(n -> n.getNodeId().equals(id))291 .findFirst()292 .orElse(null);293 } finally {294 readLock.unlock();295 }296 }297 private NodeStatus rewrite(NodeStatus status, Availability availability) {298 return new NodeStatus(299 status.getNodeId(),300 status.getExternalUri(),301 status.getMaxSessionCount(),302 status.getSlots(),303 availability,304 status.getHeartbeatPeriod(),305 status.getVersion(),306 status.getOsInfo());307 }308 public void release(SessionId id) {309 if (id == null) {310 return;311 }312 Lock writeLock = lock.writeLock();313 writeLock.lock();314 try {315 for (NodeStatus node : nodes) {316 for (Slot slot : node.getSlots()) {317 if (slot.getSession()==null) {318 continue;319 }320 if (id.equals(slot.getSession().getId())) {321 Slot released = new Slot(322 slot.getId(),323 slot.getStereotype(),324 slot.getLastStarted(),325 null);326 amend(node.getAvailability(), node, released);327 return;328 }329 }330 }331 } finally {332 writeLock.unlock();333 }334 }335 public void reserve(NodeStatus status, Slot slot) {336 Instant now = Instant.now();337 Slot reserved = new Slot(338 slot.getId(),339 slot.getStereotype(),340 now,341 new Session(342 RESERVED,343 status.getExternalUri(),344 slot.getStereotype(),345 slot.getStereotype(),346 now));347 amend(UP, status, reserved);348 }349 public void setSession(SlotId slotId, Session session) {350 Require.nonNull("Slot ID", slotId);351 Lock writeLock = lock.writeLock();352 writeLock.lock();353 try {354 NodeStatus node = getNode(slotId.getOwningNodeId());355 if (node == null) {356 LOG.warning("Grid model and reality have diverged. Unable to find node " + slotId.getOwningNodeId());357 return;358 }359 Optional<Slot> maybeSlot = node.getSlots().stream()360 .filter(slot -> slotId.equals(slot.getId()))361 .findFirst();362 if (!maybeSlot.isPresent()) {363 LOG.warning("Grid model and reality have diverged. Unable to find slot " + slotId);364 return;365 }366 Slot slot = maybeSlot.get();367 Session maybeSession = slot.getSession();368 if (maybeSession == null) {369 LOG.warning("Grid model and reality have diverged. Slot is not reserved. " + slotId);370 return;371 }372 if (!RESERVED.equals(maybeSession.getId())) {373 LOG.warning(374 "Grid model and reality have diverged. Slot has session and is not reserved. " + slotId);375 return;376 }377 Slot updated = new Slot(378 slot.getId(),379 slot.getStereotype(),380 session == null ? slot.getLastStarted() : session.getStartTime(),381 session);382 amend(node.getAvailability(), node, updated);383 } finally {384 writeLock.unlock();385 }386 }387 public void updateHealthCheckCount(NodeId id, Availability availability) {388 Require.nonNull("Node ID", id);389 Require.nonNull("Availability", availability);390 Lock writeLock = lock.writeLock();391 writeLock.lock();392 try {393 int unhealthyCount = nodeHealthCount.getOrDefault(id, 0);394 // Keep track of consecutive number of times the Node health check fails395 if (availability.equals(DOWN)) {396 nodeHealthCount.put(id, unhealthyCount + 1);397 }398 // If the Node is healthy again before crossing the threshold, then reset the count.399 if (unhealthyCount <= UNHEALTHY_THRESHOLD && availability.equals(UP)) {400 nodeHealthCount.put(id, 0);401 }402 } finally {403 writeLock.unlock();404 }405 }406 private void amend(Availability availability, NodeStatus status, Slot slot) {407 Set<Slot> newSlots = new HashSet<>(status.getSlots());408 newSlots.removeIf(s -> s.getId().equals(slot.getId()));409 newSlots.add(slot);410 NodeStatus node = getNode(status.getNodeId());411 Lock writeLock = lock.writeLock();412 writeLock.lock();413 try {414 nodes.remove(node);415 nodes.add(new NodeStatus(416 status.getNodeId(),417 status.getExternalUri(),418 status.getMaxSessionCount(),419 newSlots,420 availability,421 status.getHeartbeatPeriod(),422 status.getVersion(),423 status.getOsInfo()));424 } finally {425 writeLock.unlock();426 }427 }428}...

Full Screen

Full Screen

Source:OneShotNode.java Github

copy

Full Screen

...127 loggingOptions.getTracer(),128 eventOptions.getEventBus(),129 serverOptions.getRegistrationSecret(),130 new NodeId(UUID.randomUUID()),131 serverOptions.getExternalUri(),132 nodeOptions.getPublicGridUri().orElseThrow(() -> new ConfigException("Unable to determine public grid address")),133 stereotype,134 driverInfo);135 }136 @Override137 public Optional<CreateSessionResponse> newSession(CreateSessionRequest sessionRequest) {138 if (driver != null) {139 throw new IllegalStateException("Only expected one session at a time");140 }141 Optional<WebDriver> driver = driverInfo.createDriver(sessionRequest.getCapabilities());142 if (!driver.isPresent()) {143 return Optional.empty();144 }145 if (!(driver.get() instanceof RemoteWebDriver)) {...

Full Screen

Full Screen

Source:Grid.java Github

copy

Full Screen

...83 status.getOsInfo().get("name"),84 status.getOsInfo().get("version"));85 toReturn.add(new Node(86 status.getNodeId(),87 status.getExternalUri(),88 status.getAvailability(),89 status.getMaxSessionCount(),90 status.getSlots().size(),91 stereotypes,92 sessions,93 status.getVersion(),94 osInfo));95 }96 return toReturn.build();97 }98 public int getNodeCount() {99 return distributorStatus.getNodes().size();100 }101 public int getSessionCount() {102 return distributorStatus.getNodes().stream()103 .map(NodeStatus::getSlots)104 .flatMap(Collection::stream)105 .filter(slot -> slot.getSession()!=null)106 .filter(slot -> !slot.getSession().getId().equals(RESERVED))107 .mapToInt(slot -> 1)108 .sum();109 }110 public int getTotalSlots() {111 return distributorStatus.getNodes().stream()112 .mapToInt(status -> status.getSlots().size())113 .sum();114 }115 public int getMaxSession() {116 return distributorStatus.getNodes().stream()117 .mapToInt(NodeStatus::getMaxSessionCount)118 .sum();119 }120 public int getSessionQueueSize() {121 return queueInfoList.size();122 }123 public List<String> getSessionQueueRequests() {124 // TODO: The Grid UI expects there to be a single capability per new session request, which is not correct125 return queueInfoList.stream()126 .map(set -> set.isEmpty() ? new ImmutableCapabilities() : set.iterator().next())127 .map(JSON::toJson)128 .collect(Collectors.toList());129 }130 public List<Session> getSessions() {131 List<Session> sessions = new ArrayList<>();132 for (NodeStatus status : distributorStatus.getNodes()) {133 for (Slot slot : status.getSlots()) {134 if (slot.getSession() != null && !slot.getSession().getId().equals(RESERVED)) {135 org.openqa.selenium.grid.data.Session session = slot.getSession();136 sessions.add(137 new org.openqa.selenium.grid.graphql.Session(138 session.getId().toString(),139 session.getCapabilities(),140 session.getStartTime(),141 session.getUri(),142 status.getNodeId().toString(),143 status.getExternalUri(),144 slot)145 );146 }147 }148 }149 return sessions;150 }151}...

Full Screen

Full Screen

Source:GridRedisClient.java Github

copy

Full Screen

...114 if (maybeNode.isPresent()) {115 NodeStatus node = maybeNode.get();116 NodeStatus resultNode = new NodeStatus(117 id,118 node.getExternalUri(),119 node.getMaxSessionCount(),120 node.getSlots(),121 node.getAvailability(),122 node.getHeartbeatPeriod(),123 node.getVersion(),124 node.getOsInfo());125 return Optional.of(resultNode);126 }127 return maybeNode;128 }129 public void removeAllNodes(Set<NodeId> nodeIds) {130 nodeIds.forEach(this::removeNode);131 }132 public Set<NodeStatus> getNodes(Set<NodeId> nodeIds) {...

Full Screen

Full Screen

Source:LocalSessionMap.java Github

copy

Full Screen

...66 .filter(slot -> slot.getSession() != null)67 .map(slot -> slot.getSession().getId())68 .forEach(knownSessions::remove)));69 bus.addListener(NodeRestartedEvent.listener(nodeStatus -> knownSessions.values()70 .removeIf(value -> value.getUri().equals(nodeStatus.getExternalUri()))));71 }72 public static SessionMap create(Config config) {73 Tracer tracer = new LoggingOptions(config).getTracer();74 EventBus bus = new EventBusOptions(config).getEventBus();75 return new LocalSessionMap(tracer, bus);76 }77 @Override78 public boolean isReady() {79 return bus.isReady();80 }81 @Override82 public boolean add(Session session) {83 Require.nonNull("Session", session);84 Lock writeLock = lock.writeLock();...

Full Screen

Full Screen

Source:SessionData.java Github

copy

Full Screen

...42 session.getCapabilities(),43 session.getStartTime(),44 session.getUri(),45 currentSession.node.getNodeId().toString(),46 currentSession.node.getExternalUri(),47 currentSession.slot);48 } else {49 throw new SessionNotFoundException("No ongoing session found with the requested session id.",50 sessionId);51 }52 }53 private SessionInSlot findSession(String sessionId, Set<NodeStatus> nodeStatuses) {54 for (NodeStatus status : nodeStatuses) {55 for (Slot slot : status.getSlots()) {56 org.openqa.selenium.grid.data.Session session = slot.getSession();57 if (session!=null && sessionId.equals(session.getId().toString())) {58 return new SessionInSlot(session, status, slot);59 }60 }...

Full Screen

Full Screen

Source:AddNode.java Github

copy

Full Screen

...53 Node node = new RemoteNode(54 tracer,55 httpFactory,56 status.getNodeId(),57 status.getExternalUri(),58 registrationSecret,59 status.getSlots().stream().map(Slot::getStereotype).collect(Collectors.toSet()));60 distributor.add(node);61 return new HttpResponse();62 }63}...

Full Screen

Full Screen

getExternalUri

Using AI Code Generation

copy

Full Screen

1package com.test;2import java.net.URI;3import java.net.URISyntaxException;4import org.openqa.selenium.grid.data.NodeStatus;5public class Test {6public static void main(String[] args) throws URISyntaxException {7 System.out.println(nodeStatus.getExternalUri());8}9}

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful