def execute(self, wps_request, uuid): self._set_uuid(uuid) async = False wps_response = WPSResponse(self, wps_request, 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.status = WPSResponse.STORE_AND_UPDATE_STATUS async = True else: wps_response.status = WPSResponse.STORE_STATUS LOGGER.debug( 'Check if updating of status is not required then no need to spawn a process' ) wps_response = self._execute_process(async, wps_request, wps_response) return wps_response
def execute(self, wps_request, uuid): self._set_uuid(uuid) async = False wps_response = WPSResponse(self, wps_request, 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.status = wps_response_status.STORE_AND_UPDATE_STATUS async = True else: wps_response.status = wps_response_status.STORE_STATUS LOGGER.debug('Check if updating of status is not required then no need to spawn a process') wps_response = self._execute_process(async, wps_request, wps_response) return wps_response
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
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
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
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
def execute(self, wps_request): import multiprocessing self.uuid = str(uuid4()) async = False wps_response = WPSResponse(self, wps_request) # 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' ) file_path = config.get_config_value('server', 'outputPath') file_url = '%s:%s%s' % ( config.get_config_value('wps', 'serveraddress'), config.get_config_value('wps', 'serverport'), config.get_config_value('server', 'outputUrl')) self.status_location = os.path.join(file_path, self.uuid) + '.xml' self.status_url = os.path.join(file_url, self.uuid) + '.xml' if wps_request.status == 'true': if self.status_supported != 'true': raise OperationNotSupported( 'Process does not support the updating of status') wps_response.status = WPSResponse.STORE_AND_UPDATE_STATUS async = True else: wps_response.status = WPSResponse.STORE_STATUS # check if updating of status is not required then no need to spawn a process if async: process = multiprocessing.Process(target=self._run_process, args=(wps_request, wps_response)) process.start() else: wps_response = self._run_process(wps_request, wps_response) return wps_response
def execute(self, wps_request): import multiprocessing self.uuid = str(uuid4()) async = False wps_response = WPSResponse(self, wps_request) # 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') file_path = config.get_config_value('server', 'outputPath') file_url = '%s:%s%s' % ( config.get_config_value('wps', 'serveraddress'), config.get_config_value('wps', 'serverport'), config.get_config_value('server', 'outputUrl') ) self.status_location = os.path.join(file_path, self.uuid) + '.xml' self.status_url = os.path.join(file_url, self.uuid) + '.xml' if wps_request.status == 'true': if self.status_supported != 'true': raise OperationNotSupported('Process does not support the updating of status') wps_response.status = WPSResponse.STORE_AND_UPDATE_STATUS async = True else: wps_response.status = WPSResponse.STORE_STATUS # check if updating of status is not required then no need to spawn a process if async: process = multiprocessing.Process(target=self._run_process, args=(wps_request, wps_response)) process.start() else: wps_response = self._run_process(wps_request, wps_response) return wps_response
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
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.') else: wps_response.update_status(msg, -1) # 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) 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) except Exception as e: LOGGER.error("Could not run stored process. %s", e) return wps_response