Ejemplo n.º 1
0
def test_jobs_parser():
    fileName = data_path('test_jobs_async.xml')
    file = open(fileName, 'r')
    parser = JobSaxParser()
    jobs = parser.parseData(file)
    assert len(jobs) == 2
    __check_job(jobs[0], "1479386030738O", "COMPLETED", "anonymous")
    __check_job(jobs[1], "14793860307381", "ERROR", "anonymous")
    file.close()
Ejemplo n.º 2
0
 def test_jobs_parser(self):
     fileName = data_path('test_jobs_async.xml')
     file = open(fileName, 'r')
     parser = JobSaxParser()
     jobs = parser.parseData(file)
     assert len(jobs) == 2, \
         "Expected table list size: 1, found %d" % len(jobs)
     self.__check_job(jobs[0], "1479386030738O", "COMPLETED", "anonymous")
     self.__check_job(jobs[1], "14793860307381", "ERROR", "anonymous")
     file.close()
Ejemplo n.º 3
0
 def test_jobs_parser(self):
     fileName = data_path('test_jobs_async.xml')
     file = open(fileName, 'r')
     parser = JobSaxParser()
     jobs = parser.parseData(file)
     assert len(jobs) == 2, \
         "Expected table list size: 1, found %d" % len(jobs)
     self.__check_job(jobs[0], "1479386030738O", "COMPLETED", "anonymous")
     self.__check_job(jobs[1], "14793860307381", "ERROR", "anonymous")
     file.close()
Ejemplo n.º 4
0
    def load_async_job(self, jobid=None, name=None, verbose=False):
        """Loads an asynchronous job

        Parameters
        ----------
        jobid : str, mandatory if no name is provided, default None
            job identifier
        name : str, mandatory if no jobid is provided, default None
            job name
        verbose : bool, optional, default 'False'
            flag to display information about the process

        Returns
        -------
        A Job object
        """
        if name is not None:
            jobfilter = Filter()
            jobfilter.add_filter('name', name)
            jobs = self.search_async_jobs(jobfilter)
            if jobs is None or len(jobs) < 1:
                print("No job found for name '"+str(name)+"'")
                return None
            jobid = jobs[0].get_jobid()
        if jobid is None:
            print("No job identifier found")
            return None
        subContext = "async/" + str(jobid)
        response = self.__connHandler.execute_get(subContext)
        if verbose:
            print(response.status, response.reason)
            print(response.getheaders())
        isError = self.__connHandler.check_launch_response_status(response,
                                                                  verbose,
                                                                  200)
        if isError:
            print(response.reason)
            raise requests.exceptions.HTTPError(response.reason)
            return None
        # parse job
        jsp = JobSaxParser(async_job=True)
        job = jsp.parseData(response)[0]
        job.set_connhandler(self.__connHandler)
        # load resulst
        job.get_results()
        return job
Ejemplo n.º 5
0
    def load_async_job(self, jobid=None, name=None, verbose=False):
        """Loads an asynchronous job

        Parameters
        ----------
        jobid : str, mandatory if no name is provided, default None
            job identifier
        name : str, mandatory if no jobid is provided, default None
            job name
        verbose : bool, optional, default 'False'
            flag to display information about the process

        Returns
        -------
        A Job object
        """
        if name is not None:
            jobfilter = Filter()
            jobfilter.add_filter('name', name)
            jobs = self.search_async_jobs(jobfilter)
            if jobs is None or len(jobs) < 1:
                print("No job found for name '"+str(name)+"'")
                return None
            jobid = jobs[0].get_jobid()
        if jobid is None:
            print("No job identifier found")
            return None
        subContext = "async/" + str(jobid)
        response = self.__connHandler.execute_get(subContext)
        if verbose:
            print(response.status, response.reason)
            print(response.getheaders())
        isError = self.__connHandler.check_launch_response_status(response,
                                                                  verbose,
                                                                  200)
        if isError:
            print(response.reason)
            raise Exception(response.reason)
            return None
        # parse job
        jsp = JobSaxParser(async_job=True)
        job = jsp.parseData(response)[0]
        job.set_connhandler(self.__connHandler)
        # load resulst
        job.get_results()
        return job
Ejemplo n.º 6
0
    def search_async_jobs(self, jobfilter=None, verbose=False):
        """Searches for jobs applying the specified filter

        Parameters
        ----------
        jobfilter : JobFilter, optional, default None
            job filter
        verbose : bool, optional, default 'False'
            flag to display information about the process

        Returns
        -------
        A list of Job objects
        """
        # jobs/list?[&session=][&limit=][&offset=][&order=][&metadata_only=true|false]
        subContext = "jobs/async"
        if jobfilter is not None:
            data = jobfilter.createUrlRequest()
            if data is not None:
                subContext = subContext + '?' + self.__appendData(data)
        connHandler = self.__getconnhandler()
        response = connHandler.execute_get(subContext)
        if verbose:
            print(response.status, response.reason)
            print(response.getheaders())
        isError = connHandler.check_launch_response_status(response,
                                                           verbose,
                                                           200)
        if isError:
            print(response.reason)
            raise requests.exceptions.HTTPError(response.reason)
            return None
        # parse jobs
        jsp = JobSaxParser(async_job=True)
        jobs = jsp.parseData(response)
        if jobs is not None:
            for j in jobs:
                j.set_connhandler(connHandler)
        return jobs
Ejemplo n.º 7
0
    def retrieve_async_job(self, job_id, verbose=False):
        response = self._Tap__connHandler.execute_get('async/%s' % job_id)
        if verbose:
            print(response.status, response.reason)
            print(response.getheaders())
        isError = self._Tap__connHandler.check_launch_response_status(
            response, verbose, 200)
        if isError:
            print(response.reason)
            raise requests.exceptions.HTTPError(response.reason)
            return None

        # parse job
        jsp = JobSaxParser(async_job=True)
        jobs = jsp.parseData(response)

        try:
            job = jobs[0]
            job.set_connhandler(self._Tap__connHandler)
            return job
        except IndexError:
            return None
Ejemplo n.º 8
0
    def search_async_jobs(self, jobfilter=None, verbose=False):
        """Searches for jobs applying the specified filter

        Parameters
        ----------
        jobfilter : JobFilter, optional, default None
            job filter
        verbose : bool, optional, default 'False'
            flag to display information about the process

        Returns
        -------
        A list of Job objects
        """
        # jobs/list?[&session=][&limit=][&offset=][&order=][&metadata_only=true|false]
        subContext = "jobs/async"
        if jobfilter is not None:
            data = jobfilter.createUrlRequest()
            if data is not None:
                subContext = subContext + '?' + self.__appendData(data)
        connHandler = self.__getconnhandler()
        response = connHandler.execute_get(subContext)
        if verbose:
            print(response.status, response.reason)
            print(response.getheaders())
        isError = connHandler.check_launch_response_status(response,
                                                           verbose,
                                                           200)
        if isError:
            print(response.reason)
            raise Exception(response.reason)
            return None
        # parse jobs
        jsp = JobSaxParser(async_job=True)
        jobs = jsp.parseData(response)
        if jobs is not None:
            for j in jobs:
                j.set_connhandler(connHandler)
        return jobs