private String getFailureMessage(Result result, MonitoredService svc) { StringBuffer stringBuilder = new StringBuffer(); stringBuilder.append("Failed: "); for (Failure failure : result.getFailures()) { stringBuilder.append(" " + failure.getMessage() + "\n"); } String reason = "Selenium sequence failed: " + stringBuilder.toString(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); return stringBuilder.toString(); }
@Override public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for (tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt()) { String seleniumTestFilename = getGroovyFilename(parameters); try { Map<String, Number> responseTimes = new HashMap<String, Number>(); responseTimes.put(PollStatus.PROPERTY_RESPONSE_TIME, Double.NaN); tracker.startAttempt(); Result result = runTest( getBaseUrl(parameters, svc), getTimeout(parameters), createGroovyClass(seleniumTestFilename)); double responseTime = tracker.elapsedTimeInMillis(); responseTimes.put(PollStatus.PROPERTY_RESPONSE_TIME, responseTime); if (result.wasSuccessful()) { serviceStatus = PollStatus.available(); serviceStatus.setProperties(responseTimes); } else { serviceStatus = PollStatus.unavailable(getFailureMessage(result, svc)); } } catch (CompilationFailedException e) { serviceStatus = PollStatus.unavailable( "Selenium page sequence attempt on:" + svc.getIpAddr() + " failed : selenium-test compilation error " + e.getMessage()); String reason = "Selenium sequence failed: CompilationFailedException" + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } catch (IOException e) { serviceStatus = PollStatus.unavailable( "Selenium page sequence attempt on " + svc.getIpAddr() + " failed: IOException occurred, failed to find selenium-test: " + seleniumTestFilename); String reason = "Selenium sequence failed: IOException: " + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } catch (Exception e) { serviceStatus = PollStatus.unavailable( "Selenium page sequence attempt on " + svc.getIpAddr() + " failed:\n" + e.getMessage()); String reason = "Selenium sequence failed: Exception: " + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } } return serviceStatus; }