ResourceStatus

ResourceStatus

Module that acts as a helper for knowing the status of a resource. It takes care of switching between the CS and the RSS. The status is kept in the RSSCache object, which is a small wrapper on top of DictCache

class DIRAC.ResourceStatusSystem.Client.ResourceStatus.ResourceStatus(*args, **kwargs)

Bases: object

ResourceStatus helper that connects to CS if RSS flag is not Active. It keeps the connection to the db / server as an object member, to avoid creating a new one massively.

__init__(rssFlag=None)

Constructor, initializes the rssClient.

getElementStatus(elementName, elementType, statusType=None, default=None, vO=None)

Helper function, tries to get information from the RSS for the given Element, otherwise, it gets it from the CS.

Parameters:
  • elementName (str, list) – name of the element or list of element names

  • elementType (str) – type of the element (StorageElement, ComputingElement, FTS, Catalog)

  • statusType (None, str, list) – type of the status (meaningful only when elementType==StorageElement)

  • default (str) – defult value (meaningful only when rss is InActive)

Returns:

S_OK/S_ERROR

Return type:

dict

Example:

>>> getElementStatus('CE42', 'ComputingElement')
    S_OK( { 'CE42': { 'all': 'Active' } } } )
>>> getElementStatus('SE1', 'StorageElement', 'ReadAccess')
    S_OK( { 'SE1': { 'ReadAccess': 'Banned' } } } )
>>> getElementStatus('SE1', 'ThisIsAWrongElementType', 'ReadAccess')
    S_ERROR( xyz.. )
>>> getElementStatus('ThisIsAWrongName', 'StorageElement', 'WriteAccess')
    S_ERROR( xyz.. )
>>> getElementStatus('A_file_catalog', 'FileCatalog')
    S_OK( { 'A_file_catalog': { 'all': 'Active' } } } )
>>> getElementStatus('SE1', 'StorageElement', ['ReadAccess', 'WriteAccess'])
    S_OK( { 'SE1': { 'ReadAccess': 'Banned' , 'WriteAccess': 'Active'} } } )
>>> getElementStatus('SE1', 'StorageElement')
    S_OK( { 'SE1': { 'ReadAccess': 'Probing' ,
                     'WriteAccess': 'Active',
                     'CheckAccess': 'Degraded',
                     'RemoveAccess': 'Banned'} } } )
>>> getElementStatus(['CE1', 'CE2'], 'ComputingElement')
    S_OK( {'CE1': {'all': 'Active'},
           'CE2': {'all': 'Probing'}}}
instance = None
isStorageElementAlwaysBanned(seName, statusType)

Checks if the AlwaysBanned policy is applied to the SE given as parameter

Parameters:
  • seName – string, name of the SE

  • statusType – ReadAcces, WriteAccess, RemoveAccess, CheckAccess

Returns:

S_OK(True/False)

setElementStatus(elementName, elementType, statusType, status, reason=None, tokenOwner=None)

Tries set information in RSS and in CS.

Parameters:
  • elementName (str) – name of the element

  • elementType (str) – type of the element (StorageElement, ComputingElement, FTS, Catalog)

  • statusType (str) – type of the status (meaningful only when elementType==StorageElement)

  • reason (str) – reason for setting the status

  • tokenOwner (str) – owner of the token (meaningful only when rss is Active)

Returns:

S_OK/S_ERROR

Return type:

dict

Example:

>>> setElementStatus('CE42', 'ComputingElement', 'all', 'Active')
    S_OK(  xyz.. )
>>> setElementStatus('SE1', 'StorageElement', 'ReadAccess', 'Banned')
    S_OK(  xyz.. )
DIRAC.ResourceStatusSystem.Client.ResourceStatus.getCacheDictFromRawData(rawList)

Formats the raw data list, which we know it must have tuples of five elements. ( element1, element2, element3, elementt4, element5 ) into a dictionary of tuples with the format { ( element1, element2, element3, element5 ): element4 )}. The resulting dictionary will be the new Cache.

It happens that element1 is elementName,

element2 is elementType, element3 is statusType, element4 is status. element5 is vO

Parameters:
rawList - list

list of three element tuples [( element1, element2, element3, element4, element5 ),… ]

Returns:

dict of the form { ( elementName, elementType, statusType, vO ) : status, … }

DIRAC.ResourceStatusSystem.Client.ResourceStatus.getDictFromList(fromList)

Auxiliary method that given a list returns a dictionary of dictionaries: { site1 : { statusType1 : st1, statusType2 : st2 }, … }