示例#1
0
    def _prepareCommand(self):
        '''
      GGUSTicketsCommand requires one arguments:
      - elementName : <str>

      GGUSTickets are associated with gocDB names, so we have to transform the
      diracSiteName into a gocSiteName.
    '''

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

        return getGOCSiteName(name)
示例#2
0
    def _prepareCommand(self):
        """
      GGUSTicketsCommand requires one arguments:
      - elementName : <str>
      
      GGUSTickets are associated with gocDB names, so we have to transform the
      diracSiteName into a gocSiteName.
    """

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

        return getGOCSiteName(name)
示例#3
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':
      
      result = CSHelpers.getSEProtocolOption( elementName, 'Host' )
      if not result['OK']:
        return S_ERROR( 'No seHost for %s' % elementName )
      elementName = result['Value']
             
    return S_OK( ( element, elementName, hours ) )
示例#4
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':

            result = CSHelpers.getSEProtocolOption(elementName, 'Host')
            if not result['OK']:
                return S_ERROR('No seHost for %s' % elementName)
            elementName = result['Value']

        return S_OK((element, elementName, hours))
示例#5
0
def getGOCSites(diracSites=None):

    # FIXME: THIS SHOULD GO INTO Resources HELPER

    if diracSites is None:
        diracSites = Resources.getSites()
        if not diracSites["OK"]:
            return diracSites
        diracSites = diracSites["Value"]

    gocSites = []

    for diracSite in diracSites:
        gocSite = getGOCSiteName(diracSite)
        if not gocSite["OK"]:
            continue
        gocSites.append(gocSite["Value"])

    return S_OK(list(set(gocSites)))
示例#6
0
def getGOCSites(diracSites=None):

    #FIXME: THIS SHOULD GO INTO Resources HELPER

    if diracSites is None:
        diracSites = Resources.getSites()
        if not diracSites['OK']:
            return diracSites
        diracSites = diracSites['Value']

    gocSites = []

    for diracSite in diracSites:
        gocSite = getGOCSiteName(diracSite)
        if not gocSite['OK']:
            continue
        gocSites.append(gocSite['Value'])

    return S_OK(list(set(gocSites)))
示例#7
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':
            # for SRM and SRM only, we need to distinguish if it's tape or disk
            # if it's not SRM, then gOCDBServiceType will be None (and we'll use them all)
            try:
                se = StorageElement(elementName)
                seOptions = se.options
                seProtocols = set(se.localAccessProtocolList) | set(
                    se.localWriteProtocolList)
            except AttributeError:  # Sometimes the SE can't be instantiated properly
                self.log.error("Failure instantiating StorageElement object",
                               elementName)
                return S_ERROR("Failure instantiating StorageElement")
            if 'SEType' in seOptions and 'srm' in seProtocols:
                # Type should follow the convention TXDY
                seType = seOptions['SEType']
                diskSE = re.search('D[1-9]', seType) is not None
                tapeSE = re.search('T[1-9]', seType) is not None
                if tapeSE:
                    gOCDBServiceType = "srm.nearline"
                elif diskSE:
                    gOCDBServiceType = "srm"

            res = getSEHosts(elementName)
            if not res['OK']:
                return res
            seHosts = res['Value']

            if not seHosts:
                return S_ERROR('No seHost(s) for %s' % elementName)
            elementName = seHosts  # in this case it will return a list, because there might be more than one host only

        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("FTS not in Resources/FTSEndpoints/FTS3 ?",
                              elementName)
            else:
                elementName = gocSite['Value']

        return S_OK((element, elementName, hours, gOCDBServiceType))
示例#8
0
def getGlue2CEInfo(vo, host):
    """ call ldap for GLUE2 and get information

  :param str vo: Virtual Organisation
  :param str host: host to query for information
  :returns: result structure with result['Value'][siteID]['CEs'][ceID]['Queues'][queueName]. For
               each siteID, ceID, queueName all the GLUE2 parameters are retrieved
  """

    # get all Policies allowing given VO
    filt = "(&(objectClass=GLUE2Policy)(|(GLUE2PolicyRule=VO:%s)(GLUE2PolicyRule=vo:%s)))" % (
        vo, vo)
    polRes = __ldapsearchBDII(filt=filt,
                              attr=None,
                              host=host,
                              base="o=glue",
                              selectionString="GLUE2")

    if not polRes['OK']:
        return S_ERROR("Failed to get policies for this VO")
    polRes = polRes['Value']

    sLog.notice("Found %s policies for this VO %s" % (len(polRes), vo))
    # get all shares for this policy
    # create an or'ed list of all the shares and then call the search
    listOfSitesWithPolicies = set()
    shareFilter = ''
    for policyValues in polRes:
        # skip entries without GLUE2DomainID in the DN because we cannot associate them to a site
        if 'GLUE2DomainID' not in policyValues['attr']['dn']:
            continue
        shareID = policyValues['attr'].get('GLUE2MappingPolicyShareForeignKey',
                                           None)
        policyID = policyValues['attr']['GLUE2PolicyID']
        siteName = policyValues['attr']['dn'].split('GLUE2DomainID=')[1].split(
            ',', 1)[0]
        listOfSitesWithPolicies.add(siteName)
        if shareID is None:  # policy not pointing to ComputingInformation
            sLog.debug("Policy %s does not point to computing information" %
                       (policyID, ))
            continue
        sLog.verbose("%s policy %s pointing to %s " %
                     (siteName, policyID, shareID))
        sLog.debug("Policy values:\n%s" % pformat(policyValues))
        shareFilter += '(GLUE2ShareID=%s)' % shareID

    filt = '(&(objectClass=GLUE2Share)(|%s))' % shareFilter
    shareRes = __ldapsearchBDII(filt=filt,
                                attr=None,
                                host=host,
                                base="o=glue",
                                selectionString="GLUE2")
    if not shareRes['OK']:
        sLog.error("Could not get share information", shareRes['Message'])
        return shareRes
    shareInfoLists = {}
    for shareInfo in shareRes['Value']:
        if 'GLUE2DomainID' not in shareInfo['attr']['dn']:
            continue
        if 'GLUE2ComputingShare' not in shareInfo['objectClass']:
            sLog.debug('Share %r is not a ComputingShare: \n%s' %
                       (shareID, pformat(shareInfo)))
            continue
        sLog.debug("Found computing share:\n%s" % pformat(shareInfo))
        siteName = shareInfo['attr']['dn'].split('GLUE2DomainID=')[1].split(
            ',', 1)[0]
        shareInfoLists.setdefault(siteName, []).append(shareInfo['attr'])

    siteInfo = __getGlue2ShareInfo(host, shareInfoLists)
    if not siteInfo['OK']:
        sLog.error("Could not get CE info for",
                   "%s: %s" % (shareID, siteInfo['Message']))
        return siteInfo
    siteDict = siteInfo['Value']
    sLog.debug("Found Sites:\n%s" % pformat(siteDict))
    sitesWithoutShares = set(siteDict) - listOfSitesWithPolicies
    if sitesWithoutShares:
        sLog.error("Found some sites without any shares",
                   pformat(sitesWithoutShares))
    else:
        sLog.notice("Found information for all known sites")

    # remap siteDict to assign CEs to known sites, in case their names differ from the "gocdb name" in
    # the CS.
    newSiteDict = {}
    ceSiteMapping = getCESiteMapping().get('Value', {})
    # FIXME: pylint thinks siteDict is a tuple, so we cast
    for siteName, infoDict in dict(siteDict).items():
        for ce, ceInfo in infoDict.get('CEs', {}).items():
            ceSiteName = ceSiteMapping.get(ce, siteName)
            gocSiteName = getGOCSiteName(ceSiteName).get('Value', siteName)
            newSiteDict.setdefault(gocSiteName, {}).setdefault('CEs',
                                                               {})[ce] = ceInfo

    return S_OK(newSiteDict)
示例#9
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":
            # for SRM and SRM only, we need to distinguish if it's tape or disk
            # if it's not SRM, then gOCDBServiceType will be None (and we'll use them all)
            try:
                se = StorageElement(elementName)
                seOptions = se.options
                seProtocols = set(se.localAccessProtocolList) | set(
                    se.localWriteProtocolList)
            except AttributeError:  # Sometimes the SE can't be instantiated properly
                self.log.error("Failure instantiating StorageElement object",
                               elementName)
                return S_ERROR("Failure instantiating StorageElement")
            if "SEType" in seOptions and "srm" in seProtocols:
                # Type should follow the convention TXDY
                seType = seOptions["SEType"]
                diskSE = re.search("D[1-9]", seType) is not None
                tapeSE = re.search("T[1-9]", seType) is not None
                if tapeSE:
                    gOCDBServiceType = "srm.nearline"
                elif diskSE:
                    gOCDBServiceType = "srm"

            res = getSEHosts(elementName)
            if not res["OK"]:
                return res
            seHosts = res["Value"]

            if not seHosts:
                return S_ERROR("No seHost(s) for %s" % elementName)
            elementName = seHosts  # in this case it will return a list, because there might be more than one host only

        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("FTS not in Resources/FTSEndpoints/FTS3 ?",
                              elementName)
            else:
                elementName = gocSite["Value"]

        elif elementType == "ComputingElement":
            res = getCESiteMapping(elementName)
            if not res["OK"]:
                return res
            siteName = res["Value"][elementName]
            ceType = gConfig.getValue(
                cfgPath("Resources", "Sites",
                        siteName.split(".")[0], siteName, "CEs", elementName,
                        "CEType"))
            if ceType == "HTCondorCE":
                gOCDBServiceType = "org.opensciencegrid.htcondorce"
            elif ceType == "ARC":
                gOCDBServiceType = "ARC-CE"

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