Exemple #1
0
    def __init__(self, clients=None):
        """ Constructor.

    examples:
      >>> pdp  = PDP( None )
      >>> pdp1 = PDP( {} )
      >>> pdp2 = PDP( { 'Client1' : Client1Object } )

    :Parameters:
      **clients** - [ None, `dict` ]
        dictionary with Clients to be used in the Commands. If None, the Commands
        will create their own clients.

    """

        # decision parameters used to match policies and actions
        self.decisionParams = None

        # Helpers to discover policies and RSS metadata in CS
        self.pCaller = PolicyCaller(clients)

        # RSS State Machine, used to calculate most penalizing state while merging them
        self.rssMachine = RSSMachine('Unknown')

        self.log = gLogger.getSubLogger('PDP')
Exemple #2
0
def getValidStatus():
    '''
  Returns a list of statuses as were defined on the RSS(State)Machine
  '''

    validStatus = RSSMachine(None).getStates()
    return S_OK(validStatus)
Exemple #3
0
    def __init__(self, clients):
        '''
      Constructor. Defines members that will be used later on.
    '''

        self.pCaller = PolicyCaller(clients=clients)
        self.iGetter = InfoGetter()

        self.decissionParams = {}
        self.rssMachine = RSSMachine('Unknown')
Exemple #4
0
    def web_getResourceSummaryData(self):
        '''This method returns the data required to fill the grid.
    '''

        requestParams = self.__requestParams()
        gLogger.info(requestParams)

        pub = RPCClient('ResourceStatus/Publisher')

        elementStatuses = yield self.threadTask(
            pub.getElementStatuses, 'Resource', requestParams['name'],
            requestParams['elementType'], requestParams['statusType'],
            requestParams['status'], requestParams['tokenOwner'])
        if not elementStatuses['OK']:
            self.finish({
                'success': 'false',
                'error': elementStatuses['Message']
            })

        elementTree = collections.defaultdict(list)

        for element in elementStatuses['Value']:

            elementDict = dict(zip(elementStatuses['Columns'], element))

            elementDict['DateEffective'] = str(elementDict['DateEffective'])
            elementDict['LastCheckTime'] = str(elementDict['LastCheckTime'])
            elementDict['TokenExpiration'] = str(
                elementDict['TokenExpiration'])

            elementTree[elementDict['Name']].append(elementDict)

        elementList = []

        for elementValues in elementTree.values():

            if len(elementValues) == 1:
                elementList.append(elementValues[0])
            else:

                elementList.append(self.combine(elementValues))

        rssMachine = RSSMachine(None)

        yield self.threadTask(rssMachine.orderPolicyResults, elementList)

        timestamp = Time.dateTime().strftime("%Y-%m-%d %H:%M [UTC]")

        self.finish({
            'success': 'true',
            'result': elementList,
            'total': len(elementList),
            "date": timestamp
        })
Exemple #5
0
def getValidStatus():
  '''
  Returns a list of statuses as were defined on the RSS(State)Machine  
  '''

  validStatus = RSSMachine( None ).getStates()
  return S_OK( validStatus )


#def getValidStatusTypes():
#  '''
#  Returns from the OperationsHelper: <_rssConfigPath>/GeneralConfig/Resources
#  '''
#  #FIXME: no defaults. If it fails, I want to know it.
#  
#  #FIXME: return S_OK
#  
#  DEFAULTS = { 
#               'Site'          : ( '', ),
#               'Resource'      : ( '', ),
#               'Node'          : ( '', )
##               'StorageElement': [ 'ReadAccess', 'WriteAccess', 
##                                   'RemoveAccess', 'CheckAccess' ]
#              }
#  
#  #FIXME: it does not work with empty configuration
##  opHelper = Operations()
##  
##  sections = opHelper.getSections( '%s/GeneralConfig/Resources' % _rssConfigPath )
##  if not sections[ 'OK' ]:
##    return DEFAULTS
##  
##  result = {}
##  for section in sections[ 'Value' ]:
##    res = opHelper.getValue( '%s/GeneralConfig/Resources/%s/StatusType' % ( _rssConfigPath, section ) )
##    if res is None:
##      if DEFAULTS.has_key( section ):
##        result[ section ] = DEFAULTS[ section ]
##      else:
##        result[ section ] = []  
##    else:
##      result[ section ] = Utils.getTypedList( res )
##      
##  return result     
#  return DEFAULTS  

#def getValidPolicyResult():
#  '''
#  Returns from the OperationsHelper: RSSConfiguration/GeneralConfig/PolicyResult
#  '''
#  
#  DEFAULTS = [ 'Error', 'Unknown', 'Banned', 'Probing', 'Degraded', 'Active' ]
#  
#  result = Operations().getValue( 'RSSConfiguration/GeneralConfig/PolicyResult' )
#  if result is not None:
#    return Utils.getTypedList( result )
#  return DEFAULTS
#
#
#def getValidSiteTypes():
#  '''
#  Returns from the OperationsHelper: RSSConfiguration/GeneralConfig/SiteType
#  '''
#  
#  DEFAULTS = [ 'T1', 'T2', 'T3', 'T4' ]
#  
#  result = Operations().getValue( 'RSSConfiguration/GeneralConfig/SiteType' )
#  if result is not None:
#    return Utils.getTypedList( result )
#  return DEFAULTS
#
#
#def getValidServiceTypes():
#  '''
#  Returns from the OperationsHelper: RSSConfiguration/GeneralConfig/ServiceType
#  '''
#  
#  DEFAULTS = [ 'Computing', 'Storage', 'VO-BOX', 'VOMS', 'CondDB' ]
#  
#  result = Operations().getValue( 'RSSConfiguration/GeneralConfig/ServiceType' )
#  if result is not None:
#    return Utils.getTypedList( result )
#  return DEFAULTS
#
#
#def getValidResourceTypes():
#  '''
#  Returns from the OperationsHelper: RSSConfiguration/GeneralConfig/ResourceType
#  '''
#  
#  DEFAULTS = [ 'CE', 'CREAMCE', 'SE', 'LFC_C', 'LFC_L', 'FTS', 'VOMS' ]
#  
#  result = Operations().getValue( 'RSSConfiguration/GeneralConfig/ResourceType' )
#  if result is not None:
#    return Utils.getTypedList( result )
#  return DEFAULTS
#
#def getValidPolicyTypes():
#  '''
#  Returns from the OperationsHelper: RSSConfiguration/GeneralConfig/PolicyTypes
#  '''
#  
#  DEFAULTS = [ 'Resource_PolType', 'Alarm_PolType', 'Collective_PolType', 'RealBan_PolType' ]
#  
#  result = Operations().getValue( 'RSSConfiguration/GeneralConfig/PolicyTypes' )
#  if result is not None:
#    return Utils.getTypedList( result )
#  return DEFAULTS
#
#################################################################################
#
#views_panels = {
#  'Site'           : [ 'Site_Panel', 'Service_Computing_Panel', 
#                       'Service_Storage_Panel', 'Service_VOMS_Panel', 
#                       'Service_VO-BOX_Panel' ],
#  'Resource'       : [ 'Resource_Panel' ],
#  'StorageElement' : [ 'SE_Panel' ]
#}

################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
Exemple #6
0
    def getElementStatusTotalTimes(self,
                                   element,
                                   elementName,
                                   statusType,
                                   oldAs=None,
                                   newAs=None):
        """
    Returns a dictionary with all the possible statuses as keys and as values the
    number of seconds that <element><elementName><statusType> hold it for a time
    window between [ oldAs, newAs ]. If oldAs is not defined, it is considered 
    as datetime.min. If newAs is not defined, it is considered datetime.utcnow.

    :Parameters:
      **element** - `str`
        element family ( either Site, Resource or Node )
      **elementName** - `str`
        element name
      **statusType** - `str`
        status type of the element <elementName> (e.g. 'all', 'ReadAccess',... )
      **oldAs** - [ None, `datetime` ]
        datetime with the start point for the time window. If not specified, it
        is used the oldest time in the history.
      **newAs** - [ None, `datetime` ]
        datetime with the end point for the time window. If not specified, it
        is used datetime.utcnow.
    
    :return: S_OK( [ { StatusA : secondsA },{ StatusB : secondsB } ] ) | S_ERROR     
    """

        # Gets all history withing the window
        result = self.getElementHistory(element, elementName, statusType,
                                        oldAs, newAs)
        if not result['OK']:
            return result
        result = result['Value']

        statuses = RSSMachine(None).getStates()

        # Dictionary to be returned
        statusCounter = dict.fromkeys(statuses, 0)

        # If history is empty, return empty dictionary
        if not result:
            return S_OK(statusCounter)

        # Set defaults
        oldAs = (1 and oldAs) or datetime.datetime.min
        newAs = (1 and newAs) or datetime.datetime.utcnow()

        # If users are not behaving well, we force newAs to not be in the future.
        newAs = min(newAs, datetime.datetime.utcnow())

        # Iterate over the results in tuples.
        for statusTuple in zip(result, result[1:]):

            # Make sure the time taken as base is not older than the lower limit of
            # the window. In principle, this should be only checked on the first element,
            # but it is harmless anyway and cleaner than the if-else.
            startingPoint = max(statusTuple[0][1], oldAs)

            # Get number of seconds and add them
            statusCounter[statusTuple[0][0]] += timedelta_to_seconds(
                statusTuple[1][1] - startingPoint)

        # The method selected to iterate over the results does not take into account the
        # last one. Gets the time using as lower limit the window lower limit. This applies
        # when we have only one element in the list for example.
        statusCounter[result[-1][0]] += timedelta_to_seconds(
            newAs - max(result[-1][1], oldAs))

        return S_OK(statusCounter)