Commit 7ff003d9 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Passed JobOwner to ADQLExecutor and added QueryExecutor interface

parent 082f04b5
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import uws.UWSException;
import uws.UWSToolBox;
import uws.job.JobThread;
import uws.job.Result;
import uws.job.user.JobOwner;
import uws.service.log.UWSLog.LogLevel;

/**
@@ -223,7 +224,7 @@ public class ADQLExecutor {
		this.response = null;

		try {
			return start();
			return start(tapJob.getOwner());
		} catch(IOException ioe) {
			if (thread.isInterrupted())
				return report;
@@ -281,6 +282,7 @@ public class ADQLExecutor {
	 * @param jobId		ID of the corresponding job.
	 * @param params	All execution parameters (including the query to process).
	 * @param response	Object in which the result or the error must be written.
	 * @param jobOwner      The user executing the query
	 *
	 * @return	The resulting execution report.
	 *
@@ -290,7 +292,7 @@ public class ADQLExecutor {
	 *
	 * @see #start()
	 */
	public final TAPExecutionReport start(final Thread thread, final String jobId, final TAPParameters params, final HttpServletResponse response) throws TAPException, IOException, InterruptedException {
	public final TAPExecutionReport start(final Thread thread, final String jobId, final TAPParameters params, final HttpServletResponse response, final JobOwner jobOwner) throws TAPException, IOException, InterruptedException {
		if (this.thread != null || this.report != null)
			throw new TAPException("This ADQLExecutor has already been executed!");

@@ -300,7 +302,7 @@ public class ADQLExecutor {
		this.response = response;

		try {
			return start();
			return start(jobOwner);
		} catch(UWSException ue) {
			throw new TAPException(ue, ue.getHttpErrorCode());
		}
@@ -336,7 +338,7 @@ public class ADQLExecutor {
	 *                    			In asynchronous, the error is stored as job error report and is never propagated.</i>
	 * @throws InterruptedException	If the job has been interrupted (by the user or a time-out).
	 */
	protected final TAPExecutionReport start() throws TAPException, UWSException, IOException, InterruptedException {
	protected final TAPExecutionReport start(JobOwner jobOwner) throws TAPException, UWSException, IOException, InterruptedException {
		logger.logTAP(LogLevel.INFO, report, "START_EXEC", (report.synchronous ? "Synchronous" : "Asynchronous") + " execution of an ADQL query STARTED.", null);

		// Save the start time (for reporting usage):
@@ -379,7 +381,7 @@ public class ADQLExecutor {

			// 3. EXECUTE THE ADQL QUERY:
			startStep(ExecutionProgression.EXECUTING_ADQL);                        
			queryResult = executeADQL(adqlQuery);
			queryResult = executeADQL(adqlQuery, jobOwner);
			endStep();

			if (queryResult == null || thread.isInterrupted())
@@ -598,6 +600,7 @@ public class ADQLExecutor {
	 * </i></p>
	 *
	 * @param adql	The object representation of the ADQL query to execute.
	 * @param jobOwner The user executing the query
	 *
	 * @return	The result of the query.
	 *
@@ -607,7 +610,7 @@ public class ADQLExecutor {
	 *
	 * @see DBConnection#executeQuery(ADQLQuery)
	 */
	protected TableIterator executeADQL(final ADQLQuery adql) throws InterruptedException, DBCancelledException, TAPException {
	protected TableIterator executeADQL(final ADQLQuery adql, JobOwner jobOwner) throws InterruptedException, DBCancelledException, TAPException {
		// Log the start of execution:
		logger.logTAP(LogLevel.INFO, report, "START_DB_EXECUTION", "ADQL query: " + adql.toADQL().replaceAll("(\t|\r?\n)+", " "), null);

@@ -621,7 +624,7 @@ public class ADQLExecutor {

		try {
			// Execute the ADQL query:
			TableIterator result = dbConn.executeQuery(adql);
                        TableIterator result = dbConn.executeQuery(adql, jobOwner);
                        
			// If NULL, in a former version of the library, it means the query execution has been aborted:
			if (result == null)
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import java.util.Iterator;

import adql.db.FunctionDef;
import tap.db.DBConnection;
import tap.db.QueryExecutor;
import tap.formatter.OutputFormat;
import tap.log.DefaultTAPLog;
import tap.log.TAPLog;
@@ -455,6 +456,8 @@ public interface ServiceConnection {
	 */
	public UserIdentifier getUserIdentifier();

        public QueryExecutor getQueryExecutor();
        
	/**
	 * <i><b>[MANDATORY]</b></i>
	 * <p>This function lets enable or disable the upload capability of this TAP
+16 −4
Original line number Diff line number Diff line
@@ -23,14 +23,17 @@ package tap;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import tap.parameters.TAPExecutionDurationController;
import tap.parameters.TAPParameters;
import uws.UWSException;
import uws.UWSToolBox;
import uws.job.JobThread;
import uws.job.UWSJob;
import uws.job.user.JobOwner;
import uws.service.log.UWSLog.LogLevel;
import uws.service.request.UploadFile;

@@ -249,7 +252,7 @@ public class TAPSyncJob {
	 *
	 * @see SyncThread
	 */
	public synchronized boolean start(final HttpServletResponse response) throws IllegalStateException, IOException, TAPException {
	public synchronized boolean start(final HttpServletRequest request, final HttpServletResponse response) throws IllegalStateException, IOException, TAPException {
		if (startedAt != null)
			throw new IllegalStateException("Impossible to restart a synchronous TAP query!");

@@ -270,7 +273,13 @@ public class TAPSyncJob {
		final long timeToStop = determineMaxExecutionDuration();

		// Give to a thread which will execute the query:
		thread = new SyncThread(executor, ID, tapParams, response);
                JobOwner jobOwner = null;
                try {
                    jobOwner = UWSToolBox.getUser(request, service.getUserIdentifier());
                } catch(UWSException ex) {
                    service.getLogger().log(LogLevel.WARNING, "UWS", "Unable to retrieve user information", ex);
                }
		thread = new SyncThread(executor, ID, tapParams, response, jobOwner);
		thread.start();

		// Wait the end of the thread until the maximum execution duration is reached:
@@ -438,6 +447,7 @@ public class TAPSyncJob {
		/** Object knowing how to execute an ADQL query and which will execute
		 * it by calling {@link ADQLExecutor#start(Thread, String, TAPParameters, HttpServletResponse)}. */
		protected final ADQLExecutor executor;
                protected final JobOwner jobOwner;
		/** Response in which the query result must be written. No error should
		 * be written in it directly at this level ; the error must be
		 * propagated and it will be written in this HTTP response later on a
@@ -467,12 +477,14 @@ public class TAPSyncJob {
		 *                	and the execution parameters.
		 * @param response	HTTP response in which the ADQL query result must be
		 *                	written.
		 * @param jobOwner      The user executing the ADQL query
		 */
		public SyncThread(final ADQLExecutor executor, final String ID, final TAPParameters tapParams, final HttpServletResponse response) {
		public SyncThread(final ADQLExecutor executor, final String ID, final TAPParameters tapParams, final HttpServletResponse response, final JobOwner jobOwner) {
			super(JobThread.tg, ID);
			this.executor = executor;
			this.ID = ID;
			this.tapParams = tapParams;
                        this.jobOwner = jobOwner;
			this.response = response;
		}

@@ -522,7 +534,7 @@ public class TAPSyncJob {

			try {
				// Execute the ADQL query:
				report = executor.start(this, ID, tapParams, response);
				report = executor.start(this, ID, tapParams, response, jobOwner);

				// Log the successful end of this thread:
				executor.getLogger().logThread(LogLevel.INFO, thread, "END", "Synchronous thread \"" + ID + "\" successfully ended.", null);
+22 −1
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ import tap.TAPException;
import tap.TAPFactory;
import tap.db.DBConnection;
import tap.db.JDBCConnection;
import tap.db.QueryExecutor;
import tap.formatter.FITSFormat;
import tap.formatter.HTMLFormat;
import tap.formatter.JSONFormat;
@@ -127,6 +128,7 @@ import uws.service.UserIdentifier;
import uws.service.file.LocalUWSFileManager;
import uws.service.file.UWSFileManager;
import uws.service.log.UWSLog.LogLevel;
import static tap.config.TAPConfiguration.KEY_QUERY_EXECUTOR;

/**
 * Concrete implementation of {@link ServiceConnection}, fully parameterized
@@ -209,6 +211,8 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
	/** The method to use in order to identify a TAP user. */
	private UserIdentifier userIdentifier = null;
        
        private QueryExecutor queryExecutor = null;

	/** List of all allowed coordinate systems.
	 * <em>
	 * 	If NULL, all coord. sys. are allowed. If empty list, none is allowed.
@@ -303,7 +307,10 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
		// 9. SET A USER IDENTIFIER:
		initUserIdentifier(tapConfig);

		// 10. CONFIGURE ADQL:
                // 10. SET A QUERY EXECUTOR:
                initQueryExecutor(tapConfig);
                
		// 11. CONFIGURE ADQL:
		initCoordSys(tapConfig);
		initADQLGeometries(tapConfig);
		initUDFs(tapConfig);
@@ -1102,6 +1109,15 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
			userIdentifier = newInstance(propValue, KEY_USER_IDENTIFIER, UserIdentifier.class);
	}
        
        private void initQueryExecutor(final Properties tapConfig) throws TAPException {
		// Get the property value:
		String propValue = getProperty(tapConfig, KEY_QUERY_EXECUTOR);
		if (propValue != null)
			queryExecutor = newInstance(propValue, KEY_QUERY_EXECUTOR, QueryExecutor.class);
                else
			queryExecutor = new QueryExecutor();
	}

	/**
	 * Initialize the list of all allowed coordinate systems.
	 *
@@ -1769,6 +1785,11 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
		return userIdentifier;
	}
        
	@Override
        public QueryExecutor getQueryExecutor() {
		return queryExecutor;
        }

	@Override
	public TAPMetadata getTAPMetadata() {
		return metadata;
+2 −2
Original line number Diff line number Diff line
@@ -282,12 +282,12 @@ public class ConfigurableTAPFactory extends AbstractTAPFactory {
	public DBConnection getConnection(String jobID) throws TAPException{
		if (datasource != null){
			try{
				return new JDBCConnection(datasource.getConnection(), createADQLTranslator(), jobID, this.service.getLogger());
				return new JDBCConnection(datasource.getConnection(), createADQLTranslator(), jobID, this.service.getQueryExecutor(), this.service.getLogger());
			}catch(SQLException se){
				throw new TAPException("Impossible to establish a connection to the database using the set up datasource!", se);
			}
		}else
			return new JDBCConnection(driverPath, dbUrl, dbUser, dbPassword, createADQLTranslator(), jobID, this.service.getLogger());
			return new JDBCConnection(driverPath, dbUrl, dbUser, dbPassword, createADQLTranslator(), jobID, this.service.getQueryExecutor(), this.service.getLogger());
	}

	@Override
Loading