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) 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
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 _get_request_parser(self, operation): """Factory function returing propper parsing function """ wpsrequest = self def parse_get_getcapabilities(http_request): """Parse GET GetCapabilities request """ acceptedversions = _get_get_param(http_request, 'acceptversions') wpsrequest.check_accepted_versions(acceptedversions) def parse_get_describeprocess(http_request): """Parse GET DescribeProcess request """ version = _get_get_param(http_request, 'version') wpsrequest.check_and_set_version(version) language = _get_get_param(http_request, 'language') wpsrequest.check_and_set_language(language) wpsrequest.identifiers = _get_get_param( http_request, 'identifier', aslist=True) def parse_get_execute(http_request): """Parse GET Execute request """ version = _get_get_param(http_request, 'version') wpsrequest.check_and_set_version(version) language = _get_get_param(http_request, 'language') wpsrequest.check_and_set_language(language) wpsrequest.identifier = _get_get_param(http_request, 'identifier') wpsrequest.store_execute = _get_get_param( http_request, 'storeExecuteResponse', 'false') wpsrequest.status = _get_get_param(http_request, 'status', 'false') wpsrequest.lineage = _get_get_param( http_request, 'lineage', 'false') wpsrequest.inputs = get_data_from_kvp( _get_get_param(http_request, 'DataInputs'), 'DataInputs') if self.inputs is None: self.inputs = {} wpsrequest.outputs = {} # take responseDocument preferably resp_outputs = get_data_from_kvp( _get_get_param(http_request, 'ResponseDocument')) raw_outputs = get_data_from_kvp( _get_get_param(http_request, 'RawDataOutput')) wpsrequest.raw = False if resp_outputs: wpsrequest.outputs = resp_outputs elif raw_outputs: wpsrequest.outputs = raw_outputs wpsrequest.raw = True # executeResponse XML will not be stored and no updating of # status wpsrequest.store_execute = 'false' wpsrequest.status = 'false' if not operation: raise MissingParameterValue('Missing request value', 'request') else: self.operation = operation.lower() if self.operation == 'getcapabilities': return parse_get_getcapabilities elif self.operation == 'describeprocess': return parse_get_describeprocess elif self.operation == 'execute': return parse_get_execute else: raise OperationNotSupported( 'Unknown request {}'.format(self.operation), operation)
def __init__(self, http_request): self.http_request = http_request if http_request.method == 'GET': # service shall be WPS service = self._get_get_param('service', aslist=False) if service: if str(service).lower() != 'wps': raise OperationNotSupported( 'parameter SERVICE [%s] not supported' % service) else: raise MissingParameterValue('service', 'service') # operation shall be one of GetCapabilities, DescribeProcess, # Execute self.operation = self._get_get_param('request', aslist=False) if not self.operation: raise MissingParameterValue('request') else: self.operation = self.operation.lower() if self.operation == 'getcapabilities': pass elif self.operation == 'describeprocess': self.identifiers = self._get_get_param('identifier', aslist=True) if not self.identifiers: raise MissingParameterValue('identifier') elif self.operation == 'execute': self.identifier = self._get_get_param('identifier') self.inputs = get_input_from_kvp( self._get_get_param('datainputs')) else: raise InvalidParameterValue(self.operation) elif http_request.method == 'POST': doc = lxml.etree.fromstring(http_request.get_data()) if doc.tag == WPS.GetCapabilities().tag: self.operation = 'getcapabilities' elif doc.tag == WPS.DescribeProcess().tag: self.operation = 'describeprocess' self.identifiers = [ identifier_el.text for identifier_el in xpath_ns(doc, './ows:Identifier') ] elif doc.tag == WPS.Execute().tag: self.operation = 'execute' self.identifier = xpath_ns(doc, './ows:Identifier')[0].text self.inputs = get_input_from_xml(doc) else: raise InvalidParameterValue(doc.tag) else: raise MethodNotAllowed()