diff --git a/ResourceStatusSystem/Agent/CacheCleanerAgent.py b/ResourceStatusSystem/Agent/CacheCleanerAgent.py index c5756066826..1e252770981 100644 --- a/ResourceStatusSystem/Agent/CacheCleanerAgent.py +++ b/ResourceStatusSystem/Agent/CacheCleanerAgent.py @@ -1,18 +1,22 @@ -################################################################################ # $HeadURL$ -################################################################################ -__RCSID__ = "$Id$" -AGENT_NAME = 'ResourceStatus/CleanerAgent' +''' CacheCleanerAgent + + This agent cleans the history tables, and the cache ones if entries older + than a certan period. -from datetime import datetime,timedelta +''' -from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Base.AgentModule import AgentModule +from datetime import datetime, timedelta -from DIRAC.ResourceStatusSystem import ValidRes +from DIRAC import S_OK, S_ERROR +from DIRAC.Core.Base.AgentModule import AgentModule +from DIRAC.ResourceStatusSystem import ValidRes from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/CleanerAgent' + class CacheCleanerAgent( AgentModule ): ''' The CacheCleanerAgent tidies up the ResourceStatusDB, namely: @@ -30,13 +34,19 @@ class CacheCleanerAgent( AgentModule ): If you want to know more about the CacheCleanerAgent, scroll down to the end of the file. ''' + + # Too many public methods + # pylint: disable-msg=R0904 def initialize( self ): + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 + try: - self.rsClient = ResourceStatusClient() - self.rmClient = ResourceManagementClient() + self.rsClient = ResourceStatusClient() + self.rmClient = ResourceManagementClient() self.historyTables = [ '%sHistory' % x for x in ValidRes ] return S_OK() @@ -57,12 +67,12 @@ def execute( self ): now = datetime.utcnow().replace( microsecond = 0, second = 0 ) sixMonthsAgo = now - timedelta( days = 180 ) - for g in ValidRes: + for granularity in ValidRes: #deleter = getattr( self.rsClient, 'delete%sHistory' % g ) kwargs = { 'meta' : { 'minor' : { 'DateEnd' : sixMonthsAgo } } } - self.log.info( 'Deleting %sHistory older than %s' % ( g, sixMonthsAgo ) ) - res = self.rsClient.deleteElementHistory( g, **kwargs ) + self.log.info( 'Deleting %sHistory older than %s' % ( granularity, sixMonthsAgo ) ) + res = self.rsClient.deleteElementHistory( granularity, **kwargs ) if not res[ 'OK' ]: self.log.error( res[ 'Message' ] ) diff --git a/ResourceStatusSystem/Agent/CacheFeederAgent.py b/ResourceStatusSystem/Agent/CacheFeederAgent.py index c44204add4a..ee1731b701f 100644 --- a/ResourceStatusSystem/Agent/CacheFeederAgent.py +++ b/ResourceStatusSystem/Agent/CacheFeederAgent.py @@ -1,19 +1,22 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/CacheFeederAgent' +''' CacheFeederAgent + + This agent feeds the Cache tables with the outputs of the cache commands. + +''' from datetime import datetime from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule - from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller from DIRAC.ResourceStatusSystem.Command.ClientsInvoker import ClientsInvoker from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/CacheFeederAgent' + class CacheFeederAgent( AgentModule ): ''' The CacheFeederAgent feeds the cache tables for the client and the accounting. @@ -21,21 +24,27 @@ class CacheFeederAgent( AgentModule ): tables. ''' + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 + try: self.rmClient = ResourceManagementClient() self.clientsInvoker = ClientsInvoker() - commandsList_ClientsCache = [ + commandsListClientsCache = [ ( 'ClientsCache_Command', 'JobsEffSimpleEveryOne_Command' ), ( 'ClientsCache_Command', 'PilotsEffSimpleEverySites_Command' ), ( 'ClientsCache_Command', 'DTEverySites_Command' ), ( 'ClientsCache_Command', 'DTEveryResources_Command' ) ] - commandsList_AccountingCache = [ + commandsListAccountingCache = [ ( 'AccountingCache_Command', 'TransferQualityByDestSplitted_Command', ( 2, ), 'Always' ), ( 'AccountingCache_Command', 'FailedTransfersBySourceSplitted_Command', ( 2, ), 'Always' ), ( 'AccountingCache_Command', 'TransferQualityByDestSplittedSite_Command', ( 24, ), 'Hourly' ), @@ -51,33 +60,33 @@ def initialize( self ): ( 'AccountingCache_Command', 'RunningJobsBySiteSplitted_Command', ( 8760, ), 'Daily' ), ] - self.commandObjectsList_ClientsCache = [] - self.commandObjectsList_AccountingCache = [] + self.commandObjectsListClientsCache = [] + self.commandObjectsListAccountingCache = [] cc = CommandCaller() # We know beforehand which APIs are we going to need, so we initialize them # first, making everything faster. - APIs = [ 'ResourceStatusClient', 'WMSAdministrator', 'ReportGenerator', - 'JobsClient', 'PilotsClient', 'GOCDBClient', 'ReportsClient' ] - APIs = initAPIs( APIs, {} ) + knownAPIs = [ 'ResourceStatusClient', 'WMSAdministrator', 'ReportGenerator', + 'JobsClient', 'PilotsClient', 'GOCDBClient', 'ReportsClient' ] + knownAPIs = initAPIs( knownAPIs, {} ) - for command in commandsList_ClientsCache: + for command in commandsListClientsCache: cObj = cc.setCommandObject( command ) - for apiName, apiInstance in APIs.items(): + for apiName, apiInstance in knownAPIs.items(): cc.setAPI( cObj, apiName, apiInstance ) - self.commandObjectsList_ClientsCache.append( ( command, cObj ) ) + self.commandObjectsListClientsCache.append( ( command, cObj ) ) - for command in commandsList_AccountingCache: + for command in commandsListAccountingCache: cObj = cc.setCommandObject( command ) - for apiName, apiInstance in APIs.items(): + for apiName, apiInstance in knownAPIs.items(): cc.setAPI( cObj, apiName, apiInstance ) cArgs = command[ 2 ] - self.commandObjectsList_AccountingCache.append( ( command, cObj, cArgs ) ) + self.commandObjectsListAccountingCache.append( ( command, cObj, cArgs ) ) return S_OK() @@ -92,10 +101,10 @@ def execute( self ): try: - for co in self.commandObjectsList_ClientsCache: + for co in self.commandObjectsListClientsCache: commandName = co[0][1].split( '_' )[0] - gLogger.info( 'Executed %s' % commandName ) + self.log.info( 'Executed %s' % commandName ) try: self.clientsInvoker.setCommand( co[1] ) res = self.clientsInvoker.doCommand()['Result'] @@ -140,7 +149,7 @@ def execute( self ): now = datetime.utcnow().replace( microsecond = 0 ) - for co in self.commandObjectsList_AccountingCache: + for co in self.commandObjectsListAccountingCache: if co[0][3] == 'Hourly': if now.minute >= 10: diff --git a/ResourceStatusSystem/Agent/RSInspectorAgent.py b/ResourceStatusSystem/Agent/RSInspectorAgent.py index 52e6c35a71b..69263f05f5e 100644 --- a/ResourceStatusSystem/Agent/RSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/RSInspectorAgent.py @@ -1,8 +1,9 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/RSInspectorAgent' +''' RSInspectorAgent + + This agent inspect Resources, and evaluates policies that apply. + +''' import Queue, time @@ -16,6 +17,9 @@ from DIRAC.ResourceStatusSystem.Utilities.Utils import where from DIRAC.ResourceStatusSystem.Utilities import CS +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/RSInspectorAgent' + class RSInspectorAgent( AgentModule ): """ The RSInspector agent ( ResourceInspectorAgent ) is one of the four @@ -28,13 +32,19 @@ class RSInspectorAgent( AgentModule ): end of the file. """ + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() - self.ResourcesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ResourcesFreqs' ) - self.ResourcesToBeChecked = Queue.Queue() - self.ResourceNamesInCheck = [] + self.resourcesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ResourcesFreqs' ) + self.resourcesToBeChecked = Queue.Queue() + self.resourceNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) self.threadPool = ThreadPool( self.maxNumberOfThreads, @@ -53,9 +63,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -66,7 +73,7 @@ def execute( self ): 'TokenOwner' ] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'Resource', self.ResourcesFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'Resource', self.resourcesFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -76,40 +83,43 @@ def execute( self ): for resourceTuple in resQuery: - if ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) in self.ResourceNamesInCheck: + if ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) in self.resourceNamesInCheck: self.log.info( '%s(%s) discarded, already on the queue' % ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) ) continue resourceL = [ 'Resource' ] + resourceTuple - self.ResourceNamesInCheck.insert( 0, ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) ) - self.ResourcesToBeChecked.put( resourceL ) + self.resourceNamesInCheck.insert( 0, ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) ) + self.resourcesToBeChecked.put( resourceL ) return S_OK() except Exception, x: errorStr = where( self, self.execute ) - self.log.exception( errorStr,lException=x ) + self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): - if self.ResourceNamesInCheck: + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' + if self.resourceNamesInCheck: _msg = "Wait for queue to get empty before terminating the agent (%d tasks)" - _msg = _msg % len( self.ResourceNamesInCheck ) + _msg = _msg % len( self.resourceNamesInCheck ) self.log.info( _msg ) - while self.ResourceNamesInCheck: + while self.resourceNamesInCheck: time.sleep( 2 ) self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck( self, _arg ): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) @@ -118,7 +128,7 @@ def _executeCheck( self, _arg ): while True: - toBeChecked = self.ResourcesToBeChecked.get() + toBeChecked = self.resourcesToBeChecked.get() pepDict = { 'granularity' : toBeChecked[ 0 ], 'name' : toBeChecked[ 1 ], @@ -131,24 +141,24 @@ def _executeCheck( self, _arg ): try: - gLogger.info( "Checking Resource %s, with type/status: %s/%s" % \ + self.log.info( "Checking Resource %s, with type/status: %s/%s" % \ ( pepDict['name'], pepDict['statusType'], pepDict['status'] ) ) pepRes = pep.enforce( **pepDict ) if pepRes.has_key( 'PolicyCombinedResult' ) and pepRes[ 'PolicyCombinedResult' ].has_key( 'Status' ): pepStatus = pepRes[ 'PolicyCombinedResult' ][ 'Status' ] if pepStatus != pepDict[ 'status' ]: - gLogger.info( 'Updated Site %s (%s) from %s to %s' % + self.log.info( 'Updated Site %s (%s) from %s to %s' % ( pepDict['name'], pepDict['statusType'], pepDict['status'], pepStatus )) # remove from InCheck list - self.ResourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.resourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except Exception: self.log.exception( "RSInspector._executeCheck Checking Resource %s, with type/status: %s/%s" % \ ( pepDict['name'], pepDict['statusType'], pepDict['status'] ) ) try: - self.ResourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.resourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except IndexError: pass diff --git a/ResourceStatusSystem/Agent/SSInspectorAgent.py b/ResourceStatusSystem/Agent/SSInspectorAgent.py index d5094c91ba5..53a627cc404 100644 --- a/ResourceStatusSystem/Agent/SSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SSInspectorAgent.py @@ -1,23 +1,27 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/SSInspectorAgent' +''' SSInspectorAgent + + This agent inspect Sites, and evaluates policies that apply. + +''' -import Queue, time +import Queue +import time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadPool import ThreadPool - from DIRAC.ResourceStatusSystem.Utilities import CS from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Command import knownAPIs from DIRAC.ResourceStatusSystem.PolicySystem.PEP import PEP from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/SSInspectorAgent' + class SSInspectorAgent( AgentModule ): - """ + ''' The SSInspector agent ( SiteInspectorAgent ) is one of the four InspectorAgents of the RSS. @@ -26,15 +30,21 @@ class SSInspectorAgent( AgentModule ): If you want to know more about the SSInspectorAgent, scroll down to the end of the file. - """ + ''' + + # Too many public methods + # pylint: disable-msg=R0904 def initialize( self ): + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() - self.SitesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/SitesFreqs' ) - self.SitesToBeChecked = Queue.Queue() - self.SiteNamesInCheck = [] + self.sitesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/SitesFreqs' ) + self.sitesToBeChecked = Queue.Queue() + self.siteNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) self.threadPool = ThreadPool( self.maxNumberOfThreads, @@ -53,9 +63,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -65,7 +72,7 @@ def execute( self ): 'FormerStatus', 'SiteType', 'TokenOwner'] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'Site', self.SitesFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'Site', self.sitesFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -75,14 +82,14 @@ def execute( self ): for siteTuple in resQuery: - if ( siteTuple[ 0 ],siteTuple[ 1 ] ) in self.SiteNamesInCheck: + if ( siteTuple[ 0 ], siteTuple[ 1 ] ) in self.siteNamesInCheck: self.log.info( '%s(%s) discarded, already on the queue' % ( siteTuple[ 0 ],siteTuple[ 1 ] ) ) continue resourceL = [ 'Site' ] + siteTuple - self.SiteNamesInCheck.insert( 0, ( siteTuple[ 0 ], siteTuple[ 1 ] ) ) - self.SitesToBeChecked.put( resourceL ) + self.siteNamesInCheck.insert( 0, ( siteTuple[ 0 ], siteTuple[ 1 ] ) ) + self.sitesToBeChecked.put( resourceL ) return S_OK() @@ -91,24 +98,27 @@ def execute( self ): self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): - if self.SiteNamesInCheck: + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' + if self.siteNamesInCheck: _msg = "Wait for queue to get empty before terminating the agent (%d tasks)" - _msg = _msg % len( self.SiteNamesInCheck ) + _msg = _msg % len( self.siteNamesInCheck ) self.log.info( _msg ) - while self.SiteNamesInCheck: + while self.siteNamesInCheck: time.sleep( 2 ) self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck( self, _arg ): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient', 'GGUSTicketsClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) @@ -140,13 +150,13 @@ def _executeCheck( self, _arg ): ( pepDict['name'], pepDict['statusType'], pepDict['status'], pepStatus )) # remove from InCheck list - self.SiteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.siteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except Exception: self.log.exception( "SSInspector._executeCheck Checking Site %s, with type/status: %s/%s" % \ ( pepDict['name'], pepDict['statusType'], pepDict['status'] ) ) try: - self.SiteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.siteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except IndexError: pass diff --git a/ResourceStatusSystem/Agent/SeSInspectorAgent.py b/ResourceStatusSystem/Agent/SeSInspectorAgent.py index 2b5146359d6..071d79f4f7e 100644 --- a/ResourceStatusSystem/Agent/SeSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SeSInspectorAgent.py @@ -1,23 +1,27 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/SeSInspectorAgent' +''' SeSInspectorAgent + + This agent inspect Services, and evaluates policies that apply. + +''' -import Queue, time +import Queue +import time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadPool import ThreadPool - from DIRAC.ResourceStatusSystem.Utilities import CS from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Command import knownAPIs from DIRAC.ResourceStatusSystem.PolicySystem.PEP import PEP from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/SeSInspectorAgent' + class SeSInspectorAgent( AgentModule ): - """ + ''' The SeSInspector agent ( ServiceInspectorAgent ) is one of the four InspectorAgents of the RSS. @@ -26,13 +30,19 @@ class SeSInspectorAgent( AgentModule ): If you want to know more about the SeSInspectorAgent, scroll down to the end of the file. - """ + ''' + + # Too many public methods + # pylint: disable-msg=R0904 def initialize( self ): + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() - self.ServicesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ServicesFreqs' ) + self.servicesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ServicesFreqs' ) self.queue = Queue.Queue() self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) @@ -52,9 +62,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -65,7 +72,7 @@ def execute( self ): 'ServiceType', 'TokenOwner' ] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'Service', self.ServicesFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'Service', self.servicesFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -73,8 +80,8 @@ def execute( self ): resQuery = resQuery[ 'Value' ] self.log.info( 'Found %d candidates to be checked.' % len( resQuery ) ) - for r in resQuery: - resourceL = [ 'Service' ] + r + for service in resQuery: + resourceL = [ 'Service' ] + service # Here we peek INSIDE the Queue to know if the item is already # here. It's ok _here_ since (i.e. I know what I'm doing): # - It is a read only operation. @@ -89,10 +96,11 @@ def execute( self ): self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' if not self.queue.empty(): self.log.info( "Wait for queue to get empty before terminating the agent" ) while not self.queue.empty(): @@ -100,11 +108,13 @@ def finalize( self ): self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck(self): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) diff --git a/ResourceStatusSystem/Agent/StElInspectorAgent.py b/ResourceStatusSystem/Agent/StElInspectorAgent.py index fd9138d291f..307984cee80 100644 --- a/ResourceStatusSystem/Agent/StElInspectorAgent.py +++ b/ResourceStatusSystem/Agent/StElInspectorAgent.py @@ -1,23 +1,27 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/StElInspectorAgent' +''' StElInspectorAgent + + This agent inspect Sites, and evaluates policies that apply. + +''' -import Queue, time +import Queue +import time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadPool import ThreadPool - from DIRAC.ResourceStatusSystem.Utilities import CS from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Command import knownAPIs from DIRAC.ResourceStatusSystem.PolicySystem.PEP import PEP from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/StElInspectorAgent' + class StElInspectorAgent( AgentModule ): - """ + ''' The StElInspector agent ( StorageElementInspectorAgent ) is one of the four InspectorAgents of the RSS. @@ -26,15 +30,21 @@ class StElInspectorAgent( AgentModule ): If you want to know more about the StElInspectorAgent, scroll down to the end of the file. - """ + ''' + + # Too many public methods + # pylint: disable-msg=R0904 def initialize( self ): + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() - self.StorageElementsFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/StorageElementsFreqs' ) - self.StorageElementsToBeChecked = Queue.Queue() - self.StorageElementsNamesInCheck = [] + self.storageElementsFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/StorageElementsFreqs' ) + self.storageElementsToBeChecked = Queue.Queue() + self.storageElementsNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) self.threadPool = ThreadPool( self.maxNumberOfThreads, @@ -53,9 +63,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -66,7 +73,7 @@ def execute( self ): 'TokenOwner' ] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'StorageElement', self.StorageElementsFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'StorageElement', self.storageElementsFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -76,15 +83,15 @@ def execute( self ): for seTuple in resQuery: - if ( seTuple[ 0 ], seTuple[ 1 ] ) in self.StorageElementsNamesInCheck: + if ( seTuple[ 0 ], seTuple[ 1 ] ) in self.storageElementsNamesInCheck: self.log.info( '%s(%s) discarded, already on the queue' % ( seTuple[ 0 ], seTuple[ 1 ] ) ) continue resourceL = [ 'StorageElement' ] + seTuple # the tuple consists on ( SEName, SEStatusType ) - self.StorageElementsNamesInCheck.insert( 0, ( resourceL[ 1 ], resourceL[ 2 ] ) ) - self.StorageElementsToBeChecked.put( resourceL ) + self.storageElementsNamesInCheck.insert( 0, ( resourceL[ 1 ], resourceL[ 2 ] ) ) + self.storageElementsToBeChecked.put( resourceL ) return S_OK() @@ -93,24 +100,27 @@ def execute( self ): self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): - if self.StorageElementsNamesInCheck: + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' + if self.storageElementsNamesInCheck: _msg = "Wait for queue to get empty before terminating the agent (%d tasks)" - _msg = _msg % len( self.StorageElementsNamesInCheck ) + _msg = _msg % len( self.storageElementsNamesInCheck ) self.log.info( _msg ) - while self.StorageElementsNamesInCheck: + while self.storageElementsNamesInCheck: time.sleep( 2 ) self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck( self, _arg ): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) @@ -119,7 +129,7 @@ def _executeCheck( self, _arg ): while True: - toBeChecked = self.StorageElementsToBeChecked.get() + toBeChecked = self.storageElementsToBeChecked.get() pepDict = { 'granularity' : toBeChecked[ 0 ], 'name' : toBeChecked[ 1 ], @@ -138,16 +148,16 @@ def _executeCheck( self, _arg ): if pepRes.has_key( 'PolicyCombinedResult' ) and pepRes[ 'PolicyCombinedResult' ].has_key( 'Status' ): pepStatus = pepRes[ 'PolicyCombinedResult' ][ 'Status' ] if pepStatus != pepDict[ 'status' ]: - gLogger.info( 'Updated Site %s (%s) from %s to %s' % + self.log.info( 'Updated Site %s (%s) from %s to %s' % ( pepDict['name'], pepDict['statusType'], pepDict['status'], pepStatus )) # remove from InCheck list - self.StorageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.storageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except Exception: self.log.exception( 'StElInspector._executeCheck' ) try: - self.StorageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.storageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except IndexError: pass diff --git a/ResourceStatusSystem/Agent/TokenAgent.py b/ResourceStatusSystem/Agent/TokenAgent.py index 8f7b553b353..3142dfe9789 100644 --- a/ResourceStatusSystem/Agent/TokenAgent.py +++ b/ResourceStatusSystem/Agent/TokenAgent.py @@ -1,39 +1,46 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/TokenAgent' +''' TokenAgent + + This agent inspect all elements, and resets their tokens if necessary. + +''' import datetime from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient - from DIRAC.ResourceStatusSystem import ValidRes from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/TokenAgent' + class TokenAgent( AgentModule ): - """ + ''' TokenAgent is in charge of checking tokens assigned on resources. Notifications are sent to those users owning expiring tokens. - """ + ''' + + # Too many public methods + # pylint: disable-msg=R0904 def initialize( self ): - """ + ''' TokenAgent initialization - """ + ''' + + # Attribute defined outside __init__ + # pylint: disable-msg=W0201 - # Why only Site and StorageElement ?? - # self.ELEMENTS = [ 'Site', 'StorageElement' ] self.notifyHours = self.am_getOption( 'notifyHours', 10 ) try: self.rsClient = ResourceStatusClient() self.rmClient = ResourceManagementClient() - self.nc = NotificationClient() + self.noClient = NotificationClient() return S_OK() except Exception: @@ -41,14 +48,12 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ - def execute( self ): - """ - The main TokenAgent execution method. - Checks for tokens owned by users that are expiring, and notifies those users. - Calls rsClient.setToken() to set 'RS_SVC' as owner for those tokens that expired. - """ + ''' + The main TokenAgent execution method. + Checks for tokens owned by users that are expiring, and notifies those users. + Calls rsClient.setToken() to set 'RS_SVC' as owner for those tokens that expired. + ''' adminMail = '' @@ -59,12 +64,13 @@ def execute( self ): #reAssign the token to RS_SVC #for g in self.ELEMENTS: - for g in ValidRes: - tokensExpired = self.rsClient.getTokens( g, tokenExpiration = datetime.datetime.utcnow() ) + for granularity in ValidRes: + tokensExpired = self.rsClient.getTokens( granularity, + tokenExpiration = datetime.datetime.utcnow() ) if tokensExpired[ 'Value' ]: - adminMail += '\nLIST OF EXPIRED %s TOKENS\n' % g - adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20),'name'.ljust(15),'status type') + adminMail += '\nLIST OF EXPIRED %s TOKENS\n' % granularity + adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20), 'name'.ljust(15), 'status type') for token in tokensExpired[ 'Value' ]: @@ -72,18 +78,19 @@ def execute( self ): stype = token[ 2 ] user = token[ 9 ] - self.rsClient.setToken( g, name, stype, reason, 'RS_SVC', datetime.datetime( 9999, 12, 31, 23, 59, 59 ) ) + self.rsClient.setToken( granularity, name, stype, reason, 'RS_SVC', + datetime.datetime( 9999, 12, 31, 23, 59, 59 ) ) adminMail += ' %s %s %s\n' %( user.ljust(20), name.ljust(15), stype ) #notify token owners inNHours = datetime.datetime.utcnow() + datetime.timedelta( hours = self.notifyHours ) #for g in self.ELEMENTS: - for g in ValidRes: + for granularity in ValidRes: - tokensExpiring = self.rsClient.getTokens( g, tokenExpiration = inNHours ) + tokensExpiring = self.rsClient.getTokens( granularity, tokenExpiration = inNHours ) if tokensExpiring[ 'Value' ]: - adminMail += '\nLIST OF EXPIRING %s TOKENS\n' % g + adminMail += '\nLIST OF EXPIRING %s TOKENS\n' % granularity adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20),'name'.ljust(15),'status type') for token in tokensExpiring[ 'Value' ]: @@ -99,7 +106,7 @@ def execute( self ): if user == 'RS_SVC': continue - pdp = PDP( granularity = g, name = name, statusType = stype ) + pdp = PDP( granularity = granularity, name = name, statusType = stype ) decision = pdp.takeDecision() pcresult = decision[ 'PolicyCombinedResult' ] @@ -107,7 +114,7 @@ def execute( self ): expiration = token[ 2 ] - mailMessage = "The token for %s %s %s" % ( g, name, stype ) + mailMessage = "The token for %s %s %s" % ( granularity, name, stype ) mailMessage = mailMessage + "will expire on %s\n\n" % expiration mailMessage = mailMessage + "You can renew it with command 'dirac-rss-renew-token'.\n" mailMessage = mailMessage + "If you don't take any action, RSS will take control of the resource.\n\n" @@ -124,11 +131,11 @@ def execute( self ): mailMessage += policyMessage adminMail += policyMessage - self.nc.sendMail( self.rmClient.getUserRegistryCache( user )[ 2 ], + self.noClient.sendMail( self.rmClient.getUserRegistryCache( user )[ 2 ], 'Token for %s is expiring' % name, mailMessage ) if adminMail != '': #FIXME: 'ubeda' is not generic ;p - self.nc.sendMail( self.rmClient.getUserRegistryCache( 'ubeda' )[ 2 ], + self.noClient.sendMail( self.rmClient.getUserRegistryCache( 'ubeda' )[ 2 ], "Token's summary", adminMail ) return S_OK() diff --git a/ResourceStatusSystem/Agent/__init__.py b/ResourceStatusSystem/Agent/__init__.py index 7b97895241e..e8dab8b5837 100644 --- a/ResourceStatusSystem/Agent/__init__.py +++ b/ResourceStatusSystem/Agent/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Agent package + +''' -""" - DIRAC.ResourceStatusSystem.Agent package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Client/JobsClient.py b/ResourceStatusSystem/Client/JobsClient.py index 7ba465b075a..5d5b7782595 100644 --- a/ResourceStatusSystem/Client/JobsClient.py +++ b/ResourceStatusSystem/Client/JobsClient.py @@ -1,7 +1,11 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' JobsClient + + Module to get jobs stats. + +''' + +__RCSID__ = '$Id: $' class JobsClient( object ): """ diff --git a/ResourceStatusSystem/Client/PilotsClient.py b/ResourceStatusSystem/Client/PilotsClient.py index 646ace652cb..3026a718074 100644 --- a/ResourceStatusSystem/Client/PilotsClient.py +++ b/ResourceStatusSystem/Client/PilotsClient.py @@ -1,7 +1,11 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' PilotsClient + + Module to get pilots stats. + +''' + +__RCSID__ = '$Id: $' class PilotsClient( object ): """ diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 2a018c01a8e..5eccbf76849 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -1,13 +1,17 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceManagementClient + + Client to interact with the ResourceManagementDB. + +''' + +from datetime import datetime from DIRAC import gLogger, S_ERROR from DIRAC.Core.DISET.RPCClient import RPCClient from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB -from datetime import datetime +__RCSID__ = '$Id: $' class ResourceManagementClient: """ @@ -70,54 +74,20 @@ def __query( self, queryType, tableName, kwargs ): gateFunction = getattr( self.gate, queryType ) - meta = kwargs.pop( 'meta' ) + # If meta is None, we set it to {} + meta = ( True and kwargs.pop( 'meta' ) ) or {} params = kwargs del params[ 'self' ] meta[ 'table' ] = tableName - gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) + gLogger.debug( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) return gateFunction( params, meta ) -# def __query( self, kwargs ): -# ''' -# This method is a rather important one. It will format the input for the DB -# queries, instead of doing it on a decorator. Two dictionaries must be passed -# to the DB. First one contains 'columnName' : value pairs, being the key -# lower camel case. The second one must have, at lease, a key named 'table' -# with the right table name. -# ''' -# -# # Functions we can call, just a light safety measure. -# __INTERNAL_FUNCTIONS__ = [ 'insert', 'update', 'get', 'delete' ] -# gateFunction = None -# -# # I'm simply lazy, do not want to pass function name as argument. I get it here -# fname = sys._getframe( 1 ).f_code.co_name -# meta = kwargs.pop( 'meta' ) -# params = kwargs -# del params[ 'self' ] -# -# for _ifName in __INTERNAL_FUNCTIONS__: -# -# if fname.startswith( _ifName ): -# -# _table = fname.replace( _ifName, '' ) -# -# meta[ 'table' ] = _table -# -# gateFunction = getattr( self.gate, _ifName ) -# continue -# -# # Be careful, __eq__ method cannot be executed if we use server ! -# if gateFunction is not None: -# -# gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( _ifName, params, meta ) ) -# return gateFunction( params, meta ) -# -# return S_ERROR( 'Cannot find right call for %s' % fname ) - - def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): +################################################################################ +# ENVIRONMENT CACHE FUNCTIONS + + def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): ''' Inserts on EnvironmentCache a new row with the arguments given. @@ -134,8 +104,10 @@ def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'EnvironmentCache', locals() ) - def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): + def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): ''' Updates EnvironmentCache with the parameters given. By default, `hashEnv` will be the parameter used to select the row. @@ -153,9 +125,11 @@ def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'EnvironmentCache', locals() ) def getEnvironmentCache( self, hashEnv = None, siteName = None, - environment = None, meta = {} ): + environment = None, meta = None ): ''' Gets from EnvironmentCache all rows that match the parameters given. @@ -172,9 +146,11 @@ def getEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'EnvironmentCache', locals() ) def deleteEnvironmentCache( self, hashEnv = None, siteName = None, - environment = None, meta = {} ): + environment = None, meta = None ): ''' Deletes from EnvironmentCache all rows that match the parameters given. @@ -191,10 +167,16 @@ def deleteEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'EnvironmentCache', locals() ) + +################################################################################ +# POLICY RESULT FUNCTIONS + def insertPolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime, - meta = {} ): + meta = None ): ''' Inserts on PolicyResult a new row with the arguments given. @@ -223,10 +205,12 @@ def insertPolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'PolicyResult', locals() ) def updatePolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime, - meta = {} ): + meta = None ): ''' Updates PolicyResult with the parameters given. By default, `name`, `policyName` and `statusType` will be the parameters used to select the row. @@ -256,10 +240,12 @@ def updatePolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'PolicyResult', locals() ) def getPolicyResult( self, granularity = None, name = None, policyName = None, statusType = None, status = None, reason = None, - dateEffective = None, lastCheckTime = None, meta = {} ): + dateEffective = None, lastCheckTime = None, meta = None ): ''' Gets from PolicyResult all rows that match the parameters given. @@ -288,11 +274,13 @@ def getPolicyResult( self, granularity = None, name = None, policyName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'PolicyResult', locals() ) def deletePolicyResult( self, granularity = None, name = None, policyName = None, statusType = None, status = None, reason = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Deletes from PolicyResult all rows that match the parameters given. @@ -321,9 +309,15 @@ def deletePolicyResult( self, granularity = None, name = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'PolicyResult', locals() ) + +################################################################################ +# CLIENT CACHE FUNCTIONS + def insertClientCache( self, name, commandName, opt_ID, value, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Inserts on ClientCache a new row with the arguments given. @@ -347,10 +341,12 @@ def insertClientCache( self, name, commandName, opt_ID, value, result, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ClientCache', locals() ) def updateClientCache( self, name, commandName, opt_ID, value, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Updates ClientCache with the parameters given. By default, `name`, `commandName` and `value` will be the parameters used to select the row. @@ -375,11 +371,13 @@ def updateClientCache( self, name, commandName, opt_ID, value, result, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'ClientCache', locals() ) def getClientCache( self, name = None, commandName = None, opt_ID = None, value = None, result = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Gets from ClientCache all rows that match the parameters given. @@ -404,10 +402,12 @@ def getClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'ClientCache', locals() ) def deleteClientCache( self, name = None, commandName = None, opt_ID = None, value = None, result = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Deletes from PolicyResult all rows that match the parameters given. @@ -432,9 +432,15 @@ def deleteClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ClientCache', locals() ) + +################################################################################ +# ACCOUNTING CACHE FUNCTIONS + def insertAccountingCache( self, name, plotType, plotName, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Inserts on AccountingCache a new row with the arguments given. @@ -457,9 +463,11 @@ def insertAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'AccountingCache', locals() ) def updateAccountingCache( self, name, plotType, plotName, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Updates AccountingCache with the parameters given. By default, `name`, `plotType` and `plotName` will be the parameters used to select the row. @@ -483,10 +491,12 @@ def updateAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'AccountingCache', locals() ) def getAccountingCache( self, name = None, plotType = None, plotName = None, result = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Gets from PolicyResult all rows that match the parameters given. @@ -509,11 +519,13 @@ def getAccountingCache( self, name = None, plotType = None, plotName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'AccountingCache', locals() ) def deleteAccountingCache( self, name = None, plotType = None, plotName = None, result = None, dateEffective = None, lastCheckTime = None, - meta = {} ): + meta = None ): ''' Deletes from PolicyResult all rows that match the parameters given. @@ -536,8 +548,14 @@ def deleteAccountingCache( self, name = None, plotType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'AccountingCache', locals() ) - def insertUserRegistryCache( self, login, name, email, meta = {} ): + +################################################################################ +# USER REGISTRY CACHE FUNCTIONS + + def insertUserRegistryCache( self, login, name, email, meta = None ): ''' Inserts on UserRegistryCache a new row with the arguments given. @@ -553,9 +571,11 @@ def insertUserRegistryCache( self, login, name, email, meta = {} ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'UserRegistryCache', locals() ) - def updateUserRegistryCache( self, login, name, email, meta = {} ): + def updateUserRegistryCache( self, login, name, email, meta = None ): ''' Updates UserRegistryCache with the parameters given. By default, `login` will be the parameter used to select the row. @@ -573,9 +593,11 @@ def updateUserRegistryCache( self, login, name, email, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'UserRegistryCache', locals() ) def getUserRegistryCache( self, login = None, name = None, email = None, - meta = {} ): + meta = None ): ''' Gets from UserRegistryCache all rows that match the parameters given. @@ -592,9 +614,11 @@ def getUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'UserRegistryCache', locals() ) def deleteUserRegistryCache( self, login = None, name = None, email = None, - meta = {} ): + meta = None ): ''' Deletes from UserRegistryCache all rows that match the parameters given. @@ -611,13 +635,12 @@ def deleteUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'UserRegistryCache', locals() ) - ''' - ############################################################################## - # EXTENDED BASE API METHODS - ############################################################################## - ''' +################################################################################ +# EXTENDED BASE API METHODS def addOrModifyEnvironmentCache( self, hashEnv, siteName, environment ): ''' @@ -637,8 +660,9 @@ def addOrModifyEnvironmentCache( self, hashEnv, siteName, environment ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'EnvironmentCache', locals() ) - def addOrModifyPolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime ): ''' @@ -670,8 +694,9 @@ def addOrModifyPolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'PolicyResult', locals() ) - def addOrModifyClientCache( self, name, commandName, opt_ID, value, result, dateEffective, lastCheckTime ): ''' @@ -699,8 +724,9 @@ def addOrModifyClientCache( self, name, commandName, opt_ID, value, result, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'ClientCache', locals() ) - def addOrModifyAccountingCache( self, name, plotType, plotName, result, dateEffective, lastCheckTime ): ''' @@ -726,8 +752,9 @@ def addOrModifyAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'AccountingCache', locals() ) - def addOrModifyUserRegistryCache( self, login, name, email ): ''' Using `login` to query the database, decides whether to insert or update @@ -746,51 +773,60 @@ def addOrModifyUserRegistryCache( self, login, name, email ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'UserRegistryCache', locals() ) ################################################################################ - - ''' - ############################################################################## - # Getter functions - ############################################################################## - ''' +# Getter functions def _insertElement( self, element, kwargs ): - + ''' + Method that executes the insert method of the given element. + ''' fname = 'insert%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) def _updateElement( self, element, kwargs ): - + ''' + Method that executes the update method of the given element. + ''' fname = 'update%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) def _getElement( self, element, kwargs ): - + ''' + Method that executes the get method of the given element. + ''' fname = 'get%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) - def _deleteElement( self, element, kwargs ): + def _deleteElement( self, element, kwargs ): + ''' + Method that executes the delete method of the given element. + ''' fname = 'delete%s' % element - f = getattr( self, fname ) - return f( **kwargs ) - - ''' - ############################################################################## - # addOrModify PRIVATE FUNCTIONS - ############################################################################## - ''' + fElem = getattr( self, fname ) + return fElem( **kwargs ) + +################################################################################ +# addOrModify PRIVATE FUNCTIONS + def __addOrModifyElement( self, element, kwargs ): - + ''' + Method that executes update if the item is not new, otherwise inserts it + on the element table. + ''' del kwargs[ 'self' ] kwargs[ 'meta' ] = { 'onlyUniqueKeys' : True } sqlQuery = self._getElement( element, kwargs ) + if not sqlQuery[ 'OK' ]: + return sqlQuery del kwargs[ 'meta' ] diff --git a/ResourceStatusSystem/Client/ResourceStatus.py b/ResourceStatusSystem/Client/ResourceStatus.py index 9d3db1a1ef4..78be9a965f8 100644 --- a/ResourceStatusSystem/Client/ResourceStatus.py +++ b/ResourceStatusSystem/Client/ResourceStatus.py @@ -1,7 +1,9 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatus + + Module use to switch between the CS and the RSS. + +''' import datetime @@ -9,6 +11,8 @@ from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient +__RCSID__ = '$Id: $' + def getStorageElementStatus( elementName, statusType = None, default = None ): ''' Helper with dual access, tries to get information from the RSS for the given @@ -226,4 +230,5 @@ def __getDictFromList( l ): res[ site ][ sType ] = status return res -################################################################################ \ No newline at end of file +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 5147daac180..941382e5017 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -1,7 +1,11 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatusClient + + Client to interact with the ResourceStatusDB. + +''' + +from datetime import datetime, timedelta from DIRAC import S_OK, S_ERROR, gLogger from DIRAC.Core.DISET.RPCClient import RPCClient @@ -10,13 +14,11 @@ ValidStatusTypes, ValidSiteType, ValidServiceType, ValidResourceType from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB from DIRAC.ResourceStatusSystem.Utilities.NodeTree import Node - -from datetime import datetime, timedelta - -import sys + +__RCSID__ = '$Id: $' class ResourceStatusClient: - """ + ''' The :class:`ResourceStatusClient` class exposes the :mod:`DIRAC.ResourceStatus` API. All functions you need are on this client. @@ -42,7 +44,7 @@ class ResourceStatusClient: All functions calling methods exposed on the database or on the booster are making use of some syntactic sugar, in this case a decorator that simplifies the client considerably. - """ + ''' def __init__( self , serviceIn = None ): ''' @@ -59,51 +61,6 @@ def __init__( self , serviceIn = None ): self.gate = RPCClient( "ResourceStatus/ResourceStatus" ) else: self.gate = serviceIn - -# def __query( self, kwargs ): -# ''' -# This method is a rather important one. It will format the input for the DB -# queries, instead of doing it on a decorator. Two dictionaries must be passed -# to the DB. First one contains 'columnName' : value pairs, being the key -# lower camel case. The second one must have, at lease, a key named 'table' -# with the right table name. -# ''' -# -# # Functions we can call, just a light safety measure. -# __INTERNAL_FUNCTIONS__ = [ 'insert', 'update', 'get', 'delete' ] -# gateFunction = None -# -# # I'm simply lazy, do not want to pass function name as argument. I get it here -# fname = sys._getframe( 1 ).f_code.co_name -# meta = kwargs.pop( 'meta' ) -# params = kwargs -# del params[ 'self' ] -# -# for _ifName in __INTERNAL_FUNCTIONS__: -# -# if fname.startswith( _ifName ): -# -# _table = fname.replace( _ifName, '' ) -# -# # This is an special case with the Element tables. -# if _table.startswith( 'Element' ): -# _element = params.pop( 'element' ) -# _table = _table.replace( 'Element', _element ) -# params[ '%sName' % _element ] = params[ 'elementName' ] -# del params[ 'elementName' ] -# -# meta[ 'table' ] = _table -# -# gateFunction = getattr( self.gate, _ifName ) -# continue -# -# # Be careful, __eq__ method cannot be executed if we use server ! -# if gateFunction is not None: -# -# gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( _ifName, params, meta ) ) -# return gateFunction( params, meta ) -# -# return S_ERROR( 'Cannot find right call for %s' % fname ) def __query( self, queryType, tableName, kwargs ): ''' @@ -120,7 +77,8 @@ def __query( self, queryType, tableName, kwargs ): gateFunction = getattr( self.gate, queryType ) - meta = kwargs.pop( 'meta' ) + # If meta is None, we set it to {} + meta = ( True and kwargs.pop( 'meta' ) ) or {} params = kwargs del params[ 'self' ] @@ -132,16 +90,13 @@ def __query( self, queryType, tableName, kwargs ): meta[ 'table' ] = tableName - gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) - return gateFunction( params, meta ) - - ''' - ############################################################################## - # SITE FUNCTIONS - ############################################################################## - ''' - - def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): + gLogger.debug( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) + return gateFunction( params, meta ) + +################################################################################ +# SITE FUNCTIONS + + def insertSite( self, siteName, siteType, gridSiteName, meta = None ): ''' Inserts on Site a new row with the arguments given. @@ -159,8 +114,10 @@ def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'Site', locals() ) - def updateSite( self, siteName, siteType, gridSiteName, meta = {} ): + def updateSite( self, siteName, siteType, gridSiteName, meta = None ): ''' Updates Site with the parameters given. By default, `siteName` will be the \ parameter used to select the row. @@ -178,10 +135,12 @@ def updateSite( self, siteName, siteType, gridSiteName, meta = {} ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'Site', locals() ) def getSite( self, siteName = None, siteType = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Gets from Site all rows that match the parameters given. @@ -199,9 +158,11 @@ def getSite( self, siteName = None, siteType = None, gridSiteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'Site', locals() ) def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Deletes from Site all rows that match the parameters given. @@ -219,12 +180,14 @@ def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'Site', locals() ) def getSitePresent( self, siteName = None, siteType = None, gridSiteName = None, gridTier = None, statusType = None, status = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, formerStatus = None, meta = {} ): + tokenExpiration = None, formerStatus = None, meta = None ): ''' Gets from the view composed by Site, SiteStatus and SiteHistory all rows that match the parameters given ( not necessarily returns the same number @@ -260,15 +223,15 @@ def getSitePresent( self, siteName = None, siteType = None, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'SitePresent', locals() ) - ''' - ############################################################################## - # SERVICE FUNCTIONS - ############################################################################## - ''' - def insertService( self, serviceName, serviceType, siteName, meta = {} ): +################################################################################ +# SERVICE FUNCTIONS + + def insertService( self, serviceName, serviceType, siteName, meta = None ): ''' Inserts on Service a new row with the arguments given. @@ -286,8 +249,10 @@ def insertService( self, serviceName, serviceType, siteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'Service', locals() ) - def updateService( self, serviceName, serviceType, siteName, meta = {} ): + def updateService( self, serviceName, serviceType, siteName, meta = None ): ''' Updates Service with the parameters given. By default, `serviceName` will \ be the parameter used to select the row. @@ -306,9 +271,11 @@ def updateService( self, serviceName, serviceType, siteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'Service', locals() ) def getService( self, serviceName = None, serviceType = None, siteName = None, - meta = {} ): + meta = None ): ''' Gets from Service all rows that match the parameters given. @@ -326,9 +293,11 @@ def getService( self, serviceName = None, serviceType = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'Service', locals() ) def deleteService( self, serviceName = None, serviceType = None, - siteName = None, meta = {} ): + siteName = None, meta = None ): ''' Deletes from Service all rows that match the parameters given. @@ -346,13 +315,15 @@ def deleteService( self, serviceName = None, serviceType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'Service', locals() ) def getServicePresent( self, serviceName = None, siteName = None, siteType = None, serviceType = None, statusType = None, status = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, formerStatus = None, - meta = {} ): + meta = None ): ''' Gets from the view composed by Service, ServiceStatus and ServiceHistory all rows that match the parameters given ( not necessarily returns the same @@ -390,15 +361,15 @@ def getServicePresent( self, serviceName = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'ServicePresent', locals() ) - ''' - ############################################################################## - # RESOURCE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# RESOURCE FUNCTIONS + def insertResource( self, resourceName, resourceType, serviceType, siteName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Inserts on Resource a new row with the arguments given. @@ -420,9 +391,11 @@ def insertResource( self, resourceName, resourceType, serviceType, siteName, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'Resource', locals() ) def updateResource( self, resourceName, resourceType, serviceType, siteName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Updates Resource with the parameters given. By default, `resourceName` will be the parameter used to select the row. @@ -445,10 +418,12 @@ def updateResource( self, resourceName, resourceType, serviceType, siteName, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'Resource', locals() ) def getResource( self, resourceName = None, resourceType = None, serviceType = None, siteName = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Gets from Resource all rows that match the parameters given. @@ -470,10 +445,12 @@ def getResource( self, resourceName = None, resourceType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'Resource', locals() ) def deleteResource( self, resourceName = None, resourceType = None, serviceType = None, siteName = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Deletes from Resource all rows that match the parameters given. @@ -495,6 +472,8 @@ def deleteResource( self, resourceName = None, resourceType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'Resource', locals() ) def getResourcePresent( self, resourceName = None, siteName = None, serviceType = None, gridSiteName = None, @@ -503,7 +482,7 @@ def getResourcePresent( self, resourceName = None, siteName = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, formerStatus = None, - meta = {} ): + meta = None ): ''' Gets from the view composed by Resource, ResourceStatus and ResourceHistory all rows that match the parameters given ( not necessarily returns the same @@ -546,15 +525,15 @@ def getResourcePresent( self, resourceName = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'ResourcePresent', locals() ) - ''' - ############################################################################## - # STORAGE ELEMENT FUNCTIONS - ############################################################################## - ''' +################################################################################ +# STORAGE ELEMENT FUNCTIONS + def insertStorageElement( self, storageElementName, resourceName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Inserts on StorageElement a new row with the arguments given. @@ -570,10 +549,12 @@ def insertStorageElement( self, storageElementName, resourceName, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'StorageElement', locals() ) def updateStorageElement( self, storageElementName, resourceName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Updates StorageElement with the parameters given. By default, `storageElementName` will be the parameter used to select the row. @@ -591,9 +572,11 @@ def updateStorageElement( self, storageElementName, resourceName, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'StorageElement', locals() ) def getStorageElement( self, storageElementName = None, resourceName = None, - gridSiteName = None, meta = {} ): + gridSiteName = None, meta = None ): ''' Gets from StorageElement all rows that match the parameters given. @@ -609,11 +592,13 @@ def getStorageElement( self, storageElementName = None, resourceName = None, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElement', locals() ) def deleteStorageElement( self, storageElementName = None, resourceName = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Deletes from StorageElement all rows that match the parameters given. @@ -630,6 +615,8 @@ def deleteStorageElement( self, storageElementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'StorageElement', locals() ) def getStorageElementPresent( self, storageElementName = None, resourceName = None, gridSiteName = None, @@ -637,7 +624,7 @@ def getStorageElementPresent( self, storageElementName = None, status = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, - formerStatus = None, meta = {} ): + formerStatus = None, meta = None ): ''' Gets from the view composed by StorageElement, StorageElementStatus and StorageElementHistory all rows that match the parameters given ( not @@ -674,15 +661,15 @@ def getStorageElementPresent( self, storageElementName = None, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElementPresent', locals() ) - ''' - ############################################################################## - # GRID SITE FUNCTIONS - ############################################################################## - ''' - def insertGridSite( self, gridSiteName, gridTier, meta = {} ): +################################################################################ +# GRID SITE FUNCTIONS + + def insertGridSite( self, gridSiteName, gridTier, meta = None ): ''' Inserts on GridSite a new row with the arguments given. @@ -696,9 +683,11 @@ def insertGridSite( self, gridSiteName, gridTier, meta = {} ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'GridSite', locals() ) - def updateGridSite( self, gridSiteName, gridTier, meta = {} ): + def updateGridSite( self, gridSiteName, gridTier, meta = None ): ''' Updates GridSite with the parameters given. By default, `gridSiteName` will be the parameter used to select the row. @@ -714,8 +703,10 @@ def updateGridSite( self, gridSiteName, gridTier, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'GridSite', locals() ) - def getGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): + def getGridSite( self, gridSiteName = None, gridTier = None, meta = None ): ''' Gets from GridSite all rows that match the parameters given. @@ -730,8 +721,10 @@ def getGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'GridSite', locals() ) - def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): + def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = None ): ''' Deletes from GridSite all rows that match the parameters given. @@ -745,18 +738,18 @@ def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'GridSite', locals() ) - ''' - ############################################################################## - # ELEMENT STATUS FUNCTIONS - ############################################################################## - ''' +################################################################################ +# ELEMENT STATUS FUNCTIONS + def insertElementStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Inserts on Status a new row with the arguments given. @@ -791,11 +784,13 @@ def insertElementStatus( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementStatus', locals() ) def updateElementStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Updates Status with the parameters given. By default, `elementName` and 'statusType' will be the parameters used to select the row. @@ -831,12 +826,14 @@ def updateElementStatus( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementStatus', locals() ) def getElementStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Gets from Status all rows that match the parameters given. @@ -871,12 +868,14 @@ def getElementStatus( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementStatus', locals() ) def deleteElementStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Deletes from Status all rows that match the parameters given. @@ -911,17 +910,17 @@ def deleteElementStatus( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementStatus', locals() ) - ''' - ############################################################################## - # ELEMENT SCHEDULED STATUS FUNCTIONS - ############################################################################## - ''' +################################################################################ +# ELEMENT SCHEDULED STATUS FUNCTIONS + def insertElementScheduledStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, - tokenExpiration, meta = {} ): + tokenExpiration, meta = None ): ''' Inserts on ScheduledStatus a new row with the arguments given. @@ -956,11 +955,13 @@ def insertElementScheduledStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementScheduledStatus', locals() ) def updateElementScheduledStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, - tokenExpiration, meta = {} ): + tokenExpiration, meta = None ): ''' Updates ScheduledStatus with the parameters given. By default, `elementName`, 'statusType' and `dateEffective` will be the parameters used @@ -997,13 +998,15 @@ def updateElementScheduledStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementScheduledStatus', locals() ) def getElementScheduledStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Gets from ScheduledStatus all rows that match the parameters given. @@ -1038,13 +1041,15 @@ def getElementScheduledStatus( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementScheduledStatus', locals() ) def deleteElementScheduledStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Deletes from ScheduledStatus all rows that match the parameters given. @@ -1080,17 +1085,17 @@ def deleteElementScheduledStatus( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementScheduledStatus', locals() ) - - ''' - ############################################################################## - # ELEMENT HISTORY FUNCTIONS - ############################################################################## - ''' + +################################################################################ +# ELEMENT HISTORY FUNCTIONS + def insertElementHistory( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Inserts on History a new row with the arguments given. @@ -1125,11 +1130,13 @@ def insertElementHistory( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementHistory', locals() ) def updateElementHistory( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Updates History with the parameters given. By default, `elementName`, 'statusType', `reason` and `dateEnd` will be the parameters @@ -1166,12 +1173,14 @@ def updateElementHistory( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementHistory', locals() ) def getElementHistory( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Gets from History all rows that match the parameters given. @@ -1206,13 +1215,15 @@ def getElementHistory( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementHistory', locals() ) def deleteElementHistory( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, - meta = {} ): + meta = None ): ''' Deletes from History all rows that match the parameters given. @@ -1247,13 +1258,12 @@ def deleteElementHistory( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementHistory', locals() ) - - ''' - ############################################################################## - # CS VALID ELEMENTS - ############################################################################## - ''' + +################################################################################ +# CS VALID ELEMENTS def getValidElements( self ): ''' @@ -1311,11 +1321,8 @@ def getValidResourceTypes( self ): ''' return S_OK( ValidResourceType ) - ''' - ############################################################################## - # EXTENDED FUNCTIONS - ############################################################################## - ''' +################################################################################ +# EXTENDED FUNCTIONS def addOrModifySite( self, siteName, siteType, gridSiteName ): ''' @@ -1333,6 +1340,8 @@ def addOrModifySite( self, siteName, siteType, gridSiteName ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Site', locals() ) def addOrModifyService( self, serviceName, serviceType, siteName ): @@ -1351,6 +1360,8 @@ def addOrModifyService( self, serviceName, serviceType, siteName ): :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Service', locals() ) def addOrModifyResource( self, resourceName, resourceType, serviceType, @@ -1373,7 +1384,9 @@ def addOrModifyResource( self, resourceName, resourceType, serviceType, name of the grid site the resource belongs ( if any ) :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Resource', locals() ) def addOrModifyStorageElement( self, storageElementName, resourceName, @@ -1391,7 +1404,9 @@ def addOrModifyStorageElement( self, storageElementName, resourceName, name of the grid site the storage element belongs :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'StorageElement', locals() ) def addOrModifyGridSite( self, gridSiteName, gridTier ): @@ -1457,6 +1472,8 @@ def modifyElementStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__modifyElementStatus( locals() ) def removeElement( self, element, elementName ): @@ -1472,7 +1489,9 @@ def removeElement( self, element, elementName ): name of the individual of class element :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument + # pylint: disable-msg=W0613 return self.__removeElement( element, elementName ) def getServiceStats( self, siteName, statusType = None ): @@ -2310,11 +2329,9 @@ def getMonitoredsStatusWeb( self, granularity, selectDict, startItem, ################################################################################ - ''' - ############################################################################## - # addOrModify PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# addOrModify PRIVATE FUNCTIONS + def __addOrModifyElement( self, element, kwargs ): @@ -2322,7 +2339,9 @@ def __addOrModifyElement( self, element, kwargs ): kwargs[ 'meta' ] = { 'onlyUniqueKeys' : True } sqlQuery = self._getElement( element, kwargs ) - + if not sqlQuery[ 'OK' ]: + return sqlQuery + del kwargs[ 'meta' ] if sqlQuery[ 'Value' ]: @@ -2380,6 +2399,8 @@ def __addOrModifyElementStatus( self, element, rDict ): } sqlQuery = self._getElement( 'ElementStatus', kwargs ) + if not sqlQuery[ 'OK' ]: + return sqlQuery rDict[ 'element' ] = element @@ -2423,11 +2444,8 @@ def __setStatusDefaults( self ): return iDict - ''' - ############################################################################## - # Modify PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# Modify PRIVATE FUNCTIONS def __modifyElementStatus( self,kwargs ): @@ -2486,11 +2504,8 @@ def __modifyElementStatus( self,kwargs ): return updateSQLQuery - ''' - ############################################################################## - # remove PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# remove PRIVATE FUNCTIONS def __removeElement( self, element, elementName ): @@ -2509,11 +2524,8 @@ def __removeElement( self, element, elementName ): return sqlQuery - ''' - ############################################################################## - # stats PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# stats PRIVATE FUNCTIONS def __getStats( self, sqlQuery ): @@ -2530,42 +2542,40 @@ def __getStats( self, sqlQuery ): count['Total'] = sum( count.values() ) return S_OK( count ) - ################################################################################ +# Getter functions - ''' - ############################################################################## - # Getter functions - ############################################################################## - ''' - -# def _insertElement( self, elementTable, **kwargs ): def _insertElement( self, elementTable, paramsDict ): - + ''' + Method that executes the insert method of the given element. + ''' fname = 'insert%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) -# def _updateElement( self, elementTable, **kwargs ): def _updateElement( self, elementTable, paramsDict ): - + ''' + Method that executes the update method of the given element. + ''' fname = 'update%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) -# def _getElement( self, elementTable, **kwargs ): def _getElement( self, elementTable, paramsDict ): - + ''' + Method that executes the get method of the given element. + ''' fname = 'get%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) -# def _deleteElement( self, elementTable, **kwargs ): def _deleteElement( self, elementTable, paramsDict ): - + ''' + Method that executes the delete method of the given element. + ''' fname = 'delete%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Client/__init__.py b/ResourceStatusSystem/Client/__init__.py index 8bd3e7c4ca8..4a1c119cfc8 100644 --- a/ResourceStatusSystem/Client/__init__.py +++ b/ResourceStatusSystem/Client/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Client package + +''' -""" - DIRAC.ResourceStatusSystem.Client package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF diff --git a/ResourceStatusSystem/Command/AccountingCache_Command.py b/ResourceStatusSystem/Command/AccountingCache_Command.py index 4eac5891c9c..dd4badaf04d 100644 --- a/ResourceStatusSystem/Command/AccountingCache_Command.py +++ b/ResourceStatusSystem/Command/AccountingCache_Command.py @@ -1,21 +1,20 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' AccountingCacheCommand + The AccountingCache_Command class is a command module that collects command classes to store accounting results in the accounting cache. -""" + +''' from datetime import datetime, timedelta from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/ClientsCache_Command.py b/ResourceStatusSystem/Command/ClientsCache_Command.py index 9c88331dfa4..25b801c2f20 100644 --- a/ResourceStatusSystem/Command/ClientsCache_Command.py +++ b/ResourceStatusSystem/Command/ClientsCache_Command.py @@ -1,22 +1,21 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ClientsCache_Command -""" - The ClientsCache_Command class is a command module to know about collective clients results - (to be cached) -""" + The ClientsCache_Command class is a command module to know about collective + clients results (to be cached). + +''' import datetime from DIRAC import gLogger, S_OK, S_ERROR from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName, getDIRACSiteName - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/ClientsInvoker.py b/ResourceStatusSystem/Command/ClientsInvoker.py index 8c37269497e..146b18b82c6 100644 --- a/ResourceStatusSystem/Command/ClientsInvoker.py +++ b/ResourceStatusSystem/Command/ClientsInvoker.py @@ -1,21 +1,29 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' ClientsInvoker + + Commands invoker. + +''' +__RCSID__ = '$Id: $' class ClientsInvoker: - """ + ''' Clients Invoker is the invoker for commands to be executed on clients - """ + ''' + + def __init__( self ): + ''' Constructor + ''' + self.command = None - def setCommand(self, c): - """ Set command to c - """ - self.command = c + def setCommand( self, command ): + ''' Set command to command + ''' + self.command = command def doCommand(self): - """ Call command.doCommand - """ + ''' Call command.doCommand + ''' return self.command.doCommand() ################################################################################ diff --git a/ResourceStatusSystem/Command/Command.py b/ResourceStatusSystem/Command/Command.py index bc4c7b42f64..18ecef265d1 100644 --- a/ResourceStatusSystem/Command/Command.py +++ b/ResourceStatusSystem/Command/Command.py @@ -1,10 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' Command + + Base class for all commands. + +''' from DIRAC import gLogger +__RCSID__ = '$Id: $' + class Command( object ): """ The Command class is a simple base class for all the commands @@ -12,8 +16,8 @@ class Command( object ): """ def __init__( self ): - self.args = None - self.APIs = {} + self.args = None + self.APIs = {} ################################################################################ @@ -48,15 +52,5 @@ def doCommand( self ): if self.args is None: gLogger.error( "Before, set `self.args` with `self.setArgs(a)` function." ) -################################################################################ -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -################################################################################ - -''' - HOW DOES THIS WORK. - - will come soon... -''' - ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/CommandCaller.py b/ResourceStatusSystem/Command/CommandCaller.py index d81d114a5df..13d5241c449 100644 --- a/ResourceStatusSystem/Command/CommandCaller.py +++ b/ResourceStatusSystem/Command/CommandCaller.py @@ -1,12 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' CommandCaller + + Module that loads commands and executes them. + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem.Command.ClientsInvoker import ClientsInvoker +__RCSID__ = '$Id: $' + class CommandCaller: """ Module used for calling policies. Its class is used for invoking @@ -64,14 +68,4 @@ def _innerCall(self, c, a):#, clientIn = None): return res ################################################################################ -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -################################################################################ - -''' - HOW DOES THIS WORK. - - will come soon... -''' - -################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/DIRACAccounting_Command.py b/ResourceStatusSystem/Command/DIRACAccounting_Command.py index 5267e2e8bba..95ac76cb848 100644 --- a/ResourceStatusSystem/Command/DIRACAccounting_Command.py +++ b/ResourceStatusSystem/Command/DIRACAccounting_Command.py @@ -1,21 +1,20 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' DIRACAccounting_Command + The DIRACAccounting_Command class is a command class to interrogate the DIRAC Accounting. -""" + +''' from datetime import datetime, timedelta from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/DoNothing_Command.py b/ResourceStatusSystem/Command/DoNothing_Command.py index beec79ccca3..31fd3853e5a 100644 --- a/ResourceStatusSystem/Command/DoNothing_Command.py +++ b/ResourceStatusSystem/Command/DoNothing_Command.py @@ -1,18 +1,22 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' DoNothing_Command + + Demo Command. + +''' from DIRAC.ResourceStatusSystem.Command.Command import * -class DoNothing_Command(Command): +__RCSID__ = '$Id: $' + +class DoNothing_Command( Command ): - def doCommand(self): - """ - """ - super(DoNothing_Command, self).doCommand() + def doCommand( self ): + ''' Do nothing. + ''' + super( DoNothing_Command, self ).doCommand() - return {'Result':None} + return { 'Result' : None } doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__ diff --git a/ResourceStatusSystem/Command/GGUSTickets_Command.py b/ResourceStatusSystem/Command/GGUSTickets_Command.py index fc3c65b92ee..05e036b9739 100644 --- a/ResourceStatusSystem/Command/GGUSTickets_Command.py +++ b/ResourceStatusSystem/Command/GGUSTickets_Command.py @@ -1,20 +1,19 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' GGUSTickets_Command + The GGUSTickets_Command class is a command class to know about - the number of active present opened tickets -""" + the number of active present opened tickets. + +''' import urllib2 from DIRAC import gLogger, S_OK, S_ERROR -from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName - from DIRAC.ResourceStatusSystem.Command.Command import * +from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs + +__RCSID__ = '$Id: $' def callClient( name, clientIn ): diff --git a/ResourceStatusSystem/Command/GOCDBStatus_Command.py b/ResourceStatusSystem/Command/GOCDBStatus_Command.py index 9eeeb554e0a..e9953fb3742 100644 --- a/ResourceStatusSystem/Command/GOCDBStatus_Command.py +++ b/ResourceStatusSystem/Command/GOCDBStatus_Command.py @@ -1,23 +1,21 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' GOCDBStatus_Command The GOCDBStatus_Command class is a command class to know about present downtimes -""" +''' import urllib2 + from datetime import datetime from DIRAC import gLogger, S_OK, S_ERROR from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import convertTime +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/Jobs_Command.py b/ResourceStatusSystem/Command/Jobs_Command.py index 147c60ce831..7bf0d9878e2 100644 --- a/ResourceStatusSystem/Command/Jobs_Command.py +++ b/ResourceStatusSystem/Command/Jobs_Command.py @@ -1,19 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' Jobs_Command + The Jobs_Command class is a command class to know about present jobs efficiency -""" + +''' from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/MacroCommand.py b/ResourceStatusSystem/Command/MacroCommand.py index 283bb3a7ef1..cbc15b21602 100644 --- a/ResourceStatusSystem/Command/MacroCommand.py +++ b/ResourceStatusSystem/Command/MacroCommand.py @@ -1,26 +1,26 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' MacroCommand + The MacroCommand class is a macro class for all the macro commands for interacting with multiple commands -""" + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Command.Command import Command -class MacroCommand(Command): +__RCSID__ = '$Id: $' + +class MacroCommand( Command ): - def __init__(self): + def __init__( self ): self.commands = None self.args = None self.clients = None ################################################################################ - def setCommands(self, commandsListIn = None): + def setCommands( self, commandsListIn = None ): """ Method to be called as first at every MacroCommand instantiation. @@ -35,7 +35,7 @@ def setCommands(self, commandsListIn = None): ################################################################################ - def setArgs(self, argsListIn = None): + def setArgs( self, argsListIn = None ): """ Set the arguments of the commands. @@ -61,7 +61,7 @@ def setArgs(self, argsListIn = None): ################################################################################ - def setClient(self, clientListIn = None): + def setClient( self, clientListIn = None ): """ Set `self.clients`. If not set, a standard client will be instantiated. Then, set the clients used by the commands. @@ -87,7 +87,7 @@ def setClient(self, clientListIn = None): ################################################################################ - def doCommand(self): + def doCommand( self ): """ Calls command.doCommand for every command in the list of self.commands """ diff --git a/ResourceStatusSystem/Command/Macros_Command.py b/ResourceStatusSystem/Command/Macros_Command.py index 6744c5a7f4d..9e2a1c808b8 100644 --- a/ResourceStatusSystem/Command/Macros_Command.py +++ b/ResourceStatusSystem/Command/Macros_Command.py @@ -1,6 +1,13 @@ +# $HeadURL $ +''' MacrosCommand + +''' + from DIRAC.ResourceStatusSystem.Command.MacroCommand import MacroCommand -class TransferQualityOnSE_Command(MacroCommand): +__RCSID__ = '$Id: $' + +class TransferQualityOnSE_Command( MacroCommand ): def doCommand(self): #da decidere quali comandi @@ -12,20 +19,7 @@ def doCommand(self): # # return super(TransferQualityOnSE_Command, self).doCommand() pass - - - - - - - - - - - - - #from DIRAC.ResourceStatusSystem.Command.Command import Command # #class ProvaMacro_Command(MacroCommand): @@ -45,4 +39,7 @@ def doCommand(self): # #class provaCommand2(Command): # def doCommand(self): -# print "comando 2" \ No newline at end of file +# print "comando 2" + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/Pilots_Command.py b/ResourceStatusSystem/Command/Pilots_Command.py index 03e7d4fe3e9..169b9681e97 100644 --- a/ResourceStatusSystem/Command/Pilots_Command.py +++ b/ResourceStatusSystem/Command/Pilots_Command.py @@ -1,19 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' Pilots_Command + The Pilots_Command class is a command class to know about - present pilots efficiency -""" + present pilots efficiency. + +''' from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import Command from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/RS_Command.py b/ResourceStatusSystem/Command/RS_Command.py index 4dab276d082..dc3ef58c3b4 100644 --- a/ResourceStatusSystem/Command/RS_Command.py +++ b/ResourceStatusSystem/Command/RS_Command.py @@ -1,19 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" -RS_Command -""" +''' RS_Command -__RCSID__ = "$Id: $" +''' from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import Command from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem import ValidRes +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/__init__.py b/ResourceStatusSystem/Command/__init__.py index 4414492c465..9ae08a8da74 100644 --- a/ResourceStatusSystem/Command/__init__.py +++ b/ResourceStatusSystem/Command/__init__.py @@ -1,11 +1,8 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Command package +''' -""" - DIRAC.ResourceStatusSystem.Command package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/knownAPIs.py b/ResourceStatusSystem/Command/knownAPIs.py index 46f92ad1925..c6b09dcd4b8 100644 --- a/ResourceStatusSystem/Command/knownAPIs.py +++ b/ResourceStatusSystem/Command/knownAPIs.py @@ -1,11 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' knownAPIs + + Module used to speed up API instantiation. + +''' from DIRAC import gLogger from DIRAC.Core.DISET.RPCClient import RPCClient +__RCSID__ = '$Id: $' ''' Here are all known and relevant APIs for the ResourceStatusSystem Commands diff --git a/ResourceStatusSystem/DB/ResourceManagementDB.py b/ResourceStatusSystem/DB/ResourceManagementDB.py index 4232a60eea4..ff28fca03e1 100644 --- a/ResourceStatusSystem/DB/ResourceManagementDB.py +++ b/ResourceStatusSystem/DB/ResourceManagementDB.py @@ -1,10 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceManagementDB + + Module that provides basic methods to access the ResourceManagementDB. + +''' from DIRAC.ResourceStatusSystem.Utilities.MySQLMonkey import MySQLMonkey -from DIRAC.ResourceStatusSystem.Utilities.Decorators import CheckDBExecution, ValidateDBTypes +from DIRAC.ResourceStatusSystem.Utilities.Decorators import CheckDBExecution, ValidateDBTypes + +__RCSID__ = '$Id: $' class ResourceManagementDB(object): """ @@ -67,27 +71,27 @@ class ResourceManagementDB(object): def __init__( self, *args, **kwargs ): """Constructor.""" if len(args) == 1: - if isinstance(args[0], str): - maxQueueSize=10 - if isinstance(args[0], int): - maxQueueSize=args[0] + if isinstance( args[ 0 ], str ): + maxQueueSize = 10 + if isinstance( args[ 0 ], int ): + maxQueueSize = args[ 0 ] elif len(args) == 2: - maxQueueSize=args[1] + maxQueueSize = args[ 1 ] elif len(args) == 0: - maxQueueSize=10 + maxQueueSize = 10 if 'DBin' in kwargs.keys(): - DBin = kwargs[ 'DBin' ] + dbIn = kwargs[ 'DBin' ] if isinstance(DBin, list): from DIRAC.Core.Utilities.MySQL import MySQL - self.db = MySQL( 'localhost', DBin[0], DBin[1], 'ResourceManagementDB' ) + self.db = MySQL( 'localhost', dbIn[0], dbIn[1], 'ResourceManagementDB' ) else: - self.db = DBin + self.db = dbIn else: from DIRAC.Core.Base.DB import DB self.db = DB( 'ResourceManagementDB', 'ResourceStatus/ResourceManagementDB', maxQueueSize ) - self.mm = MySQLMonkey( self ) + self.mm = MySQLMonkey( self ) @CheckDBExecution @ValidateDBTypes @@ -219,9 +223,6 @@ def inspectSchema( self ): ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF -''' -This will go to the booster - ################################################################################ ## Web functions ################################################################################ @@ -286,5 +287,4 @@ def inspectSchema( self ): # # return finalDict # -################################################################################ -''' +################################################################################ \ No newline at end of file diff --git a/ResourceStatusSystem/DB/ResourceStatusDB.py b/ResourceStatusSystem/DB/ResourceStatusDB.py index b6fa0a2ebef..b07d561746b 100644 --- a/ResourceStatusSystem/DB/ResourceStatusDB.py +++ b/ResourceStatusSystem/DB/ResourceStatusDB.py @@ -1,11 +1,15 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatusDB + + Module that provides basic methods to access the ResourceStatusDB. + +''' from DIRAC.ResourceStatusSystem.Utilities.MySQLMonkey import MySQLMonkey from DIRAC.ResourceStatusSystem.Utilities.Decorators import CheckDBExecution, ValidateDBTypes +__RCSID__ = '$Id: $' + class ResourceStatusDB( object ): """ The ResourceStatusDB class is a front-end to the ResourceStatusDB MySQL db. @@ -78,17 +82,17 @@ def __init__( self, *args, **kwargs ): maxQueueSize = 10 if 'DBin' in kwargs.keys(): - DBin = kwargs[ 'DBin' ] + dbIn = kwargs[ 'DBin' ] if isinstance( DBin, list ): from DIRAC.Core.Utilities.MySQL import MySQL - self.db = MySQL( 'localhost', DBin[ 0 ], DBin[ 1 ], 'ResourceStatusDB' ) + self.db = MySQL( 'localhost', dbIn[ 0 ], dbIn[ 1 ], 'ResourceStatusDB' ) else: - self.db = DBin + self.db = dbIn else: from DIRAC.Core.Base.DB import DB self.db = DB( 'ResourceStatusDB', 'ResourceStatus/ResourceStatusDB', maxQueueSize ) - self.mm = MySQLMonkey( self ) + self.mm = MySQLMonkey( self ) @CheckDBExecution @ValidateDBTypes @@ -360,4 +364,4 @@ def inspectSchema( self ): ## SEName = [ x[0] for x in SEName ] ## self.updateStorageElementStatus( storageElementName = SEName, lastCheckTime = znever ) ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/DB/__init__.py b/ResourceStatusSystem/DB/__init__.py index 24b8f9ca31b..cb1b07f996e 100644 --- a/ResourceStatusSystem/DB/__init__.py +++ b/ResourceStatusSystem/DB/__init__.py @@ -1,11 +1,8 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.DB package +''' -""" - DIRAC.ResourceStatusSystem.DB package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py b/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py index 7a74459932d..4a41fd41c88 100644 --- a/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py +++ b/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py @@ -1,14 +1,14 @@ -######################################################################## -# $HeadURL: -######################################################################## - -""" The AlwaysFalse_Policy class is a policy class that... checks nothing! -""" - -__RCSID__ = "$Id: " +# $HeadURL $ +''' AlwaysFalse_Policy + + The AlwaysFalse_Policy class is a policy class that... checks nothing! + +''' from DIRAC.ResourceStatusSystem.PolicySystem.PolicyBase import PolicyBase +__RCSID__ = '$Id: $' + class AlwaysFalse_Policy( PolicyBase ): def evaluate( self, commandIn = None, knownInfo = None ): @@ -25,3 +25,6 @@ def evaluate( self, commandIn = None, knownInfo = None ): return { 'Status' : 'Active', 'Reason' : 'This is the AlwasyFalse policy' } evaluate.__doc__ = PolicyBase.evaluate.__doc__ + evaluate.__doc__ + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/Configurations.py b/ResourceStatusSystem/Policy/Configurations.py index 5d8eef9b288..252be941295 100644 --- a/ResourceStatusSystem/Policy/Configurations.py +++ b/ResourceStatusSystem/Policy/Configurations.py @@ -1,15 +1,18 @@ -""" DIRAC.ResourceStatusSystem.Policy.Configurations Module +# $HeadURL $ +''' Configurations - collects everything needed to configure policies -""" - -__RCSID__ = "$Id: " + Collects everything needed to configure policies. + +''' from DIRAC.ResourceStatusSystem.Utilities import CS -pp = CS.getTypedDictRootedAt("PolicyParameters") +__RCSID__ = '$Id: $' + +pp = CS.getTypedDictRootedAt( 'PolicyParameters' ) Policies = { + 'DT_OnGoing_Only' : { 'Description' : "Ongoing down-times", @@ -37,4 +40,8 @@ 'commandIn' : None, 'args' : None } + } + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/DT_Policy.py b/ResourceStatusSystem/Policy/DT_Policy.py index e63206626ba..984d228427c 100644 --- a/ResourceStatusSystem/Policy/DT_Policy.py +++ b/ResourceStatusSystem/Policy/DT_Policy.py @@ -1,18 +1,18 @@ -######################################################################## # $HeadURL: -######################################################################## +''' DT_Policy -""" The DT_Policy class is a policy class satisfied when a site is in downtime, - or when a downtime is revoked -""" - -__RCSID__ = "$Id: " + The DT_Policy class is a policy class satisfied when a site is in downtime, + or when a downtime is revoked. + +''' from DIRAC.ResourceStatusSystem.PolicySystem.PolicyBase import PolicyBase -class DT_Policy(PolicyBase): +__RCSID__ = '$Id: $' + +class DT_Policy( PolicyBase ): - def evaluate(self): + def evaluate( self ): """ Evaluate policy on possible ongoing or scheduled downtimes. @@ -55,3 +55,6 @@ def evaluate(self): return result evaluate.__doc__ = PolicyBase.evaluate.__doc__ + evaluate.__doc__ + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/__init__.py b/ResourceStatusSystem/Policy/__init__.py index e69de29bb2d..cbc8d7371e9 100644 --- a/ResourceStatusSystem/Policy/__init__.py +++ b/ResourceStatusSystem/Policy/__init__.py @@ -0,0 +1,8 @@ +# $HeadURL $ +''' DIRAC.ResourceStatusSystem.Policy package +''' + +__RCSID__ = '$Id: $' + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py b/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py index 58dc4752f8b..b456a80c509 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py +++ b/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py @@ -1,13 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" -Base class for Actions -""" +''' ActionBase + + Base class for Actions. + +''' -__RCSID__ = "$Id$" +__RCSID__ = '$Id: $' -class ActionBase(object): +class ActionBase( object ): + def __init__(self, granularity, name, status_type, pdp_decision, **kw): """Base class for actions. Arguments are: - granularity : string @@ -29,4 +30,4 @@ def run(self): pass ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py b/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py index 938a4dca589..4e1a3bce955 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - AlarmPolType Actions -""" - -__RCSID__ = "$Id$" +''' AlarmAction + + AlarmPolType Actions. + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Utilities import CS @@ -15,7 +13,10 @@ from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient -class AlarmAction(ActionBase): +__RCSID__ = '$Id: $' + +class AlarmAction( ActionBase ): + def __init__(self, granularity, name, status_type, pdp_decision, **kw): ActionBase.__init__( self, granularity, name, status_type, pdp_decision, **kw ) diff --git a/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py b/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py index c33961204b9..b7823e1a803 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py @@ -1,15 +1,17 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - ResourcePolType Actions -""" -__RCSID__ = "$Id$" +''' EmptyAction -from DIRAC import gLogger + Action that does nothing. + +''' + +from DIRAC import gLogger from DIRAC.ResourceStatusSystem.PolicySystem.Actions.ActionBase import ActionBase -class EmptyAction(ActionBase): +__RCSID__ = '$Id: $' + +class EmptyAction( ActionBase ): + def run(self): """Do nothing, but log it :)""" gLogger.info( 'EmptyAction at %s with %s' % (self.name, str(self.pdp_decision))) diff --git a/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py b/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py index 72bf82434e5..44160194b67 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py @@ -1,9 +1,10 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - RealBan_PolType Actions -""" +''' RealBanAction + + RealBan_PolType Actions. + +''' + import time from DIRAC.ResourceStatusSystem.Utilities import CS @@ -11,6 +12,8 @@ from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI +__RCSID__ = '$Id: $' + da = DiracAdmin() csAPI = CSAPI() diff --git a/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py b/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py index 26221614bc0..131282dc0fa 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py @@ -1,17 +1,20 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - ResourcePolType Actions -""" +''' ResourceAction + + ResourcePolType Actions. + +''' -__RCSID__ = "$Id$" +from datetime import datetime from DIRAC.ResourceStatusSystem.PolicySystem.Actions.ActionBase import ActionBase -from datetime import datetime -class ResourceAction(ActionBase): - def run(self): +__RCSID__ = '$Id: $' + +class ResourceAction( ActionBase ): + + def run( self ): + token = 'RS_SVC' if self.new_status['Action']: @@ -45,4 +48,4 @@ def run(self): self.status_type, self.new_status['EndDate'] ) ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Actions/__init__.py b/ResourceStatusSystem/PolicySystem/Actions/__init__.py index ebd5ade4fc5..0acf784052e 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/__init__.py +++ b/ResourceStatusSystem/PolicySystem/Actions/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.PolicySystem.Actions package + +''' -""" - Actions for PEP -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/PDP.py b/ResourceStatusSystem/PolicySystem/PDP.py index b926b276cb0..cdf812c6396 100644 --- a/ResourceStatusSystem/PolicySystem/PDP.py +++ b/ResourceStatusSystem/PolicySystem/PDP.py @@ -1,14 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' PDP + + PolicyDecissionPoint + +''' import datetime -from DIRAC.ResourceStatusSystem.PolicySystem import Status -from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter -from DIRAC.ResourceStatusSystem.PolicySystem.PolicyCaller import PolicyCaller -from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller +from DIRAC.ResourceStatusSystem.PolicySystem import Status +from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter +from DIRAC.ResourceStatusSystem.PolicySystem.PolicyCaller import PolicyCaller +from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller + +__RCSID__ = '$Id: $' class PDP: """ @@ -18,10 +22,26 @@ class PDP: """ def __init__( self, **clients ): - - cc = CommandCaller() - self.clients = clients - self.pc = PolicyCaller( cc, **clients ) + ''' + Constructor. Defines members that will be used later on. + ''' + + cc = CommandCaller() + self.clients = clients + self.pCaller = PolicyCaller( cc, **clients ) + self.iGetter = InfoGetter() + + self.__granularity = None + self.__name = None + self.__statusType = None + self.__status = None + self.__formerStatus = None + self.__reason = None + self.__siteType = None + self.__serviceType = None + self.__resourceType = None + self.__useNewRes = None + def setup( self, granularity = None, name = None, statusType = None, status = None, formerStatus = None, reason = None, siteType = None, @@ -51,14 +71,11 @@ def setup( self, granularity = None, name = None, statusType = None, self.__resourceType = resourceType self.__useNewRes = useNewRes - self.args = None - self.policy = None - self.knownInfo = None - self.ig = None + ################################################################################ - def takeDecision(self, policyIn=None, argsIn=None, knownInfo=None): + def takeDecision( self, policyIn = None, argsIn = None, knownInfo = None ): """ PDP MAIN FUNCTION decides policies that have to be applied, based on @@ -87,96 +104,97 @@ def takeDecision(self, policyIn=None, argsIn=None, knownInfo=None): 'EndDate: datetime.datetime (in a string)} """ - self.args = argsIn - self.policy = policyIn - self.knownInfo = knownInfo + polToEval = self.iGetter.getInfoToApply( ( 'policy', 'policyType' ), + granularity = self.__granularity, + statusType = self.__statusType, + status = self.__status, + formerStatus = self.__formerStatus, + siteType = self.__siteType, + serviceType = self.__serviceType, + resourceType = self.__resourceType, + useNewRes = self.__useNewRes ) - self.ig = InfoGetter() + policyType = polToEval[ 'PolicyType' ] # type: generator - EVAL = self.ig.getInfoToApply(('policy', 'policyType'), - granularity = self.__granularity, - statusType = self.__statusType, - status = self.__status, - formerStatus = self.__formerStatus, - siteType = self.__siteType, - serviceType = self.__serviceType, - resourceType = self.__resourceType, - useNewRes = self.__useNewRes) - - policyType = EVAL['PolicyType'] # type: generator - - if self.policy: + if policyIn: # Only the policy provided will be evaluated # FIXME: Check that the policies are valid. - singlePolicyResults = self.policy.evaluate() + singlePolicyResults = policyIn.evaluate() else: - singlePolicyResults = self._invocation(self.__granularity, - self.__name, self.__status, self.policy, - self.args, EVAL['Policies']) + singlePolicyResults = self._invocation( self.__granularity, + self.__name, self.__status, policyIn, + argsIn, polToEval['Policies'] ) - policyCombinedResults = self._policyCombination(singlePolicyResults) + policyCombinedResults = self._policyCombination( singlePolicyResults ) if policyCombinedResults == {}: - policyCombinedResults["Action"] = False - policyCombinedResults["Reason"] = 'No policy results' - policyCombinedResults["PolicyType"] = policyType + policyCombinedResults[ 'Action' ] = False + policyCombinedResults[ 'Reason' ] = 'No policy results' + policyCombinedResults[ 'PolicyType' ] = policyType - if policyCombinedResults.has_key("Status"): - newstatus = policyCombinedResults['Status'] + if policyCombinedResults.has_key( 'Status' ): + newstatus = policyCombinedResults[ 'Status' ] if newstatus != self.__status: # Policies satisfy - newPolicyType = self.ig.getNewPolicyType(self.__granularity, newstatus) - policyType = set(policyType) & set(newPolicyType) - policyCombinedResults["Action"] = True + newPolicyType = self.iGetter.getNewPolicyType( self.__granularity, newstatus ) + policyType = set( policyType ) & set( newPolicyType ) + + policyCombinedResults[ 'Action' ] = True else: # Policies does not satisfy - policyCombinedResults["Action"] = False + policyCombinedResults[ 'Action' ] = False - policyCombinedResults["PolicyType"] = policyType + policyCombinedResults[ 'PolicyType' ] = policyType return { 'SinglePolicyResults' : singlePolicyResults, 'PolicyCombinedResult' : policyCombinedResults } ################################################################################ - def _invocation(self, granularity, name, status, policy, args, policies): - """ One by one, use the PolicyCaller to invoke the policies, and putting - their results in `policyResults`. When the status is `Unknown`, invokes - `self.__useOldPolicyRes`. Always returns a list, possibly empty. - """ + def _invocation( self, granularity, name, status, policy, args, policies ): + ''' + One by one, use the PolicyCaller to invoke the policies, and putting + their results in `policyResults`. When the status is `Unknown`, invokes + `self.__useOldPolicyRes`. Always returns a list, possibly empty. + ''' policyResults = [] - for p in policies: - pName = p['Name'] - pModule = p['Module'] - extraArgs = p['args'] - commandIn = p['commandIn'] - res = self.pc.policyInvocation(granularity = granularity, name = name, - status = status, policy = policy, args = args, pName = pName, - pModule = pModule, extraArgs = extraArgs, commandIn = commandIn ) + for pol in policies: + + pName = pol[ 'Name' ] + pModule = pol[ 'Module' ] + extraArgs = pol[ 'args' ] + commandIn = pol[ 'commandIn' ] + + res = self.pCaller.policyInvocation( granularity = granularity, name = name, + status = status, policy = policy, + args = args, pName = pName, + pModule = pModule, extraArgs = extraArgs, + commandIn = commandIn ) # If res is empty, return immediately - if not res: return policyResults + if not res: + return policyResults - if not res.has_key('Status'): - print("\n\n Policy result " + str(res) + " does not return 'Status'\n\n") + if not res.has_key( 'Status' ): + print('\n\n Policy result ' + str(res) + ' does not return "Status"\n\n') raise TypeError # Else - if res['Status'] == 'Unknown': - res = self.__useOldPolicyRes(name = name, policyName = pName) + if res[ 'Status' ] == 'Unknown': + res = self.__useOldPolicyRes( name = name, policyName = pName ) - if res['Status'] not in ( 'Error', 'Unknown' ): - policyResults.append(res) + if res[ 'Status' ] not in ( 'Error', 'Unknown' ): + policyResults.append( res ) return policyResults ################################################################################ - def _policyCombination(self, pol_results): - """ + def _policyCombination( self, pol_results ): + ''' INPUT: list type OUTPUT: dict type * Compute a new status, and store it in variable newStatus, of type integer. @@ -184,79 +202,90 @@ def _policyCombination(self, pol_results): * Concatenate the Reason fields * Take the first EndDate field that exists (FIXME: Do something more clever) * Finally, return the result - """ - if pol_results == []: return {} + ''' + if pol_results == []: + return {} - pol_results.sort(key=Status.value_of_policy) + pol_results.sort( key=Status.value_of_policy ) newStatus = -1 # First, set an always invalid status try: # We are in a special status, maybe forbidden transitions - _prio, access_list, gofun = Status.statesInfo[self.__status] + _prio, access_list, gofun = Status.statesInfo[ self.__status ] if access_list != set(): # Restrictions on transitions, checking if one is suitable: - for p in pol_results: - if Status.value_of_policy(p) in access_list: - newStatus = Status.value_of_policy(p) + for polRes in pol_results: + if Status.value_of_policy( polRes ) in access_list: + newStatus = Status.value_of_policy( polRes ) break # No status from policies suitable, applying stategy and # returning result. if newStatus == -1: - newStatus = gofun(access_list) - return { 'Status': Status.status_of_value(newStatus), + newStatus = gofun( access_list ) + return { 'Status': Status.status_of_value( newStatus ), 'Reason': 'Status forced by PDP' } else: # Special Status, but no restriction on transitions - newStatus = Status.value_of_policy(pol_results[0]) + newStatus = Status.value_of_policy( pol_results[ 0 ] ) except KeyError: # We are in a "normal" status: All transitions are possible. - newStatus = Status.value_of_policy(pol_results[0]) + newStatus = Status.value_of_policy( pol_results[ 0 ] ) # At this point, a new status has been chosen. newStatus is an # integer. - worstResults = [p for p in pol_results - if Status.value_of_policy(p) == newStatus] + worstResults = [ p for p in pol_results + if Status.value_of_policy( p ) == newStatus ] # Concatenate reasons - def getReason(p): + def getReason( pol ): try: - res = p['Reason'] + res = pol[ 'Reason' ] except KeyError: res = '' return res - worstResultsReasons = [getReason(p) for p in worstResults] + worstResultsReasons = [ getReason( p ) for p in worstResults ] - def catRes(x, y): - if x and y : return x + ' |###| ' + y - elif x or y: - if x: return x - else: return y - else : return '' + def catRes( xVal, yVal ): + ''' + Concatenate xVal and yVal. + ''' + if xVal and yVal : + return xVal + ' |###| ' + yVal + elif xVal or yVal: + if xVal: + return xVal + else: + return yVal + else: + return '' - concatenatedRes = reduce(catRes, worstResultsReasons, '') + concatenatedRes = reduce( catRes, worstResultsReasons, '' ) # Handle EndDate - endDatePolicies = [p for p in worstResults if p.has_key('EndDate')] + endDatePolicies = [ p for p in worstResults if p.has_key( 'EndDate' ) ] # Building and returning result res = {} - res['Status'] = Status.status_of_value(newStatus) - if concatenatedRes != '': res['Reason'] = concatenatedRes - if endDatePolicies != []: res['EndDate'] = endDatePolicies[0]['EndDate'] + res[ 'Status' ] = Status.status_of_value( newStatus ) + if concatenatedRes != '': + res[ 'Reason' ] = concatenatedRes + if endDatePolicies != []: + res[ 'EndDate' ] = endDatePolicies[ 0 ][ 'EndDate' ] return res ################################################################################ - def __useOldPolicyRes(self, name, policyName): - """ Use the RSS Service to get an old policy result. - If such result is older than 2 hours, it returns {'Status':'Unknown'} - """ - res = self.clients['ResourceManagementClient'].getPolicyResult( name = name, policyName = policyName ) + def __useOldPolicyRes( self, name, policyName ): + ''' + Use the RSS Service to get an old policy result. + If such result is older than 2 hours, it returns {'Status':'Unknown'} + ''' + res = self.clients[ 'ResourceManagementClient' ].getPolicyResult( name = name, policyName = policyName ) if not res[ 'OK' ]: return { 'Status' : 'Unknown' } @@ -264,22 +293,22 @@ def __useOldPolicyRes(self, name, policyName): res = res[ 'Value' ] if res == []: - return {'Status':'Unknown'} + return { 'Status' : 'Unknown' } res = res[ 0 ] - oldStatus = res[5] - oldReason = res[6] - lastCheckTime = res[8] + oldStatus = res[ 5 ] + oldReason = res[ 6 ] + lastCheckTime = res[ 8 ] if ( lastCheckTime + datetime.timedelta(hours = 2) ) < datetime.datetime.utcnow(): return { 'Status' : 'Unknown' } result = {} - result[ 'Status' ] = oldStatus - result[ 'Reason' ] = oldReason - result[ 'OLD' ] = True + result[ 'Status' ] = oldStatus + result[ 'Reason' ] = oldReason + result[ 'OLD' ] = True result[ 'PolicyName' ] = policyName return result diff --git a/ResourceStatusSystem/PolicySystem/PEP.py b/ResourceStatusSystem/PolicySystem/PEP.py index dccd3049f10..98186a99acf 100644 --- a/ResourceStatusSystem/PolicySystem/PEP.py +++ b/ResourceStatusSystem/PolicySystem/PEP.py @@ -1,27 +1,27 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" +''' PEP + Module used for enforcing policies. Its class is used for: 1. invoke a PDP and collects results 2. enforcing results by: a. saving result on a DB b. raising alarms c. other.... -""" -from DIRAC import S_OK, S_ERROR +''' -from DIRAC.ResourceStatusSystem import ValidRes, ValidStatus, ValidStatusTypes, \ - ValidSiteType, ValidServiceType, ValidResourceType +from DIRAC import S_ERROR +from DIRAC.ResourceStatusSystem import ValidRes, \ + ValidStatus, ValidStatusTypes, ValidSiteType, ValidServiceType, ValidResourceType +from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient +from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient +from DIRAC.ResourceStatusSystem.PolicySystem.Actions.EmptyAction import EmptyAction +from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP +from DIRAC.ResourceStatusSystem.Utilities import Utils -from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient -from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient -from DIRAC.ResourceStatusSystem.PolicySystem.Actions.EmptyAction import EmptyAction -from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP -from DIRAC.ResourceStatusSystem.Utilities import Utils +__RCSID__ = '$Id: $' class PEP: - """ + ''' PEP (Policy Enforcement Point) initialization :params: @@ -40,10 +40,10 @@ class PEP: 'Granularity': a ValidRes (optional) } ] - """ + ''' - def __init__( self, pdp = None, clients = {} ): - """ + def __init__( self, pdp = None, clients = None ): + ''' Enforce policies, using a PDP (Policy Decision Point), based on self.__granularity (optional) @@ -61,23 +61,32 @@ def __init__( self, pdp = None, clients = {} ): :params: :attr:`pdp` : a custom PDP object (optional) :attr:`clients` : a dictionary containing modules corresponding to clients. - """ - try: self.rsClient = clients[ 'ResourceStatusClient' ] - except KeyError: self.rsClient = ResourceStatusClient() - try: self.rmClient = clients[ 'ResourceManagementClient' ] - except KeyError: self.rmClient = ResourceManagementClient() + ''' + + if clients is None: + clients = {} + + try: + self.rsClient = clients[ 'ResourceStatusClient' ] + except KeyError: + self.rsClient = ResourceStatusClient() + try: + self.rmClient = clients[ 'ResourceManagementClient' ] + except KeyError: + self.rmClient = ResourceManagementClient() self.clients = clients if not pdp: self.pdp = PDP( **clients ) -################################################################################ - def enforce( self, granularity = None, name = None, statusType = None, status = None, formerStatus = None, reason = None, siteType = None, serviceType = None, resourceType = None, tokenOwner = None, useNewRes = False, knownInfo = None ): - + ''' + Enforce policies for given set of keyworkds. To be better explained. + ''' + ## real ban flag ######################################################### realBan = False @@ -132,14 +141,14 @@ def enforce( self, granularity = None, name = None, statusType = None, policyType = res[ 'PolicyType' ] if 'Resource_PolType' in policyType: - m = Utils.voimport(actionBaseMod + ".ResourceAction") - m.ResourceAction(granularity, name, statusType, resDecisions, + action = Utils.voimport( '%s.ResourceAction' % actionBaseMod ) + action.ResourceAction(granularity, name, statusType, resDecisions, rsClient=self.rsClient, rmClient=self.rmClient).run() if 'Alarm_PolType' in policyType: - m = Utils.voimport(actionBaseMod + ".AlarmAction") - m.AlarmAction(granularity, name, statusType, resDecisions, + action = Utils.voimport( '%s.AlarmAction' % actionBaseMod ) + action.AlarmAction(granularity, name, statusType, resDecisions, Clients=self.clients, Params={"Granularity" : granularity, "SiteType" : siteType, @@ -147,8 +156,8 @@ def enforce( self, granularity = None, name = None, statusType = None, "ResourceType" : resourceType}).run() if 'RealBan_PolType' in policyType and realBan: - m = Utils.voimport(actionBaseMod + ".RealBanAction") - m.RealBanAction(granularity, name, resDecisions).run() + action = Utils.voimport( '%s.RealBanAction' % actionBaseMod ) + action.RealBanAction(granularity, name, resDecisions).run() return resDecisions diff --git a/ResourceStatusSystem/PolicySystem/PolicyBase.py b/ResourceStatusSystem/PolicySystem/PolicyBase.py index e55947d25e6..add2f15b3e5 100644 --- a/ResourceStatusSystem/PolicySystem/PolicyBase.py +++ b/ResourceStatusSystem/PolicySystem/PolicyBase.py @@ -1,26 +1,28 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" - -""" - The Policy class is a simple base class for all the policies -""" +''' PolicyBase + + The Policy class is a simple base class for all the policies. + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem import ValidRes - from DIRAC.ResourceStatusSystem.Command.ClientsInvoker import ClientsInvoker from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller -class PolicyBase(object): - """ +__RCSID__ = '$Id: $' + +class PolicyBase( object ): + ''' Base class for all the policies. Do not instantiate directly. To use, you should call at least `setArgs` and, alternatively, `setCommand` or `setCommandName` on the real policy instance. - """ + ''' - def __init__(self): + def __init__( self ): + ''' + Constructor + ''' self.args = None self.command = None self.commandName = None @@ -28,10 +30,8 @@ def __init__(self): self.infoName = None self.result = {} -################################################################################ - - def setArgs(self, argsIn): - """ + def setArgs( self, argsIn ): + ''' Set `self.args`. :params: @@ -40,69 +40,59 @@ def setArgs(self, argsIn): - `args[0]` should be a ValidRes - `args[1]` should be the name of the ValidRes - """ + ''' self.args = argsIn if self.args[0] not in ValidRes: gLogger.error( 'PolicyBase.setArgs got wrong ValidRes' ) -################################################################################ - - def setCommand(self, commandIn = None): - """ + def setCommand( self, commandIn = None ): + ''' Set `self.command`. :params: :attr:`commandIn`: a command object - """ + ''' self.command = commandIn -################################################################################ - - def setCommandName(self, commandNameIn = None): - """ + def setCommandName( self, commandNameIn = None ): + ''' Set `self.commandName`, necessary when a command object is not provided with setCommand. :params: :attr:`commandNameIn`: a tuple containing the command module and class (as strings) - """ + ''' self.commandName = commandNameIn -################################################################################ - - def setKnownInfo(self, knownInfoIn = None): - """ + def setKnownInfo( self, knownInfoIn = None ): + ''' Set `self.knownInfo`. No command will be then invoked. :params: :attr:`knownInfoIn`: a dictionary - """ + ''' self.knownInfo = knownInfoIn -################################################################################ - - def setInfoName(self, infoNameIn = None): - """ + def setInfoName( self, infoNameIn = None ): + ''' Set `self.infoName`. :params: :attr:`infoNameIn`: a string - """ + ''' self.infoName = infoNameIn -################################################################################ - # method to be extended by sub(real) policies - def evaluate(self): - """ + def evaluate( self ): + ''' Before use, call at least `setArgs` and, alternatively, `setCommand` or `setCommandName`. Invoking `super(PolicyCLASS, self).evaluate` will invoke the command (if necessary) as it is provided and returns the results. - """ + ''' if self.knownInfo: result = self.knownInfo @@ -121,12 +111,12 @@ def evaluate(self): if not self.infoName: - result = result['Result'] + result = result[ 'Result' ] else: if self.infoName in result.keys(): - result = result[self.infoName] + result = result[ self.infoName ] else: - gLogger.error( "missing 'infoName' in result" ) + gLogger.error( 'missing "infoName" in result' ) return None return result diff --git a/ResourceStatusSystem/PolicySystem/PolicyCaller.py b/ResourceStatusSystem/PolicySystem/PolicyCaller.py index 66b52cdda38..16b94d8823c 100644 --- a/ResourceStatusSystem/PolicySystem/PolicyCaller.py +++ b/ResourceStatusSystem/PolicySystem/PolicyCaller.py @@ -1,17 +1,31 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" +''' PolicyCaller + Module used for calling policies. Its class is used for invoking - real policies, based on the policy name -""" -from DIRAC import gLogger + real policies, based on the policy name. + +''' + +from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller +__RCSID__ = '$Id: $' + class PolicyCaller: + ''' + PolicyCaller loads policies, sets commands and runs them. + ''' + def __init__( self, commandCallerIn = None, **clients ): - self.cc = commandCallerIn if commandCallerIn != None else CommandCaller() + ''' + Constructor + ''' + + if commandCallerIn is None: + commandCallerIn = CommandCaller() + + self.cCaller = commandCallerIn self.clients = clients ################################################################################ @@ -19,7 +33,7 @@ def __init__( self, commandCallerIn = None, **clients ): def policyInvocation( self, granularity = None, name = None, status = None, policy = None, args = None, pName = None, pModule = None, extraArgs = None, commandIn = None ): - """ + ''' Invokes a policy: 1. If :attr:`policy` is None, import the policy module specified @@ -33,46 +47,54 @@ def policyInvocation( self, granularity = None, name = None, 3. If commandIn is specified (normally it is), use :meth:`DIRAC.ResourceStatusSystem.Command.CommandCaller.CommandCaller.setCommandObject` to get a command object - """ + ''' - p = policy - a = args + if not policy: - if not p: try: - policyModule = Utils.voimport("DIRAC.ResourceStatusSystem.Policy." + pModule) + + policyModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Policy.%s' % pModule ) + except ImportError: - gLogger.warn("Unable to import a policy module named %s, falling back on AlwaysFalse_Policy." % pModule) - policyModule = __import__("DIRAC.ResourceStatusSystem.Policy.AlwaysFalse_Policy", - globals(), locals(), ['*']) - pModule = "AlwaysFalse_Policy" + _msg = 'Unable to import a policy module named %s, falling back on AlwaysFalse_Policy.' % pModule + gLogger.warn( _msg ) + policyModule = __import__( 'DIRAC.ResourceStatusSystem.Policy.AlwaysFalse_Policy', + globals(), locals(), ['*'] ) + pModule = 'AlwaysFalse_Policy' + try: - p = getattr(policyModule, pModule)() + + policy = getattr( policyModule, pModule )() + except AttributeError as exc: print policyModule, pModule raise exc - if not a: - a = (granularity, name) + if not args: + args = ( granularity, name ) if extraArgs: - a = a + tuple(extraArgs) + args = args + tuple( extraArgs ) if commandIn: - commandIn = self.cc.setCommandObject( commandIn ) + commandIn = self.cCaller.setCommandObject( commandIn ) for clientName, clientInstance in self.clients.items(): - self.cc.setAPI( commandIn, clientName, clientInstance ) + + self.cCaller.setAPI( commandIn, clientName, clientInstance ) - res = self._innerEval(p, a, commandIn = commandIn) + res = self._innerEval( policy, args, commandIn = commandIn ) # Just adding the PolicyName to the result of the evaluation of the policy - res['PolicyName'] = pName + res[ 'PolicyName' ] = pName return res - def _innerEval(self, policy, arguments, commandIn = None): - """Policy evaluation""" - policy.setArgs(arguments) - policy.setCommand(commandIn) + def _innerEval( self, policy, arguments, commandIn = None ): + ''' + Policy evaluation + ''' + + policy.setArgs( arguments ) + policy.setCommand( commandIn ) return policy.evaluate() ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Status.py b/ResourceStatusSystem/PolicySystem/Status.py index 258b063a82d..467c3f77c9e 100644 --- a/ResourceStatusSystem/PolicySystem/Status.py +++ b/ResourceStatusSystem/PolicySystem/Status.py @@ -1,12 +1,15 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' Status + + Module that keeps the StateMachine. -from DIRAC import gLogger +''' -from DIRAC.ResourceStatusSystem.Utilities.Utils import id_fun -from DIRAC.ResourceStatusSystem import ValidStatus +from DIRAC import gLogger +from DIRAC.ResourceStatusSystem.Utilities.Utils import id_fun +from DIRAC.ResourceStatusSystem import ValidStatus + +__RCSID__ = '$Id: $' statesInfo = { 'Banned' : (0, set([0,1]), max), @@ -15,33 +18,36 @@ 'Active' : (3, set(), id_fun) } -################################################################################ - -def value_of_status(s): - try: - return int(s) +def value_of_status( status ): + ''' + Given an status, returns its index + ''' + try: + return int( status ) except ValueError: try: - return statesInfo[s][0] + return statesInfo[ status ][ 0 ] except KeyError: #Temporary fix, not anymore InvalidStatus exception raising - gLogger.error( 'value_of_status returning -1') + gLogger.error( 'value_of_status returning -1' ) return -1 -################################################################################ - -def value_of_policy(p): - return value_of_status(p['Status']) - -################################################################################ +def value_of_policy( policy ): + ''' + Given a policy, returns its status + ''' + return value_of_status( policy[ 'Status' ] ) -def status_of_value(v): +def status_of_value( value ): + ''' + To be refactored + ''' # Hack: rely on the order of values in ValidStatus try: - return ValidStatus[v] + return ValidStatus[ value ] except IndexError: #Temporary fix, not anymore InvalidStatus exception raising - gLogger.error( 'status_of_value returning -1') + gLogger.error( 'status_of_value returning -1' ) return -1 ################################################################################ diff --git a/ResourceStatusSystem/PolicySystem/__init__.py b/ResourceStatusSystem/PolicySystem/__init__.py index 8f03a29fb48..32a163b41a0 100644 --- a/ResourceStatusSystem/PolicySystem/__init__.py +++ b/ResourceStatusSystem/PolicySystem/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.PolicySystem package + +''' -""" - DIRAC.ResourceStatusSystem.PolicySystem package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Service/ResourceManagementHandler.py b/ResourceStatusSystem/Service/ResourceManagementHandler.py index 12e01f98d41..e7048d96d9d 100644 --- a/ResourceStatusSystem/Service/ResourceManagementHandler.py +++ b/ResourceStatusSystem/Service/ResourceManagementHandler.py @@ -1,16 +1,22 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceManagementHandler + + Module that allows users to access the ResourceManagementDB remotely. + +''' from DIRAC import S_OK, S_ERROR, gLogger from DIRAC.Core.DISET.RequestHandler import RequestHandler from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB -db = False +__RCSID__ = '$Id: $' +db = False def initializeResourceManagementHandler( _serviceInfo ): - + ''' + Handler initialization, where we set the ResourceManagementDB as global db. + ''' + global db db = ResourceManagementDB() diff --git a/ResourceStatusSystem/Service/ResourceStatusHandler.py b/ResourceStatusSystem/Service/ResourceStatusHandler.py index 4d2a7b94cc8..5bde5048a4c 100644 --- a/ResourceStatusSystem/Service/ResourceStatusHandler.py +++ b/ResourceStatusSystem/Service/ResourceStatusHandler.py @@ -1,17 +1,23 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatusHandler + + Module that allows users to access the ResourceStatusDB remotely. + +''' from DIRAC import gConfig, S_OK, S_ERROR, gLogger from DIRAC.Core.DISET.RequestHandler import RequestHandler - from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB from DIRAC.ResourceStatusSystem.Utilities import Utils -db = False -def initializeResourceStatusHandler( _serviceInfo ): +__RCSID__ = '$Id: $' +db = False +def initializeResourceStatusHandler( _serviceInfo ): + ''' + Handler initialization, where we set the ResourceStatusDB as global db, and + we instantiate the synchronizer. + ''' global db db = ResourceStatusDB() @@ -27,9 +33,10 @@ def initializeResourceStatusHandler( _serviceInfo ): # publisher = Publisher( VOExtension, dbIn = db, commandCallerIn = cc, # infoGetterIn = ig, WMSAdminIn = WMSAdmin ) - SyncModule = Utils.voimport("DIRAC.ResourceStatusSystem.Utilities.Synchronizer") - sync_O = SyncModule.Synchronizer() - gConfig.addListenerToNewVersionEvent( sync_O.sync ) + syncModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Utilities.Synchronizer' ) + syncObject = syncModule.Synchronizer() + gConfig.addListenerToNewVersionEvent( syncObject.sync ) + return S_OK() ################################################################################ @@ -206,7 +213,8 @@ def export_delete( self, params, meta ): ## """ get periods of time when name was in status (for a total of hours hours) ## """ ## -## gLogger.info( "ResourceStatusHandler.getPeriods: Attempting to get %s periods when it was in %s" % ( name, status ) ) +## gLogger.info( "ResourceStatusHandler.getPeriods: Attempting to get %s periods \ +## when it was in %s" % ( name, status ) ) ## ## try: ## resQuery = rsDB.getPeriods( granularity, name, status, int( hours ) ) @@ -382,7 +390,8 @@ def export_delete( self, params, meta ): ## """ Enforce all the policies. If `useNewRes` is False, use cached results only (where available). ## """ ## try: -## gLogger.info("ResourceStatusHandler.enforcePolicies: Attempting to enforce policies for %s %s" % (granularity, name)) +## gLogger.info("ResourceStatusHandler.enforcePolicies: Attempting to \ +## enforce policies for %s %s" % (granularity, name)) ## try: ## reason = serviceType = resourceType = None ## @@ -512,7 +521,8 @@ def export_delete( self, params, meta ): ## else: ## rsDB.setToken( granularity, name, 'RS_SVC', datetime( 9999, 12, 31, 23, 59, 59 ) ) ## -## gLogger.info( "ResourceStatusHandler.reAssignToken: re-assigned token %s: %s: %s" % ( granularity, name, requester ) ) +## gLogger.info( "ResourceStatusHandler.reAssignToken: re-assigned token %s: %s: \ +## %s" % ( granularity, name, requester ) ) ## return S_OK() ## except Exception, x: ## errorStr = whoRaised( x ) @@ -546,7 +556,8 @@ def export_delete( self, params, meta ): ## except OverflowError: ## pass ## rsDB.setToken( granularity, name, tokenOwner, tokenNewExpiration ) -## gLogger.info( "ResourceStatusHandler.extendToken: extended token %s: %s for %i hours" % ( granularity, name, hrs ) ) +## gLogger.info( "ResourceStatusHandler.extendToken: extended token %s: \ +## %s for %i hours" % ( granularity, name, hrs ) ) ## return S_OK() ## except Exception, x: ## errorStr = whoRaised( x ) diff --git a/ResourceStatusSystem/Service/__init__.py b/ResourceStatusSystem/Service/__init__.py index aa50271b353..e3c8e92d84d 100644 --- a/ResourceStatusSystem/Service/__init__.py +++ b/ResourceStatusSystem/Service/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Service package + +''' -""" - DIRAC.ResourceStatusSystem.Service package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Utilities/CS.py b/ResourceStatusSystem/Utilities/CS.py index b5c02e18f6e..593e8a6710a 100644 --- a/ResourceStatusSystem/Utilities/CS.py +++ b/ResourceStatusSystem/Utilities/CS.py @@ -1,110 +1,122 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' CS + + This module offers "helpers" to access the CS, and do some processing. + +''' import itertools -from DIRAC import S_OK, S_ERROR, gConfig -from DIRAC.Core.Utilities import List +from DIRAC import S_OK, S_ERROR, gConfig +from DIRAC.Core.Utilities import List +from DIRAC.ResourceStatusSystem.Utilities import Utils -from DIRAC.ResourceStatusSystem.Utilities import Utils +__RCSID__ = '$Id: $' -g_BaseRegistrySection = "/Registry" -g_BaseResourcesSection = "/Resources" -g_BaseOperationsSection = "/Operations" -g_BaseConfigSection = "/Operations/RSSConfiguration" +g_BaseRegistrySection = '/Registry' +g_BaseResourcesSection = '/Resources' +g_BaseOperationsSection = '/Operations' +g_BaseConfigSection = '/Operations/RSSConfiguration' ### CS HELPER FUNCTIONS -class CSError(Exception): +class CSError( Exception ): + ''' To be removed ''' pass -def getValue(v, default): - """Wrapper around gConfig.getValue. Returns typed values""" - res = gConfig.getValue(v, default) - if Utils.isiterable(res): - return [Utils.typedobj_of_string(e) for e in res] +def getValue( val, default ): + '''Wrapper around gConfig.getValue. Returns typed values''' + res = gConfig.getValue( val, default ) + if Utils.isiterable( res ): + return [ Utils.typedobj_of_string(e) for e in res ] else: - return Utils.typedobj_of_string(res) + return Utils.typedobj_of_string( res ) -def getTypedDictRootedAt(relpath = "", root = g_BaseConfigSection): - """Gives the configuration rooted at path in a Python dict. The +def getTypedDictRootedAt( relpath = "", root = g_BaseConfigSection ): + '''Gives the configuration rooted at path in a Python dict. The result is a Python dictionnary that reflects the structure of the - config file.""" - def getTypedDictRootedAt(path): + config file.''' + def getTypedDictRootedAt( path ): retval = {} - opts = gConfig.getOptionsDict(path) - secs = gConfig.getSections(path) + opts = gConfig.getOptionsDict( path ) + secs = gConfig.getSections( path ) - if not opts['OK']: - raise CSError, opts['Message'] - if not secs['OK']: - raise CSError, secs['Message'] + if not opts[ 'OK' ]: + raise CSError, opts[ 'Message' ] + if not secs[ 'OK' ]: + raise CSError, secs[ 'Message' ] - opts = opts['Value'] - secs = secs['Value'] + opts = opts[ 'Value' ] + secs = secs[ 'Value' ] for k in opts: - if opts[k].find(",") > -1: - retval[k] = [Utils.typedobj_of_string(e) for e in List.fromChar(opts[k])] + if opts[ k ].find( "," ) > -1: + retval[ k ] = [ Utils.typedobj_of_string(e) for e in List.fromChar(opts[k]) ] else: - retval[k] = Utils.typedobj_of_string(opts[k]) + retval[ k ] = Utils.typedobj_of_string( opts[ k ] ) for i in secs: - retval[i] = getTypedDictRootedAt(path + "/" + i) + retval[ i ] = getTypedDictRootedAt( path + "/" + i ) return retval - return getTypedDictRootedAt(root + "/" + relpath) + return getTypedDictRootedAt( root + "/" + relpath ) ################################################################################ # Mail functions ####################### def getOperationMails( op ): - return gConfig.getValue("%s/EMail/%s" %(g_BaseOperationsSection, op) ,"") + ''' Get emails from Operations section''' + return gConfig.getValue( "%s/EMail/%s" % (g_BaseOperationsSection, op) ,"" ) # Setup functions #################### def getSetup(): - return gConfig.getValue("DIRAC/Setup", "") + ''' Get setup in which we are running''' + return gConfig.getValue( "DIRAC/Setup", "" ) # VOMS functions #################### def getVOMSEndpoints(): - return Utils.unpack(gConfig.getSections("%s/VOMS/Servers/lhcb/" % g_BaseRegistrySection)) + ''' Get VOMS endpoints ''' + return Utils.unpack( gConfig.getSections( "%s/VOMS/Servers/lhcb/" % g_BaseRegistrySection ) ) # Sites functions ################### -def getSites( grids = ('LCG', 'DIRAC') ): - if isinstance(grids, basestring): - grids = (grids,) +def getSites( grids = ( 'LCG', 'DIRAC' ) ): + ''' Get sites from CS ''' + if isinstance( grids, basestring ): + grids = ( grids, ) sites = [Utils.unpack(gConfig.getSections('%s/Sites/%s' % ( g_BaseResourcesSection, grid ), True)) for grid in grids] return Utils.list_flatten(sites) -def getSiteTiers(sites): - return [getValue("%s/Sites/%s/%s/MoUTierLevel" - % (g_BaseResourcesSection, site.split(".")[0], site), 2) for site in sites] +def getSiteTiers( sites ): + ''' Get tiers from CS ''' + return [ getValue("%s/Sites/%s/%s/MoUTierLevel" + % (g_BaseResourcesSection, site.split(".")[0], site), 2) for site in sites ] -def getSiteTier(site): - return getSiteTiers([site])[0] +def getSiteTier( site ): + ''' Get tier from site ''' + return getSiteTiers( [ site ] )[ 0 ] -def getT1s(grids = 'LCG'): - sites = getSites(grids) - tiers = getSiteTiers(sites) - pairs = itertools.izip(sites, tiers) - return [s for (s, t) in pairs if t == 1] +def getT1s( grids = 'LCG' ): + ''' Get Tier 1s ''' + sites = getSites( grids ) + tiers = getSiteTiers( sites ) + pairs = itertools.izip( sites, tiers ) + return [ s for (s, t) in pairs if t == 1 ] # LFC functions ##################### def getLFCSites(): + ''' Get LFC sites ''' return Utils.unpack(gConfig.getSections('%s/FileCatalogs/LcgFileCatalogCombined' % g_BaseResourcesSection, True)) -def getLFCNode( sites = None, - readable = ('ReadOnly', 'ReadWrite')): +def getLFCNode( sites = None, readable = ( 'ReadOnly', 'ReadWrite' ) ): + ''' Get LFC node ''' if sites is None: sites = getLFCSites() @@ -123,34 +135,42 @@ def getLFCURL(site, mode): # Storage Elements functions ######## def getSEs(): + ''' Get StorageElements ''' return Utils.unpack(gConfig.getSections("/Resources/StorageElements")) -def getSEHost(SE): +def getSEHost( SE ): + ''' Get StorageElement host ''' return gConfig.getValue('%s/StorageElements/%s/AccessProtocol.1/Host' % (g_BaseResourcesSection, SE), "") def getSENodes(): + ''' Get StorageElement nodes ''' nodes = [getSEHost(SE) for SE in getSEs()] return [n for n in nodes if n != ""] -def getSEStatus(SE, accessType): +def getSEStatus( SE, accessType ): + ''' Get StorageElement status ''' return gConfig.getValue("%s/StorageElements/%s/%s" % (g_BaseResourcesSection, SE, accessType), "") def getSEToken(SE): + ''' Get StorageElement token ''' return gConfig.getValue("/Resources/StorageElements/%s/AccessProtocol.1/SpaceToken" % SE, "") # Space Tokens functions ############ def getSpaceTokens(): + ''' Get Space Tokens ''' return ["LHCb_USER", "LHCb-Disk", "LHCb-Tape"] def getSpaceTokenEndpoints(): + ''' Get Space Token Endpoints ''' return getTypedDictRootedAt(root="", relpath="/Resources/Shares/Disk") # CE functions ###################### def getCEType( site, ce, grid = 'LCG' ): + ''' Get CE types ''' res = gConfig.getValue('%s/Sites/%s/%s/CEs/%s/CEType' % (g_BaseResourcesSection, grid, site, ce), "CE") return "CREAMCE" if res == "CREAM" else "CE" @@ -158,7 +178,8 @@ def getCEType( site, ce, grid = 'LCG' ): # CondDB functions ################## def getCondDBs(): + ''' Get CondDB''' return Utils.unpack(gConfig.getSections("%s/CondDB" % g_BaseResourcesSection)) ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Utilities/Decorators.py b/ResourceStatusSystem/Utilities/Decorators.py index 941cb17bdf9..062cd2ecc97 100644 --- a/ResourceStatusSystem/Utilities/Decorators.py +++ b/ResourceStatusSystem/Utilities/Decorators.py @@ -1,12 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' Decorators + + Syntactic sugar used in the RSS, only in the DB. Eventually will dissapear. + +''' import types from DIRAC import S_ERROR +__RCSID__ = '$Id: $' + class BaseDec( object ): def __init__( self, f ): diff --git a/ResourceStatusSystem/Utilities/Exceptions.py b/ResourceStatusSystem/Utilities/Exceptions.py index 963d3640873..1c1d13f1794 100644 --- a/ResourceStatusSystem/Utilities/Exceptions.py +++ b/ResourceStatusSystem/Utilities/Exceptions.py @@ -1,16 +1,15 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' Exceptions -""" - collects: - - exceptions -""" + RSS Exceptions. Will be obsolete soon. + +''' from DIRAC.ResourceStatusSystem import ValidRes, ValidStatus, ValidSiteType, \ ValidServiceType, ValidResourceType +__RCSID__ = '$Id: $' + class RSSDBException( Exception ): """ DB exception diff --git a/ResourceStatusSystem/Utilities/InfoGetter.py b/ResourceStatusSystem/Utilities/InfoGetter.py index 6809c5f3cca..b10b4157749 100644 --- a/ResourceStatusSystem/Utilities/InfoGetter.py +++ b/ResourceStatusSystem/Utilities/InfoGetter.py @@ -1,7 +1,9 @@ -################################################################################ -# $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" +# $HeadURL: $ +''' InfoGetter + + Module used to map the policies with the CS. + +''' import copy @@ -9,6 +11,8 @@ from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem import views_panels +__RCSID__ = '$Id: $' + class InfoGetter: """ Class InfoGetter is in charge of getting information from the RSS Configurations """ diff --git a/ResourceStatusSystem/Utilities/MySQLMonkey.py b/ResourceStatusSystem/Utilities/MySQLMonkey.py index 642cda2800e..307d4283c0a 100644 --- a/ResourceStatusSystem/Utilities/MySQLMonkey.py +++ b/ResourceStatusSystem/Utilities/MySQLMonkey.py @@ -1,15 +1,19 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' MySQLMonkey -from DIRAC import S_OK#, S_ERROR -from DIRAC.ResourceStatusSystem.Utilities.Exceptions import RSSDBException + Module that generates SQL statemens in the fly out of two dictionaries. -from datetime import datetime +''' import re +from datetime import datetime + +from DIRAC import S_OK +from DIRAC.ResourceStatusSystem.Utilities.Exceptions import RSSDBException + +__RCSID__ = '$Id: $' + ################################################################################ # MySQL Monkey ################################################################################ @@ -501,7 +505,7 @@ def _checkFLOAT(self, suspicious): if type(i) not in (int, float): raise RSSDBException( 'Non numeric value "%s"' % suspicious ) - return [ '"%s"' % s.replace( microsecond = 0 ) for s in suspicious ] + return suspicious _checkNUMERIC = _checkFLOAT _checkDECIMAL = _checkFLOAT diff --git a/ResourceStatusSystem/Utilities/NodeTree.py b/ResourceStatusSystem/Utilities/NodeTree.py index c965603b597..89569b7d6d2 100644 --- a/ResourceStatusSystem/Utilities/NodeTree.py +++ b/ResourceStatusSystem/Utilities/NodeTree.py @@ -1,3 +1,10 @@ +# $HeadURL $ +''' Node + + Module used to inspect the DB. Will be obsolete soon. + +''' + class Node( object ): def __init__( self, name, level, cLevel, pLevel ): @@ -55,8 +62,5 @@ def setChildren( self, child, level = None ): # msg += ','.join( [ '<%s>' % k for k in self._levels[ self.childrenLevel ].keys() ] ) # return msg - - - - - \ No newline at end of file +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Utilities/Publisher.py b/ResourceStatusSystem/Utilities/Publisher.py index 7ed8061fd31..5c548e00357 100644 --- a/ResourceStatusSystem/Utilities/Publisher.py +++ b/ResourceStatusSystem/Utilities/Publisher.py @@ -1,26 +1,27 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" +''' Publisher + + Module not used. Will be back to life whenever the portal is ready. + +''' import copy import threading -from DIRAC import gLogger - +from DIRAC import gLogger +from DIRAC.Core.DISET.RPCClient import RPCClient from DIRAC.Core.Utilities.ThreadPool import ThreadPool from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName -from DIRAC.ResourceStatusSystem.Utilities.CS import getStorageElementStatus - from DIRAC.ResourceStatusSystem import ValidRes -from DIRAC.ResourceStatusSystem.Utilities import Utils - -from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB -from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller +from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB +from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB +from DIRAC.ResourceStatusSystem.Utilities import Utils +from DIRAC.ResourceStatusSystem.Utilities.CS import getStorageElementStatus from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter -from DIRAC.Core.DISET.RPCClient import RPCClient + +__RCSID__ = '$Id: $' class Publisher: """ diff --git a/ResourceStatusSystem/Utilities/Synchronizer.py b/ResourceStatusSystem/Utilities/Synchronizer.py index 1d56d83222e..62ff347828e 100644 --- a/ResourceStatusSystem/Utilities/Synchronizer.py +++ b/ResourceStatusSystem/Utilities/Synchronizer.py @@ -1,21 +1,21 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - This module contains a class to synchronize the content of the DataBase with what is the CS -""" +''' Synchronizer + + Module that keeps in sync the CS and the RSS database. + +''' from DIRAC import gLogger, S_OK +from DIRAC.Core.LCG.GOCDBClient import GOCDBClient from DIRAC.Core.Utilities.SiteCEMapping import getSiteCEMapping from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName, getDIRACSiteName - -from DIRAC.ResourceStatusSystem.Utilities import CS, Utils -from DIRAC.Core.LCG.GOCDBClient import GOCDBClient - from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient +from DIRAC.ResourceStatusSystem.Utilities import CS, Utils + +__RCSID__ = '$Id: $' -class Synchronizer(object): +class Synchronizer( object ): def __init__( self, rsClient = None, rmClient = None ): diff --git a/ResourceStatusSystem/Utilities/Utils.py b/ResourceStatusSystem/Utilities/Utils.py index 9b59cb6ef71..d94fa6ff5b9 100644 --- a/ResourceStatusSystem/Utilities/Utils.py +++ b/ResourceStatusSystem/Utilities/Utils.py @@ -1,10 +1,16 @@ -""" - This module collects utility functions -""" +# $HeadURL $ +''' Utils + + Module that collects utility functions. + +''' -from DIRAC import gConfig import collections +from DIRAC import gConfig + +__RCSID__ = '$Id: $' + ############################################################################# # useful functions ############################################################################# @@ -227,3 +233,6 @@ def xml_append(doc, tag, value_=None, elt_=None, **kw): return elt_.appendChild(new_elt) else: return doc.documentElement.appendChild(new_elt) + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Utilities/__init__.py b/ResourceStatusSystem/Utilities/__init__.py index ec8fc0efce6..1866d9edbb3 100644 --- a/ResourceStatusSystem/Utilities/__init__.py +++ b/ResourceStatusSystem/Utilities/__init__.py @@ -1,11 +1,8 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Utilities package +''' -""" - DIRAC.ResourceStatusSystem.Utilities package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file