Exemple #1
0
    def list_async_jobs(self, verbose=False):
        """
        Returns all the asynchronous jobs

        Parameters
        ----------
        verbose : bool, optional, default 'False'
            flag to display information about the process

        Returns
        -------
        A list of Job objects
        """
        try:
            joblist = self.__cadctap.list_async_jobs(verbose)
            cadclist = []
            if joblist is not None:
                for job in joblist:
                    newJob = JobCadc(async_job=True,
                                     connhandler=job.connHandler)
                    newJob.jobid = job.jobid
                    cadclist.append(newJob)
        except requests.exceptions.HTTPError:
            return
        return cadclist
Exemple #2
0
    def list_async_jobs(self, verbose=False):
        """
        Returns all the asynchronous jobs

        Parameters
        ----------
        verbose : bool, optional, default 'False'
            flag to display information about the process

        Returns
        -------
        A list of Job objects
        """
        try:
            joblist = self._cadctap.list_async_jobs(verbose)
            cadclist = []
            if joblist is not None:
                for job in joblist:
                    newJob = JobCadc(async_job=True,
                                     connhandler=job.connHandler)
                    newJob.jobid = job.jobid
                    cadclist.append(newJob)
        except requests.exceptions.HTTPError:
            return
        return cadclist
Exemple #3
0
    def test_job_load(self):
        connHandler = DummyConnHandlerCadc()
        job = JobCadc(async_job=True, query='query', connhandler=connHandler)
        jobid = 1234
        job.jobid = str(jobid)
        job.parameters['format'] = 'csv'
        # Job Phase response
        jobPhase = DummyResponse()
        jobPhase.set_status_code(200)
        jobPhase.set_message("OK")
        jobPhase.set_data(method='GET',
                          context=None,
                          body="ERROR",
                          headers=None)
        req = "async/" + str(jobid) + "/phase"
        connHandler.set_response(req, jobPhase)
        # Error response
        error = DummyResponse()
        error.set_status_code(200)
        error.set_message("OK")
        jobDataPath = data_path('test_jobs_async.xml')
        jobData = utils.read_file_content(jobDataPath)
        error.set_data(method='GET', context=None, body=jobData, headers=None)
        req = "async/" + str(jobid)
        connHandler.set_response(req, error)

        with pytest.raises(Exception):
            job.get_results()
Exemple #4
0
    def test_save_results(self):
        connHandler = DummyConnHandlerCadc()
        tap = TapPlusCadc("http://test:1111/tap", connhandler=connHandler)
        job = JobCadc(async_job=True, query='query', connhandler=connHandler)
        jobid = 1234
        job.jobid = str(jobid)
        job.parameters['format'] = 'csv'
        # Phase response
        responsePhase = DummyResponse()
        responsePhase.set_status_code(200)
        responsePhase.set_message("OK")
        responsePhaseHeaders = [[
            'location', 'http://test:1111/tap/async/' + str(jobid)
        ]]
        responsePhase.set_data(method='GET',
                               context=None,
                               body="COMPLETED",
                               headers=responsePhaseHeaders)
        req = "async/" + str(jobid) + "/phase"
        connHandler.set_response(req, responsePhase)
        # Results response
        responseResultsJob = DummyResponse()
        responseResultsJob.set_status_code(303)
        responseResultsJob.set_message("OK")
        responseResultsHeaders = [[
            'location',
            'http://test:1111/tap/async/' + str(jobid) + '/redirect'
        ]]

        responseResultsJob.set_data(method='GET',
                                    context=None,
                                    body=None,
                                    headers=responseResultsHeaders)
        req = "async/" + str(jobid) + "/results/result"
        connHandler.set_response(req, responseResultsJob)
        # Results redirect response
        responseRedirect = DummyResponse()
        responseRedirect.set_status_code(200)
        responseRedirect.set_message("OK")

        jobDataFile = data_path('job_1.vot')
        jobData = utils.read_file_content(jobDataFile)
        responseRedirect.set_data(method='GET',
                                  context=None,
                                  body=jobData,
                                  headers=None)
        req = "http://test:1111/tap/async/" + str(jobid) + "/redirect"
        connHandler.set_response(req, responseRedirect)
        tap.save_results(job, 'file.txt')
Exemple #5
0
    def run_query(self, query, operation, output_file=None,
                  output_format="votable", verbose=False,
                  background=False, upload_resource=None,
                  upload_table_name=None):
        """
        Runs a query

        Parameters
        ----------
        query : str, mandatory
            query to be executed
        operation : str, mandatory,
            'sync' or 'async' to run a synchronous or asynchronous job
        output_file : str, optional, default None
            file name where the results are saved if dumpToFile is True.
            If this parameter is not provided, the jobid is used instead
        output_format : str, optional, default 'votable'
            results format, 'csv', 'tsv' and 'votable'
        verbose : bool, optional, default 'False'
            flag to display information about the process
        save_to_file : bool, optional, default 'False'
            if True, the results are saved in a file instead of using memory
        background : bool, optional, default 'False'
            when the job is executed in asynchronous mode,
            this flag specifies whether the execution will wait until results
            are available
        upload_resource: str, optional, default None
            resource to be uploaded to UPLOAD_SCHEMA
        upload_table_name: str, required if uploadResource is provided,
            default None
            resource temporary table name associated to the uploaded resource

        Returns
        -------
        A Job object
        """
        if output_file is not None:
            save_to_file = True
        else:
            save_to_file = False
        if operation == 'sync':
            job = self.__cadctap.launch_job(
                query,
                None,
                output_file=output_file,
                output_format=output_format,
                verbose=verbose,
                dump_to_file=save_to_file,
                upload_resource=upload_resource,
                upload_table_name=upload_table_name)
            op = False
        elif operation == 'async':
            job = self.__cadctap.launch_job_async(
                query,
                None,
                output_file=output_file,
                output_format=output_format,
                verbose=verbose,
                dump_to_file=save_to_file,
                background=True,
                upload_resource=upload_resource,
                upload_table_name=upload_table_name)
            op = True
        cjob = JobCadc(async_job=op, query=job.parameters['query'],
                       connhandler=self.__cadctap._TapPlus__getconnhandler())
        cjob.jobid = job.jobid
        cjob.outputFile = job.outputFile
        cjob.set_response_status(job._Job__responseStatus,
                                 job._Job__responseMsg)
        cjob.remoteLocation = job.remoteLocation
        cjob.parameters['format'] = job.parameters['format']
        cjob._phase = job._phase
        if operation == 'async':
            if save_to_file:
                cjob.save_results(output_file, verbose)
            else:
                cjob.get_results()
        else:
            if job.results is not None:
                cjob.set_results(job.results)
        return cjob
Exemple #6
0
    def run_query(self,
                  query,
                  operation,
                  output_file=None,
                  output_format="votable",
                  verbose=False,
                  background=False,
                  upload_resource=None,
                  upload_table_name=None):
        """
        Runs a query

        Parameters
        ----------
        query : str, mandatory
            query to be executed
        operation : str, mandatory,
            'sync' or 'async' to run a synchronous or asynchronous job
        output_file : str, optional, default None
            file name where the results are saved if dumpToFile is True.
            If this parameter is not provided, the jobid is used instead
        output_format : str, optional, default 'votable'
            results format, 'csv', 'tsv' and 'votable'
        verbose : bool, optional, default 'False'
            flag to display information about the process
        save_to_file : bool, optional, default 'False'
            if True, the results are saved in a file instead of using memory
        background : bool, optional, default 'False'
            when the job is executed in asynchronous mode,
            this flag specifies whether the execution will wait until results
            are available
        upload_resource: str, optional, default None
            resource to be uploaded to UPLOAD_SCHEMA
        upload_table_name: str, required if uploadResource is provided,
            default None
            resource temporary table name associated to the uploaded resource

        Returns
        -------
        A Job object
        """
        if output_file is not None:
            save_to_file = True
        else:
            save_to_file = False
        if operation == 'sync':
            job = self._cadctap.launch_job(query,
                                           None,
                                           output_file=output_file,
                                           output_format=output_format,
                                           verbose=verbose,
                                           dump_to_file=save_to_file,
                                           upload_resource=upload_resource,
                                           upload_table_name=upload_table_name)
            op = False
        elif operation == 'async':
            job = self._cadctap.launch_job_async(
                query,
                None,
                output_file=output_file,
                output_format=output_format,
                verbose=verbose,
                dump_to_file=save_to_file,
                background=True,
                upload_resource=upload_resource,
                upload_table_name=upload_table_name)
            op = True
        cjob = JobCadc(async_job=op,
                       query=job.parameters['query'],
                       connhandler=self._cadctap._TapPlus__getconnhandler())
        cjob.jobid = job.jobid
        cjob.outputFile = job.outputFile
        cjob.set_response_status(job._Job__responseStatus,
                                 job._Job__responseMsg)
        cjob.remoteLocation = job.remoteLocation
        cjob.parameters['format'] = job.parameters['format']
        cjob._phase = job._phase
        if operation == 'async':
            if save_to_file:
                cjob.save_results(output_file, verbose)
            else:
                cjob.get_results()
        else:
            if job.results is not None:
                cjob.set_results(job.results)
        return cjob