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

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

Source:SauceServlet.java Github

copy

Full Screen

...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

registerVirtualSauceNodeToGrid

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.SauceServlet;2import com.paypal.selion.grid.servlets.SauceServlet.SauceConfig;3SauceConfig sauceConfig = new SauceConfig();4sauceConfig.setSauceUserName("sauceUserName");5sauceConfig.setSauceAccessKey("sauceAccessKey");6sauceConfig.setSauceHost("ondemand.saucelabs.com");7sauceConfig.setSaucePort(80);8SauceServlet sauceServlet = new SauceServlet();9sauceServlet.registerVirtualSauceNodeToGrid(sauceConfig);

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