Esempio n. 1
0
  def export_getCachedDowntimes( self, element, elementType, name, severity, startDate, endDate ):

    if elementType == 'StorageElement':
      name = CSHelpers.getSEHost( name )
      if not name['OK']:
        return name
      name = name['Value']

    if startDate > endDate:
      return S_ERROR( 'startDate > endDate' )

    res = rmClient.selectDowntimeCache( element = element, name = name, severity = severity,
                                        meta = { 'columns' : [ 'Element', 'Name', 'StartDate',
                                                               'EndDate', 'Severity',
                                                               'Description', 'Link' ] } )
    if not res[ 'OK' ]:
      return res

    downtimes = []

    for dt in res[ 'Value' ]:

      dtDict = dict( zip( res[ 'Columns' ], dt ) )

      if dtDict[ 'StartDate' ] < endDate and dtDict[ 'EndDate' ] > startDate:
        downtimes.append( dt )

    result = S_OK( downtimes )
    result[ 'Columns' ] = res[ 'Columns' ]

    return result
Esempio n. 2
0
 def export_getDowntimes( self, element, elementType, name ):
   
   if elementType == 'StorageElement':
     name = CSHelpers.getSEHost( name )
   
   return rmClient.selectDowntimeCache( element = element, name = name, 
                                        meta = { 'columns' : [ 'StartDate', 'EndDate', 
                                                               'Link', 'Description', 
                                                               'Severity' ] } )
Esempio n. 3
0
  def _prepareCommand( self ):
    '''
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    '''

    if 'name' not in self.args:
      return S_ERROR( '"name" not found in self.args' )
    elementName = self.args[ 'name' ]

    if 'element' not in self.args:
      return S_ERROR( '"element" not found in self.args' )
    element = self.args[ 'element' ]

    if 'elementType' not in self.args:
      return S_ERROR( '"elementType" not found in self.args' )
    elementType = self.args[ 'elementType' ]

    if not element in [ 'Site', 'Resource' ]:
      return S_ERROR( 'element is not Site nor Resource' )

    hours = None
    if 'hours' in self.args:
      hours = self.args[ 'hours' ]

    gocdbServiceType = None

    # Transform DIRAC site names into GOCDB topics
    if element == 'Site':

      gocSite = getGOCSiteName( elementName )
      if not gocSite[ 'OK' ]:
        return gocSite
      elementName = gocSite[ 'Value' ]

    # The DIRAC se names mean nothing on the grid, but their hosts do mean.
    elif elementType == 'StorageElement':
      # We need to distinguish if it's tape or disk
      if getStorageElementOptions( elementName )['Value']['TapeSE']:
        gocdbServiceType = "srm"
      elif getStorageElementOptions( elementName )['Value']['DiskSE']:
        gocdbServiceType = "srm.nearline"

      seHost = CSHelpers.getSEHost( elementName )
      if not seHost:
        return S_ERROR( 'No seHost for %s' % elementName )
      elementName = seHost

    return S_OK( ( element, elementName, hours, gocdbServiceType ) )
Esempio n. 4
0
  def _prepareCommand( self ):
    '''
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    '''

    if 'name' not in self.args:
      return S_ERROR( '"name" not found in self.args' )
    elementName = self.args[ 'name' ]

    if 'element' not in self.args:
      return S_ERROR( '"element" not found in self.args' )
    element = self.args[ 'element' ]

    if 'elementType' not in self.args:
      return S_ERROR( '"elementType" not found in self.args' )
    elementType = self.args[ 'elementType' ]

    if not element in [ 'Site', 'Resource' ]:
      return S_ERROR( 'element is not Site nor Resource' )

    hours = None
    if 'hours' in self.args:
      hours = self.args[ 'hours' ]

    gocdbServiceType = None

    # Transform DIRAC site names into GOCDB topics
    if element == 'Site':

      gocSite = getGOCSiteName( elementName )
      if not gocSite[ 'OK' ]:
        return gocSite
      elementName = gocSite[ 'Value' ]

    # The DIRAC se names mean nothing on the grid, but their hosts do mean.
    elif elementType == 'StorageElement':
      # We need to distinguish if it's tape or disk
      if getStorageElementOptions( elementName )['Value']['TapeSE']:
        gocdbServiceType = "srm.nearline"
      elif getStorageElementOptions( elementName )['Value']['DiskSE']:
        gocdbServiceType = "srm"

      seHost = CSHelpers.getSEHost( elementName )
      if not seHost:
        return S_ERROR( 'No seHost for %s' % elementName )
      elementName = seHost

    return S_OK( ( element, elementName, hours, gocdbServiceType ) )
Esempio n. 5
0
    def export_getDowntimes(self, element, elementType, name):

        if elementType == 'StorageElement':
            name = CSHelpers.getSEHost(name)

        return rmClient.selectDowntimeCache(
            element=element,
            name=name,
            meta={
                'columns':
                ['StartDate', 'EndDate', 'Link', 'Description', 'Severity']
            })
Esempio n. 6
0
    def _prepareCommand(self):
        """
      DowntimeCommand requires three arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>  
      
      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    """

        if "name" not in self.args:
            return S_ERROR('"name" not found in self.args')
        elementName = self.args["name"]

        if "element" not in self.args:
            return S_ERROR('"element" not found in self.args')
        element = self.args["element"]

        if "elementType" not in self.args:
            return S_ERROR('"elementType" not found in self.args')
        elementType = self.args["elementType"]

        if not element in ["Site", "Resource"]:
            return S_ERROR("element is not Site nor Resource")

        hours = None
        if "hours" in self.args:
            hours = self.args["hours"]

        # Transform DIRAC site names into GOCDB topics
        if element == "Site":

            gocSite = getGOCSiteName(elementName)
            if not gocSite["OK"]:
                return gocSite
            elementName = gocSite["Value"]

        # The DIRAC se names mean nothing on the grid, but their hosts do mean.
        elif elementType == "StorageElement":

            seHost = CSHelpers.getSEHost(elementName)
            if not seHost:
                return S_ERROR("No seHost for %s" % elementName)
            elementName = seHost

        return S_OK((element, elementName, hours))
Esempio n. 7
0
  def export_getCachedDowntimes(self, element, elementType, name, severity):

    if elementType == 'StorageElement':
      name = CSHelpers.getSEHost(name)
      if not name['OK']:
        return name
      name = name['Value']

    columns = ['Element', 'Name', 'StartDate', 'EndDate', 'Severity', 'Description', 'Link']

    res = rmClient.selectDowntimeCache(element=element, name=name, severity=severity,
                                       meta={'columns': columns})
    if not res['OK']:
      return res

    result = S_OK(res['Value'])
    result['Columns'] = columns

    return result
Esempio n. 8
0
  def doNew( self, masterParams = None ):
    '''
      Gets the parameters to run, either from the master method or from its
      own arguments.

      For every elementName, unless it is given a list, in which case it contacts
      the gocdb client. The server is not very stable, so in case of failure tries
      a second time.

      If there are downtimes, are recorded and then returned.
    '''

    if masterParams is not None:
      element, elementNames = masterParams
      #translate DIRAC CS elementNames into GOCDB elementNames
      translatedElementNames = []
      for e in elementNames:
        translatedElementNames.append(CSHelpers.getSEHost( e ))
      elementNames = translatedElementNames
      hours = None
      elementName = None
      gocdbServiceType = None

    else:
      params = self._prepareCommand()
      if not params[ 'OK' ]:
        return params
      element, elementName, hours, gocdbServiceType = params[ 'Value' ]
      elementNames = [ elementName ]

    #WARNING: checking all the DT that are ongoing or starting in given <hours> from now
    startDate = None 
    if hours is not None:
      startDate = datetime.utcnow() + timedelta( hours = hours )

    try:
      results = self.gClient.getStatus( element, elementNames, startDate )
    except urllib2.URLError:
      try:
        #Let's give it a second chance..
        results = self.gClient.getStatus( element, elementNames, startDate )
      except urllib2.URLError, e:
        return S_ERROR( e )
Esempio n. 9
0
    def export_getCachedDowntimes(self, element, elementType, name, severity,
                                  startDate, endDate):

        if elementType == 'StorageElement':
            name = CSHelpers.getSEHost(name)

        if startDate > endDate:
            return S_ERROR('startDate > endDate')

        res = rmClient.selectDowntimeCache(element=element,
                                           name=name,
                                           severity=severity,
                                           meta={
                                               'columns': [
                                                   'Element', 'Name',
                                                   'StartDate', 'EndDate',
                                                   'Severity', 'Description',
                                                   'Link'
                                               ]
                                           })
        if not res['OK']:
            return res

        downtimes = []

        for dt in res['Value']:

            dtDict = dict(zip(res['Columns'], dt))

            if dtDict['StartDate'] < endDate and dtDict['EndDate'] > startDate:
                downtimes.append(dt)

        result = S_OK(downtimes)
        result['Columns'] = res['Columns']

        return result


#...............................................................................
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
Esempio n. 10
0
    def export_getCachedDowntimes(self, element, elementType, name, severity):

        if elementType == 'StorageElement':
            name = CSHelpers.getSEHost(name)
            if not name['OK']:
                return name
            name = name['Value']

        columns = [
            'Element', 'Name', 'StartDate', 'EndDate', 'Severity',
            'Description', 'Link'
        ]

        res = rmClient.selectDowntimeCache(element=element,
                                           name=name,
                                           severity=severity,
                                           meta={'columns': columns})
        if not res['OK']:
            return res

        result = S_OK(res['Value'])
        result['Columns'] = columns

        return result
Esempio n. 11
0
    def _prepareCommand(self):
        '''
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    '''

        if 'name' not in self.args:
            return S_ERROR('"name" not found in self.args')
        elementName = self.args['name']

        if 'element' not in self.args:
            return S_ERROR('"element" not found in self.args')
        element = self.args['element']

        if 'elementType' not in self.args:
            return S_ERROR('"elementType" not found in self.args')
        elementType = self.args['elementType']

        if not element in ['Site', 'Resource']:
            return S_ERROR('element is neither Site nor Resource')

        hours = None
        if 'hours' in self.args:
            hours = self.args['hours']

        gOCDBServiceType = None

        # Transform DIRAC site names into GOCDB topics
        if element == 'Site':

            gocSite = getGOCSiteName(elementName)
            if not gocSite[
                    'OK']:  # The site is most probably not a grid site - not an issue, of course
                pass  # so, elementName remains unchanged
            else:
                elementName = gocSite['Value']

        # The DIRAC se names mean nothing on the grid, but their hosts do mean.
        elif elementType == 'StorageElement':
            # We need to distinguish if it's tape or disk
            seOptions = getStorageElementOptions(elementName)
            if not seOptions['OK']:
                return seOptions
            if seOptions['Value'].get('TapeSE'):
                gOCDBServiceType = "srm.nearline"
            elif seOptions['Value'].get('DiskSE'):
                gOCDBServiceType = "srm"

            seHost = CSHelpers.getSEHost(elementName)
            if not seHost['OK']:
                return seHost
            seHost = seHost['Value']

            if not seHost:
                return S_ERROR('No seHost for %s' % elementName)
            elementName = seHost

        elif elementType in ['FTS', 'FTS3']:
            gOCDBServiceType = 'FTS'
            try:
                #WARNING: this method presupposes that the server is an FTS3 type
                elementName = getGOCFTSName(elementName)
            except:
                return S_ERROR(
                    'No FTS3 server specified in dirac.cfg (see Resources/FTSEndpoints)'
                )

        return S_OK((element, elementName, hours, gOCDBServiceType))
Esempio n. 12
0
    def _prepareCommand(self):
        '''
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    '''

        if 'name' not in self.args:
            return S_ERROR('"name" not found in self.args')
        elementName = self.args['name']

        if 'element' not in self.args:
            return S_ERROR('"element" not found in self.args')
        element = self.args['element']

        if 'elementType' not in self.args:
            return S_ERROR('"elementType" not found in self.args')
        elementType = self.args['elementType']

        if element not in ['Site', 'Resource']:
            return S_ERROR('element is neither Site nor Resource')

        hours = None
        if 'hours' in self.args:
            hours = self.args['hours']

        gOCDBServiceType = None

        # Transform DIRAC site names into GOCDB topics
        if element == 'Site':

            gocSite = getGOCSiteName(elementName)
            if not gocSite[
                    'OK']:  # The site is most probably is not a grid site - not an issue, of course
                pass  # so, elementName remains unchanged
            else:
                elementName = gocSite['Value']

        # The DIRAC se names mean nothing on the grid, but their hosts do mean.
        elif elementType == 'StorageElement':
            # We need to distinguish if it's tape or disk
            try:
                seOptions = StorageElement(elementName).options
            except AttributeError:  # Sometimes the SE can't be instantiated properly
                self.log.error(
                    "Failure instantiating StorageElement object for %s" %
                    elementName)
                return S_ERROR("Failure instantiating StorageElement")
            if 'SEType' in seOptions:
                # Type should follow the convention TXDY
                seType = seOptions['SEType']
                diskSE = re.search('D[1-9]', seType) != None
                tapeSE = re.search('T[1-9]', seType) != None
                if tapeSE:
                    gOCDBServiceType = "srm.nearline"
                elif diskSE:
                    gOCDBServiceType = "srm"

            seHost = CSHelpers.getSEHost(elementName)
            if not seHost['OK']:
                return seHost
            seHost = seHost['Value']

            if not seHost:
                return S_ERROR('No seHost for %s' % elementName)
            elementName = seHost

        elif elementType in ['FTS', 'FTS3']:
            gOCDBServiceType = 'FTS'
            # WARNING: this method presupposes that the server is an FTS3 type
            gocSite = getGOCFTSName(elementName)
            if not gocSite['OK']:
                self.log.warn("%s not in Resources/FTSEndpoints/FTS3 ?" %
                              elementName)
            else:
                elementName = gocSite['Value']

        return S_OK((element, elementName, hours, gOCDBServiceType))
Esempio n. 13
0
  def _prepareCommand( self ):
    '''
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    '''

    if 'name' not in self.args:
      return S_ERROR( '"name" not found in self.args' )
    elementName = self.args[ 'name' ]

    if 'element' not in self.args:
      return S_ERROR( '"element" not found in self.args' )
    element = self.args[ 'element' ]

    if 'elementType' not in self.args:
      return S_ERROR( '"elementType" not found in self.args' )
    elementType = self.args[ 'elementType' ]

    if not element in [ 'Site', 'Resource' ]:
      return S_ERROR( 'element is neither Site nor Resource' )

    hours = None
    if 'hours' in self.args:
      hours = self.args[ 'hours' ]

    gocdbServiceType = None

    # Transform DIRAC site names into GOCDB topics
    if element == 'Site':

      gocSite = getGOCSiteName( elementName )
      if not gocSite[ 'OK' ]:
        return gocSite
      elementName = gocSite[ 'Value' ]

    # The DIRAC se names mean nothing on the grid, but their hosts do mean.
    elif elementType == 'StorageElement':
      # We need to distinguish if it's tape or disk
      seOptions = getStorageElementOptions( elementName )
      if not seOptions['OK']:
        return seOptions
      if seOptions['Value'].get( 'TapeSE' ):
        gocdbServiceType = "srm.nearline"
      elif seOptions['Value'].get( 'DiskSE' ):
        gocdbServiceType = "srm"

      seHost = CSHelpers.getSEHost( elementName )
      if not seHost['OK']:
        return seHost
      seHost = seHost['Value']

      if not seHost:
        return S_ERROR( 'No seHost for %s' % elementName )
      elementName = seHost
      
    elif elementType == 'FTS' or elementType == 'FTS3':
      gocdbServiceType = 'FTS'
      try:
        #WARNING: this method presupposes that the server is an FTS3 type
        elementName  = getGOCFTSName(elementName)
      except:
        return S_ERROR( 'No FTS3 server specified in dirac.cfg (see Resources/FTSEndpoints)' )

    return S_OK( ( element, elementName, hours, gocdbServiceType ) )
Esempio n. 14
0
  def _prepareCommand(self):
    '''
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    '''

    if 'name' not in self.args:
      return S_ERROR('"name" not found in self.args')
    elementName = self.args['name']

    if 'element' not in self.args:
      return S_ERROR('"element" not found in self.args')
    element = self.args['element']

    if 'elementType' not in self.args:
      return S_ERROR('"elementType" not found in self.args')
    elementType = self.args['elementType']

    if element not in ['Site', 'Resource']:
      return S_ERROR('element is neither Site nor Resource')

    hours = None
    if 'hours' in self.args:
      hours = self.args['hours']

    gOCDBServiceType = None

    # Transform DIRAC site names into GOCDB topics
    if element == 'Site':

      gocSite = getGOCSiteName(elementName)
      if not gocSite['OK']:  # The site is most probably is not a grid site - not an issue, of course
        pass  # so, elementName remains unchanged
      else:
        elementName = gocSite['Value']

    # The DIRAC se names mean nothing on the grid, but their hosts do mean.
    elif elementType == 'StorageElement':
      # We need to distinguish if it's tape or disk
      try:
        seOptions = StorageElement(elementName).options
      except AttributeError:  # Sometimes the SE can't be instantiated properly
        self.log.error(
            "Failure instantiating StorageElement object for %s" % elementName)
        return S_ERROR("Failure instantiating StorageElement")
      if 'SEType' in seOptions:
        # Type should follow the convention TXDY
        seType = seOptions['SEType']
        diskSE = re.search('D[1-9]', seType) != None
        tapeSE = re.search('T[1-9]', seType) != None
        if tapeSE:
          gOCDBServiceType = "srm.nearline"
        elif diskSE:
          gOCDBServiceType = "srm"

      seHost = CSHelpers.getSEHost(elementName)
      if not seHost['OK']:
        return seHost
      seHost = seHost['Value']

      if not seHost:
        return S_ERROR('No seHost for %s' % elementName)
      elementName = seHost

    elif elementType in ['FTS', 'FTS3']:
      gOCDBServiceType = 'FTS'
      # WARNING: this method presupposes that the server is an FTS3 type
      gocSite = getGOCFTSName(elementName)
      if not gocSite['OK']:
        self.log.warn("%s not in Resources/FTSEndpoints/FTS3 ?" % elementName)
      else:
        elementName = gocSite['Value']

    return S_OK((element, elementName, hours, gOCDBServiceType))
Esempio n. 15
0
    def _prepareCommand(self):
        """
      DowntimeCommand requires four arguments:
      - name : <str>
      - element : Site / Resource
      - elementType: <str>

      If the elements are Site(s), we need to get their GOCDB names. They may
      not have, so we ignore them if they do not have.
    """

        if "name" not in self.args:
            return S_ERROR('"name" not found in self.args')
        elementName = self.args["name"]

        if "element" not in self.args:
            return S_ERROR('"element" not found in self.args')
        element = self.args["element"]

        if "elementType" not in self.args:
            return S_ERROR('"elementType" not found in self.args')
        elementType = self.args["elementType"]

        if not element in ["Site", "Resource"]:
            return S_ERROR("element is neither Site nor Resource")

        hours = None
        if "hours" in self.args:
            hours = self.args["hours"]

        gocdbServiceType = None

        # Transform DIRAC site names into GOCDB topics
        if element == "Site":

            gocSite = getGOCSiteName(elementName)
            if not gocSite["OK"]:
                return gocSite
            elementName = gocSite["Value"]

        # The DIRAC se names mean nothing on the grid, but their hosts do mean.
        elif elementType == "StorageElement":
            # We need to distinguish if it's tape or disk
            seOptions = getStorageElementOptions(elementName)
            if not seOptions["OK"]:
                return seOptions
            if seOptions["Value"].get("TapeSE"):
                gocdbServiceType = "srm.nearline"
            elif seOptions["Value"].get("DiskSE"):
                gocdbServiceType = "srm"

            seHost = CSHelpers.getSEHost(elementName)
            if not seHost["OK"]:
                return seHost
            seHost = seHost["Value"]

            if not seHost:
                return S_ERROR("No seHost for %s" % elementName)
            elementName = seHost

        elif elementType in ["FTS", "FTS3"]:
            gocdbServiceType = "FTS"
            try:
                # WARNING: this method presupposes that the server is an FTS3 type
                elementName = getGOCFTSName(elementName)
            except:
                return S_ERROR("No FTS3 server specified in dirac.cfg (see Resources/FTSEndpoints)")

        return S_OK((element, elementName, hours, gocdbServiceType))