예제 #1
0
    def _syncNodes(self):
        """
    Method that synchronizes resources as defined on RESOURCE_NODE_MAPPING dictionary
    values. It makes one sync round per key ( elementType ). Gets from the CS the 
    eligible Node/<elementType> names and then synchronizes them with the DB. 
    If not on the DB, they are added. If in the DB but not on the CS, they are deleted.
    
    examples:
      >>> s._syncNodes() 
          S_OK( { 'Queue' : { 'added' : [], 'deleted' : [] },
                  ... } ) 
    
    :return: S_OK( { 'RESOURCE_NODE_MAPPINGValue1' : { 'added' : [], 'deleted' : [] }, ...} )
    """

        nodes = {}

        # Iterate over the different elementTypes for Node ( Queue, AccessProtocol... )
        for elementType in RESOURCE_NODE_MAPPING.values():

            # Get Node / <elementType> names from CS
            foundNodes = self.resources.getEligibleNodes(elementType)
            if not foundNodes['OK']:
                self.log.error(foundNodes['Value'])
                continue

            # Translate CS result into a list : maps NodeName to SiteName<>NodeName to
            # avoid duplicates
            # Looong list comprehension, sorry !
            foundNodes = [
                '%s<>%s' % (key, item)
                for key, subDict in foundNodes['Value'].items()
                for subList in subDict.values() for item in subList
            ]

            # Synchronize with the DB
            resSync = self.__dbSync('Node', elementType, foundNodes)
            if not resSync['OK']:
                self.log.error('Error synchronizing %s %s' %
                               ('Node', elementType))
                self.log.error(resSync['Message'])
            else:
                nodes[elementType] = resSync['Value']

        return S_OK(nodes)
예제 #2
0
 def _syncNodes( self ):
   """
   Method that synchronizes resources as defined on RESOURCE_NODE_MAPPING dictionary
   values. It makes one sync round per key ( elementType ). Gets from the CS the 
   eligible Node/<elementType> names and then synchronizes them with the DB. 
   If not on the DB, they are added. If in the DB but not on the CS, they are deleted.
   
   examples:
     >>> s._syncNodes() 
         S_OK( { 'Queue' : { 'added' : [], 'deleted' : [] },
                 ... } ) 
   
   :return: S_OK( { 'RESOURCE_NODE_MAPPINGValue1' : { 'added' : [], 'deleted' : [] }, ...} )
   """
   
   nodes = {}
   
   # Iterate over the different elementTypes for Node ( Queue, AccessProtocol... )
   for elementType in RESOURCE_NODE_MAPPING.values():
     
     # Get Node / <elementType> names from CS
     foundNodes = self.resources.getEligibleNodes( elementType )
     if not foundNodes[ 'OK' ]:
       self.log.error( foundNodes[ 'Value' ] )
       continue
     
     # Translate CS result into a list : maps NodeName to SiteName<>NodeName to 
     # avoid duplicates
     # Looong list comprehension, sorry !
     foundNodes = [ '%s<>%s' % ( key, item ) for key, subDict in foundNodes[ 'Value' ].items() 
                    for subList in subDict.values() for item in subList ]
            
     # Synchronize with the DB       
     resSync = self.__dbSync( 'Node', elementType, foundNodes )
     if not resSync[ 'OK' ]:
       self.log.error( 'Error synchronizing %s %s' % ( 'Node', elementType ) )
       self.log.error( resSync[ 'Message' ] )
     else: 
       nodes[ elementType ] = resSync[ 'Value' ] 
 
   return S_OK( nodes )
예제 #3
0
    def _syncResources(self):
        """
    Method that synchronizes resources as defined on RESOURCE_NODE_MAPPING dictionary
    keys. It makes one sync round per key ( elementType ). Gets from the CS the 
    eligible Resource/<elementType> names and then synchronizes them with the DB. 
    If not on the DB, they are added. If in the DB but not on the CS, they are deleted.
    
    examples:
      >>> s._syncResources() 
          S_OK( { 'Computing' : { 'added' : [ 'newCE01', 'newCE02' ], 'deleted' : [] },
                  'Storage'   : { 'added' : [], 'deleted' : [] },
                  ... } ) 
    
    :return: S_OK( { 'RESOURCE_NODE_MAPPINGKey1' : { 'added' : [], 'deleted' : [] }, ...} )
    """

        resources = {}

        # Iterate over the different elementTypes for Resource ( Computing, Storage... )
        for elementType in RESOURCE_NODE_MAPPING.keys():

            # Get Resource / <elementType> names from CS
            foundResources = self.resources.getEligibleResources(elementType)
            if not foundResources['OK']:
                self.log.error(foundResources['Message'])
                continue

            # Translate CS result into a list
            foundResources = foundResources['Value']

            # Synchronize with the DB
            resSync = self.__dbSync('Resource', elementType, foundResources)
            if not resSync['OK']:
                self.log.error('Error synchronizing %s %s' %
                               ('Resource', elementType))
                self.log.error(resSync['Message'])
            else:
                resources[elementType] = resSync['Value']

        return S_OK(resources)
예제 #4
0
 def _syncResources( self ):
   """
   Method that synchronizes resources as defined on RESOURCE_NODE_MAPPING dictionary
   keys. It makes one sync round per key ( elementType ). Gets from the CS the 
   eligible Resource/<elementType> names and then synchronizes them with the DB. 
   If not on the DB, they are added. If in the DB but not on the CS, they are deleted.
   
   examples:
     >>> s._syncResources() 
         S_OK( { 'Computing' : { 'added' : [ 'newCE01', 'newCE02' ], 'deleted' : [] },
                 'Storage'   : { 'added' : [], 'deleted' : [] },
                 ... } ) 
   
   :return: S_OK( { 'RESOURCE_NODE_MAPPINGKey1' : { 'added' : [], 'deleted' : [] }, ...} )
   """
   
   resources = {}
   
   # Iterate over the different elementTypes for Resource ( Computing, Storage... )
   for elementType in RESOURCE_NODE_MAPPING.keys():
     
     # Get Resource / <elementType> names from CS
     foundResources = self.resources.getEligibleResources( elementType )
     if not foundResources[ 'OK' ]:
       self.log.error( foundResources[ 'Message' ] )
       continue
     
     # Translate CS result into a list
     foundResources = foundResources[ 'Value' ]
     
     # Synchronize with the DB
     resSync = self.__dbSync( 'Resource', elementType, foundResources )
     if not resSync[ 'OK' ]:
       self.log.error( 'Error synchronizing %s %s' % ( 'Resource', elementType ) )
       self.log.error( resSync[ 'Message' ] )
     else: 
       resources[ elementType ] = resSync[ 'Value' ] 
 
   return S_OK( resources )