def is_valid(self, bundle, request=None): from chroma_core.lib.storage_plugin.manager import storage_plugin_manager from chroma_core.lib.storage_plugin.manager import PluginNotFound errors = defaultdict(list) if 'alias' in bundle.data and bundle.data['alias'] is not None: alias = bundle.data['alias'] if alias.strip() == "": errors['alias'].append("May not be blank") elif alias != alias.strip(): errors['alias'].append("No trailing whitespace allowed") if 'plugin_name' in bundle.data: try: storage_plugin_manager.get_plugin_class( bundle.data['plugin_name']) except PluginNotFound, e: errors['plugin_name'].append(e.__str__()) else: if 'class_name' in bundle.data: try: storage_plugin_manager.get_plugin_resource_class( bundle.data['plugin_name'], bundle.data['class_name']) except PluginNotFound, e: errors['class_name'].append(e.__str__())
def __init__(self, resource_manager, plugin_name): from chroma_core.lib.storage_plugin.manager import storage_plugin_manager self._resource_manager = resource_manager # Map of host ID to Session self._sessions = {} self._stopping = False self._processing_lock = threading.Lock() self._plugin_name = plugin_name self._plugin_klass = storage_plugin_manager.get_plugin_class( plugin_name) self._queue = AgentRxQueue(self._plugin_name) # Disregard any old messages self._queue.purge()
def run(self): from chroma_core.lib.storage_plugin.manager import storage_plugin_manager record = StorageResourceRecord.objects.get(id=self.root_resource_id) plugin_klass = storage_plugin_manager.get_plugin_class( record.resource_class.storage_plugin.module_name) RETRY_DELAY_MIN = 1 RETRY_DELAY_MAX = 256 retry_delay = RETRY_DELAY_MIN while not self.stopping.is_set(): last_retry = datetime.datetime.now() try: # Note: get a fresh root_resource each time as the Plugin # instance will modify it. self._scan_loop(plugin_klass, record) except Exception: run_duration = datetime.datetime.now() - last_retry if last_retry and run_duration > datetime.timedelta( seconds=RETRY_DELAY_MAX): # If the last run was long running (i.e. probably ran okay until something went # wrong) then retry quickly. retry_delay = RETRY_DELAY_MIN else: # If we've already retried recently, then start backing off. retry_delay *= 2 log.warning( "Exception in scan loop for resource %s, waiting %ss before restart" % (self.root_resource_id, retry_delay)) exc_info = sys.exc_info() backtrace = "\n".join( traceback.format_exception(*(exc_info or sys.exc_info()))) log.warning("Backtrace: %s" % backtrace) # Wait either retry_delay, or until stopping is set, whichever comes sooner self.stopping.wait(timeout=retry_delay) else: log.info("Session %s: out of scan loop cleanly" % self.root_resource_id) log.info("Session %s: Dropped out of retry loop" % self.root_resource_id) self.stopped = True