How to use disconnectVirtualSauceNodeFromGrid method of com.paypal.selion.grid.servlets.SauceServlet class

Best SeLion code snippet using com.paypal.selion.grid.servlets.SauceServlet.disconnectVirtualSauceNodeFromGrid

Source:SauceServlet.java Github

copy

Full Screen

...78 }79 /*80 * Disconnects the virtual node from the hub81 */82 private synchronized void disconnectVirtualSauceNodeFromGrid(HttpServletRequest req, HttpServletResponse resp)83 throws IOException {84 // Redirecting to login page if session is not found85 if (req.getSession(false) == null) {86 resp.sendRedirect(LoginServlet.class.getSimpleName());87 return;88 }89 String msg = "There is no sauce node running.";90 final SeLionSauceProxy proxy = (SeLionSauceProxy) getRegistry().getProxyById(PROXY_ID);91 if (proxy != null) {92 proxy.teardown();93 getRegistry().removeIfPresent(proxy);94 msg = "Sauce node shutdown successfully.";95 }96 registered = false;97 LOGGER.info(msg);98 ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(msg));99 }100 /*101 * A helper method that takes care of registering a virtual node to the hub.102 */103 private synchronized void registerVirtualSauceNodeToGrid(HttpServletRequest req, HttpServletResponse resp)104 throws ServletException, IOException {105 // Redirecting to login page if session is not found106 if (req.getSession(false) == null) {107 resp.sendRedirect(LoginServlet.class.getSimpleName());108 return;109 }110 String respMsg = "Sauce node already registered.";111 if (registered) {112 ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(respMsg));113 LOGGER.info(respMsg);114 return;115 }116 HttpClientFactory httpClientFactory = new HttpClientFactory();117 respMsg = "Sauce node registration failed. Please refer to the log file for failure details.";118 try {119 final int port = getRegistry().getHub().getConfiguration().port;120 final URL registration = new URL("http://localhost:" + port + "/grid/register");121 BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",122 registration.toExternalForm());123 request.setEntity(new StringEntity(getRegistrationRequestEntity()));124 HttpHost host = new HttpHost(registration.getHost(), registration.getPort());125 HttpClient client = httpClientFactory.getHttpClient();126 HttpResponse response = client.execute(host, request);127 if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {128 respMsg = "Sauce node registered successfully.";129 registered = true;130 }131 } catch (IOException | GridConfigurationException e) { // We catch the GridConfigurationException here to fail132 // gracefully133 // TODO Consider retrying on failure134 LOGGER.log(Level.WARNING, "Unable to register sauce node: ", e);135 } finally {136 httpClientFactory.close();137 }138 LOGGER.info(respMsg);139 ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(respMsg));140 }141 /*142 * Update the registration request entity143 */144 private String getRegistrationRequestEntity() throws FileNotFoundException {145 // update the registration request with the max concurrent sessions/vms146 final GridNodeConfiguration gnc =147 GridNodeConfiguration.loadFromJSON(SeLionGridConstants.NODE_SAUCE_CONFIG_FILE);148 // get the max concurrent vm's allowed for the account from sauce labs149 final SauceLabsRestApi restApi;150 try {151 restApi = new SauceLabsRestApi();152 } catch (GridConfigurationException e) {153 throw e;154 }155 final int maxConcurrent = restApi.getMaxConcurrency();156 if (maxConcurrent != -1) {157 // update max sessions158 gnc.maxSession = maxConcurrent;159 // update browser max instances for all saucelabs "browser" types160 for (MutableCapabilities caps : gnc.capabilities) {161 if (caps.getBrowserName().equals(SAUCELABS_BROWSER_NAME)) {162 caps.setCapability(MAX_INSTANCES_CONFIG_PROPERTY, maxConcurrent);163 }164 }165 }166 // ensure the proxy host, port, id is set for http://ondemand.saucelabs.com:80167 if (StringUtils.isBlank(gnc.host)) {168 gnc.host = PROXY_HOST;169 }170 if (StringUtils.isBlank(gnc.id)) {171 gnc.id = PROXY_ID;172 }173 if (gnc.port == null || gnc.port < 0) {174 gnc.port = PROXY_PORT;175 }176 return new RegistrationRequest(gnc, SeLionSauceProxy.class.getSimpleName(),177 "SeLion Grid Virtual Sauce Proxy").toJson().toString();178 }179 @Override180 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {181 if (request.getParameter(SHUTDOWN_PARAM) != null) {182 disconnectVirtualSauceNodeFromGrid(request, response);183 return;184 }185 registerVirtualSauceNodeToGrid(request, response);186 }187 @Override188 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,189 IOException {190 if (request.getParameter(SHUTDOWN_PARAM) != null) {191 disconnectVirtualSauceNodeFromGrid(request, response);192 return;193 }194 registerVirtualSauceNodeToGrid(request, response);195 }196}...

Full Screen

Full Screen

disconnectVirtualSauceNodeFromGrid

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.sauce;2import java.io.IOException;3import org.testng.annotations.Test;4import com.paypal.selion.annotations.WebTest;5import com.paypal.selion.grid.servlets.SauceServlet;6public class DisconnectVirtualSauceNodeFromGrid{7 public void disconnectVirtualSauceNodeFromGrid() throws IOException{8 SauceServlet servlet = new SauceServlet();9 servlet.disconnectVirtualSauceNodeFromGrid("virtualSauceNode");10 }11}

Full Screen

Full Screen

disconnectVirtualSauceNodeFromGrid

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.SauceServlet;2SauceServlet sauceServlet = new SauceServlet();3sauceServlet.disconnectVirtualSauceNodeFromGrid();4import com.paypal.selion.grid.servlets.SauceServlet;5SauceServlet sauceServlet = new SauceServlet();6sauceServlet.disconnectVirtualSauceNodeFromGrid();7import com.paypal.selion.grid.servlets.SauceServlet;8SauceServlet sauceServlet = new SauceServlet();9sauceServlet.disconnectVirtualSauceNodeFromGrid();10import com.paypal.selion.grid.servlets.SauceServlet;11SauceServlet sauceServlet = new SauceServlet();12sauceServlet.disconnectVirtualSauceNodeFromGrid();13import com.paypal.selion.grid.servlets.SauceServlet;14SauceServlet sauceServlet = new SauceServlet();15sauceServlet.disconnectVirtualSauceNodeFromGrid();16import com.paypal.selion.grid.servlets.SauceServlet;17SauceServlet sauceServlet = new SauceServlet();18sauceServlet.disconnectVirtualSauceNodeFromGrid();19import com.paypal.selion.grid.servlets.SauceServlet;20SauceServlet sauceServlet = new SauceServlet();21sauceServlet.disconnectVirtualSauceNodeFromGrid();22import com.paypal.selion.grid.servlets.SauceServlet;23SauceServlet sauceServlet = new SauceServlet();24sauceServlet.disconnectVirtualSauceNodeFromGrid();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeLion 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