Ejemplo n.º 1
0
    def execute(self, wps_request, uuid):
        self._set_uuid(uuid)
        self.async_ = False
        response_cls = get_response("execute")
        wps_response = response_cls(wps_request, process=self, uuid=self.uuid)

        LOGGER.debug(
            'Check if status storage and updating are supported by this process'
        )
        if wps_request.store_execute == 'true':
            if self.store_supported != 'true':
                raise StorageNotSupported(
                    'Process does not support the storing of the execute response'
                )

            if wps_request.status == 'true':
                if self.status_supported != 'true':
                    raise OperationNotSupported(
                        'Process does not support the updating of status')

                wps_response.store_status_file = True
                self.async_ = True
            else:
                wps_response.store_status_file = False

        LOGGER.debug(
            'Check if updating of status is not required then no need to spawn a process'
        )

        wps_response = self._execute_process(self.async_, wps_request,
                                             wps_response)

        return wps_response
Ejemplo n.º 2
0
    def get_capabilities(self, wps_request, uuid):

        response_cls = response.get_response("capabilities")
        return response_cls(wps_request,
                            uuid,
                            version=wps_request.version,
                            processes=self.processes)
Ejemplo n.º 3
0
    def describe(self, wps_request, uuid, identifiers):

        response_cls = response.get_response("describe")
        return response_cls(wps_request,
                            uuid,
                            processes=self.processes,
                            identifiers=identifiers)
Ejemplo n.º 4
0
    def execute(self, wps_request, uuid):
        self._set_uuid(uuid)
        self.async_ = False
        response_cls = get_response("execute")
        wps_response = response_cls(wps_request, process=self, uuid=self.uuid)

        LOGGER.debug('Check if status storage and updating are supported by this process')
        if wps_request.store_execute == 'true':
            if self.store_supported != 'true':
                raise StorageNotSupported('Process does not support the storing of the execute response')

            if wps_request.status == 'true':
                if self.status_supported != 'true':
                    raise OperationNotSupported('Process does not support the updating of status')

                wps_response.store_status_file = True
                self.async_ = True
            else:
                wps_response.store_status_file = False

        LOGGER.debug('Check if updating of status is not required then no need to spawn a process')

        wps_response = self._execute_process(self.async_, wps_request, wps_response)

        return wps_response
Ejemplo n.º 5
0
    def describe(self, wps_request, uuid, identifiers):

        response_cls = response.get_response("describe")
        return response_cls(wps_request, uuid, processes=self.processes,
                            identifiers=identifiers)
Ejemplo n.º 6
0
    def get_capabilities(self, wps_request, uuid):

        response_cls = response.get_response("capabilities")
        return response_cls(wps_request, uuid, version=wps_request.version, processes=self.processes)
Ejemplo n.º 7
0
    def _run_process(self, wps_request, wps_response):
        try:
            self._set_grass(wps_request)
            # if required set HOME to the current working directory.
            if config.get_config_value('server', 'sethomedir') is True:
                os.environ['HOME'] = self.workdir
                LOGGER.info('Setting HOME to current working directory: %s',
                            os.environ['HOME'])
            LOGGER.debug('ProcessID=%s, HOME=%s', self.uuid,
                         os.environ.get('HOME'))
            wps_response.update_status('PyWPS Process started', 0)
            wps_response = self.handler(wps_request, wps_response)

            # if (not wps_response.status_percentage) or (wps_response.status_percentage != 100):
            LOGGER.debug(
                'Updating process status to 100% if everything went correctly')
            wps_response.update_status('PyWPS Process {} finished'.format(
                self.title),
                                       100,
                                       STATUS.DONE_STATUS,
                                       clean=self. async)
        except Exception as e:
            traceback.print_exc()
            LOGGER.debug(
                'Retrieving file and line number where exception occurred')
            exc_type, exc_obj, exc_tb = sys.exc_info()
            found = False
            while not found:
                # search for the _handler method
                m_name = exc_tb.tb_frame.f_code.co_name
                if m_name == '_handler':
                    found = True
                else:
                    if exc_tb.tb_next is not None:
                        exc_tb = exc_tb.tb_next
                    else:
                        # if not found then take the first
                        exc_tb = sys.exc_info()[2]
                        break
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            method_name = exc_tb.tb_frame.f_code.co_name

            # update the process status to display process failed
            msg = 'Process error: %s.%s Line %i %s' % (fname, method_name,
                                                       exc_tb.tb_lineno, e)
            LOGGER.error(msg)

            if not wps_response:
                raise NoApplicableCode(
                    'Response is empty. Make sure the _handler method is returning a valid object.'
                )
            elif wps_request.raw:
                raise
            else:
                wps_response.update_status(msg, -1, status=STATUS.ERROR_STATUS)

        # tr
        stored_request = dblog.get_first_stored()
        if stored_request:
            try:
                (uuid, request_json) = (stored_request.uuid,
                                        stored_request.request)
                if not PY2:
                    request_json = request_json.decode('utf-8')
                new_wps_request = WPSRequest()
                new_wps_request.json = json.loads(request_json)
                process_identifier = new_wps_request.identifier
                process = self.service.prepare_process_for_execution(
                    process_identifier)
                process._set_uuid(uuid)
                process. async = True
                response_cls = get_response("execute")
                new_wps_response = response_cls(new_wps_request,
                                                process=process,
                                                uuid=uuid)
                new_wps_response.status = STATUS.STORE_AND_UPDATE_STATUS
                process._run_async(new_wps_request, new_wps_response)
                dblog.remove_stored(uuid)
            except Exception as e:
                LOGGER.error("Could not run stored process. %s", e)

        return wps_response
Ejemplo n.º 8
0
    def _run_process(self, wps_request, wps_response):
        try:
            self._set_grass()
            # if required set HOME to the current working directory.
            if config.get_config_value('server', 'sethomedir') is True:
                os.environ['HOME'] = self.workdir
                LOGGER.info('Setting HOME to current working directory: %s', os.environ['HOME'])
            LOGGER.debug('ProcessID=%s, HOME=%s', self.uuid, os.environ.get('HOME'))
            wps_response.update_status('PyWPS Process started', 0)
            wps_response = self.handler(wps_request, wps_response)

            # if (not wps_response.status_percentage) or (wps_response.status_percentage != 100):
            LOGGER.debug('Updating process status to 100% if everything went correctly')
            wps_response.update_status('PyWPS Process {} finished'.format(self.title),
                                       100, STATUS.DONE_STATUS, clean=self.async)
        except Exception as e:
            traceback.print_exc()
            LOGGER.debug('Retrieving file and line number where exception occurred')
            exc_type, exc_obj, exc_tb = sys.exc_info()
            found = False
            while not found:
                # search for the _handler method
                m_name = exc_tb.tb_frame.f_code.co_name
                if m_name == '_handler':
                    found = True
                else:
                    if exc_tb.tb_next is not None:
                        exc_tb = exc_tb.tb_next
                    else:
                        # if not found then take the first
                        exc_tb = sys.exc_info()[2]
                        break
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            method_name = exc_tb.tb_frame.f_code.co_name

            # update the process status to display process failed
            msg = 'Process error: %s.%s Line %i %s' % (fname, method_name, exc_tb.tb_lineno, e)
            LOGGER.error(msg)

            if not wps_response:
                raise NoApplicableCode('Response is empty. Make sure the _handler method is returning a valid object.')
            elif wps_request.raw:
                raise
            else:
                wps_response.update_status(msg, -1, status=STATUS.ERROR_STATUS)

        # tr
        stored_request = dblog.get_first_stored()
        if stored_request:
            try:
                (uuid, request_json) = (stored_request.uuid, stored_request.request)
                if not PY2:
                    request_json = request_json.decode('utf-8')
                new_wps_request = WPSRequest()
                new_wps_request.json = json.loads(request_json)
                process_identifier = new_wps_request.identifier
                process = self.service.prepare_process_for_execution(process_identifier)
                process._set_uuid(uuid)
                process.async = True
                response_cls = get_response("execute")
                new_wps_response = response_cls(new_wps_request, process=process, uuid=uuid)
                new_wps_response.status = STATUS.STORE_AND_UPDATE_STATUS
                process._run_async(new_wps_request, new_wps_response)
                dblog.remove_stored(uuid)
            except Exception as e:
                LOGGER.error("Could not run stored process. %s", e)

        return wps_response