Example #1
0
    def launch_next_process(self):
        """Look at the queue of async process, if the queue is not empty launch the next pending request.
        """
        try:
            LOGGER.debug("Checking for stored requests")

            stored_request = dblog.get_first_stored()
            if not stored_request:
                LOGGER.debug("No stored request found")
                return

            (uuid, request_json) = (stored_request.uuid,
                                    stored_request.request)
            if not PY2:
                request_json = request_json.decode('utf-8')
            LOGGER.debug("Launching the stored request %s", str(uuid))
            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
            new_wps_response = ExecuteResponse(new_wps_request,
                                               process=process,
                                               uuid=uuid)
            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)
Example #2
0
    def launch_next_process(self):
        """Look at the queue of async process, if the queue is not empty launch the next pending request.
        """
        try:
            LOGGER.debug("Checking for stored requests")

            stored_request = dblog.get_first_stored()
            if not stored_request:
                LOGGER.debug("No stored request found")
                return

            (uuid, request_json) = (stored_request.uuid, stored_request.request)
            if not PY2:
                request_json = request_json.decode('utf-8')
            LOGGER.debug("Launching the stored request %s", str(uuid))
            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
            new_wps_response = ExecuteResponse(new_wps_request, process=process, uuid=uuid)
            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)
Example #3
0
    def _run_process(self, wps_request, wps_response):
        #added because of http://stackoverflow.com/questions/30241911/psycopg2-error-databaseerror-error-with-no-message-from-the-libpq
        #db.get_engine(application).dispose()

        try:
            self._set_grass()
            wps_response = self.handler(wps_request, wps_response)

            # if status not yet set to 100% then do it after execution was successful
            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', 100, wps_response_status.DONE_STATUS)
        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.')
            else:
                wps_response.update_status(msg, -1)

        # tr
        stored_requests = dblog.get_first_stored()
        if stored_requests:
            (uuid, request_json) = stored_requests
            new_wps_request = WPSRequest()
            new_wps_request.json = json.loads(request_json)
            new_wps_response = WPSResponse(self, new_wps_request, uuid)
            new_wps_response.status = wps_response_status.STORE_AND_UPDATE_STATUS
            self._set_uuid(uuid)
            self._run_async(new_wps_request, new_wps_response)
            dblog.remove_stored(uuid)

        return wps_response
Example #4
0
    def _run_process(self, wps_request, wps_response):
        try:
            self._set_grass()
            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', 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.')
            else:
                wps_response.update_status(msg, -1)

        # tr
        stored_requests = dblog.get_first_stored()
        if len(stored_requests) > 0:
            (uuid, request_json) = stored_requests[0]
            new_wps_request = WPSRequest()
            new_wps_request.json = json.loads(request_json)
            new_wps_response = WPSResponse(self, new_wps_request, uuid)
            new_wps_response.status = STATUS.STORE_AND_UPDATE_STATUS
            self._set_uuid(uuid)
            self._run_async(new_wps_request, new_wps_response)
            dblog.remove_stored(uuid)


        return wps_response
Example #5
0
    def _run_process(self, wps_request, wps_response):
        try:
            self._set_grass()
            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.')
            else:
                wps_response.update_status(msg, -1)

        # tr
        stored_request = dblog.get_first_stored()
        if stored_request:
            (uuid, request_json) = (stored_request.uuid, stored_request.request)
            new_wps_request = WPSRequest()
            new_wps_request.json = json.loads(request_json)
            new_wps_response = WPSResponse(self, new_wps_request, uuid)
            new_wps_response.status = STATUS.STORE_AND_UPDATE_STATUS
            self._set_uuid(uuid)
            self._run_async(new_wps_request, new_wps_response)
            dblog.remove_stored(uuid)

        return wps_response
Example #6
0
    def _run_process(self, wps_request, wps_response):
        try:
            wps_response = self.handler(wps_request, wps_response)

            # if status not yet set to 100% then do it after execution was successful
            if wps_response.status_percentage != 100:
                LOGGER.debug(
                    'Updating process status to 100% if everything went correctly'
                )
                wps_response.update_status('PyWPS Process finished', 100)
        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)
            wps_response.update_status(msg, -1)

        # tr
        stored_requests = dblog.get_first_stored()
        if len(stored_requests) > 0:
            (uuid, request_json) = stored_requests[0]
            new_wps_request = WPSRequest()
            new_wps_request.json = json.loads(request_json)
            new_wps_response = WPSResponse(self, new_wps_request, uuid)
            new_wps_response.status = WPSResponse.STORE_AND_UPDATE_STATUS
            self._set_uuid(uuid)
            self._run_async(new_wps_request, new_wps_response)
            dblog.remove_stored(uuid)

        return wps_response
Example #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
Example #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
Example #9
0
    def _run_process(self, wps_request, wps_response):
        #added because of http://stackoverflow.com/questions/30241911/psycopg2-error-databaseerror-error-with-no-message-from-the-libpq
        #db.get_engine(application).dispose()

        try:
            self._set_grass()
            wps_response = self.handler(wps_request, wps_response)

            # if status not yet set to 100% then do it after execution was successful
            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', 100,
                                           wps_response_status.DONE_STATUS)
        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.'
                )
            else:
                wps_response.update_status(msg, -1)

        # tr
        stored_requests = dblog.get_first_stored()
        if stored_requests:
            (uuid, request_json) = stored_requests
            new_wps_request = WPSRequest()
            new_wps_request.json = json.loads(request_json)
            new_wps_response = WPSResponse(self, new_wps_request, uuid)
            new_wps_response.status = wps_response_status.STORE_AND_UPDATE_STATUS
            self._set_uuid(uuid)
            self._run_async(new_wps_request, new_wps_response)
            dblog.remove_stored(uuid)

        return wps_response