def _init_selector(self): selector = None mode = self._cache_config.get_torrent_selection_mechanism() if mode == 'local_folder': selector = LocalFolderSelector.LocalFolderSelector(self._cache_config.get_torrent_directory()) self._logger.info("Run in local folder mode") elif mode == 'SIS': #selector = self._cache_config.get_ws_client() selector = IoP_WSClientImpl(self._cache_config.get_sis_iop_url()) selector.set_torrent_dir(self._cache_config.get_torrent_directory()) #FIXME: we now create these instances twice!!! once in cache config and then here! Should rather use a wrapper here! self._logger.info("Run in WS torrent selection mode") else: raise ConfigurationException("Unsupported torrent selection mechanism!"+str()) assert selector is not None self._logger.info("Use torrent selection method "+str(selector)) interval = self._cache_config.get_torrent_selection_interval() max_torrents = self._cache_config.get_max_torrents() assert max_torrents >= self.max_downloads stay_in_torrents = self._cache_config.get_stay_in_torrents() self.torrent_selection = TorrentSelection.start_torrent_selection( self, selector, selection_interval=interval, max_torrents=max_torrents, stay_in_torrents=stay_in_torrents)
def _update_from_sis(self): def set_attribute(attribute, func_name): if attribute is not None: func_name(attribute) ws_client = IoP_WSClientImpl(self.get_sis_iop_url()) config_dict = {} try: config_dict = ws_client.retrieve_configuration_parameters( net_utils.get_own_ip_addr()) self._logger.warning("Config dict returned was: %s" % config_dict) if len(config_dict.keys()) == 0: self._logger.warning( "Received an empty dict. Cache configuration was not updated." ) return max_torrents = int( min( float(config_dict.get('u')) / float(config_dict.get('ulow')), float(config_dict.get('d')) / float(config_dict.get('dlow')))) sis_modes = { 'Collaboration': constants.SELECTION_MODE_IOP, 'Plain': constants.SELECTION_MODE_LOCAL, 'Combination': constants.SELECTION_MODE_LOCAL } set_attribute(config_dict.get('t'), self.set_torrent_selection_interval) set_attribute(config_dict.get('u'), self.set_upload_limit) set_attribute(config_dict.get('d'), self.set_download_limit) set_attribute(config_dict.get('slots'), self.set_max_upload_slots_per_download) set_attribute(config_dict.get('remotes'), self.set_establish_remote_connections) set_attribute(config_dict.get('x'), self.set_stay_in_torrents) set_attribute(config_dict.get('localIPs'), self.set_ip_prefixes) set_attribute(sis_modes[config_dict.get('mode')], self.set_torrent_selection_mechanism) set_attribute(max_torrents, self.set_max_torrents) set_attribute(max_torrents, self.set_max_downloads) except: self._logger.error( "Failed to retrieve cache configuration from SIS at %s" % self.get_sis_iop_url()) self._logger.error("Cache configuration was not updated.", exc_info=True) self._logger.error("Received config dict was: %s" % config_dict) raise ConfigurationException( "Failed to retrieve cache configuration from SIS at %s" % self.get_sis_iop_url()) return
def setUp(self): self.wsclient = IoP_WSClientImpl(sis_iop_endpoint_url="http://localhost:8080/sis/IoPEndpoint") self._logger = logging.getLogger(self.__class__.__name__)
def __init__(self, own_addr, emit_interval, sis_iop_endpoint_url="http://localhost:8080/sis/IoPEndpoint"): self._emit_interval = emit_interval # in seconds self._ws = IoP_WSClientImpl(sis_iop_endpoint_url) self._last_timestamp = time.time() self._own_address = own_addr self._logger = logging.getLogger("Status.%s" % self.__class__.__name__)