class MonitoredStatus_Command(Command): """ The MonitoredStatus_Command class is a command class to know about monitored status. """ def doCommand(self): """ Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getMonitoredStatus` :params: :attr:`args`: a tuple - `args[0]`: string - should be a ValidRes - `args[1]`: string - should be the name of the ValidRes - `args[2]`: optional string - a ValidRes (get status of THIS ValidRes for name in args[1], will call getGeneralName) :returns: {'MonitoredStatus': 'Active'|'Probing'|'Banned'} """ super(MonitoredStatus_Command, self).doCommand() if self.client is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient self.client = ResourceStatusClient(timeout=self.timeout) try: if len(self.args) == 3: if ValidRes.index(self.args[2]) >= ValidRes.index(self.args[0]): raise InvalidRes, where(self, self.doCommand) toBeFound = self.client.getGeneralName(self.args[0], self.args[1], self.args[2])[0] statuses = self.client.getMonitoredStatus(self.args[2], toBeFound) else: toBeFound = self.args[1] statuses = self.client.getMonitoredStatus(self.args[0], toBeFound) if not statuses: gLogger.warn("No status found for %s" % toBeFound) return {"Result": "Unknown"} except: gLogger.exception("Exception when calling ResourceStatusClient for %s %s" % (self.args[0], self.args[1])) return {"Result": "Unknown"} if len(statuses) == 1: res = statuses[0] else: i = 0 for status in statuses: ind = ValidStatus.index(status) if ind > i: i = ind res = ValidStatus[i] return {"Result": res} doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
def doCommand(self, RSClientIn=None): """ Returns simple pilots efficiency :attr:`args`: - args[0]: string - should be a ValidRes - args[1]: string - should be the name of the ValidRes returns: { 'Result': 'Good'|'Fair'|'Poor'|'Idle'|'Bad' } """ super(PilotsEffSimple_Command, self).doCommand() if self.args[0] in ('Service', 'Services'): if RSClientIn is not None: rsc = RSClientIn else: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient rsc = ResourceStatusClient() try: name = rsc.getGeneralName(self.args[0], self.args[1], 'Site')['Value'][0] except: gLogger.error( "PilotsEffSimple_Command: can't get a general name for %s %s" % (self.args[0], self.args[1])) return {'Result': 'Unknown'} granularity = 'Site' elif self.args[0] in ('Site', 'Sites', 'Resource', 'Resources'): name = self.args[1] granularity = self.args[0] else: raise InvalidRes, where(self, self.doCommand) if self.client is None: from DIRAC.ResourceStatusSystem.Client.PilotsClient import PilotsClient self.client = PilotsClient() try: res = self.client.getPilotsSimpleEff(granularity, name, timeout=self.timeout) if res is None: return {'Result': 'Idle'} if res[name] is None: return {'Result': 'Idle'} except: gLogger.exception("Exception when calling PilotsClient for %s %s" % (granularity, name)) return {'Result': 'Unknown'} return {'Result': res[name]}
def doCommand(self, RSClientIn = None): """ Returns simple pilots efficiency :attr:`args`: - args[0]: string - should be a ValidRes - args[1]: string - should be the name of the ValidRes returns: { 'Result': 'Good'|'Fair'|'Poor'|'Idle'|'Bad' } """ super(PilotsEffSimple_Command, self).doCommand() if self.args[0] in ('Service', 'Services'): if RSClientIn is not None: rsc = RSClientIn else: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient rsc = ResourceStatusClient() try: name = rsc.getGeneralName(self.args[0], self.args[1], 'Site')[0] except: gLogger.error("PilotsEffSimple_Command: can't get a general name for %s %s" %(self.args[0], self.args[1])) return {'Result':'Unknown'} granularity = 'Site' elif self.args[0] in ('Site', 'Sites', 'Resource', 'Resources'): name = self.args[1] granularity = self.args[0] else: raise InvalidRes, where(self, self.doCommand) if self.client is None: from DIRAC.ResourceStatusSystem.Client.PilotsClient import PilotsClient self.client = PilotsClient() try: res = self.client.getPilotsSimpleEff(granularity, name, timeout = self.timeout) if res is None: return {'Result':'Idle'} if res[name] is None: return {'Result':'Idle'} except: gLogger.exception("Exception when calling PilotsClient for %s %s" %(granularity, name)) return {'Result':'Unknown'} return {'Result':res[name]}
def getPilotsSimpleEff(self, granularity, name, siteName = None, RPCWMSAdmin = None, timeout = None): """ Return pilots simple efficiency of entity in args for periods :Parameters: `granularity` string - should be a ValidRes (Site or Resource) `name` string or list - names of the ValidRes `siteName` string - optional site name, in case granularity is `Resource` `RPCWMSAdmin` RPCClient to RPCWMSAdmin :return: { 'PilotsEff': 'Good'|'Fair'|'Poor'|'Idle'|'Bad' } """ if RPCWMSAdmin is not None: RPC = RPCWMSAdmin else: from DIRAC.Core.DISET.RPCClient import RPCClient RPC = RPCClient("WorkloadManagement/WMSAdministrator", timeout = timeout) if granularity in ('Site', 'Sites'): res = RPC.getPilotSummaryWeb({'GridSite':name},[],0,300) elif granularity in ('Resource', 'Resources'): if siteName is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient rsc = ResourceStatusClient() siteName = rsc.getGeneralName(granularity, name, 'Site') if not siteName[ 'OK' ]: raise RSSException, where( self, self.getPilotsSimpleEff ) + " " + res[ 'Message' ] if siteName[ 'Value' ] is None or siteName[ 'Value' ] == []: return {} siteName = siteName['Value'] res = RPC.getPilotSummaryWeb({'ExpandSite':siteName},[],0,50) else: raise InvalidRes, where(self, self.getPilotsSimpleEff) if not res['OK']: raise RSSException, where(self, self.getPilotsSimpleEff) + " " + res['Message'] else: res = res['Value']['Records'] if len(res) == 0: return {} effRes = {} try: if granularity in ('Site', 'Sites'): for r in res: name = r[0] try: eff = r[14] except IndexError: eff = 'Idle' effRes[name] = eff elif granularity in ('Resource', 'Resources'): eff = None for r in res: if r[1] == name: try: eff = r[14] except IndexError: eff = 'Idle' break effRes[name] = eff return effRes except IndexError: return {}
class PilotsEffSimpleCachedCommand(Command): def __init__(self, args=None, clients=None): super(PilotsEffSimpleCachedCommand, self).__init__(args, clients) if 'ResourceStatusClient' in self.apis: self.rsClient = self.apis['ResourceStatusClient'] else: self.rsClient = ResourceStatusClient() if 'ResourceManagementClient' in self.apis: self.rmClient = self.apis['ResourceManagementClient'] else: self.emClient = ResourceManagementClient() def doCommand(self): """ Returns simple pilots efficiency :attr:`args`: - args[0]: string: should be a ValidElement - args[1]: string should be the name of the ValidElement returns: { 'Result': 'Good'|'Fair'|'Poor'|'Idle'|'Bad' } """ if self.args[0] == 'Service': name = self.rsClient.getGeneralName(self.args[0], self.args[1], 'Site') name = name['Value'][0] granularity = 'Site' elif self.args[0] == 'Site': name = self.args[1] granularity = self.args[0] else: return self.returnERROR( S_ERROR('%s is not a valid granularity' % self.args[0])) clientDict = { 'name': name, 'commandName': 'PilotsEffSimpleEverySites', 'value': 'PE_S', 'opt_ID': 'NULL', 'meta': { 'columns': 'Result' } } res = self.rmClient.getClientCache(**clientDict) if res['OK']: res = res['Value'] if res == None or res == []: res = S_OK('Idle') else: res = S_OK(res[0]) else: res = self.returnERROR(res) return res ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
def getPilotsSimpleEff(self, granularity, name, siteName=None, RPCWMSAdmin=None): if RPCWMSAdmin is not None: RPC = RPCWMSAdmin else: from DIRAC.Core.DISET.RPCClient import RPCClient RPC = RPCClient("WorkloadManagement/WMSAdministrator") if granularity == 'Site': res = RPC.getPilotSummaryWeb({'GridSite': name}, [], 0, 300) elif granularity == 'Resource': if siteName is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient rsClient = ResourceStatusClient() siteName = rsClient.getGeneralName(granularity, name, 'Site') if not siteName['OK']: print res['Message'] return {} if siteName['Value'] is None or siteName['Value'] == []: return {} siteName = siteName['Value'] res = RPC.getPilotSummaryWeb({'ExpandSite': siteName}, [], 0, 50) else: return {} if not res['OK']: print res['Message'] return {} res = res['Value']['Records'] if len(res) == 0: return {} effRes = {} try: if granularity == 'Site': for r in res: name = r[0] try: eff = r[14] except IndexError: eff = 'Idle' effRes[name] = eff elif granularity == 'Resource': eff = None for r in res: if r[1] == name: try: eff = r[14] except IndexError: eff = 'Idle' break effRes[name] = eff return effRes except IndexError: return {} ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
def getPilotsSimpleEff(self, granularity, name, siteName=None, RPCWMSAdmin=None, timeout=None): """ Return pilots simple efficiency of entity in args for periods :Parameters: `granularity` string - should be a ValidRes (Site or Resource) `name` string or list - names of the ValidRes `siteName` string - optional site name, in case granularity is `Resource` `RPCWMSAdmin` RPCClient to RPCWMSAdmin :return: { 'PilotsEff': 'Good'|'Fair'|'Poor'|'Idle'|'Bad' } """ if RPCWMSAdmin is not None: RPC = RPCWMSAdmin else: from DIRAC.Core.DISET.RPCClient import RPCClient RPC = RPCClient("WorkloadManagement/WMSAdministrator", timeout=timeout) if granularity in ('Site', 'Sites'): res = RPC.getPilotSummaryWeb({'GridSite': name}, [], 0, 300) elif granularity in ('Resource', 'Resources'): if siteName is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient rsc = ResourceStatusClient() siteName = rsc.getGeneralName(granularity, name, 'Site') if not siteName['OK']: raise RSSException, where( self, self.getPilotsSimpleEff) + " " + res['Message'] if siteName['Value'] is None or siteName['Value'] == []: return {} siteName = siteName['Value'] res = RPC.getPilotSummaryWeb({'ExpandSite': siteName}, [], 0, 50) else: raise InvalidRes, where(self, self.getPilotsSimpleEff) if not res['OK']: raise RSSException, where( self, self.getPilotsSimpleEff) + " " + res['Message'] else: res = res['Value']['Records'] if len(res) == 0: return {} effRes = {} try: if granularity in ('Site', 'Sites'): for r in res: name = r[0] try: eff = r[14] except IndexError: eff = 'Idle' effRes[name] = eff elif granularity in ('Resource', 'Resources'): eff = None for r in res: if r[1] == name: try: eff = r[14] except IndexError: eff = 'Idle' break effRes[name] = eff return effRes except IndexError: return {}
class MonitoredStatusCommand(Command): """ The MonitoredStatus_Command class is a command class to know about monitored status. """ def __init__(self, args=None, clients=None): super(MonitoredStatusCommand, self).__init__(args, clients) if 'ResourceStatusClient' in self.apis: self.rsClient = self.apis['ResourceStatusClient'] else: self.rsClient = ResourceStatusClient() def doCommand(self): """ Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getMonitoredStatus` :params: :attr:`args`: a tuple - `args[0]`: string - should be a ValidElement - `args[1]`: string - should be the name of the ValidElement - `args[2]`: optional string - a ValidElement (get status of THIS ValidElement for name in args[1], will call getGeneralName) :returns: {'MonitoredStatus': 'Active'|'Probing'|'Banned'} """ # try: validElements = RssConfiguration.getValidElements() if len(self.args) == 3: if validElements.index(self.args[2]) >= validElements.index( self.args[0]): return self.returnERROR( S_ERROR('Error in MonitoredStatus_Command')) toBeFound = self.rsClient.getGeneralName(self.args[0], self.args[1], self.args[2])['Value'] else: toBeFound = self.args[1] res = self.rsClient.getMonitoredStatus(self.args[2], toBeFound) if res['OK']: res = res['Value'] if res: res = S_OK(res[0][0]) else: res = S_OK(None) else: res = self.returnERROR(res) # except Exception, e: # _msg = '%s (%s): %s' % ( self.__class__.__name__, self.args, e ) # gLogger.exception( _msg ) # return S_ERROR( _msg ) return res # doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__ ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
class MonitoredStatusCommand( Command ): """ The MonitoredStatus_Command class is a command class to know about monitored status. """ def __init__( self, args = None, clients = None ): super( MonitoredStatusCommand, self ).__init__( args, clients ) if 'ResourceStatusClient' in self.apis: self.rsClient = self.apis[ 'ResourceStatusClient' ] else: self.rsClient = ResourceStatusClient() def doCommand( self ): """ Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getMonitoredStatus` :params: :attr:`args`: a tuple - `args[0]`: string - should be a ValidElement - `args[1]`: string - should be the name of the ValidElement - `args[2]`: optional string - a ValidElement (get status of THIS ValidElement for name in args[1], will call getGeneralName) :returns: {'MonitoredStatus': 'Active'|'Probing'|'Banned'} """ # try: validElements = RssConfiguration.getValidElements() if len( self.args ) == 3: if validElements.index( self.args[2] ) >= validElements.index( self.args[0] ): return self.returnERROR( S_ERROR( 'Error in MonitoredStatus_Command' ) ) toBeFound = self.rsClient.getGeneralName( self.args[0], self.args[1], self.args[2] )[ 'Value' ] else: toBeFound = self.args[1] res = self.rsClient.getMonitoredStatus( self.args[2], toBeFound ) if res[ 'OK' ]: res = res[ 'Value' ] if res: res = S_OK( res[ 0 ][ 0 ] ) else: res = S_OK( None ) else: res = self.returnERROR( res ) # except Exception, e: # _msg = '%s (%s): %s' % ( self.__class__.__name__, self.args, e ) # gLogger.exception( _msg ) # return S_ERROR( _msg ) return res # doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__ ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
class MonitoredStatus_Command( Command ): """ The MonitoredStatus_Command class is a command class to know about monitored status. """ def doCommand( self ): """ Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getMonitoredStatus` :params: :attr:`args`: a tuple - `args[0]`: string - should be a ValidRes - `args[1]`: string - should be the name of the ValidRes - `args[2]`: optional string - a ValidRes (get status of THIS ValidRes for name in args[1], will call getGeneralName) :returns: {'MonitoredStatus': 'Active'|'Probing'|'Banned'} """ super( MonitoredStatus_Command, self ).doCommand() if self.client is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient self.client = ResourceStatusClient( timeout = self.timeout ) try: if len( self.args ) == 3: if ValidRes.index( self.args[2] ) >= ValidRes.index( self.args[0] ): raise InvalidRes, where( self, self.doCommand ) toBeFound = self.client.getGeneralName( self.args[0], self.args[1], self.args[2] ) if not toBeFound[ 'OK' ]: return {'Result' : 'Unknown'} toBeFound = toBeFound['Value'] statuses = self.client.getMonitoredStatus( self.args[2], toBeFound ) if not statuses['OK']: return {'Result' : 'Unknown'} statuses = statuses['Value'] else: toBeFound = self.args[1] statuses = self.client.getMonitoredStatus( self.args[0], toBeFound ) if not statuses['OK']: return {'Result' : 'Unknown'} statuses = statuses['Value'] if not statuses: gLogger.warn( "No status found for %s" % toBeFound ) return {'Result':'Unknown'} except: gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( self.args[0], self.args[1] ) ) return {'Result':'Unknown'} # statuses is a list of statuses. We take the worst returned # status. assert(type(statuses) == list) statuses.sort(key=value_of_status) res = statuses[0] if len(statuses) > 1: gLogger.info( ValidStatus ) gLogger.info( statuses ) return {'Result':res} doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
def getPilotsSimpleEff( self, granularity, name, siteName = None, RPCWMSAdmin = None ): if RPCWMSAdmin is not None: RPC = RPCWMSAdmin else: from DIRAC.Core.DISET.RPCClient import RPCClient RPC = RPCClient( "WorkloadManagement/WMSAdministrator" ) if granularity == 'Site': res = RPC.getPilotSummaryWeb( { 'GridSite' : name }, [], 0, 300 ) elif granularity == 'Resource': if siteName is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient rsClient = ResourceStatusClient() siteName = rsClient.getGeneralName( granularity, name, 'Site' ) if not siteName[ 'OK' ]: print res[ 'Message' ] return {} if siteName[ 'Value' ] is None or siteName[ 'Value' ] == []: return {} siteName = siteName['Value'] res = RPC.getPilotSummaryWeb( { 'ExpandSite' : siteName }, [], 0, 50 ) else: return {} if not res['OK']: print res[ 'Message' ] return {} res = res['Value']['Records'] if len(res) == 0: return {} effRes = {} try: if granularity == 'Site': for r in res: name = r[0] try: eff = r[14] except IndexError: eff = 'Idle' effRes[name] = eff elif granularity == 'Resource': eff = None for r in res: if r[1] == name: try: eff = r[14] except IndexError: eff = 'Idle' break effRes[name] = eff return effRes except IndexError: return {} ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
class PilotsEffSimpleCachedCommand( Command ): def __init__( self, args = None, clients = None ): super( PilotsEffSimpleCachedCommand, self ).__init__( args, clients ) if 'ResourceStatusClient' in self.apis: self.rsClient = self.apis[ 'ResourceStatusClient' ] else: self.rsClient = ResourceStatusClient() if 'ResourceManagementClient' in self.apis: self.rmClient = self.apis[ 'ResourceManagementClient' ] else: self.emClient = ResourceManagementClient() def doCommand( self ): """ Returns simple pilots efficiency :attr:`args`: - args[0]: string: should be a ValidElement - args[1]: string should be the name of the ValidElement returns: { 'Result': 'Good'|'Fair'|'Poor'|'Idle'|'Bad' } """ if self.args[0] == 'Service': name = self.rsClient.getGeneralName( self.args[0], self.args[1], 'Site' ) name = name[ 'Value' ][ 0 ] granularity = 'Site' elif self.args[0] == 'Site': name = self.args[1] granularity = self.args[0] else: return self.returnERROR( S_ERROR( '%s is not a valid granularity' % self.args[ 0 ] ) ) clientDict = { 'name' : name, 'commandName' : 'PilotsEffSimpleEverySites', 'value' : 'PE_S', 'opt_ID' : 'NULL', 'meta' : { 'columns' : 'Result' } } res = self.rmClient.getClientCache( **clientDict ) if res[ 'OK' ]: res = res[ 'Value' ] if res == None or res == []: res = S_OK( 'Idle' ) else: res = S_OK( res[ 0 ] ) else: res = self.returnERROR( res ) return res ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF