From: <st...@us...> - 2007-08-15 16:43:24
|
Revision: 5001 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=5001&view=rev Author: steve_l Date: 2007-08-15 09:43:21 -0700 (Wed, 15 Aug 2007) Log Message: ----------- SFOS-393 www waitforpage component doesnt fail abnormally when there is a timeout SFOS-394 www liveness and waitfor pages uses seconds and not milliseconds for sleeps -inconsistent with rest of the system SFOS-395 www liveness page tries to read the error text from the far end after an IO exception Modified Paths: -------------- trunk/core/components/www/src/org/smartfrog/services/www/LivenessPageChecker.java trunk/core/components/www/src/org/smartfrog/services/www/WaitForPageImpl.java trunk/core/components/www/src/org/smartfrog/services/www/livenessPage.sf trunk/core/components/www/test/org/smartfrog/services/www/servers/test/tomcat/components.sf Modified: trunk/core/components/www/src/org/smartfrog/services/www/LivenessPageChecker.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/LivenessPageChecker.java 2007-08-15 16:37:49 UTC (rev 5000) +++ trunk/core/components/www/src/org/smartfrog/services/www/LivenessPageChecker.java 2007-08-15 16:43:21 UTC (rev 5001) @@ -109,9 +109,9 @@ * Mime types */ protected HashMap mimeTypeMap; + private String errorMessage; - /** * create a new liveness page * @@ -277,7 +277,7 @@ int responseCode = connection.getResponseCode(); if (responseCode <= 0) { - throw new SmartFrogLivenessException("endpoint " + toString() + logAndRaise("Endpoint " + toString() + " is not returning HTTP responses"); } @@ -292,8 +292,7 @@ String message = "endpoint " + toString() + " returned error " + response + text; - log.error(message); - throw new SmartFrogLivenessException(message); + logAndRaise(message); } //now fetch the file @@ -302,9 +301,7 @@ if (mimeTypeMap != null) { String mimeType = connection.getContentType(); if (null == mimeTypeMap.get(mimeType)) { - String message = "Unexpected mimetype: " + mimeType; - log.error(message); - throw new SmartFrogLivenessException(message); + logAndRaise("Unexpected mimetype: " + mimeType); } } @@ -312,14 +309,26 @@ postProcess(responseCode, response, body); } catch (IOException exception) { - String text = maybeGetErrorText(connection); + //String text = maybeGetErrorText(connection); String message = "Failed to read " + targetURL.toString() + "\n" - + text + "\n" + exception.getMessage(); - throw new SmartFrogLivenessException(message, exception); + + "\n" + exception.getMessage(); + logAndRaise(message); } } /** + * Log the error message and raise an exception. + * The error text is also saved to {@link #errorMessage} + * @param message message to report + * @throws SmartFrogLivenessException + */ + private void logAndRaise(String message) throws SmartFrogLivenessException { + errorMessage = message; + log.error(message); + throw new SmartFrogLivenessException(message); + } + + /** * just a little something for subclassers out there * * @param responseCode @@ -571,7 +580,16 @@ this.fetchErrorText = fetchErrorText; } + /** + * Get any error message raised by the last poll + * @return + */ + public String getErrorMessage() { + return errorMessage; + } + + /** * query the enabled flag. * Overrides other options * Modified: trunk/core/components/www/src/org/smartfrog/services/www/WaitForPageImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/WaitForPageImpl.java 2007-08-15 16:37:49 UTC (rev 5000) +++ trunk/core/components/www/src/org/smartfrog/services/www/WaitForPageImpl.java 2007-08-15 16:43:21 UTC (rev 5001) @@ -24,6 +24,7 @@ import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.prim.TerminationRecord; import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.utils.SmartFrogThread; import java.rmi.RemoteException; @@ -33,19 +34,20 @@ public class WaitForPageImpl extends LivenessPageComponent implements WaitForPage, Runnable { - int timeout = 0; + private int timeout = 0; /** thread to do the work */ - private Thread worker = null; + private SmartFrogThread worker; + public static final String ERROR_WAIT_FOR_TIMEOUT = "Timeout waiting for a page to go live: \n"; public WaitForPageImpl() throws RemoteException { } - public Thread getWorker() { + public SmartFrogThread getWorker() { return worker; } - public void setWorker(Thread worker) { + public void setWorker(SmartFrogThread worker) { this.worker = worker; } @@ -72,8 +74,8 @@ throws SmartFrogException, RemoteException { super.sfStart(); timeout = sfResolve(ATTR_TIMEOUT, timeout, true); - worker=new Thread(this); - worker.setName(this.sfCompleteName().toString()); + worker=new SmartFrogThread(this); + worker.setName(sfCompleteName().toString()); worker.start(); } @@ -85,7 +87,7 @@ */ public synchronized void sfTerminateWith(TerminationRecord status) { super.sfTerminateWith(status); - Thread thread = getWorker(); + SmartFrogThread thread = getWorker(); if (thread != null && thread.isAlive()) { thread.interrupt(); } @@ -114,8 +116,8 @@ */ public void run() { long now = System.currentTimeMillis(); - long endTime = now+timeout*1000; - long sleepTime = getCheckFrequency()*1000; + long endTime = now+timeout; + long sleepTime = getCheckFrequency(); boolean timedOut; boolean success=false; boolean interrupted=false; @@ -148,7 +150,9 @@ if(!success) { //on a failure, grab the full text getLivenessPage().setFetchErrorText(true); + //poll the site lastException=poll(); + //and check that the success flag didnt change success=lastException==null; } TerminationRecord record; @@ -157,15 +161,21 @@ if(success) { //successful exit record = TerminationRecord.normal(name); + //now do a terminate with the relevant message + getHelper().sfSelfDetachAndOrTerminate(record); } else { //failure. Abnormal termination + String errorText = ERROR_WAIT_FOR_TIMEOUT + getLivenessPage().getTargetURL(); + if (getLivenessPage().getErrorMessage() != null) { + errorText = errorText + "\n" + getLivenessPage().getErrorMessage(); + } record = TerminationRecord.abnormal( - "Timeout waiting for a page to go live"+getLivenessPage().getTargetURL(), - name, - lastException); + errorText, + name, + lastException); + //always terminate with an error if something went wrong + sfTerminate(record); } - //now do a terminate with the relevant exception - getHelper().sfSelfDetachAndOrTerminate(record); } /** Modified: trunk/core/components/www/src/org/smartfrog/services/www/livenessPage.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/livenessPage.sf 2007-08-15 16:37:49 UTC (rev 5000) +++ trunk/core/components/www/src/org/smartfrog/services/www/livenessPage.sf 2007-08-15 16:43:21 UTC (rev 5001) @@ -76,8 +76,10 @@ maximumResponseCode extends OptionalInteger; //flag to follow redirects followRedirects extends OptionalBoolean; + //check frequency. This is the number of pings between checks - //and so lets us probe less often than normal. default=1 + //and so lets us probe less often than normal. + //this is in milliseconds checkFrequency extends OptionalInteger; //flag to say that the check is on/off; useful during development @@ -102,7 +104,7 @@ maximumResponseCode 299; minimumResponseCode 200; followRedirects true; - checkFrequency 1; + checkFrequency 1000; enabled true; checkOnStartup false; checkOnLiveness true; @@ -123,9 +125,11 @@ WaitForPage extends LivenessPage { WaitForPageSchema extends Schema { + //timeout in milliseconds timeout extends Integer; } sfClass "org.smartfrog.services.www.WaitForPageImpl"; + checkFrequency 500; fetchErrorText false; checkOnLiveness false; sfShouldTerminate true; Modified: trunk/core/components/www/test/org/smartfrog/services/www/servers/test/tomcat/components.sf =================================================================== --- trunk/core/components/www/test/org/smartfrog/services/www/servers/test/tomcat/components.sf 2007-08-15 16:37:49 UTC (rev 5000) +++ trunk/core/components/www/test/org/smartfrog/services/www/servers/test/tomcat/components.sf 2007-08-15 16:43:21 UTC (rev 5001) @@ -33,11 +33,11 @@ // a boolean property that is true if tomcat.home is non-empty tomcat.present IF (tomcat.home != "") THEN true ELSE false FI; +//tomcat fails big time if this is not set +jdk.home OPTIONAL("") PROPERTY test.jdk.home ; -jdk.home PROPERTY test.jdk.home ; - /** * A local page for liveness; assumes port 8080 */ @@ -131,12 +131,13 @@ /* * one test with a 10s shutdown */ -testWaitForTimesOut extends DeployTomcatTests { +testWaitForTimesOut extends ExpectDeployFailure { condition extends NoRunningServer; description "Wait for a few seconds for tomcat, then give up"; - tests extends WaitForTomcat { - timeout 5000; + + action extends WaitForTomcat { + timeout 1000; } - expectTerminate true; exitType FailingTestCompound:exitType; + exitText "Timeout waiting for a page to go live"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |