예제 #1
0
    def update_queue(self, app_id, http_data):
        """ Creates a queue entry in the database.

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.
    Returns:
      A tuple of a encoded response, error code, and error detail.
    """
        # TODO implement.
        request = taskqueue_service_pb.TaskQueueUpdateQueueRequest(http_data)
        response = taskqueue_service_pb.TaskQueueUpdateQueueResponse()
        return (response.Encode(), 0, "")
예제 #2
0
    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
예제 #3
0
  def remote_request(self, app_id, 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_id: The application ID that is sending this request.
      http_request_data: Encoded protocol buffer.
    """
    global task_queue    
    apirequest = remote_api_pb.Request()
    apirequest.ParseFromString(http_request_data)
    apiresponse = remote_api_pb.Response()
    response = None
    errcode = 0
    errdetail = ""
    method = ""
    http_request_data = ""

    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()

    logger.debug('Method: {}'.format(method))
    if method == "FetchQueueStats":
      response, errcode, errdetail = task_queue.fetch_queue_stats(app_id,
                                                 http_request_data)
    elif method == "PurgeQueue":
      response, errcode, errdetail = task_queue.purge_queue(app_id,
                                                 http_request_data)
    elif method == "Delete":
      response, errcode, errdetail = task_queue.delete(app_id,
                                                 http_request_data)
    elif method == "QueryAndOwnTasks":
      response, errcode, errdetail = task_queue.query_and_own_tasks(
                                                 app_id,
                                                 http_request_data)
    elif method == "Add":
      response, errcode, errdetail = task_queue.add(app_id,
                                                 http_request_data)
    elif method == "BulkAdd":
      response, errcode, errdetail = task_queue.bulk_add(app_id,
                                                 http_request_data)
    elif method == "ModifyTaskLease":
      response, errcode, errdetail = task_queue.modify_task_lease(app_id,
                                                 http_request_data)
    elif method == "UpdateQueue":
      response = taskqueue_service_pb.TaskQueueUpdateQueueResponse()
      response, errcode, errdetail = response.Encode(), 0, ""
    elif method == "FetchQueues":
      response, errcode, errdetail = task_queue.fetch_queue(app_id,
                                                 http_request_data)
    elif method == "QueryTasks":
      response, errcode, errdetail = task_queue.query_tasks(app_id,
                                                 http_request_data)
    elif method == "FetchTask":
      response, errcode, errdetail = task_queue.fetch_task(app_id,
                                                 http_request_data)
    elif method == "ForceRun":
      response, errcode, errdetail = task_queue.force_run(app_id,
                                                 http_request_data)
    elif method == "DeleteQueue":
      response = taskqueue_service_pb.TaskQueueDeleteQueueResponse()
      response, errcode, errdetail = response.Encode(), 0, ""
    elif method == "PauseQueue":
      response, errcode, errdetail = task_queue.pause_queue(app_id,
                                                 http_request_data)
    elif method == "DeleteGroup":
      response, errcode, errdetail = task_queue.delete_group(app_id,
                                                 http_request_data)
    elif method == "UpdateStorageLimit":
      response, errcode, errdetail = task_queue.update_storage_limit(
                                                 app_id,
                                                 http_request_data)

    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())