From 2463d5fe98e0c72c420bf68321aebe7ec8aadd57 Mon Sep 17 00:00:00 2001 From: gmantele <gmantele@ari.uni-heidelberg.de> Date: Wed, 14 Sep 2016 18:32:53 +0200 Subject: [PATCH] [UWS,TAP] Follow up to the following commit about executionDuration: 47d36bfb6d4d246b281b53041ee1fde330b102ec In the UWS and TAP configuration files the executionDuration has to be provided into milliseconds. But the UWS parameter MUST be in seconds. So now, UWS is still keeping this duration in seconds (in its ExecutionDurationController) but TAP keeps it in milliseconds (in order to avoid unexpected silent modification of the API) and converts it into seconds for its controller (i.e. TAPExecutionDurationController), for the default home page and for the Capabilities page. --- src/tap/TAPSyncJob.java | 10 ++-- .../TAPExecutionDurationController.java | 13 +++-- src/tap/resource/HomePage.java | 12 ++-- src/uws/config/ConfigurableUWSFactory.java | 56 +++++++++---------- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/tap/TAPSyncJob.java b/src/tap/TAPSyncJob.java index bb6f867..c403dbb 100644 --- a/src/tap/TAPSyncJob.java +++ b/src/tap/TAPSyncJob.java @@ -48,7 +48,7 @@ import uws.service.log.UWSLog.LogLevel; * </p> * * @author Grégory Mantelet (CDS;ARI) - * @version 2.1 (01/2016) + * @version 2.1 (09/2016) */ public class TAPSyncJob { @@ -83,7 +83,7 @@ public class TAPSyncJob { * Create a synchronous TAP job. * * @param service Description of the TAP service which is in charge of this synchronous job. - * @param params Parameters of the query to execute. It must mainly contain the ADQL query to execute. + * @param params Parameters of the query to execute. It must mainly contain the ADQL query to execute. * * @throws NullPointerException If one of the parameters is NULL. */ @@ -248,12 +248,12 @@ public class TAPSyncJob { if (timeout && error != null && error instanceof InterruptedException){ // Log the timeout: if (thread.isAlive()) - service.getLogger().logTAP(LogLevel.WARNING, this, "TIME_OUT", "Time out (after " + tapParams.getExecutionDuration() + "ms) for the synchonous job " + ID + ", but the thread can not be interrupted!", null); + service.getLogger().logTAP(LogLevel.WARNING, this, "TIME_OUT", "Time out (after " + tapParams.getExecutionDuration() + "seconds) for the synchonous job " + ID + ", but the thread can not be interrupted!", null); else - service.getLogger().logTAP(LogLevel.INFO, this, "TIME_OUT", "Time out (after " + tapParams.getExecutionDuration() + "ms) for the synchonous job " + ID + ".", null); + service.getLogger().logTAP(LogLevel.INFO, this, "TIME_OUT", "Time out (after " + tapParams.getExecutionDuration() + "seconds) for the synchonous job " + ID + ".", null); // Report the timeout to the user: - throw new TAPException("Time out! The execution of this synchronous TAP query was limited to " + tapParams.getExecutionDuration() + "ms. You should try again but in asynchronous execution.", UWSException.ACCEPTED_BUT_NOT_COMPLETE); + throw new TAPException("Time out! The execution of this synchronous TAP query was limited to " + tapParams.getExecutionDuration() + "seconds. You should try again but in asynchronous execution.", UWSException.ACCEPTED_BUT_NOT_COMPLETE); } // CASE: ERRORS else if (!thread.isSuccess()){ diff --git a/src/tap/parameters/TAPExecutionDurationController.java b/src/tap/parameters/TAPExecutionDurationController.java index 0f3985c..d3f8d20 100644 --- a/src/tap/parameters/TAPExecutionDurationController.java +++ b/src/tap/parameters/TAPExecutionDurationController.java @@ -16,7 +16,7 @@ package tap.parameters; * You should have received a copy of the GNU Lesser General Public License * along with TAPLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2012,2014 - UDS/Centre de DonnĂ©es astronomiques de Strasbourg (CDS), + * Copyright 2012-2016 - UDS/Centre de DonnĂ©es astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ @@ -42,7 +42,7 @@ import uws.job.parameters.InputParamController; * </ul> * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (11/2014) + * @version 2.1 (09/2016) */ public class TAPExecutionDurationController implements InputParamController { @@ -80,7 +80,7 @@ public class TAPExecutionDurationController implements InputParamController { // Get the default value from the service connection: long defaultVal = TAPJob.UNLIMITED_DURATION; if (service.getExecutionDuration() != null && service.getExecutionDuration().length >= 2) - defaultVal = service.getExecutionDuration()[0]; + defaultVal = service.getExecutionDuration()[0] / 1000; // ServiceConnection keeps limits in MILLISECONDS, but the controller MUST work in SECONDS (TAP input and output for this parameter are always in seconds) // The default value is also limited by the maximum value if any: long maxVal = getMaxDuration(); @@ -95,7 +95,7 @@ public class TAPExecutionDurationController implements InputParamController { public final long getMaxDuration(){ if (service.getExecutionDuration() != null && service.getExecutionDuration().length >= 2){ if (service.getExecutionDuration()[1] > 0) - return service.getExecutionDuration()[1]; + return service.getExecutionDuration()[1] / 1000; // ServiceConnection keeps limits in MILLISECONDS, but the controller MUST work in SECONDS (TAP input and output for this parameter are always in seconds) } return TAPJob.UNLIMITED_DURATION; } @@ -107,9 +107,10 @@ public class TAPExecutionDurationController implements InputParamController { return getDefault(); // Get the default and maximum durations for comparison: - long defaultDuration = (Long)getDefault(), maxDuration = getMaxDuration(); + long defaultDuration = (Long)getDefault(), + maxDuration = getMaxDuration(); - // Parse the given duration: + // Parse the given duration: Long duration; if (value instanceof Long) duration = (Long)value; diff --git a/src/tap/resource/HomePage.java b/src/tap/resource/HomePage.java index 2fc9807..38acad4 100644 --- a/src/tap/resource/HomePage.java +++ b/src/tap/resource/HomePage.java @@ -16,7 +16,7 @@ package tap.resource; * You should have received a copy of the GNU Lesser General Public License * along with TAPLibrary. If not, see <http://www.gnu.org/licenses/>. * - * Copyright 2015 - Astronomisches Rechen Institut (ARI) + * Copyright 2015-2016 - Astronomisches Rechen Institut (ARI) */ import java.io.IOException; @@ -37,7 +37,7 @@ import uws.UWSToolBox; * * <p><i>Note: * This class is using the two following {@link TAP} attributes in order to display the home page: - * {@link TAP#homePageURI} and {@link TAP#homePageMimeType}. The MIME type is used only for the third case below (local file). + * {@link TAP#homePageURI} and {@link TAP#homePageMimeType}. The MIME type is used only for the third case below (local file). * </i></p> * * <p> @@ -52,7 +52,7 @@ import uws.UWSToolBox; * </p> * * @author Grégory Mantelet (ARI) - * @version 2.1 (11/2015) + * @version 2.1 (09/2016) * @since 2.0 */ public class HomePage extends ForwardResource { @@ -86,7 +86,7 @@ public class HomePage extends ForwardResource { public boolean executeResource(final HttpServletRequest request, final HttpServletResponse response) throws IOException, TAPException{ // Try by default a forward toward the specified file: boolean written = forward(tap.homePageURI, tap.homePageMimeType, request, response); - + // DEFAULT: list all available resources: if (!written){ // Set the content type: HTML document @@ -141,8 +141,8 @@ public class HomePage extends ForwardResource { // Execution duration limit: writer.print("\n\t\t\t<div class=\"formField\">\n\t\t\t\t<input id=\"toggleDuration\" type=\"checkbox\" onclick=\"toggleTextInput('EXECUTIONDURATION');\" /><label for=\"toggleDuration\"><strong>Duration limit:</strong></label> <input id=\"EXECUTIONDURATION\" type=\"text\" value=\"-1\" list=\"durationList\" disabled=\"disabled\" /> seconds <em>(a value ≤ 0 means 'default value')</em>\n\t\t\t\t<datalist id=\"durationList\">"); if (tap.getServiceConnection().getExecutionDuration() != null && tap.getServiceConnection().getExecutionDuration().length >= 2){ - writer.print("\n\t\t\t\t\t<option value=\"" + tap.getServiceConnection().getExecutionDuration()[0] + "\">Default</option>"); - writer.print("\n\t\t\t\t\t<option value=\"" + tap.getServiceConnection().getExecutionDuration()[1] + "\">Maximum</option>"); + writer.print("\n\t\t\t\t\t<option value=\"" + (tap.getServiceConnection().getExecutionDuration()[0] / 1000) + "\">Default</option>"); + writer.print("\n\t\t\t\t\t<option value=\"" + (tap.getServiceConnection().getExecutionDuration()[1] / 1000) + "\">Maximum</option>"); } writer.print("\n\t\t\t\t</datalist>\n\t\t\t</div>"); diff --git a/src/uws/config/ConfigurableUWSFactory.java b/src/uws/config/ConfigurableUWSFactory.java index e6fc325..0781498 100644 --- a/src/uws/config/ConfigurableUWSFactory.java +++ b/src/uws/config/ConfigurableUWSFactory.java @@ -68,7 +68,7 @@ import uws.service.request.UWSRequestParser; * Concrete implementation of a {@link UWSFactory} which is parameterized by a UWS configuration file. * * @author Grégory Mantelet (ARI) - * @version 4.2 (06/2016) + * @version 4.2 (09/2016) * @since 4.2 */ public class ConfigurableUWSFactory implements UWSFactory { @@ -167,7 +167,7 @@ public class ConfigurableUWSFactory implements UWSFactory { controller = new ExecutionDurationController(); // Set the default execution duration: - controller.setDefaultExecutionDuration(durationController.parseDuration(propValue)); + controller.setDefaultExecutionDuration(durationController.parseDuration(propValue) / 1000); // parseDuration(...) returns a duration in ms while executionDuration must be in seconds // Update the map of controllers for this job list: mapControllers.put(UWSJob.PARAM_EXECUTION_DURATION, controller); @@ -203,7 +203,7 @@ public class ConfigurableUWSFactory implements UWSFactory { controller = new ExecutionDurationController(); // Set the maximum execution duration: - controller.setMaxExecutionDuration(durationController.parseDuration(propValue)); + controller.setMaxExecutionDuration(durationController.parseDuration(propValue) / 1000); // parseDuration(...) returns a duration in ms while executionDuration must be in seconds // Update the map of controllers for this job list: mapControllers.put(UWSJob.PARAM_EXECUTION_DURATION, controller); @@ -389,7 +389,7 @@ public class ConfigurableUWSFactory implements UWSFactory { /* Note: it is possible if the same property key is found more than once in a property file. * In this case, the second list of parameters should update the first one. */ Map<String,InputParamController> jlParameters = jobParams.get(jlName); - + // If no list of controllers exists, create an empty one: if (jlParameters == null) jlParameters = new HashMap<String,InputParamController>(); @@ -433,10 +433,10 @@ public class ConfigurableUWSFactory implements UWSFactory { /* a parameter name must NOT contain any space character */ else if (!paramName.replaceFirst("\\s", "_").equals(paramName)) throw new UWSException("Incorrect syntax for the parameter name \"" + paramName + "\"! Space characters are forbidden."); - + // CASE: CUSTOM CONTROLLER if (matcher.group(4) != null){ - jlParameters.put(paramName, newInstance(matcher.group(4), jlName+"."+UWSConfiguration.KEY_PARAMETERS, InputParamController.class, new Class<?>[0], new Object[0])); + jlParameters.put(paramName, newInstance(matcher.group(4), jlName + "." + UWSConfiguration.KEY_PARAMETERS, InputParamController.class, new Class<?>[0], new Object[0])); } // CASE: STRING/NUMERIC/DURATION else{ @@ -446,41 +446,41 @@ public class ConfigurableUWSFactory implements UWSFactory { modif = true; else modif = false; - + // CASE: STRING if (matcher.group(11) != null){ - + // Create the controller: StringParamController controller = new StringParamController(paramName); - + // Set its modification flag: controller.allowModification(modif); - + // Set its default value, if any: if (matcher.group(12).length() > 0) controller.setDefaultValue(matcher.group(12)); - + // Set the regular expression: if (matcher.group(13).length() > 0) controller.setRegExp((matcher.group(15) != null ? "(?i)" : "") + matcher.group(13)); - + // Add the controller: jlParameters.put(paramName, controller); - + } - + // CASE: NUMERIC/DURATION else if (matcher.group(7) != null){ - + // CASE: NUMERIC if (matcher.group(7).trim().equalsIgnoreCase("numeric")){ - + // Create the controller: NumericParamController controller = new NumericParamController(); - + // Set its modification flag: controller.allowModification(modif); - + // Set the default value: if (matcher.group(8).trim().length() > 0){ try{ @@ -489,7 +489,7 @@ public class ConfigurableUWSFactory implements UWSFactory { throw new UWSException("Wrong numeric format for the default value of the parameter \"" + paramName + "\": \"" + matcher.group(8).trim() + "\"!"); } } - + // Set the minimum value: if (matcher.group(9).trim().length() > 0){ try{ @@ -498,7 +498,7 @@ public class ConfigurableUWSFactory implements UWSFactory { throw new UWSException("Wrong numeric format for the minimum value of the parameter \"" + paramName + "\": \"" + matcher.group(9).trim() + "\"!"); } } - + // Set the maximum value: if (matcher.group(10).trim().length() > 0){ try{ @@ -507,20 +507,20 @@ public class ConfigurableUWSFactory implements UWSFactory { throw new UWSException("Wrong numeric format for the maximum value of the parameter \"" + paramName + "\": \"" + matcher.group(10).trim() + "\"!"); } } - + // Add the controller: jlParameters.put(paramName, controller); - + } // CASE: DURATION else{ - + // Create the controller: DurationParamController controller = new DurationParamController(); - + // Set its modification flag: controller.allowModification(modif); - + // Set the default value: if (matcher.group(8).trim().length() > 0){ try{ @@ -531,7 +531,7 @@ public class ConfigurableUWSFactory implements UWSFactory { throw new UWSException("Incorrect syntax for the default duration of the parameter \"" + paramName + "\"! Cause: " + pe.getMessage()); } } - + // Set the minimum value: if (matcher.group(9).trim().length() > 0){ try{ @@ -542,7 +542,7 @@ public class ConfigurableUWSFactory implements UWSFactory { throw new UWSException("Incorrect syntax for the minimu duration of the parameter \"" + paramName + "\"! Cause: " + pe.getMessage()); } } - + // Set the maximum value: if (matcher.group(10).trim().length() > 0){ try{ @@ -553,7 +553,7 @@ public class ConfigurableUWSFactory implements UWSFactory { throw new UWSException("Incorrect syntax for the maximum duration of the parameter \"" + paramName + "\"! Cause: " + pe.getMessage()); } } - + // Add the controller: jlParameters.put(paramName, controller); } -- GitLab