def __getSelectionData(self): callback = {} lhcbGroup = credentials.getSelectedGroup() lhcbUser = str(credentials.getUsername()) RPC = getRPCClient("ResourceStatus/ResourceStatus") client = ResourceStatusClient(serviceIn=RPC) if len(request.params) > 0: tmp = {} for i in request.params: tmp[i] = str(request.params[i]) callback["extra"] = tmp #### result = client.getSitePresent(meta={'columns': 'SiteName'}) if result["OK"]: sites = result["Value"] try: sites = list(sites) except Exception, x: gLogger.error("Exception during convertion to a list: %s" % str(x)) sites = [] # Will return error on length check tier1 = gConfig.getValue("/Website/PreferredSites", []) # Always return a list if len(sites) > 0: tier1.reverse() tier1 = [[x] for x in tier1] sites = [x for x in sites if x not in tier1 ] # Removes sites which are in tier1 list for i in tier1: sites.insert(0, i) sites.insert(0, ["All"]) else: sites = [["Nothing to display"]]
def initialize(self): # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: self.rsClient = ResourceStatusClient() self.sitesFreqs = CS.getTypedDictRootedAtOperations( 'CheckingFreqs/SitesFreqs') self.sitesToBeChecked = Queue.Queue() self.siteNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption('maxThreadsInPool', 1) self.threadPool = ThreadPool(self.maxNumberOfThreads, self.maxNumberOfThreads) if not self.threadPool: self.log.error('Can not create Thread Pool') return S_ERROR('Can not create Thread Pool') for _i in xrange(self.maxNumberOfThreads): self.threadPool.generateJobAndQueueIt(self._executeCheck, args=(None, )) return S_OK() except Exception: errorStr = "SSInspectorAgent initialization" self.log.exception(errorStr) return S_ERROR(errorStr)
def __init__(self, clients=None): """ Constructor examples: >>> pep = PEP() >>> pep1 = PEP( { 'ResourceStatusClient' : ResourceStatusClient() } ) >>> pep2 = PEP( { 'ResourceStatusClient' : ResourceStatusClient(), 'ClientY' : None } ) :Parameters: **clients** - [ None, `dict` ] dictionary with clients to be used in the commands issued by the policies. If not defined, the commands will import them. It is a measure to avoid opening the same connection every time a policy is evaluated. """ if clients is None: clients = {} # PEP uses internally two of the clients: ResourceStatusClient and ResouceManagementClient if 'ResourceStatusClient' in clients: self.rsClient = clients['ResourceStatusClient'] else: self.rsClient = ResourceStatusClient() if 'ResourceManagementClient' in clients: self.rmClient = clients['ResourceManagementClient'] else: self.rmClient = ResourceManagementClient() self.clients = clients # Pass to the PDP the clients that are going to be used on the Commands self.pdp = PDP(clients)
def initializeHandler(cls, serviceInfoDict): """Initialization of client objects """ cls.rsClient = ResourceStatusClient() cls.rmClient = ResourceManagementClient() return S_OK()
def doCommand( self ): """ Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getResourceStats` :params: :attr:`args`: a tuple - `args[0]` string, a ValidRes. Should be in ('Site', 'Service') - `args[1]` should be the name of the Site or Service :returns: """ super( ResourceStats_Command, self ).doCommand() if self.client is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient self.client = ResourceStatusClient( timeout = self.timeout ) try: res = self.client.getResourceStats( self.args[0], self.args[1] )['Value'] except: gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( self.args[0], self.args[1] ) ) return {'Result':'Unknown'} return {'Result':res}
def __init__(self, *args, **kwargs): AgentModule.__init__(self, *args, **kwargs) self.diracAdmin = None self.default_value = None self.rsClient = ResourceStatusClient()
def doCommand( self ): """ Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getServiceStats` :params: :attr:`args`: a tuple - args[1]: a ValidRes - args[0]: should be the name of the Site :returns: {'Active':xx, 'Probing':yy, 'Banned':zz, 'Total':xyz} """ super( ServiceStats_Command, self ).doCommand() if self.client is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient self.client = ResourceStatusClient( timeout = self.timeout ) try: res = self.client.getServiceStats( self.args[0], self.args[1] )['Value'] except: gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( self.args[0], self.args[1] ) ) return {'Result':'Unknown'} return {'Result':res}
def doCommand( self ): """ Return getPeriods from ResourceStatus Client - args[0] should be a ValidRes - args[1] should be the name of the ValidRes - args[2] should be the present status - args[3] are the number of hours requested """ super( RSPeriods_Command, self ).doCommand() if self.client is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient self.client = ResourceStatusClient() try: res = self.client.getPeriods( self.args[0], self.args[1], self.args[2], self.args[3] )['Value'] except: gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( self.args[0], self.args[1] ) ) return {'Result':'Unknown'} return {'Result':res}
def test_fileOperations(self): """ this test requires the SE to be properly defined in the CS """ from DIRAC import gConfig testSE = 'testSE' rssClient = ResourceStatusClient() result = rssClient.getStorageElementsList('Read') #result = gConfig.getSections( '/Resources/StorageElements' ) #if result['OK'] and result['Value']: # testSE = result['Value'][0] if result['Ok']: testSE = result['Value'][0] result = self.fc.addFile({ testFile: { 'PFN': 'testfile', 'SE': testSE, 'Size': 0, 'GUID': 0, 'Checksum': '0' } }) self.assert_(result['OK']) if gConfig.getValue( '/Resources/StorageElements/%s/AccessProtocol.1/Host' % testSE, ''): result = self.fc.getReplicas(testFile) self.assert_(result['OK']) self.assert_(testFile in result['Value']['Successful'])
def __init__(self): """ Constructor. Initializes logger and ResourceStatusClient. """ self.log = gLogger.getSubLogger(self.__class__.__name__) self.rssClient = ResourceStatusClient()
def setUp( self ): self.mockRSS = Mock() self.RSCli = ResourceStatusClient( serviceIn = self.mockRSS ) self.RMCli = ResourceManagementClient( serviceIn = self.mockRSS ) self.PilotsCli = PilotsClient() self.JobsCli = JobsClient()
def __init__(self, args=None, clients=None): super(ServiceStatsCommand, self).__init__(args, clients) if 'ResourceStatusClient' in self.apis: self.rsClient = self.apis['ResourceStatusClient'] else: self.rsClient = ResourceStatusClient()
def initialize(self): ''' Standard initialize. Uses the ProductionManager shifterProxy to modify the ResourceStatus DB ''' self.rsClient = ResourceStatusClient() return S_OK()
def __init__(self, name, decisionParams, enforcementResult, singlePolicyResults, clients=None): super(EmailAction, self).__init__(name, decisionParams, enforcementResult, singlePolicyResults, clients) if clients is not None and "ResourceStatusClient" in clients: self.rsClient = clients["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 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}
def __init__(self): """ Constructor """ self.log = gLogger.getSubLogger(self.__class__.__name__) self.compoDB = ComponentMonitoringDB() self.rsClient = ResourceStatusClient()
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): """ 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(PilotsEffSimpleCached_Command, self).doCommand() client = self.client if client is None: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient self.client = ResourceStatusClient(timeout=self.timeout) if self.args[0] in ('Service', 'Services'): try: name = self.client.getGeneralName(self.args[0], self.args[1], 'Site')['Value'][0] except: gLogger.error( "PilotsEffSimpleCached_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'): name = self.args[1] granularity = self.args[0] else: raise InvalidRes, where(self, self.doCommand) try: if client is None: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient self.client = ResourceManagementClient(timeout=self.timeout) res = self.client.getCachedResult(name, 'PilotsEffSimpleEverySites', 'PE_S', 'NULL')['Value'] if res == None: return {'Result': 'Idle'} if res == []: return {'Result': 'Idle'} except: gLogger.exception( "Exception when calling ResourceManagementClient for %s %s" % (granularity, name)) return {'Result': 'Unknown'} return {'Result': res[0]}
def initialize(self): """ Standard initialize. :return: S_OK """ self.rsClient = ResourceStatusClient() return S_OK()
def __init__(self): """ Constructor, initializes the rssClient. """ self.log = gLogger.getSubLogger(self.__class__.__name__) self.rssConfig = RssConfiguration() self.__opHelper = Operations() self.rssFlag = ResourceStatus().rssFlag self.rsClient = ResourceStatusClient()
def initialize(self): """TokenAgent initialization""" self.notifyHours = self.am_getOption("notifyHours", self.notifyHours) self.adminMail = self.am_getOption("adminMail", self.adminMail) self.rsClient = ResourceStatusClient() self.diracAdmin = DiracAdmin() return S_OK()
def initialize(self): """Standard initialize. :return: S_OK """ self.rsClient = ResourceStatusClient() self.months = self.am_getOption("Months", self.months) return S_OK()
def initializePublisherHandler( _serviceInfo ): ''' Handler initialization in the usual horrible way. ''' global rsClient rsClient = ResourceStatusClient() global rmClient rmClient = ResourceManagementClient() return S_OK()
def initialize( self ): ''' TokenAgent initialization ''' self.notifyHours = self.am_getOption( 'notifyHours', self.notifyHours ) self.adminMail = self.am_getOption( 'adminMail', self.adminMail ) self.rsClient = ResourceStatusClient() self.diracAdmin = DiracAdmin() return S_OK()
def __init__(self, rsClient=None, rmClient=None): self.GOCDBClient = GOCDBClient() self.rsClient = ResourceStatusClient( ) if rsClient == None else rsClient self.rmClient = ResourceManagementClient( ) if rmClient == None else rmClient self.synclist = [ 'Sites', 'Resources', 'StorageElements', 'Services', 'RegistryUsers' ]
def __init__(self, granularity, name, status_type, pdp_decision, **kw): ActionBase.__init__(self, granularity, name, status_type, pdp_decision, **kw) try: self.rsClient = self.kw["Clients"]['ResourceStatusClient'] except KeyError: self.rsClient = ResourceStatusClient() try: self.rmClient = self.kw["Clients"]['ResourceManagementClient'] except KeyError: self.rmClient = ResourceManagementClient()
def test__emailActionAgent(): rssClient = ResourceStatusClient() # clean up res = rssClient.delete('ResourceStatusCache') assert res['OK'] is True res = action.run() assert res['OK'] is True res = agent.execute() assert res['OK'] is True
def initialize(self): """ Define the commands to be executed, and instantiate the clients that will be used. """ self.am_setOption('shifterProxy', 'DataManager') self.rmClient = ResourceManagementClient() self.commands['Downtime'] = [{'Downtime': {}}] self.commands['SpaceTokenOccupancy'] = [{'SpaceTokenOccupancy': {}}] self.commands['GOCDBSync'] = [{'GOCDBSync': {}}] self.commands['FreeDiskSpace'] = [{'FreeDiskSpace': {}}] # PilotsCommand # self.commands[ 'Pilots' ] = [ # { 'PilotsWMS' : { 'element' : 'Site', 'siteName' : None } }, # { 'PilotsWMS' : { 'element' : 'Resource', 'siteName' : None } } # ] # FIXME: do not forget about hourly vs Always ...etc # AccountingCacheCommand # self.commands[ 'AccountingCache' ] = [ # {'SuccessfullJobsBySiteSplitted' :{'hours' :24, 'plotType' :'Job' }}, # {'FailedJobsBySiteSplitted' :{'hours' :24, 'plotType' :'Job' }}, # {'SuccessfullPilotsBySiteSplitted' :{'hours' :24, 'plotType' :'Pilot' }}, # {'FailedPilotsBySiteSplitted' :{'hours' :24, 'plotType' :'Pilot' }}, # {'SuccessfullPilotsByCESplitted' :{'hours' :24, 'plotType' :'Pilot' }}, # {'FailedPilotsByCESplitted' :{'hours' :24, 'plotType' :'Pilot' }}, # {'RunningJobsBySiteSplitted' :{'hours' :24, 'plotType' :'Job' }}, # # {'RunningJobsBySiteSplitted' :{'hours' :168, 'plotType' :'Job' }}, # # {'RunningJobsBySiteSplitted' :{'hours' :720, 'plotType' :'Job' }}, # # {'RunningJobsBySiteSplitted' :{'hours' :8760, 'plotType' :'Job' }}, # ] # VOBOXAvailability # self.commands[ 'VOBOXAvailability' ] = [ # { 'VOBOXAvailability' : {} } # # Reuse clients for the commands self.clients['GOCDBClient'] = GOCDBClient() self.clients['ReportGenerator'] = RPCClient( 'Accounting/ReportGenerator') self.clients['ReportsClient'] = ReportsClient() self.clients['ResourceStatusClient'] = ResourceStatusClient() self.clients['ResourceManagementClient'] = ResourceManagementClient() self.clients['WMSAdministrator'] = RPCClient( 'WorkloadManagement/WMSAdministrator') self.cCaller = CommandCaller return S_OK()
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 getSiteMaskLogging(self, site=None, printOutput=False): """Retrieves site mask logging information. Example usage: >>> print diracAdmin.getSiteMaskLogging('LCG.AUVER.fr') {'OK': True, 'Value': } :returns: S_OK,S_ERROR """ result = self.__checkSiteIsValid(site) if not result['OK']: return result rssClient = ResourceStatusClient() result = rssClient.selectStatusElement('Site', 'History', name=site, statusType='ComputingAccess') if not result['OK']: return result siteDict = {} for logTuple in result['Value']: status, reason, siteName, dateEffective, dateTokenExpiration, eType, sType, eID, lastCheckTime, author = logTuple result = getSiteFullNames(siteName) if not result['OK']: continue for sName in result['Value']: if site is None or (site and site == sName): siteDict.setdefault(sName, []) siteDict[sName].append((status, reason, dateEffective, author, dateTokenExpiration)) if printOutput: if site: print '\nSite Mask Logging Info for %s\n' % site else: print '\nAll Site Mask Logging Info\n' for site, tupleList in siteDict.items(): if not site: print '\n===> %s\n' % site for tup in tupleList: print str( tup[0] ).ljust( 8 ) + str( tup[1] ).ljust( 20 ) + \ '( ' + str( tup[2] ).ljust( len( str( tup[2] ) ) ) + ' ) "' + str( tup[3] ) + '"' print ' ' return S_OK(siteDict)