Best SeLion code snippet using com.paypal.selion.node.servlets.NodeForceRestartServlet
Source:SeLionRemoteProxy.java
...49import com.paypal.selion.grid.servlets.GridAutoUpgradeDelegateServlet;50import com.paypal.selion.logging.SeLionGridLogger;51import com.paypal.selion.node.servlets.LogServlet;52import com.paypal.selion.node.servlets.NodeAutoUpgradeServlet;53import com.paypal.selion.node.servlets.NodeForceRestartServlet;54import com.paypal.selion.pojos.BrowserInformationCache;55import com.paypal.selion.pojos.SeLionGridConstants;56import com.paypal.test.utilities.logging.SimpleLogger;57import com.paypal.test.utilities.logging.SimpleLoggerSettings;58/**59 * This is a customized {@link DefaultRemoteProxy} for SeLion. <br>60 * <br>61 * This proxy, when utilized can: <br>62 * <ul>63 * <li>Count unique test sessions. After "n" test sessions, the proxy disconnects from the grid and issues a requests to64 * {@link NodeForceRestartServlet}. The number of unique sessions is controlled via the json config file65 * <code>SeLionConfig.json</code> with the setting <code>uniqueSessionCount</code>.<br>66 * <br>67 * For example:68 *69 * <pre>70 * "uniqueSessionCount": 2571 * </pre>72 *73 * Here the value 25 indicates that the proxy will stop accepting new connections after 25 unique sessions and trigger a74 * graceful shutdown (see below). A value of <=0 indicates that this feature is disabled.</li>75 *76 * <li>Request remote proxy to shutdown either forcefully or gracefully -- issues a request to77 * {@link NodeForceRestartServlet}. In the case of a graceful restart, the proxy respects a wait timeout for any78 * sessions in progress to complete. This is controlled via the json config file <code>SeLionConfig.json</code> with the79 * setting <code>nodeRecycleThreadWaitTimeout</code>.<br>80 * <br>81 * For example:82 *83 * <pre>84 * "nodeRecycleThreadWaitTimeout": 30085 * </pre>86 *87 * Here the value 300 is in seconds -- the proxy will wait this amount of time before forcing a shutdown action. A value88 * of 0 indicates that the proxy will wait indefinitely.</li>89 *90 * <li>Request remote proxy to auto upgrade -- issues a request to {@link NodeAutoUpgradeServlet}.</li>91 *92 * <li>Determine whether the remote proxy supports {@link NodeAutoUpgradeServlet}, {@link NodeForceRestartServlet}, and93 * {@link LogServlet}</li>94 * </ul>95 */96public class SeLionRemoteProxy extends DefaultRemoteProxy {97 private static final SeLionGridLogger LOGGER = SeLionGridLogger.getLogger(SeLionRemoteProxy.class);98 private static final int DEFAULT_MAX_SESSIONS_ALLOWED = 50;99 private static final int CONNECTION_TIMEOUT = 30000;100 private volatile boolean scheduledShutdown;101 private volatile int totalSessionsCompleted, totalSessionsStarted;102 private final boolean canForceShutdown, canAutoUpgrade, canViewLogs;103 private final long proxyStartMillis;104 private final SimpleLogger proxyLogger;105 private final String machine;106 private final NodeRecycleThread nodeRecycleThread;107 private final Lock accessLock;108 /**109 * @param request110 * a {@link RegistrationRequest} request which represents the basic information that is to be consumed by111 * the grid when it is registering a new node.112 * @param registry113 * a {@link GridRegistry} object that represents the Grid's registry.114 * @throws IOException115 */116 public SeLionRemoteProxy(RegistrationRequest request, GridRegistry registry) throws IOException {117 super(request, registry);118 proxyStartMillis = System.currentTimeMillis();119 scheduledShutdown = false;120 totalSessionsCompleted = 0;121 totalSessionsStarted = 0;122 machine = getRemoteHost().getHost();123 nodeRecycleThread = new NodeRecycleThread(getId());124 accessLock = new ReentrantLock();125 // Setup the proxy logger126 SimpleLoggerSettings loggerSettings = new SimpleLoggerSettings();127 loggerSettings.setUserLogFileName(machine + ".log");128 loggerSettings.setLogsDir(SeLionGridConstants.LOGS_DIR);129 loggerSettings.setDevLevel(Level.OFF);130 loggerSettings.setLoggerName(machine);131 loggerSettings.setClassName(SeLionRemoteProxy.class.getSimpleName());132 loggerSettings.setIdentifier("SeLion-Grid-" + SeLionBuildInfo.getBuildValue(SeLionBuildProperty.SELION_VERSION));133 loggerSettings.setMaxFileCount(1);134 loggerSettings.setMaxFileSize(5);135 proxyLogger = SimpleLogger.getLogger(loggerSettings);136 // Log initialization info137 final int port = getRemoteHost().getPort();138 StringBuffer info = new StringBuffer();139 info.append("New proxy instantiated for the node ").append(machine).append(":").append(port);140 proxyLogger.info(info.toString());141 info = new StringBuffer();142 if (isEnabledMaxUniqueSessions()) {143 info.append("SeLionRemoteProxy will attempt to recycle the node ");144 info.append(machine).append(":").append(port).append(" after ").append(getMaxSessionsAllowed())145 .append(" unique sessions");146 } else {147 info.append("SeLionRemoteProxy will not attempt to recycle the node ");148 info.append(machine).append(":").append(port).append(" based on unique session counting.");149 }150 proxyLogger.info(info.toString());151 // Enable the cache to store the browser information only when the152 // "com.paypal.selion.grid.servlets.GridStatistics" is enabled - results in153 // better memory management if the servlet is not loaded154 if (isSupportedOnHub(GridStatistics.class)) {155 updateBrowserCache(request);156 }157 // detect presence of SeLion servlet capabilities on proxy158 canForceShutdown = isSupportedOnNode(NodeForceRestartServlet.class);159 canAutoUpgrade = isSupportedOnNode(NodeAutoUpgradeServlet.class);160 canViewLogs = isSupportedOnNode(LogServlet.class);161 }162 /**163 * Determine if the hub supports the servlet in question by looking at the registry configuration.164 * @param servlet165 * the {@link HttpServlet} to ping166 * @return <code>true</code> or <code>false</code>167 */168 private boolean isSupportedOnHub(Class<? extends HttpServlet> servlet) {169 LOGGER.entering();170 final boolean response = getRegistry().getHub().getConfiguration().servlets.contains(servlet.getCanonicalName());171 LOGGER.exiting(response);172 return response;173 }174 /**175 * Determine if the remote proxy supports the servlet in question by sending a http request to the remote. The176 * proxy configuration could also be used to make a similar decision. This approach allows the remote to use a177 * servlet which implements the same functionality as the `servlet` expected but does not necessarily reside in the178 * same namespace. This method expects the `servlet` to return HTTP 200 OK as an indication that the remote proxy179 * supports the `servlet` in question.180 *181 * @param servlet182 * the {@link HttpServlet} to ping183 * @return <code>true</code> or <code>false</code>184 */185 private boolean isSupportedOnNode(Class<? extends HttpServlet> servlet) {186 LOGGER.entering();187 RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)188 .setSocketTimeout(CONNECTION_TIMEOUT).build();189 CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();190 String url = String.format("http://%s:%d/extra/%s", machine, getRemoteHost().getPort(),191 servlet.getSimpleName());192 try {193 HttpGet get = new HttpGet(url);194 final HttpResponse getResponse = client.execute(get);195 if (getResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {196 proxyLogger.warning("Node " + getId() + " does not have or support " + servlet.getSimpleName());197 LOGGER.exiting(false);198 return false;199 }200 } catch (IOException e) {201 LOGGER.log(Level.SEVERE, e.getMessage(), e);202 LOGGER.exiting(false);203 return false;204 } finally {205 try {206 client.close();207 } catch (IOException e) {208 LOGGER.log(Level.SEVERE, e.getMessage(), e);209 }210 }211 LOGGER.exiting(true);212 return true;213 }214 private HttpResponse sendToNodeServlet(Class<? extends HttpServlet> servlet, List<NameValuePair> nvps) {215 LOGGER.entering();216 RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)217 .setSocketTimeout(CONNECTION_TIMEOUT).build();218 CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();219 String url = String.format("http://%s:%d/extra/%s", machine, this.getRemoteHost().getPort(),220 servlet.getSimpleName());221 HttpResponse postResponse = null;222 try {223 HttpPost post = new HttpPost(url);224 post.setEntity(new UrlEncodedFormEntity(nvps));225 postResponse = client.execute(post);226 } catch (IOException e) {227 LOGGER.log(Level.SEVERE, e.getMessage(), e);228 } finally {229 try {230 client.close();231 } catch (IOException e) {232 LOGGER.log(Level.SEVERE, e.getMessage(), e);233 }234 }235 LOGGER.exiting(postResponse);236 return postResponse;237 }238 /**239 * Upgrades the node by calling {@link NodeAutoUpgradeServlet} and then {@link #requestNodeShutdown}240 *241 * @param downloadJSON242 * the download.json to install on node243 * @return <code>true</code> on success. <code>false</code> when an error occured.244 */245 public boolean upgradeNode(String downloadJSON) {246 LOGGER.entering(downloadJSON);247 // verify the servlet is supported on the node248 if (!supportsAutoUpgrade()) {249 LOGGER.exiting(false);250 return false;251 }252 // call the NodeAutoUpgradeServlet on the node253 proxyLogger.fine("Upgrading node " + getId());254 List<NameValuePair> nvps = new ArrayList<>();255 nvps.add(new BasicNameValuePair(NodeAutoUpgradeServlet.TOKEN_PARAMETER,256 NodeAutoUpgradeServlet.CONFIGURED_TOKEN_VALUE));257 NameValuePair jsonNVP = new BasicNameValuePair(GridAutoUpgradeDelegateServlet.PARAM_JSON, downloadJSON);258 nvps.add(jsonNVP);259 HttpResponse response = sendToNodeServlet(NodeAutoUpgradeServlet.class, nvps);260 if (response == null) {261 proxyLogger.warning("Node " + getId() + " failed to upgrade and returned a null response.");262 LOGGER.exiting(false);263 return false;264 }265 final int responseStatusCode = response.getStatusLine().getStatusCode();266 if (responseStatusCode != HttpStatus.SC_OK) {267 proxyLogger.warning("Node " + getId() + " failed to upgrade and returned HTTP " + responseStatusCode);268 LOGGER.exiting(false);269 return false;270 }271 requestNodeShutdown();272 LOGGER.exiting(true);273 return true;274 }275 /**276 * @return whether the proxy has reached the max unique sessions277 */278 private boolean isMaxUniqueSessionsReached() {279 if (!isEnabledMaxUniqueSessions()) {280 return false;281 }282 return totalSessionsStarted >= getMaxSessionsAllowed();283 }284 @Override285 public TestSession getNewSession(Map<String, Object> requestedCapability) {286 LOGGER.entering();287 // verification should be before lock to avoid unnecessarily acquiring lock288 if (isMaxUniqueSessionsReached() || scheduledShutdown) {289 LOGGER.exiting(null);290 return logSessionInfo();291 }292 try {293 accessLock.lock();294 // As per double-checked locking pattern need to have check once again295 // to avoid spawning additional session then maxSessionAllowed296 if (isMaxUniqueSessionsReached() || scheduledShutdown) {297 LOGGER.exiting(null);298 return logSessionInfo();299 }300 TestSession session = super.getNewSession(requestedCapability);301 if (session != null) {302 // count ONLY if the session was a valid one303 totalSessionsStarted++;304 if (isMaxUniqueSessionsReached()) {305 startNodeRecycleThread();306 }307 proxyLogger.fine("Beginning session #" + totalSessionsStarted + " (" + session.toString() + ")");308 }309 LOGGER.exiting((session != null) ? session.toString() : null);310 return session;311 } finally {312 accessLock.unlock();313 }314 }315 private TestSession logSessionInfo() {316 proxyLogger.fine("Was max sessions reached? " + (isMaxUniqueSessionsReached()) + " on node " + getId());317 proxyLogger.fine("Was this a scheduled shutdown? " + (scheduledShutdown) + " on node " + getId());318 return null;319 }320 private void startNodeRecycleThread() {321 if (!getNodeRecycleThread().isAlive()) {322 getNodeRecycleThread().start();323 }324 }325 private void stopNodeRecycleThread() {326 if (getNodeRecycleThread().isAlive()) {327 try {328 getNodeRecycleThread().shutdown();329 getNodeRecycleThread().join(2000); // Wait no longer than 2x the recycle thread's loop330 } catch (InterruptedException e) { // NOSONAR331 // ignore332 }333 }334 }335 private void updateBrowserCache(RegistrationRequest request) throws MalformedURLException {336 // Update the browser information cache. Used by GridStatics servlet337 for (MutableCapabilities desiredCapabilities : request.getConfiguration().capabilities) {338 Map<String, ?> capabilitiesMap = desiredCapabilities.asMap();339 String browserName = capabilitiesMap.get(CapabilityType.BROWSER_NAME).toString();340 String maxInstancesAsString = capabilitiesMap.get("maxInstances").toString();341 if (StringUtils.isNotBlank(browserName) && StringUtils.isNotBlank(maxInstancesAsString)) {342 int maxInstances = Integer.valueOf(maxInstancesAsString);343 BrowserInformationCache cache = BrowserInformationCache.getInstance();344 cache.updateBrowserInfo(getRemoteHost(), browserName, maxInstances);345 }346 }347 }348 @Override349 public void afterSession(TestSession session) {350 LOGGER.entering();351 totalSessionsCompleted++;352 proxyLogger.fine("Completed session #" + totalSessionsCompleted + " (" + session.toString() + ")");353 proxyLogger.fine("Total number of slots used: " + getTotalUsed() + " on node: " + getId());354 LOGGER.exiting();355 }356 /**357 * Gracefully shuts the node down by;<br>358 * <br>359 * 1. Stops accepting new sessions<br>360 * 2. Waits for sessions to complete<br>361 * 3. Calls {@link #forceNodeShutdown}<br>362 */363 public void requestNodeShutdown() {364 LOGGER.entering();365 scheduledShutdown = true;366 startNodeRecycleThread();367 LOGGER.exiting();368 }369 /**370 * Forcefully shuts the node down by calling {@link NodeForceRestartServlet}371 */372 public synchronized void forceNodeShutdown() {373 LOGGER.entering();374 // stop the node recycle thread375 stopNodeRecycleThread();376 // verify the servlet is supported on the node377 if (!canForceShutdown) {378 // allow this proxy to keep going379 disableMaxSessions();380 scheduledShutdown = false;381 LOGGER.exiting();382 return;383 }384 // clean up the test slots385 for (TestSlot slot : getTestSlots()) {386 if (slot.getSession() != null) {387 totalSessionsCompleted++;388 proxyLogger.info("Timing out session #" + totalSessionsCompleted + " (" + slot.getSession().toString()389 + ")");390 getRegistry().forceRelease(slot, SessionTerminationReason.TIMEOUT);391 }392 }393 // call the node servlet394 List<NameValuePair> nvps = new ArrayList<>();395 nvps.add(new BasicNameValuePair(NodeForceRestartServlet.TOKEN_PARAMETER,396 NodeForceRestartServlet.CONFIGURED_TOKEN_VALUE));397 HttpResponse response = sendToNodeServlet(NodeForceRestartServlet.class, nvps);398 if (response == null) {399 proxyLogger.warning("Node " + getId() + " failed to shutdown and returned a null response.");400 // stop the polling thread, mark this proxy as down, force this proxy to re-register401 teardown("it failed to shutdown and must re-register");402 LOGGER.exiting();403 return;404 }405 final int responseStatusCode = response.getStatusLine().getStatusCode();406 if (responseStatusCode != HttpStatus.SC_OK) {407 proxyLogger.warning("Node " + getId() + " did not shutdown and returned HTTP " + responseStatusCode);408 // stop the polling thread, mark this proxy as down, force this proxy to re-register409 teardown("it failed to shutdown and must re-register");410 LOGGER.exiting();411 return;412 }413 // stop the polling thread, mark this proxy as down414 teardown("it is shutdown");415 proxyLogger.info("Node " + getId() + " shutdown successfully.");416 LOGGER.exiting();417 }418 private void teardown(String reason) {419 addNewEvent(new RemoteUnregisterException(String.format("Unregistering node %s because %s.",420 getId(), reason)));421 teardown();422 }423 /**424 * Thread will recycle the node when all active sessions are completed425 */426 class NodeRecycleThread extends Thread {427 private static final int DEFAULT_TIMEOUT = 0; // Waits forever428 private volatile boolean running;429 private final String nodeId;430 NodeRecycleThread(String nodeId) {431 super();432 running = false;433 this.nodeId = nodeId;434 }435 @Override436 public void run() {437 LOGGER.entering();438 running = true;439 int timeout = getThreadWaitTimeout();440 int expired = 0;441 proxyLogger.fine("Started NodeRecycleThread with " + ((timeout == 0) ? "no" : "a " + timeout + " second")442 + " timeout for node " + nodeId);443 while (keepLooping(expired, timeout)) {444 try {445 sleep(1000);446 expired += 1;447 } catch (InterruptedException e) {448 if (running) {449 // SEVERE, only if shutdown() was not called450 LOGGER.log(Level.SEVERE, e.getMessage(), e);451 }452 running = false;453 proxyLogger.warning("NodeRecycleThread was interrupted.");454 LOGGER.exiting();455 return;456 }457 }458 if (wasExpired(expired, timeout)) {459 proxyLogger.info("Timeout occurred while waiting for sessions to complete. Shutting down the node.");460 } else {461 proxyLogger.info("All sessions are complete. Shutting down the node.");462 }463 forceNodeShutdown();464 LOGGER.exiting();465 }466 int getThreadWaitTimeout() {467 final String key = "nodeRecycleThreadWaitTimeout";468 return config.custom.containsKey(key) ? Integer.parseInt(config.custom.get(key)) : DEFAULT_TIMEOUT;469 }470 private boolean keepLooping(int expired, int timeout) {471 return (getTotalUsed() > 0) && running && ((expired < timeout) || (timeout == 0));472 }473 private boolean wasExpired(int expired, int timeout) {474 return (expired >= timeout) && (timeout != 0);475 }476 public void shutdown() {477 LOGGER.entering();478 running = false;479 proxyLogger.fine("Shutting down NodeRecycleThread for node " + nodeId);480 interrupt();481 LOGGER.exiting();482 }483 }484 /**485 * @return the {@link NodeRecycleThread} associated with this proxy486 */487 private NodeRecycleThread getNodeRecycleThread() {488 return nodeRecycleThread;489 }490 /**491 * disables the max session count for this node.492 */493 private void disableMaxSessions() {494 proxyLogger.warning("Disabling max unique sessions for Node " + getId());495 config.custom.put("uniqueSessionCount", "-1");496 }497 /**498 * @return an integer value which represents the number of unique sessions this proxy allows for before499 * automatically spinning up a {@link NodeRecycleThread}500 */501 private int getMaxSessionsAllowed() {502 final String key = "uniqueSessionCount";503 return config.custom.containsKey(key) ? Integer.parseInt(config.custom.get(key)) : DEFAULT_MAX_SESSIONS_ALLOWED;504 }505 /**506 * @return total uptime since proxy came online in minutes507 */508 public long getUptimeInMinutes() {509 return TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - proxyStartMillis);510 }511 /**512 * @return total number of sessions completed since proxy came online513 */514 public int getTotalSessionsComplete() {515 return totalSessionsCompleted;516 }517 /**518 * @return total number of sessions started since proxy came online519 */520 public int getTotalSessionsStarted() {521 return totalSessionsStarted;522 }523 /**524 * @return <code>true</code> or <code>false</code>, whether the proxy is scheduled for recycle525 */526 public boolean isScheduledForRecycle() {527 return getNodeRecycleThread().isAlive();528 }529 /**530 * @return whether the proxy supports/has running {@link NodeForceRestartServlet}531 */532 public boolean supportsForceShutdown() {533 return canForceShutdown;534 }535 /**536 * @return whether the proxy supports/has running {@link NodeAutoUpgradeServlet}537 */538 public boolean supportsAutoUpgrade() {539 return canAutoUpgrade;540 }541 /**542 * @return whether the proxy supports/has running {@link LogServlet}543 */544 public boolean supportsViewLogs() {...
Source:GridAutoUpgradeDelegateServlet.java
...27import org.openqa.grid.internal.RemoteProxy;28import org.openqa.grid.web.servlet.RegistryBasedServlet;29import com.paypal.selion.logging.SeLionGridLogger;30import com.paypal.selion.node.servlets.NodeAutoUpgradeServlet;31import com.paypal.selion.node.servlets.NodeForceRestartServlet;32import com.paypal.selion.pojos.SeLionGridConstants;33import com.paypal.selion.proxy.SeLionRemoteProxy;34import com.paypal.selion.utils.ServletHelper;35/**36 * This {@link RegistryBasedServlet} servlet is responsible for getting the following information from a Grid admin, and37 * relaying it to each of the nodes, so that they may go about gracefully upgrading themselves once they are done with38 * servicing any of the tests that are already running. This information is captured by {@link NodeAutoUpgradeServlet}39 * which actually undertakes the task of creating a simple properties file and dumps in all of this relayed information.40 * <ul>41 * <li>The URL from where Selenium jar, ChromeDriver binary, IEDriverServer binary can be downloaded.42 * <li>The checksum associated with the each of the artifacts so that it can be cross checked to ascertain validity of43 * the same.44 * </ul>45 * <br>46 * Requires the hub to also have {@link LoginServlet} available. Furthermore, only nodes which use47 * {@link SeLionRemoteProxy}, {@link NodeAutoUpgradeServlet}, and {@link NodeForceRestartServlet} or implement support48 * for the HTTP requests <b>/extra/NodeAutoUpgradeServlet</b> and <b>/extra/NodeForceRestartServlet</b> are compatible.<br>49 * <br>50 * If there isn't a process, such as SeLion's Grid with <i>continuousRestart</i> on, monitoring and restarting the node51 * on exit(), the node will be shutdown but not restarted.52 */53public class GridAutoUpgradeDelegateServlet extends RegistryBasedServlet {54 private static final long serialVersionUID = 1L;55 private static final SeLionGridLogger LOGGER = SeLionGridLogger.getLogger(GridAutoUpgradeDelegateServlet.class);56 /**57 * Resource path to the grid auto upgrade html template file58 */59 public static final String RESOURCE_PAGE_FILE = "/com/paypal/selion/html/gridAutoUpgradeDelegateServlet.html";60 public static final String PENDING_NODE_FILE = "/com/paypal/selion/html/gridAutoUpgradePendingNode.html";61 /**62 * Request parameter which may contain the list of nodes which fail to upgrade...
Source:GridForceRestartDelegateServlet.java
...13| the specific language governing permissions and limitations under the License. |14\*-------------------------------------------------------------------------------------------------------------------*/15package com.paypal.selion.grid.servlets;16import com.paypal.selion.logging.SeLionGridLogger;17import com.paypal.selion.node.servlets.NodeForceRestartServlet;18import com.paypal.selion.proxy.SeLionRemoteProxy;19import com.paypal.selion.utils.ServletHelper;20import org.openqa.grid.internal.ProxySet;21import org.openqa.grid.internal.GridRegistry;22import org.openqa.grid.internal.RemoteProxy;23import org.openqa.grid.web.servlet.RegistryBasedServlet;24import javax.servlet.ServletException;25import javax.servlet.http.HttpServletRequest;26import javax.servlet.http.HttpServletResponse;27import java.io.IOException;28import java.util.ArrayList;29import java.util.Iterator;30import java.util.List;31/**32 * This {@link RegistryBasedServlet} based servlet is responsible for sending restart requests to all the registered33 * nodes.<br>34 * <br>35 * This requires the hub to also have {@link LoginServlet} available. Furthermore, only nodes which use36 * {@link SeLionRemoteProxy} and {@link NodeForceRestartServlet} or implement support for the HTTP request37 * <b>/extra/NodeForceRestartServlet</b> are compatible.<br>38 * <br>39 * If there isn't a process, such as SeLion's Grid with <i>continuousRestart</i> on, monitoring and restarting the node40 * on exit(), the node will be shutdown but not restarted.41 */42public class GridForceRestartDelegateServlet extends RegistryBasedServlet {43 /**44 * Resource path to the grid auto upgrade html template file45 */46 public static final String RESOURCE_PAGE_FILE = "/com/paypal/selion/html/gridForceRestartDelegateServlet.html";47 private static final long serialVersionUID = 1L;48 private static final SeLionGridLogger LOGGER = SeLionGridLogger.getLogger(GridForceRestartDelegateServlet.class);49 /**50 * Request parameter used to perform the restart. Value must be 'restart_nodes'.51 */...
NodeForceRestartServlet
Using AI Code Generation
1package com.paypal.selion.node.servlets;2import java.io.IOException;3import java.io.PrintWriter;4import javax.servlet.ServletException;5import javax.servlet.http.HttpServlet;6import javax.servlet.http.HttpServletRequest;7import javax.servlet.http.HttpServletResponse;8public class NodeForceRestartServlet extends HttpServlet {9private static final long serialVersionUID = 1L;10public NodeForceRestartServlet() {11super();12}13protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
NodeForceRestartServlet
Using AI Code Generation
1package com.paypal.selion.node.servlets;2import java.io.IOException;3import java.io.PrintWriter;4import javax.servlet.ServletException;5import javax.servlet.http.HttpServlet;6import javax.servlet.http.HttpServletRequest;7import javax.servlet.http.HttpServletResponse;8public class NodeForceRestartServlet extends HttpServlet {9 private static final long serialVersionUID = 1L;10 public NodeForceRestartServlet() {11 super();12 }13 protected void doGet(HttpServletRequest request, HttpServletResponse response)14 throws ServletException, IOException {15 response.setContentType("text/html
NodeForceRestartServlet
Using AI Code Generation
1import com.paypal.selion.node.servlets.NodeForceRestartServlet;2import com.paypal.selion.node.servlets.NodeForceRestartServlet;3public class NodeForceRestartServletTest extends BaseTest {4 public void testDoGet() throws Exception {5 NodeForceRestartServlet servlet = new NodeForceRestartServlet();6 servlet.doGet(null, null);7 }8}9public class NodeForceRestartServletTest extends BaseTest {10 public void testDoGet() throws Exception {11 NodeForceRestartServlet servlet = new NodeForceRestartServlet();12 servlet.doGet(null, null);13 }14}15package com.paypal.selion.node.servlets;16import com.paypal.selion.node.servlets.NodeForceRestartServlet;17import org.testng.annotations.Test;18public class NodeForceRestartServletTest extends BaseTest {19 public void testDoGet() throws Exception {20 NodeForceRestartServlet servlet = new NodeForceRestartServlet();21 servlet.doGet(null, null);22 }23}24package com.paypal.selion.node.servlets;25import com.paypal.selion.node.servlets.NodeForceRestartServlet;26import org.testng.annotations.Test;27public class NodeForceRestartServletTest extends BaseTest {28 public void testDoGet() throws Exception {29 NodeForceRestartServlet servlet = new NodeForceRestartServlet();30 servlet.doGet(null, null);31 }32}33package com.paypal.selion.node.servlets;34import com.paypal.selion.node.servlets.NodeForceRestartServlet;35import org.testng.annotations.Test;36public class NodeForceRestartServletTest extends BaseTest {37 public void testDoGet() throws Exception {38 NodeForceRestartServlet servlet = new NodeForceRestartServlet();39 servlet.doGet(null, null);40 }41}42package com.paypal.selion.node.servlets;43import com.paypal.selion.node.servlets.NodeForceRestartServlet;44import org.testng.annotations.Test;45public class NodeForceRestartServletTest extends BaseTest {46 public void testDoGet() throws Exception {47 NodeForceRestartServlet servlet = new NodeForceRestartServlet();48 servlet.doGet(null, null);49 }50}51package com.paypal.selion.node.servlets;52import com.paypal.selion.node.servlets.NodeForceRestartServlet;53import org.testng.annotations.Test;
NodeForceRestartServlet
Using AI Code Generation
1package com.paypal.selion.node.servlets;2import java.io.IOException;3import javax.servlet.ServletException;4import javax.servlet.http.HttpServlet;5import javax.servlet.http.HttpServletRequest;6import javax.servlet.http.HttpServletResponse;7public class NodeForceRestartServlet extends HttpServlet {8 private static final long serialVersionUID = 1L;9 public NodeForceRestartServlet() {10 super();11 }12 protected void doGet(HttpServletRequest request, HttpServletResponse response)13 throws ServletException, IOException {14 response.getWriter().append("Served at: ").append(request.getContextPath());15 }16 protected void doPost(HttpServletRequest request, HttpServletResponse response)17 throws ServletException, IOException {18 doGet(request, response);19 }20}21package com.paypal.selion.node.servlets;22import java.io.IOException;23import java.io.PrintWriter;24import javax.servlet.ServletException;25import javax.servlet.http.HttpServlet;26import javax.servlet.http.HttpServletRequest;27import javax.servlet.http.HttpServletResponse;28public class NodeForceRestartServlet extends HttpServlet {29 private static final long serialVersionUID = 1L;30 public NodeForceRestartServlet() {31 super();32 }33 protected void doGet(HttpServletRequest request, HttpServletResponse response)34 throws ServletException, IOException {35 response.getWriter().append("Served at: ").append(request.getContextPath());36 }37 protected void doPost(HttpServletRequest request, HttpServletResponse response)38 throws ServletException, IOException {39 doGet(request, response);40 }41}42package com.paypal.selion.node.servlets;43import java.io.IOException;44import java.io.PrintWriter;45import javax.servlet.ServletException;46import javax.servlet.http.HttpServlet;47import javax.servlet.http.HttpServletRequest;48import javax.servlet.http.HttpServletResponse;49public class NodeForceRestartServlet extends HttpServlet {50 private static final long serialVersionUID = 1L;51 public NodeForceRestartServlet() {52 super();53 }54 protected void doGet(HttpServletRequest request, HttpServletResponse response)55 throws ServletException, IOException {56 response.getWriter().append("Served at: ").append(request.getContextPath());57 }58 protected void doPost(HttpServletRequest
NodeForceRestartServlet
Using AI Code Generation
1import com.paypal.selion.node.servlets.NodeForceRestartServlet;2public class 3 {3 public static void main(String[] args) {4 NodeForceRestartServlet nodeForceRestartServlet = new NodeForceRestartServlet();5 nodeForceRestartServlet.doGet();6 }7}8import com.paypal.selion.node.servlets.NodeForceRestartServlet;9public class 4 {10 public static void main(String[] args) {11 NodeForceRestartServlet nodeForceRestartServlet = new NodeForceRestartServlet();12 nodeForceRestartServlet.doPost();13 }14}15import com.paypal.selion.node.servlets.NodeForceRestartServlet;16public class 5 {17 public static void main(String[] args) {18 NodeForceRestartServlet nodeForceRestartServlet = new NodeForceRestartServlet();19 nodeForceRestartServlet.doPut();20 }21}22import com.paypal.selion.node.servlets.NodeForceRestartServlet;23public class 6 {24 public static void main(String[] args) {25 NodeForceRestartServlet nodeForceRestartServlet = new NodeForceRestartServlet();26 nodeForceRestartServlet.doDelete();27 }28}29import com.paypal.selion.node.servlets.NodeForceRestartServlet;30public class 7 {31 public static void main(String[] args) {32 NodeForceRestartServlet nodeForceRestartServlet = new NodeForceRestartServlet();33 nodeForceRestartServlet.doHead();34 }35}36import com.paypal.selion.node.servlets.NodeForceRestartServlet;37public class 8 {38 public static void main(String[] args) {39 NodeForceRestartServlet nodeForceRestartServlet = new NodeForceRestartServlet();40 nodeForceRestartServlet.doOptions();41 }42}
NodeForceRestartServlet
Using AI Code Generation
1package com.paypal.selion.node.servlets;2import java.io.IOException;3import java.util.concurrent.TimeUnit;4import org.openqa.grid.internal.Registry;5import org.openqa.grid.internal.RemoteProxy;6import org.openqa.grid.internal.TestSession;7import org.openqa.grid.selenium.proxy.DefaultRemoteProxy;8import org.openqa.grid.web.servlet.RegistryBasedServlet;9import org.openqa.selenium.remote.SessionId;10import javax.servlet.ServletException;11import javax.servlet.http.HttpServletRequest;12import javax.servlet.http.HttpServletResponse;13public class NodeForceRestartServlet extends RegistryBasedServlet {14 private static final long serialVersionUID = 1L;15 public NodeForceRestartServlet() {16 this(null);17 }18 public NodeForceRestartServlet(Registry registry) {19 super(registry);20 }21 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {22 String proxyId = request.getParameter("proxyId");23 if (registry == null) {24 response.getWriter().print("No registry found. Shutting down node.");25 response.getWriter().close();26 System.exit(0);27 }28 RemoteProxy proxy = registry.getProxyById(proxyId);29 if (proxy == null) {30 response.getWriter().print("No proxy found for proxyId: " + proxyId);31 response.getWriter().close();32 return;33 }34 if (!(proxy instanceof DefaultRemoteProxy)) {35 response.getWriter().print("Proxy found for proxyId: " + proxyId + " is not a DefaultRemoteProxy instance.");36 response.getWriter().close();37 return;38 }39 DefaultRemoteProxy defaultProxy = (DefaultRemoteProxy) proxy;40 if (defaultProxy.getTestSessions().size() > 0) {41 TestSession testSession = defaultProxy.getTestSessions().get(0);42 SessionId sessionId = testSession.getExternalKey();43 response.getWriter().print("Session: " + sessionId + " is still active on proxy: " + proxyId);44 response.getWriter().close();45 return;46 }47 try {48 TimeUnit.SECONDS.sleep(10);49 } catch (InterruptedException e) {50 e.printStackTrace();51 }52 response.getWriter().print("Proxy: " + proxyId + " has been restarted.");53 response.getWriter().close();54 defaultProxy.forceRestart();55 }56}57package com.paypal.selion.node.servlets;58import java.io.IOException;59import java
NodeForceRestartServlet
Using AI Code Generation
1package com.paypal.selion.node.servlets;2import java.io.IOException;3import javax.servlet.ServletException;4import javax.servlet.http.HttpServlet;5import javax.servlet.http.HttpServletRequest;6import javax.servlet.http.HttpServletResponse;7import org.openqa.grid.internal.Registry;8import org.openqa.grid.web.servlet.RegistryBasedServlet;9import com.paypal.selion.node.servlets.processors.RequestProcessor;10public class NodeForceRestartServlet extends RegistryBasedServlet {11 private static final long serialVersionUID = 1L;12 public NodeForceRestartServlet() {13 this(null);14 }15 public NodeForceRestartServlet(Registry registry) {16 super(registry);17 }18 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {19 RequestProcessor processor = new RequestProcessor(request, response);20 processor.process();21 }22}23package com.paypal.selion.node.servlets.processors;24import java.io.IOException;25import java.util.HashMap;26import java.util.Map;27import javax.servlet.http.HttpServletRequest;28import javax.servlet.http.HttpServletResponse;29import org.openqa.grid.common.RegistrationRequest;30import org.openqa.grid.internal.Registry;31import org.openqa.grid.internal.RemoteProxy;32import org.openqa.grid.web.servlet.RegistryBasedServlet;33import com.paypal.selion.node.servlets.processors.utilities.ServletHelper;34public class RequestProcessor {35 private HttpServletRequest request;36 private HttpServletResponse response;37 private Registry registry;38 private Map<String, Object> params;39 private String node;40 public RequestProcessor(HttpServletRequest request, HttpServletResponse response) {41 this.request = request;42 this.response = response;43 this.registry = RegistryBasedServlet.getRegistry();44 this.params = new HashMap<String, Object>();45 this.node = request.getParameter("node");46 }47 public void process() throws IOException {48 if (node == null) {49 ServletHelper.writeErrorToResponse(response, "No node specified");50 return;51 }52 RemoteProxy proxy = registry.getProxyById(node);53 if (proxy == null) {
NodeForceRestartServlet
Using AI Code Generation
1package com.paypal.selion.node.servlets;2import java.io.IOException;3import javax.servlet.ServletException;4import javax.servlet.http.HttpServlet;5import javax.servlet.http.HttpServletRequest;6import javax.servlet.http.HttpServletResponse;7import org.apache.commons.lang.StringUtils;8import org.openqa.grid.internal.Registry;9import org.openqa.grid.internal.RemoteProxy;10import org.openqa.grid.web.servlet.RegistryBasedServlet;11import com.paypal.selion.node.servlets.processors.RequestProcessor;12import com.paypal.selion.node.servlets.processors.RequestProcessorFactory;13import com.paypal.selion.node.servlets.processors.RestartRequestProcessor;14import com.paypal.selion.node.servlets.processors.ShutdownRequestProcessor;15import com.paypal.selion.node.servlets.processors.StatusRequestProcessor;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!