Ejemplo n.º 1
0
    def export_putRequest(self, requestJSON):
        """put a new request into RequestDB

        :param cls: class ref
        :param str requestJSON: request serialized to JSON format
        """
        requestDict = json.loads(requestJSON)
        requestName = requestDict.get("RequestID", requestDict.get("RequestName", "***UNKNOWN***"))
        request = Request(requestDict)

        # Check whether the credentials in the Requests are correct and allowed to be set
        isAuthorized = RequestValidator.setAndCheckRequestOwner(request, self.getRemoteCredentials())

        if not isAuthorized:
            return S_ERROR(DErrno.ENOAUTH, "Credentials in the requests are not allowed")

        optimized = request.optimize()
        if optimized.get("Value", False):
            gLogger.debug("putRequest: request was optimized")
        else:
            gLogger.debug("putRequest: request unchanged", optimized.get("Message", "Nothing could be optimized"))

        valid = self.validate(request)
        if not valid["OK"]:
            gLogger.error("putRequest: request %s not valid: %s" % (requestName, valid["Message"]))
            return valid

        # If NotBefore is not set or user defined, we calculate its value

        now = datetime.datetime.utcnow().replace(microsecond=0)
        extraDelay = datetime.timedelta(0)
        if request.Status not in Request.FINAL_STATES and (not request.NotBefore or request.NotBefore < now):
            # We don't delay if it is the first insertion
            if getattr(request, "RequestID", 0):
                # If it is a constant delay, just set it
                if self.constantRequestDelay:
                    extraDelay = datetime.timedelta(minutes=self.constantRequestDelay)
                else:
                    # If there is a waiting Operation with Files
                    op = request.getWaiting().get("Value")
                    if op and len(op):
                        attemptList = [opFile.Attempt for opFile in op if opFile.Status == "Waiting"]
                        if attemptList:
                            maxWaitingAttempt = max([opFile.Attempt for opFile in op if opFile.Status == "Waiting"])
                            # In case it is the first attempt, extraDelay is 0
                            # maxWaitingAttempt can be None if the operation has no File, like the ForwardDiset
                            extraDelay = datetime.timedelta(
                                minutes=2 * math.log(maxWaitingAttempt) if maxWaitingAttempt else 0
                            )

                request.NotBefore = now + extraDelay

        gLogger.info(
            "putRequest: request %s not before %s (extra delay %s)"
            % (request.RequestName, request.NotBefore, extraDelay)
        )

        requestName = request.RequestName
        gLogger.info("putRequest: Attempting to set request '%s'" % requestName)
        return self.__requestDB.putRequest(request)
Ejemplo n.º 2
0
    def export_putRequest(self, requestJSON):
        """forward request from local RequestDB to central RequestManager

        :param self: self reference
        :param str requestType: request type
        """

        gMonitor.addMark("reqReceived", 1)

        requestDict = json.loads(requestJSON)
        requestName = requestDict.get(
            "RequestID", requestDict.get("RequestName", "***UNKNOWN***"))
        gLogger.info("putRequest: got request '%s'" % requestName)

        # We only need the object to check the authorization
        request = Request(requestDict)
        # Check whether the credentials in the Requests are correct and allowed to be set
        isAuthorized = RequestValidator.setAndCheckRequestOwner(
            request, self.getRemoteCredentials())

        if not isAuthorized:
            return S_ERROR(DErrno.ENOAUTH,
                           "Credentials in the requests are not allowed")

        forwardable = self.__forwardable(requestDict)
        if not forwardable["OK"]:
            gLogger.warn("putRequest: %s" % forwardable["Message"])

        setRequest = self.requestManager().putRequest(requestJSON)
        if not setRequest["OK"]:
            gLogger.error(
                "setReqeuest: unable to set request '%s' @ RequestManager: %s"
                % (requestName, setRequest["Message"]))
            # # put request to the request file cache
            save = self.__saveRequest(requestName, requestJSON)
            if not save["OK"]:
                gLogger.error(
                    "setRequest: unable to save request to the cache: %s" %
                    save["Message"])
                return save
            gLogger.info("setRequest: %s is saved to %s file" %
                         (requestName, save["Value"]))
            return S_OK({"set": False, "saved": True})

        gLogger.info(
            "setRequest: request '%s' has been set to the ReqManager" %
            (requestName))
        return S_OK({"set": True, "saved": False})
Ejemplo n.º 3
0
  def export_putRequest(self, requestJSON):
    """ forward request from local RequestDB to central RequestManager

    :param self: self reference
    :param str requestType: request type
    """

    gMonitor.addMark('reqReceived', 1)

    requestDict = json.loads(requestJSON)
    requestName = requestDict.get("RequestID", requestDict.get('RequestName', "***UNKNOWN***"))
    gLogger.info("putRequest: got request '%s'" % requestName)

    # We only need the object to check the authorization
    request = Request(requestDict)
    # Check whether the credentials in the Requests are correct and allowed to be set
    isAuthorized = RequestValidator.setAndCheckRequestOwner(request, self.getRemoteCredentials())

    if not isAuthorized:
      return S_ERROR(DErrno.ENOAUTH, "Credentials in the requests are not allowed")

    forwardable = self.__forwardable(requestDict)
    if not forwardable["OK"]:
      gLogger.warn("putRequest: %s" % forwardable["Message"])

    setRequest = self.requestManager().putRequest(requestJSON)
    if not setRequest["OK"]:
      gLogger.error(
          "setReqeuest: unable to set request '%s' @ RequestManager: %s" %
          (requestName, setRequest["Message"]))
      # # put request to the request file cache
      save = self.__saveRequest(requestName, requestJSON)
      if not save["OK"]:
        gLogger.error("setRequest: unable to save request to the cache: %s" % save["Message"])
        return save
      gLogger.info("setRequest: %s is saved to %s file" % (requestName, save["Value"]))
      return S_OK({"set": False, "saved": True})

    gLogger.info("setRequest: request '%s' has been set to the ReqManager" % (requestName))
    return S_OK({"set": True, "saved": False})
Ejemplo n.º 4
0
  def export_putRequest(self, requestJSON):
    """ put a new request into RequestDB

    :param cls: class ref
    :param str requestJSON: request serialized to JSON format
    """
    requestDict = json.loads(requestJSON)
    requestName = requestDict.get("RequestID", requestDict.get('RequestName', "***UNKNOWN***"))
    request = Request(requestDict)

    # Check whether the credentials in the Requests are correct and allowed to be set
    isAuthorized = RequestValidator.setAndCheckRequestOwner(request, self.getRemoteCredentials())

    if not isAuthorized:
      return S_ERROR(DErrno.ENOAUTH, "Credentials in the requests are not allowed")

    optimized = request.optimize()
    if optimized.get("Value", False):
      gLogger.debug("putRequest: request was optimized")
    else:
      gLogger.debug(
          "putRequest: request unchanged",
          optimized.get(
              "Message",
              "Nothing could be optimized"))

    valid = self.validate(request)
    if not valid["OK"]:
      gLogger.error("putRequest: request %s not valid: %s" % (requestName, valid["Message"]))
      return valid

    # If NotBefore is not set or user defined, we calculate its value

    now = datetime.datetime.utcnow().replace(microsecond=0)
    extraDelay = datetime.timedelta(0)
    if request.Status not in Request.FINAL_STATES and (
            not request.NotBefore or request.NotBefore < now):
      # We don't delay if it is the first insertion
      if getattr(request, 'RequestID', 0):
        # If it is a constant delay, just set it
        if self.constantRequestDelay:
          extraDelay = datetime.timedelta(minutes=self.constantRequestDelay)
        else:
          # If there is a waiting Operation with Files
          op = request.getWaiting().get('Value')
          if op and len(op):
            attemptList = [opFile.Attempt for opFile in op if opFile.Status == "Waiting"]
            if attemptList:
              maxWaitingAttempt = max(
                  [opFile.Attempt for opFile in op if opFile.Status == "Waiting"])
              # In case it is the first attempt, extraDelay is 0
              # maxWaitingAttempt can be None if the operation has no File, like the ForwardDiset
              extraDelay = datetime.timedelta(
                  minutes=2 * math.log(maxWaitingAttempt) if maxWaitingAttempt else 0)

        request.NotBefore = now + extraDelay

    gLogger.info("putRequest: request %s not before %s (extra delay %s)" %
                 (request.RequestName, request.NotBefore, extraDelay))

    requestName = request.RequestName
    gLogger.info("putRequest: Attempting to set request '%s'" % requestName)
    return self.__requestDB.putRequest(request)