Example #1
0
    def getFSUUID(self,name_or_ip,_user="",cached=True):
        """
        returns UUID of a fileserver, which is used as key for server-entries
        in other tables. This does not silently update the Cache
        """
        if cached :
        # local Cache first
            if name_or_ip in self.localCache["FSUUIDs"].keys() :
                return self.localCache["FSUUIDs"][name_or_ip]
            else :
                name_or_ip =self.getDNSInfo(name_or_ip)["names"][0] 
                if name_or_ip in self.localCache["FSUUIDs"].keys() :
                    return self.localCache["FSUUIDs"][name_or_ip]
        # then DB
            if  self._CFG.DB_CACHE:
                from DBManager import DBManager
                from afs.model.FileServer import FileServer
                self.Logger.debug("looking up FSUUID in DB_Cache for serv=%s" % name_or_ip)
                DNSInfo=self.getDNSInfo(name_or_ip)
                thisDBManager=DBManager(self._CFG)
                fs=thisDBManager.getFromCacheByListElement(FileServer,FileServer.servernames_js,DNSInfo["names"][0])         
                if fs != None :
                    # store it in localCache 
                    self.localCache["FSUUIDs"][name_or_ip] = fs.uuid                  
                    return fs.uuid

        # not found in local cache and not in DB Cache, get it from live-system
            
        from afs.dao.VLDbDAO import VLDbDAO
        self.Logger.debug("getFSUUID: called with %s" % name_or_ip)
        DNSInfo=self.getDNSInfo(name_or_ip)
        uuid=""
        _vlDAO=VLDbDAO()
        try :
            uuid=_vlDAO.getFsUUID(DNSInfo["names"][0],_user=_user,_cfg=self._CFG)
        except :
            return None
        # store it in localCache 
        self.localCache["FSUUIDs"][name_or_ip] = uuid                  
        return uuid
Example #2
0
    def getHostnameByFSUUID(self,uuid,_user="",cached=True) :
        """
        returns hostname of a fileserver by uuid
        """
        self.Logger.debug("called with %s, cached=%s" % (uuid,cached))
        self.Logger.debug("self._CFG=%s" % (self._CFG))
        if cached :
            # local Cache first
            for hn in self.localCache["FSUUIDs"] :
                if self.localCache["FSUUIDs"][hn] == uuid :
                    return hn
            # then DB 
            if self._CFG.DB_CACHE:
                from DBManager import DBManager
                from afs.model.FileServer import FileServer
                thisDBManager=DBManager(self._CFG)
                fs=thisDBManager.getFromCache(FileServer,uuid=uuid)
                self.Logger.debug("looking up hostname in DB_Cache for uuid=%s" % uuid)
                if fs != None :
                    self.localCache["FSUUIDs"][fs.servernames[0]] = fs.uuid                  
                    return fs.servernames[0]

        # not found in local cache and not in DB Cache, or cacheing disabled.
        # get it from live-system
        from afs.dao.VLDbDAO import VLDbDAO
        _vlDAO=VLDbDAO()
        name_or_ip=None
        for fs in _vlDAO.getFsServList(_cfg=self._CFG,_user="" ) :
            if fs['uuid'] == uuid :
               name_or_ip = fs['name_or_ip']
        if name_or_ip == None :
            raise LookupUtilError("No Server with uuid=%s registered in live-system" % uuid)
        # store it in localCache 
        self.Logger.debug("getHostnameByFSUUID: got name_or_ip =%s from live-system" % name_or_ip)
        name_or_ip=self.getDNSInfo(name_or_ip)["names"][0]
        self.localCache["FSUUIDs"][name_or_ip] = uuid                  
        self.Logger.debug("returning: %s" % name_or_ip)
        return name_or_ip
Example #3
0
 def __init__(self,conf=None):
     
     self._vlDAO  = VLDbDAO()
     self._volDAO = VolumeDAO()
            
     # LOAD Configuration from file if exist
     # FIXME Move in decorator
     if conf:
         self._CFG = conf
     else:
         self._CFG = afs.defaultConfig
     
     # DB INIT    
     if self._CFG.DB_CACHE :
         import sqlalchemy.orm
         from sqlalchemy import func, or_
         self.DbSession = sqlalchemy.orm.sessionmaker(bind=self._CFG.DB_ENGINE,expire_on_commit=False)
Example #4
0
class CellService(object):
    """
    Provides Service about a Cell global information.
    The cellname is set in the methods so that we 
    can use this for more than one cell.
    """
    def __init__(self,conf=None):
        
        self._vlDAO  = VLDbDAO()
        self._volDAO = VolumeDAO()
               
        # LOAD Configuration from file if exist
        # FIXME Move in decorator
        if conf:
            self._CFG = conf
        else:
            self._CFG = afs.defaultConfig
        
        # DB INIT    
        if self._CFG.DB_CACHE :
            import sqlalchemy.orm
            from sqlalchemy import func, or_
            self.DbSession = sqlalchemy.orm.sessionmaker(bind=self._CFG.DB_ENGINE,expire_on_commit=False)

    
    
    ###############################################
    # Server Section
    ###############################################    
    """
    Retrieve Server List
    """
    def getFsList(self):

        nameList = self._vlDAO.getFsServList(self._CFG.CELL_NAME, self._CFG.Token);
        ipList   = self._vlDAO.getFsServList(self._CFG.CELL_NAME, self._CFG.Token, noresolve=True );
        
        nameDict = {}
        for el in nameList:
            nameDict[el['uuid']] = el['serv']
        
        fsList = []
        for el in ipList:
            el['servername'] = nameDict[el['uuid']]
            el['fileserver'] = 1
            serv = Server()
            serv.setByDict(el) 
            print "Before _______________________________"
            print serv
            
            # Cache Stuffz
            serv = self._setServIntoCache(serv)
            fsList.append(serv)
            
        return  fsList
          
    """
    Retrieve Server List
    """
    def getPartList(self, serv,):

        # FIXME look up server ip use only ip 
        list =self._volDAO.getPartList(serv, self._CFG.CELL_NAME, self._CFG.Token )
      
        partList = []
        for el in list:
            part = Partition()
            part.setByDict(el)
            # Cache Stuff
            part = self._setPartIntoCache(part)
            partList.append(part)
        return partList
    
    
    
    ################################################
    #  Internal Cache Management 
    ################################################


    def _getPartFromCache(self, serv, part):
        #STORE info into  CACHE
        if not self._CFG.DB_CACHE:
            return None
        
        part = afsutil.canonicalizePartition(part)
        session = self.DbSession()
        # Do update
        part = session.query(Partition).filter(Partition.part == part).filter(Partition.serv == serv).first

        session.close()
        return part
        
    def _setPartIntoCache(self,part):
         #STORE info into  CACHE
        if not self._CFG.DB_CACHE:
            return part
        
        session = self.DbSession()
        partCache = session.query(Partition).filter(Partition.part == part.part).filter(Partition.serv == part.serv).first()
       
        
        if partCache:
            partCache.copyObj(part)         
        else:
            session.add(part) 
            partCache = part 
        
        session.flush() 
        session.commit()  
        session.close()
        
        return  partCache
    
    def _delPartFromCache(self,part):
         #STORE info into  CACHE
        if not self._CFG.DB_CACHE:
            return None
        session = self.DbSession()
        # Do update
        session.delete(part)
            
        session.commit()
        session.close()


    def _setServIntoCache(self,serv):
         #STORE info into  CACHE

        if not self._CFG.DB_CACHE:
            return serv
        
        session = self.DbSession()
        servCache = session.query(Server).filter(Server.serv == serv.serv).first()
        session.flush()
        
        if servCache:
            servCache.copyObj(serv)
        else:
            session.add(serv)
            servCache = serv
        
        session.commit()  
        session.close()

        return servCache