Example #1
0
    def available(self, jobIDList=None):
        """This method returns the number of available slots in the target CE. The CE
       instance polls for waiting and running jobs and compares to the limits
       in the CE parameters.

       :param jobIDList: list of already existing job IDs to be checked against
       :type jobIDList: python:list
    """

        # If there are no already registered jobs
        if jobIDList is not None and not jobIDList:
            result = S_OK()
            result['RunningJobs'] = 0
            result['WaitingJobs'] = 0
            result['SubmittedJobs'] = 0
        else:
            result = self.ceParameters.get('CEType')
            if result and result == 'CREAM':
                result = self.getCEStatus(jobIDList)
            else:
                result = self.getCEStatus()
            if not result['OK']:
                #self.log.warn( 'Could not obtain CE dynamic information' )
                #self.log.warn( result['Message'] )
                return result
        runningJobs = result['RunningJobs']
        waitingJobs = result['WaitingJobs']
        submittedJobs = result['SubmittedJobs']
        availableProcessors = result.get('AvailableProcessors')
        ceInfoDict = dict(result)

        maxTotalJobs = int(self.ceParameters.get('MaxTotalJobs', 0))
        ceInfoDict['MaxTotalJobs'] = maxTotalJobs
        waitingToRunningRatio = float(
            self.ceParameters.get('WaitingToRunningRatio', 0.0))
        # if there are no Running job we can submit to get at most 'MaxWaitingJobs'
        # if there are Running jobs we can increase this to get a ratio W / R 'WaitingToRunningRatio'
        maxWaitingJobs = int(
            max(int(self.ceParameters.get('MaxWaitingJobs', 0)),
                runningJobs * waitingToRunningRatio))

        self.log.verbose('Max Number of Jobs:', maxTotalJobs)
        self.log.verbose('Max W/R Ratio:', waitingToRunningRatio)
        self.log.verbose('Max Waiting Jobs:', maxWaitingJobs)

        # Determine how many more jobs can be submitted
        message = '%s CE: SubmittedJobs=%s' % (self.ceName, submittedJobs)
        message += ', WaitingJobs=%s, RunningJobs=%s' % (waitingJobs,
                                                         runningJobs)
        totalJobs = runningJobs + waitingJobs

        message += ', MaxTotalJobs=%s' % (maxTotalJobs)

        if totalJobs >= maxTotalJobs:
            self.log.verbose('Max Number of Jobs reached:', maxTotalJobs)
            result['Value'] = 0
            message = 'There are %s waiting jobs and total jobs %s >= %s max total jobs' % (
                waitingJobs, totalJobs, maxTotalJobs)
        else:
            additionalJobs = 0
            if waitingJobs < maxWaitingJobs:
                additionalJobs = maxWaitingJobs - waitingJobs
                if totalJobs + additionalJobs >= maxTotalJobs:
                    additionalJobs = maxTotalJobs - totalJobs
            #For SSH CE case
            if int(self.ceParameters.get('MaxWaitingJobs', 0)) == 0:
                additionalJobs = maxTotalJobs - runningJobs

            if availableProcessors is not None:
                additionalJobs = min(additionalJobs, availableProcessors)
            result['Value'] = additionalJobs

        result['Message'] = message
        result['CEInfoDict'] = ceInfoDict
        return result
Example #2
0
  def available(self, jobIDList=None):
    """This method returns the number of available slots in the target CE. The CE
       instance polls for waiting and running jobs and compares to the limits
       in the CE parameters.

       :param jobIDList: list of already existing job IDs to be checked against
       :type jobIDList: python:list
    """

    # If there are no already registered jobs
    if jobIDList is not None and not jobIDList:
      result = S_OK()
      result['RunningJobs'] = 0
      result['WaitingJobs'] = 0
      result['SubmittedJobs'] = 0
    else:
      result = self.ceParameters.get('CEType')
      if result and result == 'CREAM':
        result = self.getCEStatus(jobIDList)
      else:
        result = self.getCEStatus()
      if not result['OK']:
        return result
    runningJobs = result['RunningJobs']
    waitingJobs = result['WaitingJobs']
    submittedJobs = result['SubmittedJobs']
    availableProcessors = result.get('AvailableProcessors')
    ceInfoDict = dict(result)

    maxTotalJobs = int(self.ceParameters.get('MaxTotalJobs', 0))
    ceInfoDict['MaxTotalJobs'] = maxTotalJobs
    waitingToRunningRatio = float(self.ceParameters.get('WaitingToRunningRatio', 0.0))
    # if there are no Running job we can submit to get at most 'MaxWaitingJobs'
    # if there are Running jobs we can increase this to get a ratio W / R 'WaitingToRunningRatio'
    maxWaitingJobs = int(max(int(self.ceParameters.get('MaxWaitingJobs', 0)),
                             runningJobs * waitingToRunningRatio))

    self.log.verbose('Max Number of Jobs:', maxTotalJobs)
    self.log.verbose('Max W/R Ratio:', waitingToRunningRatio)
    self.log.verbose('Max Waiting Jobs:', maxWaitingJobs)

    # Determine how many more jobs can be submitted
    message = '%s CE: SubmittedJobs=%s' % (self.ceName, submittedJobs)
    message += ', WaitingJobs=%s, RunningJobs=%s' % (waitingJobs, runningJobs)
    totalJobs = runningJobs + waitingJobs

    message += ', MaxTotalJobs=%s' % (maxTotalJobs)

    if totalJobs >= maxTotalJobs:
      self.log.verbose('Max Number of Jobs reached:', maxTotalJobs)
      result['Value'] = 0
      message = 'There are %s waiting jobs and total jobs %s >= %s max total jobs' % (
          waitingJobs, totalJobs, maxTotalJobs)
    else:
      additionalJobs = 0
      if waitingJobs < maxWaitingJobs:
        additionalJobs = maxWaitingJobs - waitingJobs
        if totalJobs + additionalJobs >= maxTotalJobs:
          additionalJobs = maxTotalJobs - totalJobs
      # For SSH CE case
      if int(self.ceParameters.get('MaxWaitingJobs', 0)) == 0:
        additionalJobs = maxTotalJobs - runningJobs

      if availableProcessors is not None:
        additionalJobs = min(additionalJobs, availableProcessors)
      result['Value'] = additionalJobs

    result['Message'] = message
    result['CEInfoDict'] = ceInfoDict
    return result
Example #3
0
    def available(self, jobIDList=None):
        """This method returns the number of available slots in the target CE. The CE
        instance polls for waiting and running jobs and compares to the limits
        in the CE parameters.

        :param list jobIDList: list of already existing job IDs to be checked against
        """

        # If there are no already registered jobs
        if jobIDList is not None and not jobIDList:
            result = S_OK()
            result["RunningJobs"] = 0
            result["WaitingJobs"] = 0
            result["SubmittedJobs"] = 0
        else:
            result = self.ceParameters.get("CEType")
            if result and result == "CREAM":
                result = self.getCEStatus(jobIDList)  # pylint: disable=too-many-function-args
            else:
                result = self.getCEStatus()
            if not result["OK"]:
                return result
        runningJobs = result["RunningJobs"]
        waitingJobs = result["WaitingJobs"]
        submittedJobs = result["SubmittedJobs"]
        availableProcessors = result.get("AvailableProcessors")
        ceInfoDict = dict(result)

        maxTotalJobs = int(self.ceParameters.get("MaxTotalJobs", 0))
        ceInfoDict["MaxTotalJobs"] = maxTotalJobs
        waitingToRunningRatio = float(
            self.ceParameters.get("WaitingToRunningRatio", 0.0))
        # if there are no Running job we can submit to get at most 'MaxWaitingJobs'
        # if there are Running jobs we can increase this to get a ratio W / R 'WaitingToRunningRatio'
        maxWaitingJobs = int(
            max(int(self.ceParameters.get("MaxWaitingJobs", 0)),
                runningJobs * waitingToRunningRatio))

        self.log.verbose("Max Number of Jobs:", maxTotalJobs)
        self.log.verbose("Max W/R Ratio:", waitingToRunningRatio)
        self.log.verbose("Max Waiting Jobs:", maxWaitingJobs)

        # Determine how many more jobs can be submitted
        message = "%s CE: SubmittedJobs=%s" % (self.ceName, submittedJobs)
        message += ", WaitingJobs=%s, RunningJobs=%s" % (waitingJobs,
                                                         runningJobs)
        totalJobs = runningJobs + waitingJobs

        message += ", MaxTotalJobs=%s" % (maxTotalJobs)

        if totalJobs >= maxTotalJobs:
            self.log.verbose("Max Number of Jobs reached:", maxTotalJobs)
            result["Value"] = 0
            message = "There are %s waiting jobs and total jobs %s >= %s max total jobs" % (
                waitingJobs,
                totalJobs,
                maxTotalJobs,
            )
        else:
            additionalJobs = 0
            if waitingJobs < maxWaitingJobs:
                additionalJobs = maxWaitingJobs - waitingJobs
                if totalJobs + additionalJobs >= maxTotalJobs:
                    additionalJobs = maxTotalJobs - totalJobs
            # For SSH CE case
            if int(self.ceParameters.get("MaxWaitingJobs", 0)) == 0:
                additionalJobs = maxTotalJobs - runningJobs

            if availableProcessors is not None:
                additionalJobs = min(additionalJobs, availableProcessors)
            result["Value"] = additionalJobs

        result["Message"] = message
        result["CEInfoDict"] = ceInfoDict
        return result
Example #4
0
    def __init__(self,
                 name=None,
                 scope=None,
                 prompt=None,
                 issuer=None,
                 jwks_uri=None,
                 client_id=None,
                 redirect_uri=None,
                 client_secret=None,
                 proxy_endpoint=None,
                 token_endpoint=None,
                 providerOfWhat=None,
                 scopes_supported=None,
                 userinfo_endpoint=None,
                 max_proxylifetime=None,
                 revocation_endpoint=None,
                 registration_endpoint=None,
                 grant_types_supported=None,
                 authorization_endpoint=None,
                 introspection_endpoint=None,
                 response_types_supported=None,
                 **kwargs):
        """ OIDCClient constructor
    """
        super(OAuth2, self).__init__()
        self.exceptions = exceptions
        self.verify = False

        __optns = {}
        self.parameters = {}
        self.parameters['name'] = name or kwargs.get('ProviderName')
        self.log = gLogger.getSubLogger("OAuth2/%s" % self.parameters['name'])

        # Get information from CS
        result = S_OK()
        for instance in (providerOfWhat and [providerOfWhat]
                         or getInfoAboutProviders().get('Value') or []):
            result = getInfoAboutProviders(
                of=instance, providerName=self.parameters['name'])
            if result['OK']:
                break
        self.parameters['providerOfWhat'] = instance or None
        if not result['OK']:
            return result
        __csDict = result.get('Value') or {}

        # Get configuration from providers server
        self.parameters['issuer'] = issuer or kwargs.get(
            'issuer') or __csDict.get('issuer')
        if self.parameters['issuer']:
            result = self.getWellKnownDict()
            if not result['OK']:
                self.log.warn('Cannot get settings remotely:' %
                              result['Message'])
            elif isinstance(result['Value'], dict):
                __optns = result['Value']

        for d in [__csDict, kwargs]:
            for key, value in d.iteritems():
                __optns[key] = value

        # Get redirect URL from CS
        authAPI = getAuthAPI()
        if authAPI:
            redirect_uri = '%s/auth/redirect' % authAPI.strip('/')

        # Check client Id
        self.parameters['client_id'] = client_id or __optns.get('client_id')
        if not self.parameters['client_id']:
            raise Exception('client_id parameter is absent.')

        # Create list of all possible scopes
        self.parameters['scope'] = scope or __optns.get('scope') or []
        if not isinstance(self.parameters['scope'], list):
            self.parameters['scope'] = self.parameters['scope'].split(',')

        # Init main OAuth2 options
        self.parameters['prompt'] = prompt or __optns.get('prompt')
        self.parameters['redirect_uri'] = redirect_uri or __optns.get(
            'redirect_uri')
        self.parameters['client_secret'] = client_secret or __optns.get(
            'client_secret')
        self.parameters['token_endpoint'] = token_endpoint or __optns.get(
            'token_endpoint')
        self.parameters['proxy_endpoint'] = proxy_endpoint or __optns.get(
            'proxy_endpoint')
        self.parameters['scopes_supported'] = scopes_supported or __optns.get(
            'scopes_supported')
        self.parameters[
            'userinfo_endpoint'] = userinfo_endpoint or __optns.get(
                'userinfo_endpoint')
        self.parameters[
            'max_proxylifetime'] = max_proxylifetime or __optns.get(
                'max_proxylifetime') or 86400
        self.parameters[
            'revocation_endpoint'] = revocation_endpoint or __optns.get(
                'revocation_endpoint')
        self.parameters[
            'registration_endpoint'] = registration_endpoint or __optns.get(
                'registration_endpoint')
        self.parameters[
            'authorization_endpoint'] = authorization_endpoint or __optns.get(
                'authorization_endpoint')
        self.parameters[
            'introspection_endpoint'] = introspection_endpoint or __optns.get(
                'introspection_endpoint')