コード例 #1
0
    def test_api_collection_view_data_exists(self, *mocks):
        request = Request({})
        view = ApiCollectionView({}, request)
        resp = view.fetch()

        self.assertEqual(FETCH_JOBS.keys(), [])
        self.assertEqual(resp, {'status': FetchJob.STATUS_COMPLETE,
                                'reason': None})
コード例 #2
0
ファイル: api.py プロジェクト: DanielBaird/BCCVL_Visualiser
    def fetch(self):
        """This is a fetch endpoint to fetch data from the data url specified.

        This endpoint requires an additional WMS parameter
        DATA_URL. The DATA_URL, should point to a downloadable file
        which can be used as raster data input for mapserver.
        """

        LOG.debug('Processing ows request')
        data_url = None
        try:
            data_url = self.request.GET.getone('DATA_URL')
        except:
            LOG.warn('No data_url provided')
            data_url = None
            return self.StatusResponse(FetchJob.STATUS_FAILED,
                                       'No data_url provided')

        # Check if a job has been submitted or data has been dowbloaded for
        # this data url.
        datadir = data_dir(self.request, data_url)
        job = FETCH_JOBS.get(datadir)
        if job:
            # existing job,... return status
            reason = job.reason
            status = job.status
            # TODO: if job is completed it can be removed right away
            #       elif clause below should catch that case anyway
            if job.status in (FetchJob.STATUS_FAILED,
                              FetchJob.STATUS_COMPLETE):
                # job in end state ... delete it and report state back
                del FETCH_JOBS[datadir]
            return self.StatusResponse(status, reason)
        elif os.path.exists(datadir):
            # no job ... and path exists
            lockfile = datadir + '.lock'
            if os.path.exists(lockfile):
                # no job ... lockfile exists -> job in progress
                return self.StatusResponse(FetchJob.STATUS_IN_PROGRESS)
            else:
                return self.StatusResponse(FetchJob.STATUS_COMPLETE)

        # Submit a new fetch job with datadir as job ID.
        job = FetchJob(datadir)
        FETCH_JOBS[datadir] = job
        # TODO: should we really hang on to request object for a potentially
        # long time?
        FETCH_EXECUTOR.submit(fn=fetch_worker,
                              request=self.request,
                              data_url=data_url,
                              job=job)
        return self.StatusResponse(job.status, job.reason)
コード例 #3
0
ファイル: api.py プロジェクト: BCCVL/BCCVL_Visualiser
    def fetch(self):
        """This is a fetch endpoint to fetch data from the data url specified.

        This endpoint requires an additional WMS parameter
        DATA_URL. The DATA_URL, should point to a downloadable file
        which can be used as raster data input for mapserver.
        """

        LOG.debug('Processing ows request')
        data_url = None
        try:
            data_url = self.request.GET.getone('DATA_URL')
        except:
            LOG.warn('No data_url provided')
            data_url = None
            return self.StatusResponse(FetchJob.STATUS_FAILED,
                                       'No data_url provided')

        # Check if a job has been submitted or data has been dowbloaded for
        # this data url.
        datadir = data_dir(self.request, data_url)
        job = FETCH_JOBS.get(datadir)
        if job:
            # existing job,... return status
            reason = job.reason
            status = job.status
            # TODO: if job is completed it can be removed right away
            #       elif clause below should catch that case anyway
            if job.status in (FetchJob.STATUS_FAILED,
                              FetchJob.STATUS_COMPLETE):
                # job in end state ... delete it and report state back
                del FETCH_JOBS[datadir]
            return self.StatusResponse(status, reason)
        elif os.path.exists(datadir):
            # no job ... and path exists
            lockfile = datadir + '.lock'
            if os.path.exists(lockfile):
                # no job ... lockfile exists -> job in progress
                return self.StatusResponse(FetchJob.STATUS_IN_PROGRESS)
            else:
                return self.StatusResponse(FetchJob.STATUS_COMPLETE)

        # Submit a new fetch job with datadir as job ID.
        job = FetchJob(datadir)
        FETCH_JOBS[datadir] = job
        # TODO: should we really hang on to request object for a potentially
        # long time?
        FETCH_EXECUTOR.submit(fn=fetch_worker, request=self.request,
                              data_url=data_url, job=job)
        return self.StatusResponse(job.status, job.reason)
コード例 #4
0
    def test_api_collection_view_not_submit_job(self, *mocks):
        request = Request({})
        view = ApiCollectionView({}, request)
        resp = view.fetch()

        # Check that second fetch does not submit another job
        resp = view.fetch()
        self.assertEqual(FETCH_JOBS.keys(), ['/tmp/def'])
        self.assertEqual(resp, {'status': FetchJob.STATUS_PENDING,
                                'reason': None})

        job = FETCH_JOBS['/tmp/def']
        self.assertEqual(view.request, request)
        self.assertEqual(job.status, FetchJob.STATUS_PENDING)
        self.assertEqual(resp, {'status': FetchJob.STATUS_PENDING,
                                'reason': None})
コード例 #5
0
    def test_api_collection_view_remove_completed_job(self, *mocks):
        request = Request({})
        view = ApiCollectionView({}, request)
        resp = view.fetch()

        job = FETCH_JOBS['/tmp/def']
        self.assertEqual(view.request, request)
        self.assertEqual(job.status, FetchJob.STATUS_PENDING)
        self.assertEqual(resp, {'status': FetchJob.STATUS_PENDING,
                                'reason': None})

        job.update(status=FetchJob.STATUS_COMPLETE,
                   start_timestamp=datetime.datetime.now())
        self.assertEqual(job.status, FetchJob.STATUS_COMPLETE)

        resp = view.fetch()
        self.assertEqual(job.status, FetchJob.STATUS_COMPLETE)
        self.assertEqual(FETCH_JOBS.keys(), [])
        self.assertEqual(resp, {'status': FetchJob.STATUS_COMPLETE,
                                'reason': None})