コード例 #1
0
ファイル: nibbler.py プロジェクト: hl0103/nimbusfs-client
    def __init__(self, fabnet_host, security_provider, parallel_put_count=3, \
            parallel_get_count=3, cache_dir='/tmp', cache_size=None):
        if not isinstance(security_provider, AbstractSecurityManager):
            raise Exception('Invalid security provider type!')
        self.__parallel_put_count = parallel_put_count
        self.__parallel_get_count = parallel_get_count
        self.security_provider = security_provider
        self.fabnet_gateway = FabnetGateway(fabnet_host, security_provider)

        prikey = self.security_provider.get_prikey()
        self.metadata_key = hashlib.sha1(str(prikey)).hexdigest()
        self.metadata_f_name = 'md-%s.bin' % self.metadata_key
        self.db_cache = DataBlockCache(cache_dir, cache_size,
                                       self.metadata_key)

        self.journal = None
        self.metadata = None
        self.transactions_manager = None
        self.put_manager = None
        self.get_manager = None
        self.delete_manager = None

        DataBlock.SECURITY_MANAGER = self.security_provider
        DataBlock.LOCK_MANAGER = DBLocksManager()

        self.journal = Journal(self.metadata_key, \
                self.db_cache.get_static_cache_path('journal.bin'), self.fabnet_gateway)
コード例 #2
0
ファイル: nibbler.py プロジェクト: fabregas/nimbusfs-client
    def __init__(self, fabnet_host, security_provider, parallel_put_count=3, \
            parallel_get_count=3, cache_dir='/tmp', cache_size=None):
        if not isinstance(security_provider, AbstractSecurityManager):
            raise Exception('Invalid security provider type!')
        self.__parallel_put_count = parallel_put_count
        self.__parallel_get_count = parallel_get_count
        self.security_provider = security_provider
        self.fabnet_gateway = FabnetGateway(fabnet_host, security_provider)

        prikey = self.security_provider.get_prikey()
        self.metadata_key = hashlib.sha1(str(prikey)).hexdigest()
        self.metadata_f_name = 'md-%s.bin'%self.metadata_key
        self.db_cache = DataBlockCache(cache_dir, cache_size, self.metadata_key)

        self.journal = None
        self.metadata = None
        self.transactions_manager = None
        self.put_manager = None
        self.get_manager = None
        self.delete_manager = None

        DataBlock.SECURITY_MANAGER = self.security_provider
        DataBlock.LOCK_MANAGER = DBLocksManager()

        self.journal = Journal(self.metadata_key, \
                self.db_cache.get_static_cache_path('journal.bin'), self.fabnet_gateway)
コード例 #3
0
ファイル: nibbler.py プロジェクト: hl0103/nimbusfs-client
class Nibbler:
    def __init__(self, fabnet_host, security_provider, parallel_put_count=3, \
            parallel_get_count=3, cache_dir='/tmp', cache_size=None):
        if not isinstance(security_provider, AbstractSecurityManager):
            raise Exception('Invalid security provider type!')
        self.__parallel_put_count = parallel_put_count
        self.__parallel_get_count = parallel_get_count
        self.security_provider = security_provider
        self.fabnet_gateway = FabnetGateway(fabnet_host, security_provider)

        prikey = self.security_provider.get_prikey()
        self.metadata_key = hashlib.sha1(str(prikey)).hexdigest()
        self.metadata_f_name = 'md-%s.bin' % self.metadata_key
        self.db_cache = DataBlockCache(cache_dir, cache_size,
                                       self.metadata_key)

        self.journal = None
        self.metadata = None
        self.transactions_manager = None
        self.put_manager = None
        self.get_manager = None
        self.delete_manager = None

        DataBlock.SECURITY_MANAGER = self.security_provider
        DataBlock.LOCK_MANAGER = DBLocksManager()

        self.journal = Journal(self.metadata_key, \
                self.db_cache.get_static_cache_path('journal.bin'), self.fabnet_gateway)

    def get_security_provider(self):
        return self.security_provider

    def start(self):
        self.fabnet_gateway.init_socket_processor()
        if not self.journal.foreign_exists():
            raise NoJournalFoundException('No journal for key = %s' %
                                          self.metadata_key)

        self.metadata = MetadataFile(
            self.db_cache.get_static_cache_path(self.metadata_f_name),
            self.journal)
        self.transactions_manager = TransactionsManager(
            self.metadata, self.db_cache, user_id=self.metadata_key)

        SmartFileObject.setup_transaction_manager(self.transactions_manager)

        self.put_manager = WorkersManager(PutWorker, self.fabnet_gateway, \
                self.transactions_manager, self.__parallel_put_count)
        self.get_manager = WorkersManager(GetWorker, self.fabnet_gateway, \
                self.transactions_manager, self.__parallel_get_count)
        self.delete_manager = WorkersManager(DeleteWorker, self.fabnet_gateway, \
                self.transactions_manager, 2)

        self.put_manager.start()
        self.get_manager.start()
        self.delete_manager.start()

    def is_registered(self):
        self.fabnet_gateway.init_socket_processor()
        return self.journal.foreign_exists()

    def register_user(self):
        self.fabnet_gateway.init_socket_processor()
        self.journal.init()
        if self.metadata:
            self.metadata.close()
            self.metadata = MetadataFile(
                self.db_cache.get_static_cache_path(self.metadata_f_name),
                self.journal)

    def on_error(self, error_msg):
        pass

    def stop(self):
        self.fabnet_gateway.force_close_all_connections()
        if self.put_manager:
            self.put_manager.stop()
        if self.get_manager:
            self.get_manager.stop()
        if self.delete_manager:
            self.delete_manager.stop()
        if self.metadata:
            self.metadata.close()
        if self.journal:
            self.journal.close()
        if self.transactions_manager:
            self.transactions_manager.close()
        self.db_cache.stop()

    def __make_item_fs(self, item_md):
        return FSItem(item_md.name, item_md.is_dir(), item_md.create_date,
                      item_md.last_modify_date, item_md.size)

    def find(self, path):
        path = to_nimbus_path(path)
        path_obj = self.transactions_manager.find_inprogress_file(path)
        if not path_obj:
            try:
                path_obj = self.metadata.find(path)
            except PathException, err:
                #logger.debug('[get_resource] %s'%str(err))
                return

        if path_obj:
            return self.__make_item_fs(path_obj)
コード例 #4
0
ファイル: nibbler.py プロジェクト: fabregas/nimbusfs-client
class Nibbler:
    def __init__(self, fabnet_host, security_provider, parallel_put_count=3, \
            parallel_get_count=3, cache_dir='/tmp', cache_size=None):
        if not isinstance(security_provider, AbstractSecurityManager):
            raise Exception('Invalid security provider type!')
        self.__parallel_put_count = parallel_put_count
        self.__parallel_get_count = parallel_get_count
        self.security_provider = security_provider
        self.fabnet_gateway = FabnetGateway(fabnet_host, security_provider)

        prikey = self.security_provider.get_prikey()
        self.metadata_key = hashlib.sha1(str(prikey)).hexdigest()
        self.metadata_f_name = 'md-%s.bin'%self.metadata_key
        self.db_cache = DataBlockCache(cache_dir, cache_size, self.metadata_key)

        self.journal = None
        self.metadata = None
        self.transactions_manager = None
        self.put_manager = None
        self.get_manager = None
        self.delete_manager = None

        DataBlock.SECURITY_MANAGER = self.security_provider
        DataBlock.LOCK_MANAGER = DBLocksManager()

        self.journal = Journal(self.metadata_key, \
                self.db_cache.get_static_cache_path('journal.bin'), self.fabnet_gateway)

    def get_security_provider(self):
        return self.security_provider
        
    def start(self):
        self.fabnet_gateway.init_socket_processor()
        if not self.journal.foreign_exists():
            raise NoJournalFoundException('No journal for key = %s'%self.metadata_key)

        self.metadata = MetadataFile(self.db_cache.get_static_cache_path(self.metadata_f_name), self.journal)
        self.transactions_manager = TransactionsManager(self.metadata, self.db_cache, user_id=self.metadata_key)

        SmartFileObject.setup_transaction_manager(self.transactions_manager)

        self.put_manager = WorkersManager(PutWorker, self.fabnet_gateway, \
                self.transactions_manager, self.__parallel_put_count)  
        self.get_manager = WorkersManager(GetWorker, self.fabnet_gateway, \
                self.transactions_manager, self.__parallel_get_count)  
        self.delete_manager = WorkersManager(DeleteWorker, self.fabnet_gateway, \
                self.transactions_manager, 2)  

        self.put_manager.start()
        self.get_manager.start()
        self.delete_manager.start()

    def is_registered(self):
        self.fabnet_gateway.init_socket_processor()
        return self.journal.foreign_exists()

    def register_user(self):
        self.fabnet_gateway.init_socket_processor()
        self.journal.init()
        if self.metadata:
            self.metadata.close()
            self.metadata = MetadataFile(self.db_cache.get_static_cache_path(self.metadata_f_name), self.journal)

    def on_error(self, error_msg):
        pass

    def stop(self):
        self.fabnet_gateway.force_close_all_connections()
        if self.put_manager:
            self.put_manager.stop()
        if self.get_manager:
            self.get_manager.stop()
        if self.delete_manager:
            self.delete_manager.stop()
        if self.metadata:
            self.metadata.close()
        if self.journal:
            self.journal.close()
        if self.transactions_manager:
            self.transactions_manager.close()
        self.db_cache.stop()

    def __make_item_fs(self, item_md):
        return FSItem(item_md.name, item_md.is_dir(), item_md.create_date, item_md.last_modify_date, item_md.size)

    def find(self, path):
        path = to_nimbus_path(path)
        path_obj = self.transactions_manager.find_inprogress_file(path)
        if not path_obj:
            try:
                path_obj = self.metadata.find(path)
            except PathException, err:
                #logger.debug('[get_resource] %s'%str(err))
                return

        if path_obj:
            return self.__make_item_fs(path_obj)