Commit a8d98f64 authored by gmantele's avatar gmantele
Browse files

[UWS,TAP] Add the property 'creationTime' to a UWS (and so TAP as well) job.

This property is displayed in the XML and JSON serialization of a job item.
It is also backuped and restored from a UWS backup file.

/!\ WARNING: Small modification of the API! Since creationTime must be
             set by the UWS service at creation of a job, this date must also
             be imported at backup restoration. Hence the modification of the
             interface uws.service.UWSFactory and its implementations
             (particularly tap.AbstractTAPFactory). Similarly the class
             uws.job.UWSJob and tap.job.TAPJob have underwent exactly the same
             modification in one of their constructors.

This commit also adds the new optional jobRef items: creationTime, runID and
ownerID in the XML and JSON serializations.
parent 15f2fb81
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -124,15 +124,16 @@ public final class Json4Uws {
			json.put("version", UWS.VERSION);
			json.put(UWSJob.PARAM_JOB_ID, job.getJobId());
			json.put(UWSJob.PARAM_PHASE, job.getPhase());
			json.put(UWSJob.PARAM_RUN_ID, job.getRunId());
			if (job.getOwner() != null)
				json.put(UWSJob.PARAM_OWNER, job.getOwner().getPseudo());
			json.put(UWSJob.PARAM_CREATION_TIME, ISO8601Format.format(job.getCreationTime()));
			if (reference){
				if (jobsListUrl != null){
					jobsListUrl.setJobId(job.getJobId());
					json.put("href", jobsListUrl.getRequestURL());
				}
			}else{
				json.put(UWSJob.PARAM_RUN_ID, job.getRunId());
				if (job.getOwner() != null)
					json.put(UWSJob.PARAM_OWNER, job.getOwner().getPseudo());
				json.put(UWSJob.PARAM_QUOTE, job.getQuote());
				if (job.getStartTime() != null)
					json.put(UWSJob.PARAM_START_TIME, ISO8601Format.format(job.getStartTime()));
+38 −37
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package tap;
 * 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-2016 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -28,6 +28,12 @@ import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import adql.db.DBChecker;
import adql.parser.ADQLParser;
import adql.parser.ADQLQueryFactory;
import adql.parser.ParseException;
import adql.parser.QueryChecker;
import adql.query.ADQLQuery;
import tap.db.DBConnection;
import tap.error.DefaultTAPErrorWriter;
import tap.metadata.TAPMetadata;
@@ -43,19 +49,13 @@ import uws.service.UWS;
import uws.service.UWSService;
import uws.service.backup.UWSBackupManager;
import uws.service.error.ServiceErrorWriter;
import adql.db.DBChecker;
import adql.parser.ADQLParser;
import adql.parser.ADQLQueryFactory;
import adql.parser.ParseException;
import adql.parser.QueryChecker;
import adql.query.ADQLQuery;

/**
 * Default implementation of most of the {@link TAPFactory} function.
 * Only the functions related with the database connection stay abstract.
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.1 (01/2016)
 * @version 2.2 (09/2017)
 */
public abstract class AbstractTAPFactory extends TAPFactory {

@@ -279,14 +279,15 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	 * <p>This implementation provides a basic {@link TAPJob} instance.</p>
	 *
	 * <p>
	 * 	If you need to add or modify the behavior of some functions of a {@link TAPJob},
	 * 	you must override this function and return your own extension of {@link TAPJob}.
	 * 	If you need to add or modify the behavior of some functions of a
	 * 	{@link TAPJob}, you must override this function and return your own
	 * 	extension of {@link TAPJob}.
	 * </p>
	 */
	@Override
	protected TAPJob createTAPJob(final String jobId, final JobOwner owner, final TAPParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws UWSException{
	protected TAPJob createTAPJob(final String jobId, final long creationTime, final JobOwner owner, final TAPParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws UWSException{
		try{
			return new TAPJob(jobId, owner, params, quote, startTime, endTime, results, error);
			return new TAPJob(jobId, creationTime, owner, params, quote, startTime, endTime, results, error);
		}catch(TAPException te){
			if (te.getCause() != null && te.getCause() instanceof UWSException)
				throw (UWSException)te.getCause();
+104 −97
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package tap;
 * 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-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -25,6 +25,10 @@ import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import adql.parser.ADQLParser;
import adql.parser.ADQLQueryFactory;
import adql.parser.QueryChecker;
import adql.query.ADQLQuery;
import tap.db.DBConnection;
import tap.metadata.TAPSchema;
import tap.parameters.TAPParameters;
@@ -42,10 +46,6 @@ import uws.service.backup.UWSBackupManager;
import uws.service.error.ServiceErrorWriter;
import uws.service.file.UWSFileManager;
import uws.service.request.RequestParser;
import adql.parser.ADQLParser;
import adql.parser.ADQLQueryFactory;
import adql.parser.QueryChecker;
import adql.query.ADQLQuery;

/**
 * <p>Let build essential objects of the TAP service.</p>
@@ -63,7 +63,7 @@ import adql.query.ADQLQuery;
 * </ul>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (04/2015)
 * @version 2.2 (09/2017)
 */
public abstract class TAPFactory implements UWSFactory {

@@ -335,24 +335,27 @@ public abstract class TAPFactory implements UWSFactory {
	 * <p>Creates a UWS job with the following attributes.</p>
	 *
	 * <p>
	 * 	This implementation just call {@link #createTAPJob(String, JobOwner, TAPParameters, long, long, long, List, ErrorSummary)}
	 * 	with the given parameters, in order to ensure that the returned object is always a {@link TAPJob}.
	 * 	This implementation just call {@link #createTAPJob(String, long, JobOwner, TAPParameters, long, long, long, List, ErrorSummary)}
	 * 	with the given parameters, in order to ensure that the returned object
	 * 	is always a {@link TAPJob}.
	 * </p>
	 *
	 * <p><i>Note 1:
	 * 	This function is mainly used to restore a UWS job at the UWS initialization.
	 * 	This function is mainly used to restore a UWS job at the UWS
	 * 	initialization.
	 * </i></p>
	 *
	 * <p><i>Note 2:
	 * 	The job phase is chosen automatically from the given job attributes (i.e. no endTime => PENDING, no result and no error => ABORTED, ...).
	 * 	The job phase is chosen automatically from the given job attributes
	 * 	(i.e. no endTime => PENDING, no result and no error => ABORTED, ...).
	 * </i></p>
	 *
	 * @see uws.service.AbstractUWSFactory#createJob(java.lang.String, uws.job.user.JobOwner, uws.job.parameters.UWSParameters, long, long, long, java.util.List, uws.job.ErrorSummary)
	 * @see #createTAPJob(String, JobOwner, TAPParameters, long, long, long, List, ErrorSummary)
	 * @see uws.service.AbstractUWSFactory#createJob(String, long, JobOwner, UWSParameters, long, long, long, List, ErrorSummary)
	 * @see #createTAPJob(String, long, JobOwner, TAPParameters, long, long, long, List, ErrorSummary)
	 */
	@Override
	public final UWSJob createJob(String jobId, JobOwner owner, final UWSParameters params, long quote, long startTime, long endTime, List<Result> results, ErrorSummary error) throws UWSException{
		return createTAPJob(jobId, owner, (TAPParameters)params, quote, startTime, endTime, results, error);
	public final UWSJob createJob(String jobId, long creationTime, JobOwner owner, final UWSParameters params, long quote, long startTime, long endTime, List<Result> results, ErrorSummary error) throws UWSException{
		return createTAPJob(jobId, creationTime, owner, (TAPParameters)params, quote, startTime, endTime, results, error);
	}

	/**
@@ -363,6 +366,8 @@ public abstract class TAPFactory implements UWSFactory {
	 * </i></p>
	 *
	 * @param jobId			ID of the job (NOT NULL).
	 * @param creationTime	Creation date/time of the job (SHOULD NOT BE
	 *                    	NEGATIVE OR NULL).
	 * @param owner			Owner of the job.
	 * @param params		List of all input job parameters.
	 * @param quote			Its quote (in seconds).
@@ -374,8 +379,10 @@ public abstract class TAPFactory implements UWSFactory {
	 * @return	A new PENDING asynchronous job.
	 *
	 * @throws UWSException	If there is an error while creating the job.
	 *
	 * @since 2.2
	 */
	protected abstract TAPJob createTAPJob(final String jobId, final JobOwner owner, final TAPParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws UWSException;
	protected abstract TAPJob createTAPJob(final String jobId, final long creationTime, final JobOwner owner, final TAPParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws UWSException;

	/**
	 * <p>Create the thread which will execute the task described by the given UWSJob instance.</p>
+76 −62
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package tap;
 * 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-2016 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -37,15 +37,18 @@ import uws.job.user.JobOwner;
import uws.service.log.UWSLog.LogLevel;

/**
 * <p>Description of a TAP job. This class is used for asynchronous but also synchronous queries.</p>
 * Description of a TAP job. This class is used for asynchronous but also
 * synchronous queries.
 *
 * <p>
 * 	On the contrary to {@link UWSJob}, it is loading parameters from {@link TAPParameters} instances rather than {@link UWSParameters}.
 * 	However, {@link TAPParameters} is an extension of {@link UWSParameters}. That's what allow the UWS library to use both {@link TAPJob} and {@link TAPParameters}.
 * 	On the contrary to {@link UWSJob}, it is loading parameters from
 * 	{@link TAPParameters} instances rather than {@link UWSParameters}. However,
 * 	{@link TAPParameters} is an extension of {@link UWSParameters}. That's what
 * 	allow the UWS library to use both {@link TAPJob} and {@link TAPParameters}.
 * </p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.1 (01/2016)
 * @version 2.2 (09/2017)
 */
public class TAPJob extends UWSJob {
	private static final long serialVersionUID = 1L;
@@ -134,22 +137,33 @@ public class TAPJob extends UWSJob {
	}

	/**
	 * <p>Restore a job in a state defined by the given parameters.
	 * The phase must be set separately with {@link #setPhase(uws.job.ExecutionPhase, boolean)}, where the second parameter is true.</p>
	 * Restore a job in a state defined by the given parameters.
	 * The phase must be set separately with {@link #setPhase(uws.job.ExecutionPhase, boolean)},
	 * where the second parameter is true.
	 *
	 * @param jobID			ID of the job.
	 * @param creationTime	Creation date/time of the job (SHOULD NOT BE NEGATIVE OR NULL).
	 * @param owner			User who owns this job.
	 * @param params	Set of not-standard UWS parameters (i.e. what is called by {@link UWSJob} as additional parameters ; they includes all TAP parameters).
	 * @param params		Set of not-standard UWS parameters (i.e. what is
	 *              		called by {@link UWSJob} as additional parameters ;
	 *              		they includes all TAP parameters).
	 * @param quote			Quote of this job.
	 * @param startTime	Date/Time at which this job started. <i>(if not null, it means the job execution was finished, so a endTime should be provided)</i>
	 * @param startTime		Date/Time at which this job started.
	 *                 		<i>(if not null, it means the job execution was
	 *                 		finished, so a endTime should be provided)</i>
	 * @param endTime		Date/Time at which this job finished.
	 * @param results	List of results. <i>NULL if the job has not been executed, has been aborted or finished with an error.</i>
	 * @param results		List of results.
	 *               		<i>NULL if the job has not been executed, has been
	 *               		aborted or finished with an error.</i>
	 * @param error			Error with which this job ends.
	 *
	 * @throws TAPException	If one of the given parameters has a forbidden or wrong value.
	 * @throws TAPException	If one of the given parameters has a forbidden or
	 *                     	wrong value.
	 *
	 * @since 2.2
	 */
	public TAPJob(final String jobID, final JobOwner owner, final TAPParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws TAPException{
		super(jobID, owner, params, quote, startTime, endTime, results, error);
	public TAPJob(final String jobID, final long creationTime, final JobOwner owner, final TAPParameters params, final long quote, final long startTime, final long endTime, final List<Result> results, final ErrorSummary error) throws TAPException{
		super(jobID, creationTime, owner, params, quote, startTime, endTime, results, error);
		this.tapParams = params;
		this.tapParams.check();
	}
+17 −17
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ import uws.service.request.UWSRequestParser;
 * Concrete implementation of a {@link UWSFactory} which is parameterized by a UWS configuration file.
 *
 * @author Gr&eacute;gory Mantelet (ARI)
 * @version 4.2 (06/2017)
 * @version 4.3 (09/2017)
 * @since 4.2
 */
public class ConfigurableUWSFactory implements UWSFactory {
@@ -632,8 +632,8 @@ public class ConfigurableUWSFactory implements UWSFactory {
	}

	@Override
	public UWSJob createJob(String jobID, JobOwner owner, UWSParameters params, long quote, long startTime, long endTime, List<Result> results, ErrorSummary error) throws UWSException{
		return new UWSJob(jobID, owner, params, quote, startTime, endTime, results, error);
	public UWSJob createJob(String jobID, long creationTime, JobOwner owner, UWSParameters params, long quote, long startTime, long endTime, List<Result> results, ErrorSummary error) throws UWSException{
		return new UWSJob(jobID, creationTime, owner, params, quote, startTime, endTime, results, error);
	}

	@Override
Loading