def remote_request(self, app_info, http_request_data): """ Receives a remote request to which it should give the correct response. The http_request_data holds an encoded protocol buffer of a certain type. Each type has a particular response type. Args: app_info: A dictionary containing the application, module, and version ID of the app that is sending this request. http_request_data: Encoded protocol buffer. """ apirequest = remote_api_pb.Request() apirequest.ParseFromString(http_request_data) apiresponse = remote_api_pb.Response() response = None errcode = 0 errdetail = "" method = "" http_request_data = "" app_id = app_info['app_id'] if not apirequest.has_method(): errcode = taskqueue_service_pb.TaskQueueServiceError.INVALID_REQUEST errdetail = "Method was not set in request" apirequest.set_method("NOT_FOUND") else: method = apirequest.method() if not apirequest.has_request(): errcode = taskqueue_service_pb.TaskQueueServiceError.INVALID_REQUEST errdetail = "Request missing in call" apirequest.set_method("NOT_FOUND") apirequest.clear_request() else: http_request_data = apirequest.request() start_time = time.time() request_log = method if apirequest.has_request_id(): request_log += ': {}'.format(apirequest.request_id()) logger.debug(request_log) result = None if method == "FetchQueueStats": result = self.queue_handler.fetch_queue_stats( app_id, http_request_data) elif method == "PurgeQueue": result = self.queue_handler.purge_queue(app_id, http_request_data) elif method == "Delete": result = self.queue_handler.delete(app_id, http_request_data) elif method == "QueryAndOwnTasks": result = self.queue_handler.query_and_own_tasks( app_id, http_request_data) elif method == "Add": result = self.queue_handler.add(app_info, http_request_data) elif method == "BulkAdd": result = self.queue_handler.bulk_add(app_info, http_request_data) elif method == "ModifyTaskLease": result = self.queue_handler.modify_task_lease( app_id, http_request_data) elif method == "UpdateQueue": response = taskqueue_service_pb.TaskQueueUpdateQueueResponse() result = self.queue_handler.Encode(), 0, "" elif method == "FetchQueues": result = self.queue_handler.fetch_queue(app_id, http_request_data) elif method == "QueryTasks": result = self.queue_handler.query_tasks(app_id, http_request_data) elif method == "FetchTask": result = self.queue_handler.fetch_task(app_id, http_request_data) elif method == "ForceRun": result = self.queue_handler.force_run(app_id, http_request_data) elif method == "DeleteQueue": response = taskqueue_service_pb.TaskQueueDeleteQueueResponse() result = self.queue_handler.Encode(), 0, "" elif method == "PauseQueue": result = self.queue_handler.pause_queue(app_id, http_request_data) elif method == "DeleteGroup": result = self.queue_handler.delete_group(app_id, http_request_data) elif method == "UpdateStorageLimit": result = self.queue_handler.update_storage_limit( app_id, http_request_data) if result: response, errcode, errdetail = result elapsed_time = round(time.time() - start_time, 3) timing_log = 'Elapsed: {}'.format(elapsed_time) if apirequest.has_request_id(): timing_log += ' ({})'.format(apirequest.request_id()) logger.debug(timing_log) if response is not None: apiresponse.set_response(response) # If there was an error add it to the response. if errcode != 0: apperror_pb = apiresponse.mutable_application_error() apperror_pb.set_code(errcode) apperror_pb.set_detail(errdetail) self.write(apiresponse.Encode()) status = taskqueue_service_pb.TaskQueueServiceError.ErrorCode_Name( errcode) return method, status
def remote_request(self, app_info, http_request_data): """ Receives a remote request to which it should give the correct response. The http_request_data holds an encoded protocol buffer of a certain type. Each type has a particular response type. Args: app_info: A dictionary containing the application, module, and version ID of the app that is sending this request. http_request_data: Encoded protocol buffer. """ apirequest = remote_api_pb.Request() apirequest.ParseFromString(http_request_data) apiresponse = remote_api_pb.Response() response = None errcode = 0 errdetail = "" method = "" http_request_data = "" app_id = app_info['app_id'] if not apirequest.has_method(): errcode = taskqueue_service_pb.TaskQueueServiceError.INVALID_REQUEST errdetail = "Method was not set in request" apirequest.set_method("NOT_FOUND") else: method = apirequest.method() if not apirequest.has_request(): errcode = taskqueue_service_pb.TaskQueueServiceError.INVALID_REQUEST errdetail = "Request missing in call" apirequest.set_method("NOT_FOUND") apirequest.clear_request() else: http_request_data = apirequest.request() start_time = time.time() request_log = method if apirequest.has_request_id(): request_log += ': {}'.format(apirequest.request_id()) logger.debug(request_log) result = None if method == "FetchQueueStats": result = self.queue_handler.fetch_queue_stats(app_id, http_request_data) elif method == "PurgeQueue": result = self.queue_handler.purge_queue(app_id, http_request_data) elif method == "Delete": result = self.queue_handler.delete(app_id, http_request_data) elif method == "QueryAndOwnTasks": result = self.queue_handler.query_and_own_tasks(app_id, http_request_data) elif method == "Add": result = self.queue_handler.add(app_info, http_request_data) elif method == "BulkAdd": result = self.queue_handler.bulk_add(app_info, http_request_data) elif method == "ModifyTaskLease": result = self.queue_handler.modify_task_lease(app_id, http_request_data) elif method == "UpdateQueue": response = taskqueue_service_pb.TaskQueueUpdateQueueResponse() result = self.queue_handler.Encode(), 0, "" elif method == "FetchQueues": result = self.queue_handler.fetch_queue(app_id, http_request_data) elif method == "QueryTasks": result = self.queue_handler.query_tasks(app_id, http_request_data) elif method == "FetchTask": result = self.queue_handler.fetch_task(app_id, http_request_data) elif method == "ForceRun": result = self.queue_handler.force_run(app_id, http_request_data) elif method == "DeleteQueue": response = taskqueue_service_pb.TaskQueueDeleteQueueResponse() result = self.queue_handler.Encode(), 0, "" elif method == "PauseQueue": result = self.queue_handler.pause_queue(app_id, http_request_data) elif method == "DeleteGroup": result = self.queue_handler.delete_group(app_id, http_request_data) elif method == "UpdateStorageLimit": result = self.queue_handler.update_storage_limit( app_id, http_request_data) if result: response, errcode, errdetail = result elapsed_time = round(time.time() - start_time, 3) timing_log = 'Elapsed: {}'.format(elapsed_time) if apirequest.has_request_id(): timing_log += ' ({})'.format(apirequest.request_id()) logger.debug(timing_log) if response is not None: apiresponse.set_response(response) # If there was an error add it to the response. if errcode != 0: apperror_pb = apiresponse.mutable_application_error() apperror_pb.set_code(errcode) apperror_pb.set_detail(errdetail) self.write(apiresponse.Encode()) status = taskqueue_service_pb.TaskQueueServiceError.ErrorCode_Name(errcode) return method, status