Exemplo n.º 1
0
  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}
Exemplo n.º 2
0
    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"]]
Exemplo n.º 3
0
  def __changeSiteStatus( self, site, comment, statusType, status, printOutput = False ):
    """
      Change the RSS status of the given site
    """
    result = self.__checkSiteIsValid( site )
    if not result['OK']:
      return result

    wmsAdmin = RPCClient( 'WorkloadManagement/WMSAdministrator' )
    result = wmsAdmin.allowSite( site, comment )
    if not result['OK']:
      return result
    
    rsc = ResourceStatusClient()
    proxyInfo = getProxyInfo()
    if not proxyInfo[ 'OK' ]:
      return proxyInfo
    userName = proxyInfo[ 'Value' ][ 'username' ]   
    
    tomorrow = datetime.utcnow().replace( microsecond = 0 ) + timedelta( days = 1 )
  
    result = rsc.modifyStatusElement( 'Site', 'Status', 
                                      name = site, 
                                      statusType = statusType,
                                      status     = status,
                                      reason     = comment,  
                                      tokenOwner = userName, 
                                      tokenExpiration = tomorrow )

    return result
Exemplo n.º 4
0
  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}
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
  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}
Exemplo n.º 7
0
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__
Exemplo n.º 8
0
    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'])
Exemplo n.º 9
0
    def __init__(self, *args, **kwargs):

        AgentModule.__init__(self, *args, **kwargs)
        self.diracAdmin = None
        self.default_value = None

        self.rsClient = ResourceStatusClient()
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
  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"]]
Exemplo n.º 12
0
    def initialize(self):
        ''' Standard initialize.
        Uses the ProductionManager shifterProxy to modify the ResourceStatus DB
    '''

        self.rsClient = ResourceStatusClient()

        return S_OK()
Exemplo n.º 13
0
    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()
Exemplo n.º 14
0
    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()
Exemplo n.º 15
0
    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}
Exemplo n.º 16
0
    def __init__(self):
        """ Constructor
    
    """

        self.log = gLogger.getSubLogger(self.__class__.__name__)

        self.compoDB = ComponentMonitoringDB()
        self.rsClient = ResourceStatusClient()
Exemplo n.º 17
0
    def initialize(self):
        """ Standard initialize.

    :return: S_OK

    """

        self.rsClient = ResourceStatusClient()
        return S_OK()
Exemplo n.º 18
0
    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]}
Exemplo n.º 19
0
    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()
Exemplo n.º 20
0
    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()
Exemplo n.º 21
0
    def initialize(self):
        """Standard initialize.

        :return: S_OK

        """

        self.rsClient = ResourceStatusClient()
        self.months = self.am_getOption("Months", self.months)
        return S_OK()
Exemplo n.º 22
0
  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()
Exemplo n.º 23
0
    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'
        ]
Exemplo n.º 24
0
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
Exemplo n.º 25
0
    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()
Exemplo n.º 26
0
    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()
Exemplo n.º 27
0
  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]} 
Exemplo n.º 28
0
    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)
Exemplo n.º 29
0
  def __getMode( self ):
    """
      Get's flag defined ( or not ) on the RSSConfiguration. If defined as 1,
      we use RSS, if not, we use CS.
    """

    res = self.rssConfig.getConfigState()

    if res == 'Active':
      if self.rssClient is None:
        self.rssClient = ResourceStatusClient()
      return True

    self.rssClient = None
    return False
Exemplo n.º 30
0
    def __getMode(self):
        """
      Gets flag defined (or not) on the RSSConfiguration.
      If defined as 'Active', we use RSS, if not, we use the CS when possible (and WMS for Sites).
    """

        res = self.rssConfig.getConfigState()

        if res == 'Active':
            if self.rssClient is None:
                self.rssClient = ResourceStatusClient()
            return True

        self.rssClient = None
        return False
Exemplo n.º 31
0
    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()

        cacheLifeTime = int(self.rssConfig.getConfigCache())

        # RSSCache only affects the calls directed to RSS, if using the CS it is not used.
        self.rssCache = RSSCache(cacheLifeTime, self.__updateRssCache)
Exemplo n.º 32
0
class StorageElementsStats_Command( Command ):
  """
  The StorageElementsStats_Command class is a command class to know about
  present storageElementss stats
  """

  def doCommand( self ):
    """
    Uses :meth:`DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.getStorageElementsStats`

    :params:
      :attr:`args`: a tuple
        - `args[0]` should be in ['Site', 'Resource']

        - `args[1]` should be the name of the Site or Resource

    :returns:

    """
    super( StorageElementsStats_Command, self ).doCommand()

    if self.args[0] in ( 'Service', 'Services' ):
      granularity = 'Site'
      name = self.args[1].split( '@' )[1]
    elif self.args[0] in ( 'Site', 'Sites', 'Resource', 'Resources' ):
      granularity = self.args[0]
      name = self.args[1]
    else:
      raise InvalidRes, where( self, self.doCommand )

    if self.client is None:
      from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient
      self.client = ResourceStatusClient( timeout = self.timeout )

    try:
      resR = self.client.getStorageElementsStats( granularity, name, 'Read' )['Value']
      resW = self.client.getStorageElementsStats( granularity, name, 'Write' )['Value']
    except:
      gLogger.exception( "Exception when calling ResourceStatusClient for %s %s" % ( granularity, name ) )
      return {'Result':'Unknown'}

    res = {}
    for key in ValidStatus:
      res[ key ] = resR[ key ] + resW[ key ]

    return {'Result':res}

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
Exemplo n.º 33
0
    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])
        except:
            gLogger.exception("Exception when calling ResourceStatusClient for %s %s" % (self.args[0], self.args[1]))
            return {"Result": "Unknown"}

        return {"Result": res}
Exemplo n.º 34
0
class ServiceStats_Command( Command ):
  """
  The ServiceStats_Command class is a command class to know about
  present services stats
  """

  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}

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
Exemplo n.º 35
0
    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])
        except:
            gLogger.exception("Exception when calling ResourceStatusClient for %s %s" % (self.args[0], self.args[1]))
            return {"Result": "Unknown"}

        return {"Result": res}
Exemplo n.º 36
0
  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()
Exemplo n.º 37
0
class ResourceStats_Command( Command ):
  """
  The ResourceStats_Command class is a command class to know about
  present resources stats
  """

  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}

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
Exemplo n.º 38
0
    def __init__(self, rStatus=None, rManagement=None, defaultStatus="Unknown"):

        # Warm up local CS
        CSHelpers.warmUp()

        if rStatus is None:
            self.rStatus = ResourceStatusClient()
        if rManagement is None:
            self.rManagement = ResourceManagementClient()
        self.defaultStatus = defaultStatus

        self.rssConfig = RssConfiguration()
        self.tokenOwner = "rs_svc"
        result = getProxyInfo()
        if result['OK']:
            self.tokenOwner = result['Value']['username']
Exemplo n.º 39
0
  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 )   
Exemplo n.º 40
0
  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' ]
Exemplo n.º 41
0
    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])
        except:
            gLogger.exception("Exception when calling ResourceStatusClient for %s %s" % (self.args[0], self.args[1]))
            return {"Result": "Unknown"}

        return {"Result": res}
Exemplo n.º 42
0
    def initialize(self):
        ''' Standard initialize.
        Uses the ProductionManager shifterProxy to modify the ResourceStatus DB
    '''

        self.maxCacheLifetime = self.am_getOption('maxCacheLifetime',
                                                  self.maxCacheLifetime)
        self.maxHistoryLifetime = self.am_getOption('maxHistoryLifetime',
                                                    self.maxHistoryLifetime)
        self.maxLogLifetime = self.am_getOption('maxLogLifetime',
                                                self.maxLogLifetime)

        self.rsClient = ResourceStatusClient()
        self.rmClient = ResourceManagementClient()

        return S_OK()
Exemplo n.º 43
0
  def initialize( self ):

    # Attribute defined outside __init__ 
    # pylint: disable-msg=W0201

    try:
      self.rsClient             = ResourceStatusClient()
      self.resourcesFreqs       = CS.getTypedDictRootedAtOperations( 'CheckingFreqs/ResourcesFreqs' )
      self.resourcesToBeChecked = Queue.Queue()
      self.resourceNamesInCheck = []

      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 = "RSInspectorAgent initialization"
      self.log.exception( errorStr )
      return S_ERROR( errorStr )
Exemplo n.º 44
0
class RSPeriodsCommand( Command ):

  def __init__( self, args = None, clients = None ):
    
    super( RSPeriodsCommand, self ).__init__( args, clients )
    
    if 'ResourceStatusClient' in self.apis:
      self.rsClient = self.apis[ 'ResourceStatusClient' ]
    else:
      self.rsClient = ResourceStatusClient()      

  def doCommand( self ):
    """
    Return getPeriods from ResourceStatus Client

    - args[0] should be a ValidElement

    - args[1] should be the name of the ValidElement

    - args[2] should be the present status

    - args[3] are the number of hours requested
    """

#    try:
      
    res = self.rsClient.getPeriods( self.args[0], self.args[1], self.args[2], self.args[3] )
    
#    except Exception, e:
#      _msg = '%s (%s): %s' % ( self.__class__.__name__, self.args, e )
#      gLogger.exception( _msg )
#      return S_ERROR( _msg )

    return res
Exemplo n.º 45
0
  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 )
Exemplo n.º 46
0
    def __init__(self, name, decisionParams, enforcementResult, singlePolicyResults, clients=None):

        super(LogStatusAction, self).__init__(name, decisionParams, enforcementResult, singlePolicyResults, clients)

        if clients is not None and "ResourceStatusClient" in clients:
            self.rsClient = clients["ResourceStatusClient"]
        else:
            self.rsClient = ResourceStatusClient()
Exemplo n.º 47
0
 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()   
Exemplo n.º 48
0
  def initialize( self ):
    ''' Standard initialize.
        Uses the ProductionManager shifterProxy to modify the ResourceStatus DB
    '''

    self.rsClient = ResourceStatusClient()

    return S_OK()
Exemplo n.º 49
0
class LogStatusAction(BaseAction):
  '''
    Action that registers on the database a new entry on the <element>Status table.
    It adds or modifies if the record exists on the table.
  '''

  def __init__(self, name, decisionParams, enforcementResult, singlePolicyResults,
               clients=None):

    super(LogStatusAction, 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 run(self):
    '''
      Checks it has the parameters it needs and tries to addOrModify in the
      database.
    '''
    # Minor security checks

    element = self.decisionParams['element']
    if element is None:
      return S_ERROR('element should not be None')

    name = self.decisionParams['name']
    if name is None:
      return S_ERROR('name should not be None')

    statusType = self.decisionParams['statusType']
    if statusType is None:
      return S_ERROR('statusType should not be None')

    status = self.enforcementResult['Status']
    if status is None:
      return S_ERROR('status should not be None')

    elementType = self.decisionParams['elementType']
    if elementType is None:
      return S_ERROR('elementType should not be None')

    reason = self.enforcementResult['Reason']
    if reason is None:
      return S_ERROR('reason should not be None')

    # Truncate reason to fit in database column
    reason = (reason[:508] + '..') if len(reason) > 508 else reason

    resLogUpdate = self.rsClient.addOrModifyStatusElement(element, 'Status',
                                                          name=name, statusType=statusType,
                                                          status=status, elementType=elementType,
                                                          reason=reason
                                                          )

    return resLogUpdate
Exemplo n.º 50
0
 def __init__( self ):
   """ Constructor
   
   """
 
   self.log = gLogger.getSubLogger( self.__class__.__name__ )
 
   self.compoDB  = ComponentMonitoringDB()
   self.rsClient = ResourceStatusClient()
Exemplo n.º 51
0
  def initialize( self ):
    """ Standard initialize.
    
    :return: S_OK
    
    """

    self.rsClient = ResourceStatusClient()
    return S_OK()
Exemplo n.º 52
0
 def __init__( self, decissionParams, enforcementResult, singlePolicyResults, clients = None):
   
   super( LogStatusAction, self ).__init__( decissionParams, enforcementResult, 
                                            singlePolicyResults, clients )
   self.actionName = 'LogStatusAction'
   
   if clients is not None and 'ResourceStatusClient' in clients:
     self.rsClient = clients[ 'ResourceStatusClient' ]
   else:
     self.rsClient = ResourceStatusClient()
Exemplo n.º 53
0
    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()
Exemplo n.º 54
0
class LogStatusAction(BaseAction):
    """
    Action that registers on the database a new entry on the <element>Status table.
    It adds or modifies if the record exists on the table.
  """

    def __init__(self, name, decisionParams, enforcementResult, singlePolicyResults, clients=None):

        super(LogStatusAction, 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 run(self):
        """
      Checks it has the parameters it needs and tries to addOrModify in the
      database.
    """
        # Minor security checks

        element = self.decisionParams["element"]
        if element is None:
            return S_ERROR("element should not be None")

        name = self.decisionParams["name"]
        if name is None:
            return S_ERROR("name should not be None")

        statusType = self.decisionParams["statusType"]
        if statusType is None:
            return S_ERROR("statusType should not be None")

        status = self.enforcementResult["Status"]
        if status is None:
            return S_ERROR("status should not be None")

        elementType = self.decisionParams["elementType"]
        if elementType is None:
            return S_ERROR("elementType should not be None")

        reason = self.enforcementResult["Reason"]
        if reason is None:
            return S_ERROR("reason should not be None")

        # Truncate reason to fit in database column
        reason = (reason[:508] + "..") if len(reason) > 508 else reason

        resLogUpdate = self.rsClient.addOrModifyStatusElement(
            element, "Status", name=name, statusType=statusType, status=status, elementType=elementType, reason=reason
        )

        return resLogUpdate
Exemplo n.º 55
0
 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()  
Exemplo n.º 56
0
  def initialize( self ):
    ''' Standard initialize.
        Uses the ProductionManager shifterProxy to modify the ResourceStatus DB
    '''

    self.maxCacheLifetime = self.am_getOption( 'maxCacheLifetime', self.maxCacheLifetime )
    self.maxHistoryLifetime = self.am_getOption( 'maxHistoryLifetime', self.maxHistoryLifetime )
    self.maxLogLifetime = self.am_getOption( 'maxLogLifetime', self.maxLogLifetime )

    self.rsClient = ResourceStatusClient()
    self.rmClient = ResourceManagementClient()

    return S_OK()
Exemplo n.º 57
0
  def initialize( self ):
    ''' TokenAgent initialization
        Uses the ProductionManager shifterProxy to modify the ResourceStatus DB
    '''

    self.notifyHours = self.am_getOption( 'notifyHours', self.notifyHours )

    self.rsClient = ResourceStatusClient()
    self.rmClient = ResourceManagementClient()
    self.noClient = NotificationClient()

    self.diracAdmin = DiracAdmin()

    return S_OK()
Exemplo n.º 58
0
class StorageElementsStatsCommand( Command ):
  """
  The StorageElementsStats_Command class is a command class to know about
  present storageElementss stats
  """

  def __init__( self, args = None, clients = None ):
    
    super( StorageElementsStatsCommand, 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.getStorageElementStats`

    :params:
      :attr:`args`: a tuple
        - `args[0]` should be in ['Site', 'Resource']

        - `args[1]` should be the name of the Site or Resource

    :returns:

    """

#    try:

    if self.args[0] == 'Service':
      granularity = 'Site'
      name        = self.args[1].split( '@' )[1]
    elif self.args[0] in [ 'Site', 'Resource' ]:
      granularity = self.args[0]
      name        = self.args[1]
    else:
      return self.returnERROR( S_ERROR( '%s is not a valid granularity' % self.args[ 0 ] ) )

    res = self.rsClient.getStorageElementStats( granularity, name, statusType = None )
    if not res[ 'OK' ]:
      return 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